Security 加密 (C)
C SDK 把加密参数集中在 DarraUa_SessionConfig 几个字段, 没有独立 "Security 对象" 或 "CertificateManager 类". 证书生成需要外部工具 (OpenSSL) 或自己调用底层 darra_opcua_security.h 的 X509 API.
子页跳转
- 生成证书 / 服务端互信配置 / 故障排查请参考 证书生成与配置.
- Session 创建时如何传安全参数请参考 配置与创建.
- 服务端支持的安全模式探测请参考 GetEndpoints.
三种 SecurityMode
typedef enum {
DARRA_UA_MSG_SECURITY_MODE_INVALID = 0,
DARRA_UA_MSG_SECURITY_MODE_NONE = 1,
DARRA_UA_MSG_SECURITY_MODE_SIGN = 2,
DARRA_UA_MSG_SECURITY_MODE_SIGN_ENCRYPT = 3
} DarraUa_MessageSecurityMode;
| Mode | 数据完整性 | 机密性 | 适用 |
|---|---|---|---|
NONE | × | × | 开发期 / 内网 / 调试 |
SIGN | ✓ | × | 防篡改, 不防嗅探 |
SIGN_ENCRYPT | ✓ | ✓ | 生产推荐 |
DarraUa_SessionConfig cfg;
DarraUa_SessionConfig_Init(&cfg);
cfg.security_mode = DARRA_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 密码 */
SecurityPolicyUri
支持 (当前实现):
| URI | 说明 |
|---|---|
http://opcfoundation.org/UA/SecurityPolicy#None | 不加密 |
http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256 | 主用 |
http://opcfoundation.org/UA/SecurityPolicy#Aes128_Sha256_RsaOaep | (可选) |
http://opcfoundation.org/UA/SecurityPolicy#Aes256_Sha256_RsaPss | (可选) |
UserToken
typedef enum {
DARRA_UA_USER_TOKEN_ANONYMOUS = 0,
DARRA_UA_USER_TOKEN_USERNAME = 1,
DARRA_UA_USER_TOKEN_CERTIFICATE = 2,
DARRA_UA_USER_TOKEN_ISSUED = 3
} DarraUa_UserTokenType;
| Token | 配置 |
|---|---|
| Anonymous | cfg.user_token_type = ...ANONYMOUS; |
| Username | cfg.user_token_type = ...USERNAME; cfg.username/password = ... |
| Certificate | (后续版本完善) 用户证书参数 |
| Issued | (本 SDK 暂不实现) |
证书工具
C SDK 不内置 "GenerateSelfSigned" 高层 API, 推荐用 OpenSSL 命令行生成 PFX. 高级用户可直接调 darra_opcua_security.h 的 X509 / RSA / SHA / AES 底层函数 (一般无需, Stack 内部已用).
详细见 证书生成与配置.