[r886]: / trunk / mqttsparkplug / mqttsparkplug-example / Device_1 / Plc Logic / Application2_1 / Edge2 / AdditionalStepsToRegisterAClientCertificateWithtest_mosquitto_org / svnobj  Maximize  Restore  History

Download this file

44 lines (43 with data), 10.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// To view the source and documentation, Right click > Browse > Go to definition ...
// wait a few cycles, incase the getClientCert already finds the right client cert
IF countClientCert > 6 THEN
    IF NOT getClientCert.xProvideCertificate THEN
        //There is no Certificate registered, so generate a CSR
        getClientCert.xCreateCSR := TRUE;
    END_IF
ELSE
    countClientCert := countClientCert + 1;
END_IF
// If xProvideCertificate is set, 
IF getClientCert.xProvideCertificate THEN
    WaitForTheServerToRegisterCert( IN := TRUE,
                                    PT := T#1S,
                                    Q => ); //1sec timer
    IF WaitForTheServerToRegisterCert.Q THEN
        StillGettingClientCertificate := FALSE;
//dirty hack: UTF8toUTF16 also works on strings, if every character is less than 0x80.. STRING_TO_WSTRING only does 255 chars
Stu.ConvertUTF8toUTF16( sourceStart := ADR( getClientCert.sCSRorClientCertOut ),
                        dwTargetBufferSize := SIZEOF( wsCSRorClientCertOut ),
                        bStrictConversion := FALSE );
//convert the " " to %20 etc
//add the CSR to the end of the httpPost.  note Standard64.WCONCAT() only works on 255 chars
STU.StrConcatW( pstFrom := ADR( wsCSRorClientCertOut ),
                pstTo := ADR( httpPost ),
                iBufferSize := TO_INT( SIZEOF( httpPost ) ) );
// This Web_Client.WebClient sends the CSR to test.mosquitto.org to be signed 
RegisterCSR( xExecute :=,
             udiTimeOut :=,
             eContentType := Web_Client.CONTENT_TYPE.APPLICATION_FORM,
             pwsAdditionalHeader :=,
             pwsPostValue := ADR( httpPost ),
             xCloseConnection :=,
             hCert :=,
             xDone =>,
             xBusy =>,
             xError =>,
             eError =>,
             httpResult => );
// If the result of the httpPost does not begine with '-----BEGIN' then there was an error ...
// ... and a CSR was not successfully signed
    getClientCert.sClientCert := RegisterCSR.httpResult.sContent;
    getClientCert.xInstallCertFromString := TRUE;