Skip to main content

Security Encryption

This section covers SDK encryption-related topics API and certificate tools.

Subpage Redirect
  • 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 get_endpoints.

Three types SecurityMode​

from darra_opcua import MessageSecurityMode

MessageSecurityMode.NONE # 1 (Conflict with the Python keyword "None"; use NONE uppercase)
MessageSecurityMode.Sign # 2
MessageSecurityMode.SignAndEncrypt # 3
MessageSecurityMode.Invalid # 0 (Placeholder/invalid value; not a valid mode)

Pass the following when constructing a Session:

from darra_opcua import OpcUaSession, MessageSecurityMode

with OpcUaSession(
"opc.tcp://server:4840",
security_mode=MessageSecurityMode.SignAndEncrypt,
client_cert_path=r"C:\certs\client.pfx",
client_key_path="123456") as ua: # client_key_path = PFX Password
ua.connect()
ModeData IntegrityConfidentialityApplicable
NONE××Development / Internal Network / Debugging
Sign✓×Tamper-proof, but not sniffer-proof
SignAndEncrypt✓✓Production Recommendations

Sign / SignAndEncrypt Must be provided client_cert_path (PFX file containing the private key; no separate private key file is required).

SecurityPolicyUri​

Support (Current Implementation):

  • http://opcfoundation.org/UA/SecurityPolicy#None
  • http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256 (Primary Use)

Do Not Disturb Press Now security_policy_uri security_mode Auto-Select (NONE → #None, Other → #Basic256Sha256).

UserToken​

from darra_opcua import UserTokenType

UserTokenType.Anonymous # 0
UserTokenType.Username # 1
UserTokenType.Certificate # 2
UserTokenType.Issued # 3

ConstructorSorted by: Whether or Not the Token Type Is Automatically username Determined: If a username is provided, username use it; otherwise, use "Anonymous."

TokenConstruction Parameters
AnonymousDo not disclose username
Usernameusername="...", password="..."
CertificateNo corresponding constructor parameters (the current constructor does not support user certificate tokens)
IssuedNo corresponding constructor parameters (not supported by this constructor)

Certificate Tools​

The Python SDK has no built-in certificate generation module; use the OpenSSL CLI or the Python cryptography package to generate a PFX. See Certificate Generation and Configuration for details.

Next Step​