[341ca1]: / project / scenario_5b021564 / additionalstepstoregisteraclientcertificatewithtest_mosquitto_org_1db6b845 / 1db6b845db554120831380d568372e10.object  Maximize  Restore  History

Download this file

1 lines (1 with data), 5.4 kB

1
{"payload":{"meta":{"Graph":{"@Type":"81297157","@Value":{"Guid":"(Guid)1db6b845-db55-4120-8313-80d568372e10","ParentGuid":"(Guid)5b021564-ecc4-4ac9-8ad1-ee45df139b22","Name":"(string)AdditionalStepsToRegisterAClientCertificateWithtest_mosquitto_org","Properties":{"@Type":"2c41fa04:IDictionary","@Value":{}},"TypeGuid":"(Guid)f8a58466-d7f6-439f-bbb8-d4600e41d099","EmbeddedTypeGuids":{"@Type":"[Guid]","@Value":["(Guid)a9ed5b7e-75c5-4651-af16-d2c27e98cb94","(Guid)3b83b776-fb25-43b8-99f2-3c507c9143fc"]}}},"TypeInfos":{"2c41fa04":"{2c41fa04-1834-41c1-816e-303c7aa2c05b}","81297157":"{81297157-7ec9-45ce-845e-84cab2b88ade}","Guid":"System.Guid","string":"System.String"}},"object":{"Graph":{"@Type":"f8a58466","@Value":{"Implementation":{"@Type":"3b83b776","@Value":{"TextDocument":{"@Type":"f3878285","@Value":{"TextBlobForSerialisation":"(string)// This function_block, getClientCert, interacts with CODESYS Runtime's Certificate Store\n// To view the source and documentation, Right click > Browse > Go to definition ..\n// .. then right click SparkplugB.\"GetClientCert\" > Browse > Go to definition\ngetClientCert( xUseCertStore := TRUE,\n               xCreateSelfSigned :=,\n               xCreateCSR :=,\n               xInstallCertFromString :=,\n               sCommonName :=,\n               sCountry :=,\n               sOrganization :=,\n               uliValidity :=,\n               sClientCert :=,\n               xProvideCertificate =>,\n               hCert => hCert,\n               sCSRorClientCertOut => );\n\n// wait a few cycles, incase the getClientCert already finds the right client cert\nIF countClientCert > 6 THEN\n    IF NOT getClientCert.xProvideCertificate THEN\n        //There is no Certificate registered, so generate a CSR\n        getClientCert.xCreateCSR := TRUE;\n    END_IF\nELSE\n    countClientCert := countClientCert + 1;\nEND_IF\n\n// If xProvideCertificate is set, \nIF getClientCert.xProvideCertificate THEN\n    WaitForTheServerToRegisterCert( IN := TRUE,\n                                    PT := T#1S,\n                                    Q => ); //1sec timer\n\n    IF WaitForTheServerToRegisterCert.Q THEN\n        StillGettingClientCertificate := FALSE;\n    END_IF\nEND_IF\n\n(* 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\nhttpPost := \"submit=Submit&csr=\";\n//dirty hack: UTF8toUTF16 also works on strings, if every character is less than 0x80.. STRING_TO_WSTRING only does 255 chars\n//            I know that for BASE64 encoded CSRs, every character is below 0x80\nStu.ConvertUTF8toUTF16( sourceStart := ADR( getClientCert.sCSRorClientCertOut ),\n                        targetStart := ADR( wsCSRorClientCertOut ),\n                        dwTargetBufferSize := SIZEOF( wsCSRorClientCertOut ),\n                        bStrictConversion := FALSE );\n\n//convert the \" \" to %20 etc\nWeb_CLient.URL_ENCODE_WSTRING2( pwIn := ADR( wsCSRorClientCertOut ), \n\t\t\t\t\t\t\t\tpwOut := ADR(wsCSRorClientCertOut), udiSizeOut := SIZEOF(wsCSRorClientCertOut) );\n//add the CSR to the end of the httpPost.  note Standard64.WCONCAT() only works on 255 chars\nSTU.StrConcatW( pstFrom := ADR( wsCSRorClientCertOut ),\n                pstTo := ADR( httpPost ),\n                iBufferSize := TO_INT( SIZEOF( httpPost ) ) );\n\nIF LEN( getClientCert.sCSRorClientCertOut ) > 0 AND (getClientCert.xCreateCSR = TRUE) THEN\n    //once a CSR is generated, execute the http Post\n    RegisterCSR.xExecute := TRUE;\nEND_IF\n\n// This Web_Client.WebClient sends the CSR to test.mosquitto.org to be signed \nRegisterCSR( xExecute :=,\n             udiTimeOut :=,\n             sURL := 'https://test.mosquitto.org/ssl/index.php', //form for submitting CSRs to mosquitto.org\n             eRequestType := Web_Client.POST,\n             eContentType := Web_Client.CONTENT_TYPE.APPLICATION_FORM,\n             pwsAdditionalHeader :=,\n             pwsPostValue := ADR( httpPost ),\n             xCloseConnection :=,\n             hCert :=,\n             xDone =>,\n             xBusy =>,\n             xError =>,\n             eError =>,\n             httpResult => );\n\n// Once signed, we just register the signed version of the certificate in the store\n// If the result of the httpPost does not begine with '-----BEGIN' then there was an error ..\n// .. and a CSR was not successfully signed\nIF RegisterCSR.xDone AND (FIND( RegisterCSR.httpResult.sContent,\n                                '-----BEGIN' ) = 1) THEN\n    //SUCCESS\n    getClientCert.sClientCert := RegisterCSR.httpResult.sContent;\n    getClientCert.xInstallCertFromString := TRUE;\nEND_IF","LineInfoPersistence":"(string)1db6b845-db55-4120-8313-80d568372e10_Impl_LineIds"}}}},"Interface":{"@Type":"a9ed5b7e","@Value":{"TextDocument":{"@Type":"f3878285","@Value":{"TextBlobForSerialisation":"(string)METHOD AdditionalStepsToRegisterAClientCertificateWithtest_mosquitto_org","LineInfoPersistence":"(string)1db6b845-db55-4120-8313-80d568372e10_Decl_LineIds"}}}}}},"TypeInfos":{"3b83b776":"{3b83b776-fb25-43b8-99f2-3c507c9143fc}","a9ed5b7e":"{a9ed5b7e-75c5-4651-af16-d2c27e98cb94}","f3878285":"{f3878285-8e4f-490b-bb1b-9acbb7eb04db}","f8a58466":"{f8a58466-d7f6-439f-bbb8-d4600e41d099}","string":"System.String"}}},"FormatVersion":"1.0"}