Server certificate
This section covers a situation where the client wants to verify the server certificate but the server does not want to verify the client certificate. In this case the communication flow described in chapter Transport layer is shortened as follows.
Verification of the server certificate
The server certificate is verified on the client side. A check is performed to ascertain whether it is signed by a particular certificate authority. If this is not the case, the client aborts the connection, since it does not trust the server.
Application in TwinCAT
In TwinCAT, the file path to the CA certificate (.PEM or .DER file) or the content of the .PEM file is specified as a string. The certificate presented by the server is then checked in the IoT driver. If the certificate chain is not signed by the specified CA, the connection to the server is aborted. The following code illustrates the described connection parameters as an example. The sample code refers to the HTTP client, the MQTT client and the WebSocket client. The HTTP client is used as an example.
PROGRAM MAIN
VAR
fbClient : FB_IotHttpClient;
END_VAR
fbClient.stTLS.sCA:= 'C:\TwinCAT\3.1\Config\Certificates\someCA.pem';
If the user does not have the CA certificate, a connection can still be established. A boolean variable is available for this purpose, which prevents TwinCAT from verifying the server certificate. Although the connection is encrypted with the public key of the unverified server certificate, it is more vulnerable to man-in-the-middle attacks.
fbClient.stTLS.sCA.bNoServerCertCheck:= TRUE;