Skip to main content

Certificate Generation and Configuration

Prerequisite Reading

Generate Client PFX​

The C++ SDK has no built-in CertificateManager (the C# SDK has one, but there is no equivalent C++ API), so generate certificates yourself with OpenSSL.

OpenSSL Command​

# Generate a private key + self-signed certificate
openssl req -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes \
-subj "/CN=MyClient/O=Darra/C=CN" \
-addext "subjectAltName=URI:urn:darra:opcua:client"

# Pack as PFX (including private key)
openssl pkcs12 -export -out client.pfx -inkey key.pem -in cert.pem \
-password pass:123456

# Export the public key DER at the same time for import on the server
openssl x509 -in cert.pem -outform DER -out client.der
SAN URI It must be

urn:darra:opcua:client the message CreateSession sent by the client in is ApplicationUriHard-coded urn:darra:opcua:client, ConnectionConfig There is no field provided to change it. Therefore, SAN the certificate can only URI: be set to this one value; if you create your own, the server URI will reject it, stating that "SAN URI does not ApplicationUri match ."

Importing Trust on the Server Side​

Copy the client's public key (client.der or cert.pem) to the server's "Trusted Client Certificates" directory:

ServerPath
Darra Software PLC Server%ProgramData%/Darra/PKI/trusted/certs/ (Restart the service after copying to apply the changes)
The customer's current serverImported by the remote operations team; the path is in the format <server>pki//trusted/certs/ or uploaded to the management console.

By default auto_accept_untrusted = false, the Darra server does not automatically trust new client certificates.

Passed when the client is constructed PFX​

#include <darra/opcua/client.hpp>

ConnectionConfig cfg;
cfg.endpoint_url = "opc.tcp://server:4840";
cfg.security_mode = MessageSecurityMode::SignAndEncrypt;
cfg.client_cert_path = "C:/certs/client.pfx"; // Client PFX, private key included in the packet
cfg.client_key_path = "123456"; // The password PFX for this (the field name is a historical remnant; it is not the private key path)
cfg.server_cert_path = ""; // Empty = Do not provide a server certificate; use automatic discovery

Session s(cfg);
s.Connect();

Where do server certificates come from?​

server_cert_path There are two paths:

  1. Gaveserver_cert_path → Load this server certificate directly to establish a secure connection once
  2. Leave blank → Automatic transition from None to Secure: First, open a channel set to SecurityMode=None → GetEndpoints Retrieve the server certificate for the matching endpoint DER → Close the channel and reconnect → Then use Sign / to SignAndEncrypt open the actual channel
No TOFU, and fingerprints are not stored.

Leave blankNo"Initial trust + subsequent fingerprint verification." Each connection goes through the process again from the beginning; it was found GetEndpoints that no SDK trust cache is stored and no fingerprint comparison is performed. To permanently trust a specific server certificate, you must explicitly provide it server_cert_path.

cfg.server_cert_path = "C:/certs/server.pfx";   // Set a Server Certificate
The path must point to a PFX

(PKCS#12) file with no password; if not, DER pressNo password PFX Loading... The password is always blank. Enter .der / .pem to proceed.Loading will inevitably fail, and when they fail, SDKLog only one WARN Back to the Top: Part 2 — No error messages, no exceptions thrown, and no API to confirm which certificate was ultimately used. You might think the server’s identity is fixed, but it isn’t.

Troubleshooting​

The codes in the table below areProtocol Layer 32-bit Status Code, These are not C++ Status enumeration members. The C++ enumeration only includes Status BadSecurityModeRejected one; for the remaining entries, please compare ex.status_code() their values or look them up by name Stack::StatusName(code):

catch (Exception const& ex) {
std::cerr << ex.what() << " (0x" << std::hex << ex.status_code() << ")\n";
}
0x CodeStatusCodeReasonResolve
0x801A0000BadCertificateUntrustedThe server does not trust the client.Copy "client.der " to the server's trusted directory.
0x80120000BadCertificateInvalidCertificate expired / not yet valid / incorrect formatRegenerate
0x80140000BadCertificateTimeInvalidThe certificate is not within its validity period (the other party determines this based on its own clock)Synchronize the times on both devices or renew the certificate
—BadCertificateUriInvalidCertificate SAN.URI Does Not ApplicationUri MatchSAN It must be URI:urn:darra:opcua:client
—BadCertificateHostNameInvalidThe SAN.DNS certificate does not match the connected host.Add when generating subjectAltName=DNS:server.example.com
0x80130000BadSecurityChecksFailedGeneral security validation failedCheck the server logs to determine the specific cause.
0x80540000BadSecurityModeRejectedThe server does not support this SecurityModeGetEndpoints Check which ones the server actually supports
—BadSecurityPolicyRejectedThe server does not support Basic256Sha256.Enable this policy in the server configuration

The three codes marked with "—" are OPC UA protocol standard names; they are not included in this document's SDK C state table or C++ Status enumeration, so they can only be identified by their names in the server logs.

SAN URI Importance​

In OPC UA, the client certificate must contain the URI: field in its SAN and that value must match the ApplicationUri. This SDK's ApplicationUri is hard-coded to urn:darra:opcua:client, so the SAN can only be that value. Verify with openssl x509 -in cert.pem -text -noout:

openssl x509 -in cert.pem -text -noout | grep "URI:"
# Expected output: URI:urn:darra:opcua:client

Time Synchronization (NTP)​

Certificates have an expiration date, and the other party will determine whether the certificate has expired based on its own system time (status code BadCertificateTimeInvalid, 0x80140000). When this system loads SDK a certificate,Not doing it Local time validation is performed on the server. If the time difference between two machines is excessive, synchronize them first:

w32tm /resync

Next Step​