Security Encryption
This section covers SDK encryption-related topics API and certificate tools.
- For information on generating certificates, configuring server-to-server trust, and troubleshooting, please refer to Certificate Generation and Configuration.
- For information on how to pass security parameters when creating a Session, please refer to Constructor.
- For information on security mode detection supported by the server, please refer to GetEndpoints.
Three types SecurityMode
public enum MessageSecurityMode { Invalid, None, Sign, SignAndEncrypt }
Pass the following when constructing a Session:
using DarraOpcUa_Client;
var (pfxPath, password) = CertificateManager.EnsureClientCertificate();
using var ua = new DarraOpcUa("opc.tcp://server:4840",
securityMode: MessageSecurityMode.SignAndEncrypt,
clientCertPath: pfxPath,
clientKeyPath: password); // Enter the PFX password — not the path to the private key file.
| Mode | Data Integrity | Confidentiality | Applicable |
|---|---|---|---|
| None | × | × | Development / Internal Network / Debugging |
| Sign | ✓ | × | Tamper-proof, but not sniffer-proof |
| SignAndEncrypt | ✓ | ✓ | Production Recommendations |
Sign / SignAndEncrypt Next clientCertPath Required; if missing, Connect() discard
OpcUaException, it is StatusCode DarraInvalidArgument, and will not be downgraded to plaintext.
SecurityPolicyUri
Support (Current Implementation):
http://opcfoundation.org/UA/SecurityPolicy#Nonehttp://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256(Primary Use)
Do not pass; press securityPolicyUri the button; securityMode auto-select: None → #None, others → #Basic256Sha256.
Other policies (Basic128Rsa15 / Basic256 / Aes128_Sha256_RsaOaep, etc.) are not currently supported by this implementation.
UserToken
public enum UserTokenType { Anonymous, Username, Certificate, Issued }
Select by construction parameters:
| Token | Construction Parameters |
|---|---|
| Anonymous | Do not share username |
| Username | username: "...", password: "..." |
| Certificate | Not currently available |
| Issued | Not currently available |
Certificate / Issued is used solely to identify the capabilities published GetEndpoints by the server; connection paths are not currently provided.
CertificateManager (Certificate Tool)
using DarraOpcUa_Client;
// Retrieve the client PFX (generate a self-signed certificate if it does not exist), and return the path and password
var (pfxPath, password) = CertificateManager.EnsureClientCertificate();
// Force a new self-signing certificate
var (newPfxPath, newPassword) = CertificateManager.ForceRegenerate();
// View the currently cached certificate
Console.WriteLine(CertificateManager.DescribeCachedCertificate());
For more details, see Certificate Generation and Configuration.