Application Certificate
OPC UA applications use X.509 v3 certificates to identify themselves and
provide public keys for secure communication. Each application certificate
must contain exactly one URI Subject Alternative Name (SAN) equal to its
applicationUri. Server certificates must also contain a DNS name or static
IP address identifying the server; client certificates do not require one.
The subject Common Name identifies the application. The helpers below use
applicationName for this field. See OPC UA Part 6, section 6.2.2 for the full
certificate requirements.
Note
See An Introduction to Public Key Infrastructure for an introduction to certificate management.
Creating a certificate with Mako
Import opcua.init to generate example self-signed certificates:
Function |
Arguments |
Requested SANs |
|---|---|---|
|
|
URI only |
|
|
DNS and URI |
Both functions return the application certificate and private key as PEM strings, or raise an error if generation fails. They request RSA-2048 keys, SHA-256 signatures, a validity start one day before the current UTC time, and a fixed 3,650-day lifetime from the current time. The server helper requires a nonempty hostname.
The example uses the server generator:
local init = require("opcua.init")
local hostname = "localhost"
local applicationName = "RealTimeLogic OPC UA Server"
local applicationUri = "urn:localhost:RealTimeLogic"
print("generating private key")
local certificate, key = init.genServerCertificate(hostname, applicationName, applicationUri)
print(key)
print(certificate)
Run it with:
mako create_certificate_aes128_rsa_oaep.lua
The script prints the private key and certificate for inspection. These helpers are examples; applications can supply their own certificates and private keys.
Important
The helpers require Mako signing profiles opcuaClient and
opcuaServer with self-signing support. They sign with the application’s
own key and create no CA certificate. The resulting application certificate
has CA:FALSE and includes keyCertSign for self-signing. They approve
only the requested application URI and, for servers, hostname. Peers must
trust the application certificate directly. Signing errors are reported
before initialization writes files. The example subject uses
organization RealTimeLogic. See the Mako certificate API.
Creating a certificate with OpenSSL
Save this server example as aes128_rsa_oaep.conf. For a client certificate,
use extendedKeyUsage = clientAuth and omit DNS.1. Set the subject and SAN
values to identify your application and server.
[req]
default_bits = 2048
prompt = no
default_md = sha256
distinguished_name = dn
x509_extensions = v3_req
[dn]
O = Example Organization
CN = Example OPC UA Server
[v3_req]
basicConstraints = critical,CA:FALSE
keyUsage = critical,digitalSignature,nonRepudiation,keyEncipherment,dataEncipherment,keyCertSign
extendedKeyUsage = serverAuth,clientAuth
subjectAltName = @alt_names
[alt_names]
URI.1 = urn:localhost:RealTimeLogic
DNS.1 = localhost
Generate a self-signed RSA application certificate suitable for the
Aes128_Sha256_RsaOaep security policy:
openssl req -config aes128_rsa_oaep.conf -newkey rsa:2048 -sha256 -x509 -days 365 -nodes -keyout aes128_rsa_oaep.key -out aes128_rsa_oaep.pem
This writes an unencrypted example private key. The peer application must be configured to trust the certificate.