Diff of /trunk/mqttsparkplug/mqttsparkplug-example/Device_1/Plc Logic/Application1/Edge1/AdditionalStepsToRegisterAClientCertificateWithtest_mosquitto_org/svnobj [r885] .. [r886]  Maximize  Restore

Switch to unified view

a/trunk/mqttsparkplug/mqttsparkplug-example/Device_1/Plc Logic/Application1/Edge1/AdditionalStepsToRegisterAClientCertificateWithtest_mosquitto_org/svnobj b/trunk/mqttsparkplug/mqttsparkplug-example/Device_1/Plc Logic/Application1/Edge1/AdditionalStepsToRegisterAClientCertificateWithtest_mosquitto_org/svnobj
1
Gx_lö'!0…jüo Œ M‡¹âÐ
1
Gx_lÈ'!0jüo‡¥šR‘ØnQFSystem.StringL{f8a58466-d7f6-439f-bbb8-d4600e41d099}ImplementationL{3b83b776-fb25-43b8-99f2-3c507c9143fc}TextDocumentL{f3878285-8e4f-490b-bb1b-9acbb7eb04db}TextLinesL{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}    Id
2
hSystem.StringL{f8a58466-d7f6-439f-bbb8-d4600e41d099}ImplementationL{3b83b776-fb25-43b8-99f2-3c507c9143fc}TextDocumentL{f3878285-8e4f-490b-bb1b-9acbb7eb04db}TextLinesL{a5de0b0b-1cb5-4913-ac21-9d70293ec00d}   Id
3
longTagText
²// This function_block, getClientCert, interacts with CODESYS Runtime's Certificate Store¨// To view the source and documentation, Right click > Browse > Go to definition ...œ// ... then right click SparkplugB."GetClientCert" > Browse > Go to definitionZgetClientCert(xUseCertStore          := TRUE,P              xCreateSelfSigned      :=,P              xCreateCSR             :=,P              xInstallCertFromString :=,P              sCommonName            :=,P              sCountry               :=,P              sOrganization          :=,P              uliValidity            :=,P              sClientCert            :=,P              xProvideCertificate    =>,\              hCert                  => hCert,R              sCSRorClientCertOut    =>);¤// wait a few cycles, incase the getClientCert already finds the right client cert6IF countClientCert > 6 THENb    IF NOT getClientCert.xProvideCertificate THEN ~        //There is no Certificate registered, so generate a CSR!R        getClientCert.xCreateCSR := TRUE;"    END_IF#ELSE$V    countClientCert := countClientCert + 1;%END_IF&D// If xProvideCertificate is set, 'RIF getClientCert.xProvideCertificate THEN(œ    WaitForTheServerToRegisterCert(IN := TRUE, PT := T#1S, Q =>); //1sec timer)X    IF WaitForTheServerToRegisterCert.Q THEN*^        StillGettingClientCertificate := FALSE;+ò(* Below this line is specific to registering a CSR with test.mosquitto.org.  Other servers will have other procedures *),n//We are going to use a HTTP Post to get our CSR signed-BhttpPost := "submit=Submit&csr=";.ú//dirty hack: UTF8toUTF16 also works on strings, if every character is less than 0x80.. STRING_TO_WSTRING only does 255 chars/ //            I know that for BASE64 encoded CSRs, every character is below 0x80Stu.ConvertUTF8toUTF16(sourceStart        := ADR(getClientCert.sCSRorClientCertOut),1Ž                       targetStart        := ADR(wsCSRorClientCertOut),2”                       dwTargetBufferSize := SIZEOF(wsCSRorClientCertOut),3h                       bStrictConversion  := FALSE);48//convert the " " to %20 etcwsCSRorClientCertOut := Web_CLient.URL_ENCODE_WSTRING(pwIn := ADR(wsCSRorClientCertOut));6¸//add the CSR to the end of the httpPost.  note Standard64.WCONCAT() only works on 255 chars7ìSTU.StrConcatW(pstFrom := ADR(wsCSRorClientCertOut), pstTo := ADR(httpPost), iBufferSize := TO_INT(SIZEOF(httpPost)));IF LEN(getClientCert.sCSRorClientCertOut) > 0 AND (getClientCert.xCreateCSR = TRUE) THEN9h    //once a CSR is generated, execute the http Post:B    RegisterCSR.xExecute := TRUE;;œ// This Web_Client.WebClient sends the CSR to test.mosquitto.org to be signed <FRegisterCSR(xExecute            :=,=F            udiTimeOut          :=,>ô            sURL                := 'https://test.mosquitto.org/ssl/index.php', //form for submitting CSRs to mosquitto.org?f            eRequestType        := Web_Client.POST,@˜            eContentType        := Web_Client.CONTENT_TYPE.APPLICATION_FORM,AF            pwsAdditionalHeader :=,Bb            pwsPostValue        := ADR(httpPost),CF            xCloseConnection    :=,DF            hCert               :=,EF            xDone               =>,FF            xBusy               =>,GF            xError              =>,HF            eError              =>,IH            httpResult          =>);J¦// Once signed, we just register the signed version of the certificate in the storeK¼// If the result of the httpPost does not begine with '-----BEGIN' then there was an error ...LX// ... and a CSR was not successfully signedIF RegisterCSR.xDone AND (FIND(RegisterCSR.httpResult.sContent, '-----BEGIN') = 1) THENN    //SUCCESS    getClientCert.sClientCert            := RegisterCSR.httpResult.sContent;Pb    getClientCert.xInstallCertFromString := TRUE;QInterfaceRL{a9ed5b7e-75c5-4651-af16-d2c27e98cb94}SMETHOD AdditionalStepsToRegisterAClientCertificateWithtest_mosquitto_orgÐÐÐEPÐÐ 
2
longTagText
²// This function_block, getClientCert, interacts with CODESYS Runtime's Certificate Store¨// To view the source and documentation, Right click > Browse > Go to definition ...œ// ... then right click SparkplugB."GetClientCert" > Browse > Go to definitionJgetClientCert( xUseCertStore := TRUE,H               xCreateSelfSigned :=,:               xCreateCSR :=,R               xInstallCertFromString :=,<               sCommonName :=,6               sCountry :=,@               sOrganization :=,<               uliValidity :=,<               sClientCert :=,L               xProvideCertificate =>,<               hCert => hCert,P               sCSRorClientCertOut => );¤// wait a few cycles, incase the getClientCert already finds the right client cert6IF countClientCert > 6 THENb    IF NOT getClientCert.xProvideCertificate THEN ~        //There is no Certificate registered, so generate a CSR!R        getClientCert.xCreateCSR := TRUE;"    END_IF#ELSE$V    countClientCert := countClientCert + 1;%END_IF&D// If xProvideCertificate is set, 'RIF getClientCert.xProvideCertificate THEN(^    WaitForTheServerToRegisterCert( IN := TRUE,)^                                    PT := T#1S,*p                                    Q => ); //1sec timer+X    IF WaitForTheServerToRegisterCert.Q THEN,^        StillGettingClientCertificate := FALSE;-ò(* Below this line is specific to registering a CSR with test.mosquitto.org.  Other servers will have other procedures *).n//We are going to use a HTTP Post to get our CSR signed/BhttpPost := "submit=Submit&csr=";0ú//dirty hack: UTF8toUTF16 also works on strings, if every character is less than 0x80.. STRING_TO_WSTRING only does 255 chars1 //            I know that for BASE64 encoded CSRs, every character is below 0x80Stu.ConvertUTF8toUTF16( sourceStart := ADR( getClientCert.sCSRorClientCertOut ),3†                        targetStart := ADR( wsCSRorClientCertOut ),4š                        dwTargetBufferSize := SIZEOF( wsCSRorClientCertOut ),5j                        bStrictConversion := FALSE );68//convert the " " to %20 etcwsCSRorClientCertOut := Web_CLient.URL_ENCODE_WSTRING( pwIn := ADR( wsCSRorClientCertOut ) );8¸//add the CSR to the end of the httpPost.  note Standard64.WCONCAT() only works on 255 chars9nSTU.StrConcatW( pstFrom := ADR( wsCSRorClientCertOut ),:R                pstTo := ADR( httpPost ),;|                iBufferSize := TO_INT( SIZEOF( httpPost ) ) );IF LEN( getClientCert.sCSRorClientCertOut ) > 0 AND (getClientCert.xCreateCSR = TRUE) THEN=h    //once a CSR is generated, execute the http Post>B    RegisterCSR.xExecute := TRUE;?œ// This Web_Client.WebClient sends the CSR to test.mosquitto.org to be signed @2RegisterCSR( xExecute :=,A6             udiTimeOut :=,BØ             sURL := 'https://test.mosquitto.org/ssl/index.php', //form for submitting CSRs to mosquitto.orgCZ             eRequestType := Web_Client.POST,DŒ             eContentType := Web_Client.CONTENT_TYPE.APPLICATION_FORM,EH             pwsAdditionalHeader :=,FZ             pwsPostValue := ADR( httpPost ),GB             xCloseConnection :=,H,             hCert :=,I,             xDone =>,J,             xBusy =>,K.             xError =>,L.             eError =>,M:             httpResult => );N¦// Once signed, we just register the signed version of the certificate in the storeO¼// If the result of the httpPost does not begine with '-----BEGIN' then there was an error ...PX// ... and a CSR was not successfully signedIF RegisterCSR.xDone AND (FIND( RegisterCSR.httpResult.sContent,Rp                                '-----BEGIN' ) = 1) THENS    //SUCCESS    getClientCert.sClientCert := RegisterCSR.httpResult.sContent;Ub    getClientCert.xInstallCertFromString := TRUE;VInterfaceWL{a9ed5b7e-75c5-4651-af16-d2c27e98cb94}XMETHOD AdditionalStepsToRegisterAClientCertificateWithtest_mosquitto_orgÐÐÐETÐÐ   
4
­±ÚÐ-
ÐÐ  
3
­ÚÐ-
ÐÐ  
5
­²ÚÐ-ÐÐ  
4
­ÚÐ-ÐÐ  
6
­³ÚÐ-ÐÐ  
5
­ÚÐ-ÐÐ  
7
­´ÚÐ-ÐÐ  
6
­ÚÐ-ÐÐ  
8
­µÚÐ-ÐÐ  
7
­ÚÐ-ÐÐ  
9
­¶ÚÐ-ÐÐ  
8
­ÚÐ-ÐÐ  
10
­·ÚÐ-ÐÐ  
9
­ÚÐ-ÐÐ  
11
­¸ÚÐ-ÐÐ  
10
­ÚÐ-ÐÐ  
12
­¹ÚÐ-ÐÐ  
11
­ÚÐ-ÐÐ  
13
­ºÚÐ-ÐÐ  
12
­   ÚÐ-ÐÐ    
14
­»ÚÐ-ÐÐ  
13
­
15
­¼ÚÐ-ÐÐ  
14
ÚÐ-ÐÐ    
15
­ÚÐ-ÐÐ  
16
­½ÚÐ-ÐÐ  
16
­ÚÐ-ÐÐ  
17
­¾ÚÐ-ÐÐ  
17
­
ÚÐ-ÐÐ    
18
­¿ÚÐ-ÐÐ  
18
­ÚÐ-ÐÐ  
19
­ÀÚÐ-ÐÐ  
19
­ÚÐ-ÐÐ  
20
­ÁÚÐ-ÐÐ  
20
­ÚÐ-ÐÐ  
21
­ÂÚÐ-ÐÐ  
21
­ÚÐ-ÐÐ  
22
­ÃÚÐ-ÐÐ  
22
­ÚÐ-ÐÐ  
23
­ÄÚÐ- ÐÐ  
23
­ÚÐ- ÐÐ  
24
­ÅÚÐ-!ÐÐ  
24
­ÚÐ-!ÐÐ  
25
­ÆÚÐ-"ÐÐ  
25
­ÚÐ-"ÐÐ  
26
­ÇÚÐ-#ÐÐ  
26
­ÚÐ-#ÐÐ  
27
­ÈÚÐ-$ÐÐ  
27
­ÚÐ-$ÐÐ  
28
­ÉÚÐ-%ÐÐ  
28
­ÚÐ-%ÐÐ  
29
­ÊÚÐ-ÐÐ  
29
­ÚÐ-ÐÐ  
30
­ËÚÐ-&ÐÐ  
30
­ÚÐ-&ÐÐ  
31
­ÌÚÐ-'ÐÐ  
31
­ÚÐ-'ÐÐ  
32
­ÍÚÐ-(ÐÐ  
32
­ÚÐ-(ÐÐ  
33
­ÎÚÐ-ÐÐ  
33
­ÚÐ-)ÐÐ  
34
­ÏÚÐ-)ÐÐ  
34
­ÚÐ-*ÐÐ  
35
­ÐÚÐ-*ÐÐ  
35
­ÚÐ-ÐÐ  
36
­ ÚÐ-+ÐÐ  
37
­!ÚÐ-,ÐÐ  
36
­ÑÚÐ-"ÐÐ  
38
­"ÚÐ-"ÐÐ  
37
­ÒÚÐ-%ÐÐ  
39
­#ÚÐ-%ÐÐ  
38
­ÓÚÐ-ÐÐ  
40
­$ÚÐ-ÐÐ  
39
­ÔÚÐ-+ÐÐ  
41
­%ÚÐ--ÐÐ  
40
­ÕÚÐ-ÐÐ  
42
­&ÚÐ-.ÐÐ  
41
­ÖÚÐ-,ÐÐ  
43
­'ÚÐ-/ÐÐ  
42
­×ÚÐ--ÐÐ  
44
­(ÚÐ-0ÐÐ  
43
­ØÚÐ-.ÐÐ  
45
­)ÚÐ-1ÐÐ  
44
­ÙÚÐ-/ÐÐ  
46
­*ÚÐ-2ÐÐ  
45
­ÚÚÐ-0ÐÐ  
47
­+ÚÐ-3ÐÐ  
48
­,ÚÐ-4ÐÐ  
46
­ÛÚÐ-1ÐÐ  
49
­-ÚÐ-5ÐÐ  
47
­ÜÚÐ-2ÐÐ  
50
­.ÚÐ-ÐÐ  
48
­ÝÚÐ-3ÐÐ  
51
­/ÚÐ-6ÐÐ  
49
­ÞÚÐ-ÐÐ  
52
­0ÚÐ-7ÐÐ  
50
­ßÚÐ-4ÐÐ  
53
­1ÚÐ-8ÐÐ  
51
­àÚÐ-5ÐÐ  
54
­2ÚÐ-9ÐÐ  
52
­áÚÐ-6ÐÐ  
55
­3ÚÐ-:ÐÐ  
53
­âÚÐ-7ÐÐ  
56
­4ÚÐ-;ÐÐ  
54
­ãÚÐ-ÐÐ  
57
­5ÚÐ-ÐÐ  
55
­äÚÐ-8ÐÐ  
58
­6ÚÐ-<ÐÐ  
56
­åÚÐ-9ÐÐ  
59
­7ÚÐ-=ÐÐ  
57
­æÚÐ-:ÐÐ  
60
­8ÚÐ->ÐÐ  
58
­çÚÐ-%ÐÐ  
61
­9ÚÐ-%ÐÐ  
59
­èÚÐ-ÐÐ  
62
­:ÚÐ-ÐÐ  
60
­éÚÐ-;ÐÐ  
63
­;ÚÐ-?ÐÐ  
61
­êÚÐ-<ÐÐ  
64
­<ÚÐ-@ÐÐ  
62
­ëÚÐ-=ÐÐ  
65
­=ÚÐ-AÐÐ  
63
­ìÚÐ->ÐÐ  
66
­>ÚÐ-BÐÐ  
64
­íÚÐ-?ÐÐ  
67
­?ÚÐ-CÐÐ  
65
­îÚÐ-@ÐÐ  
68
­@ÚÐ-DÐÐ  
66
­ïÚÐ-AÐÐ  
69
­AÚÐ-EÐÐ  
67
­ðÚÐ-BÐÐ  
70
­BÚÐ-FÐÐ  
68
­ñÚÐ-CÐÐ  
71
­CÚÐ-GÐÐ  
69
­òÚÐ-DÐÐ  
72
­DÚÐ-HÐÐ  
70
­óÚÐ-EÐÐ  
73
­EÚÐ-IÐÐ  
71
­ôÚÐ-FÐÐ  
74
­FÚÐ-JÐÐ  
72
­õÚÐ-GÐÐ  
75
­GÚÐ-KÐÐ  
73
­öÚÐ-HÐÐ  
76
­HÚÐ-LÐÐ  
74
­÷ÚÐ-IÐÐ  
77
­IÚÐ-MÐÐ  
75
­øÚÐ-ÐÐ  
78
­JÚÐ-ÐÐ  
76
­ùÚÐ-JÐÐ  
79
­KÚÐ-NÐÐ  
80
­LÚÐ-OÐÐ  
77
­úÚÐ-KÐÐ  
81
­MÚÐ-PÐÐ  
78
­ûÚÐ-LÐÐ  
82
­NÚÐ-QÐÐ  
79
­üÚÐ-MÐÐ  
83
­OÚÐ-RÐÐ  
80
­ýÚÐ-NÐÐ  
84
­PÚÐ-SÐÐ  
81
­þÚÐ-OÐÐ  
85
­QÚÐ-TÐÐ  
82
­ÿÚÐ-PÐÐ  
86
­RÚÐ-UÐÐ  
83
­¸ÚÐ-%ÐQRÐEÐÐ    
87
­¸ÚÐ-%ÐVWÐEÐÐ    
84
­ÚÐ-S
88
­ÚÐ-X