Encryption Configuration
This covers only the practical steps. For the encryption OPC UA principles, see OPC UA Concepts of Safety.
- Basics — Security Models — Concept / SecurityMode / UserToken
- Quick Start — Enable Encryption — Tabs Multilingual Example
- Connection Troubleshooting — StatusCode Quick Reference
SecurityMode Which one should I choose?
| Scenario | Mode |
|---|---|
| Intranet Development and Integration Testing | None |
| Internal Network Production | Sign + Username |
| Public Network / Cross-Campus | SignAndEncrypt + Username or Certificate |
SecurityPolicy is fixed to use Basic256Sha256 (SDK the deprecated Basic128Rsa15 / is not supported Basic256).
Generate a Client Certificate (PFX)
Choose either one.
OpenSSL (Cross-platform):
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,DNS:my-host"
openssl pkcs12 -export -out client.pfx -inkey key.pem -in cert.pem -password pass:123456
openssl x509 -in cert.pem -outform DER -out cert.der # Public key, copy to the server
SDK Automatically Generated Internally (C#) — No need to write the commands OpenSSL yourself:
// Self-sign and save to disk if missing; reuse if already present. Returns (pfxPath, pfxPassword)
var (pfxPath, pwd) = CertificateManager.EnsureClientCertificate();
// Force regenerate (test scenario)
var (pfxPath2, pwd2) = CertificateManager.ForceRegenerate();
The actual generation parameters are hard-coded CertificateManager, Custom Subject / ApplicationUri / Expiration Date Not Accepted:
| Item | Value |
|---|---|
| SubjectName | CN=DarraOpcUaClient, O=Darra, C=CN |
| ApplicationUri (SAN URI) | urn:darra:opcua:client |
| Validity Period | 5 years |
| Key Length | RSA 2048 |
| Save Path | %AppData%/Darra/OpcUa/pki/client.pfx |
| PFX Password | Random Strong Passwords, DPAPI Save to a bypass file client.pfx.pwd |
The sent CreateSession by the client in is ApplicationUriHard-Coded Constantsurn:darra:opcua:client (public constant CertificateManager.ApplicationUri), and there are no fields that can modify it. Therefore, the certificate's SAN URI: You can only enter this one value —— If you enter your own value, the server URI will reject it,OpenSSL stating that it "SAN URI does not ApplicationUri match." The value in the command must also SAN URI match this exact value.
SDK Certificate Issued by the Communication University of China
using var ua = new DarraOpcUa("opc.tcp://server:4840",
securityMode: MessageSecurityMode.SignAndEncrypt,
securityPolicyUri: "http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256",
clientCertPath: @"C:\certs\client.pfx",
clientKeyPath: "123456"); // PFX password (field name reuses client_key_path)
ua.Connect();
Mutual Trust
The server trusts the client: Copy the client's public key .der to the server's "trusted" directory.
| Server | Path |
|---|---|
| Darra Software PLC Server | %ProgramData%\Darra\PKI\trusted\certs\ (Configuration option trust_list_dir; this is the default value; copy it and restart the service for the changes to take effect) |
| The customer's current server | Imported 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. Client certificates not in the trusted directory will be rejected %ProgramData%\Darra\PKI\rejected\certs\, and the connection will be denied.
Client Trusts Server — No TOFU, does not store fingerprints
SDK There are no TOFU (Trust-On-First-Use) implementations: Server certificate fingerprints are not stored, and consistency checks are not performed across connections. Therefore, serverCertPath: null is not equal to"Man-in-the-middle protection" — It simply rediscovers the certificate with every connection; an imposter can still use a different certificate to gain access the next time they connect.
There are only two sources for server certificates; choose one based on whether you want it to be fixed:
// Option one: pre-provision the server certificate — the only way to "trust only this one server"
serverCertPath: @"C:\trusted\server.pfx" // Must be PKCS#12(PFX) and must have no password
// Option two: not pre-provisioned — every connection uses None→Secure auto-discovery, no fixed identity
serverCertPath: null
Actual behavior when not preconfigured: First, open a plaintext channel with a value of SecurityMode=None → GetEndpoints Retrieve the server's self-signed certificate → Close the channel and reconnect → Then open an encrypted channel.Certificates are not stored on the disk, fingerprints are not saved, and no comparisons are made.
When loading PFX fails for the path specified in the preset, SDK If only one WARN message is logged, it automatically reverts to auto-discovery., It does not throw exceptions, and there is no API to determine "whether a pre-configured certificate or an automatically discovered one is being used." Uploading a file DER willLoading will inevitably fail Then a silent downgrade—you thought you had pinned the identity, but you actually hadn't. If you pass an incorrect format, check the logs to see if this Server cert PFX load failed WARN message appears.
Common Mistakes
| Error | Reason | Resolve |
|---|---|---|
| BadCertificateUriInvalid | SAN URI ≠ ApplicationUri | When regenerating the certificate, make sure the two match. |
| BadCertificateUntrusted | The server does not trust the client | Copy the client's .der directory to the server's pki/trusted/certs/ directory. |
| BadCertificateHostNameInvalid | The host and certificate do not SAN.DNS match | Use "IP and" or "plus" DNS SAN |
| BadCertificateTimeInvalid | The server determined that the certificate is not valid. | Synchronize the times on both systems or renew the certificate (This process does not perform a local time check when loading SDK the certificate.) |
| BadSecurityPolicyRejected | Basic256Sha256 is not enabled on the server. | Enable this policy in the server configuration |
Contents of the Diagnostic Certificate (SearchThe one in the cache SDK Self-managed certificate (does not accept arbitrary path parameters):
// Returns one line of text: Subject=...; Thumbprint=...; NotBefore=...; NotAfter=...; HasPrivateKey=...
Console.WriteLine(CertificateManager.DescribeCachedCertificate());
Self-signed: Use PFX OpenSSL/keytool to view the contents (openssl pkcs12 -in client.pfx -nokeys | openssl x509 -text), but there is no SDK option to "view any certificate by path API."
BadCertificateTimeInvalid ByServer-side Determined based on its own clock; this occurs when the certificate is loaded SDKNot doing it Local time validation does not check for message timestamp discrepancies (status codes UA_STATUS_BAD_CERTIFICATE_TIME_INVALID / UA_STATUS_BAD_INVALID_TIMESTAMP are never SDK returned). So don't count on the system "blocking SDK requests if the clock is off" — you should still NTP do what needs to be done.