Skip to main content

Enable Encryption

In a production environment, it is strongly recommended to use Sign or SignAndEncrypt + Basic256Sha256. There are only three steps: generate a certificate → import it into the server’s trust store → pass it to the client during construction PFX.

Further Reading

Generate a Client Certificate (PFX)​

// If it does not exist, generate it automatically and write it to disk; if it already exists, reuse it directly. Returns (pfxPath, pfxPassword)
var (pfxPath, pwd) = CertificateManager.EnsureClientCertificate();

Subject / SAN URI / The validity period is SDK hard-coded and cannot be customized — it is SAN URI always urn:darra:opcua:client.PFX The password is a random, strong password stored in a bypass DPAPI file client.pfx.pwd; it is not a fixed password that you set yourself.

Import and Trust on the Server​

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

  • 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 via the "Trusted Client Certificates" page in the admin panel

By default auto_accept_untrusted = false, the Darra server does not automatically trust new client certificates; certificates not in the trusted directory are rejected %ProgramData%\Darra\PKI\rejected\certs\, and the connection is denied.

The client does not verify the server's identity (none TOFU)

serverCertPath When not transmitted SDKDo not store server certificate fingerprints; do not perform cross-session comparisons —— There is no implementation TOFU. At this point, every connection uses a plaintext channel with None to GetEndpoints retrieve the server's self-signed certificate and then upgrade the encryption, Can't prevent man-in-the-middle attacks. To specify "only this server," you must explicitly pass serverCertPath (PKCS#12 PFX, no password); passing DER will cause the load to fail andSilent Downgrade Back to Auto-Discovery.

Pass the certificate when constructing the client​

using var ua = new DarraOpcUa(
endpointUrl: "opc.tcp://server:4840",
securityMode: MessageSecurityMode.SignAndEncrypt,
clientCertPath: @"C:\certs\client.pfx",
clientKeyPath: "123456" // PFX Password
);
ua.Connect();

SecurityMode Select​

PatternTamper-proofEncryptionPerformance OverheadWhen to Use
None××0Intranet, Development, Performance-Sensitive
Sign✓×Low (~5%)Prevention MITM—it doesn't matter if the traffic is visible
SignAndEncrypt✓✓Medium (~15%)Public Network, Factory Intranet, Default Recommendation

SecurityPolicy​

The current implementation supports two options:

  • http://opcfoundation.org/UA/SecurityPolicy#None — For None mode only
  • http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256 — Sign and SignAndEncrypt Default
SDK Default Behavior

If no strategy is passed to the C#, Java, or Python wrapper, the strategy is automatically securityMode selected securityPolicyUri as follows: None → #None; all others → #Basic256Sha256. When calling the protocol stack directly in C, this inference does not occur: if left blank security_policy_uri, it always falls back to the default #None; in C, you must explicitly pass a strategy URI.

UserToken (Login credentials)​

An encrypted channel and a login identity are two separate things:

// Encryption + Username and Password
using var ua = new DarraOpcUa(
endpointUrl: "opc.tcp://server:4840",
securityMode: MessageSecurityMode.SignAndEncrypt,
username: "operator",
password: "secret",
clientCertPath: @"C:\certs\client.pfx",
clientKeyPath: "123456");

Troubleshooting Certificate Mutual Trust Issues​

ErrorReasonResolve
BadCertificateUntrustedThe server did not add the client certificate to the trusted list.Copy the client .der to the server %ProgramData%\Darra\PKI\trusted\certs\
BadCertificateInvalidCertificate expired / not yet valid / incorrect formatRegenerate
BadCertificateUriInvalidCertificate SAN.URI Does Not ApplicationUri MatchSAN It must be URI:urn:darra:opcua:client (ApplicationUri a hard-coded constant)
BadSecurityChecksFailedGeneral security validation failed (not specific to any particular cause)Check the server logs to determine the specific cause.
BadSecurityModeRejectedThe server does not support this mode.Switch to a less secure mode or check the server configuration

For a detailed investigation, see FAQ → Encryption Configuration.