Skip to main content

Security Encryption (C)

All C SDK encryption parameters are configured inside DarraUa_SessionConfig; there is no separate Security object to build. Certificates are produced by an external tool (OpenSSL) or by calling the X509 interface of opcua_security.h directly.

Subpage Redirect

Three types SecurityMode​

typedef enum {
UA_MSG_SECURITY_MODE_INVALID = 0,
UA_MSG_SECURITY_MODE_NONE = 1,
UA_MSG_SECURITY_MODE_SIGN = 2,
UA_MSG_SECURITY_MODE_SIGN_ENCRYPT = 3
} DarraUa_MessageSecurityMode;
ModeData IntegrityConfidentialityApplicable
NONE××Development / Internal Network / Debugging
SIGN✓×Tamper-proof, but not sniffer-proof
SIGN_ENCRYPT✓✓Production Recommendations
DarraUa_SessionConfig cfg;
DarraUa_SessionConfig_Init(&cfg);
cfg.security_mode = UA_MSG_SECURITY_MODE_SIGN_ENCRYPT;
cfg.security_policy_uri = "http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256";
cfg.client_cert_path = "C:/certs/client.pfx";
cfg.client_key_path = "123456"; /* PFX Password */

SecurityPolicyUri​

If left blank security_policy_uri, it will always revert to the default http://opcfoundation.org/UA/SecurityPolicy#None, regardless security_mode of. To use Sign /, you must SignAndEncrypt explicitly set the policy to URI #Basic256Sha256; otherwise, it will attempt to enable encrypted mode using an unencrypted policy, and you won't be able to connect at all.

The current version implements SDK only the following two channels:

URINote
http://opcfoundation.org/UA/SecurityPolicy#NoneUnencrypted
http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256Main Use, Sign / Use this for everything SignAndEncrypt

#Aes128_Sha256_RsaOaep "Not currently #Aes256_Sha256_RsaPss available": Even if you fill in the field, there is no corresponding encryption/decryption path, so you cannot connect.

Field Semantics

cfg.security_policy_uri: You can enter any string, but encryption and decryption implementations are provided URI only for SDK the two fields listed above. Do not enter anything in any other fields.

UserToken​

typedef enum {
UA_USER_TOKEN_ANONYMOUS = 0,
UA_USER_TOKEN_USERNAME = 1,
UA_USER_TOKEN_CERTIFICATE = 2,
UA_USER_TOKEN_ISSUED = 3
} DarraUa_UserTokenType;

The enumeration defines 4 types; the connection paths in the current version only implement the first two:

TokenConfigurationConnection Path
Anonymouscfg.user_token_type = UA_USER_TOKEN_ANONYMOUS;Available (default)
Usernamecfg.user_token_type = UA_USER_TOKEN_USERNAME;
cfg.username = "operator";
cfg.password = "123456";
Available
CertificateEnumeration definedNot currently available
IssuedEnumeration definedNot currently available

UA_USER_TOKEN_CERTIFICATE / UA_USER_TOKEN_ISSUED Currently, this is used only to identify the token capabilities published GetEndpoints by the server (user_token_types), and identity is not assembled using these two types of tokens when establishing a session. Client certificates (cfg.client_cert_path) are used for channel-level signing and are not X.509 user identity tokens.

Certificate Tools​

The C SDK provides no interface for generating self-signed certificates; we recommend generating the PFX from the OpenSSL command line. If needed you can call the built-in X509 / RSA / SHA / AES encryption functions in opcua_security.h directly (generally unnecessary for standard operations).

For more details, see Certificate Generation and Configuration.

Next Step​