OPC UA security: modes, policies, certificates and user identity
Part of the OPC UA guide
OPC UA security works at two levels. The secure channel authenticates the two applications with X.509 certificates and signs, or signs and encrypts, every message between them. The session on top of it authenticates the user, by anonymous access, user name and password, or a user certificate. Both are part of the protocol itself, and both are negotiated per endpoint, so the settings on the client have to match an endpoint the server offers.
This page is part of the OPC UA guide. The model is defined in Part 2 of the OPC UA specification, the services in Part 4, the algorithms in Part 6 and the policy definitions in Part 7. The connection steps referred to here are laid out on the client and server page.
Message security modes
Each endpoint has one of three message security modes.
| Mode | Value | What it does |
|---|---|---|
| None | 1 | No signing and no encryption. Anyone on the path can read and alter messages. |
| Sign | 2 | Each message carries a signature. Tampering is detected; the content is readable on the wire. |
| SignAndEncrypt | 3 | Each message is signed and encrypted. |
Sign is enough to stop a device on the network from injecting a write. SignAndEncrypt also hides tag names, values and, depending on the configuration, user credentials. Mode None is for commissioning on an isolated bench, and many servers ship with it disabled.
Security policies
The security policy names the set of algorithms used for the mode. It is identified by a URI of the form http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256.
| Policy | Symmetric encryption | Signatures and key exchange | Status |
|---|---|---|---|
None | None | None | No protection |
Basic128Rsa15 | AES-128 | RSA PKCS #1 v1.5, SHA-1 | Deprecated |
Basic256 | AES-256 | RSA-OAEP, SHA-1 | Deprecated |
Basic256Sha256 | AES-256 | RSA-OAEP key exchange, SHA-256 signatures, 2048-bit keys or longer | Current |
Aes128_Sha256_RsaOaep | AES-128 | RSA-OAEP key exchange, SHA-256 signatures | Current |
Aes256_Sha256_RsaPss | AES-256 | RSA-OAEP with SHA-256, RSA-PSS signatures | Current |
Basic128Rsa15 and Basic256 depend on SHA-1 and were deprecated by the OPC Foundation. Older controllers may offer nothing newer, in which case the firmware needs updating or the server needs to sit behind a network boundary. Basic256Sha256 is the policy most clients and servers have in common. Later versions of the specification add policies based on elliptic curves.
A client does not choose a mode and a policy independently of the server. It picks one endpoint from the GetEndpoints list, and that endpoint fixes both. If the client is set to Basic256Sha256 with SignAndEncrypt and the server offers only Basic256, there is no matching endpoint and the connection fails before any certificate is examined.
Application instance certificates
Every OPC UA application, client or server, has an application instance certificate: an X.509 v3 certificate with a private key that identifies that one installation. Three fields in it are checked:
- The validity period. A controller whose clock has reset to its default date will see every certificate as not yet valid or expired, and report
BadCertificateTimeInvalid. - The application URI, in the subject alternative name. It has to match the application URI the application states in its own description, or the peer reports
BadCertificateUriInvalid. - The host names or IP addresses, also in the subject alternative name, which a client can compare with the address it connected to (
BadCertificateHostNameInvalid).
Most plant-floor certificates are self-signed, so there is no certificate authority to vouch for them. Trust is established by placing the certificate in the other side’s trust list.
Trust lists and the first connection
Each application keeps a trust list, usually as folders or a store with three parts: trusted certificates, issuer certificates and rejected certificates. The sequence on a first connection is the same on almost every product:
- The client connects with a secured endpoint and presents its certificate.
- The server does not know the certificate, refuses the connection with
BadSecurityChecksFailedorBadCertificateUntrusted, and saves the certificate in its rejected list. - Someone with access to the server moves the certificate from rejected to trusted, in the PLC engineering software or the server’s administration tool.
- The client connects again and succeeds.
The same happens in the other direction: the client has to trust the server’s certificate, and client tools usually prompt for it.
Some servers have a setting that accepts any client certificate automatically. It removes step 3 and with it the application authentication, since any client that generates a certificate is then let in. Leave it off outside commissioning.
Where there are many applications, certificates can be issued by a certificate authority instead, so that each application trusts the authority once and checks revocation lists. Part 12 of the specification defines a Global Discovery Server that can issue and renew certificates and distribute trust lists centrally.
If an application is reinstalled or its certificate regenerated, it has a new key and is a stranger again. A client that connected for years and fails after a server replacement is usually holding the old server certificate.
What happens on the wire
OpenSecureChannel is protected with asymmetric cryptography: the client signs the request with its private key and encrypts it with the server’s public key. Each side contributes a nonce, and both derive the same symmetric signing and encryption keys from them. All later messages use those symmetric keys, which is what keeps the cost per message low.
The channel has a lifetime, and the client renews it before it expires (the specification recommends at 75 percent of the lifetime) with another OpenSecureChannel exchange that produces new keys. Sequence numbers in each message let the receiver reject replayed or reordered messages.
In CreateSession and ActivateSession, each side signs data supplied by the other, including the peer’s certificate and nonce. This proves that each holds the private key for the certificate it presented.
User identity
The application certificate says which software is connecting. The user identity token, sent in ActivateSession, says on whose behalf. Each endpoint lists the token types it accepts.
| Token type | What is sent | Notes |
|---|---|---|
| Anonymous | Nothing | The server applies whatever rights it gives unidentified users |
| UserName | User name and password | The password is encrypted with the server’s certificate when a policy is in force |
| X509 | A user certificate, with a signature | The user needs a private key |
| IssuedToken | A token from an external authorization service | For example a JSON Web Token |
The pairing of mode None with a UserName token deserves care. Without a security policy on either the channel or the token, the password crosses the network in the clear.
What a user may do is decided by the server. The UserAccessLevel attribute of a variable gives the read and write rights of the current session’s user, and recent versions of the specification add roles and per-node role permissions. A client that can read a node but receives BadUserAccessDenied on a write has connected correctly and lacks rights. For a data collector, a dedicated account that can read and cannot write is the appropriate default.
Settings that are worth checking
- Disable mode None endpoints on production servers, or restrict them to the engineering network.
- Disable the deprecated policies where every client supports
Basic256Sha256or newer. - Turn off automatic acceptance of client certificates.
- Disable anonymous access, or make anonymous read-only.
- Keep controller clocks synchronized, since certificate validity depends on them.
- Note certificate expiry dates. Many products generate certificates valid for a fixed number of years, and they all expire together.
- Keep port
4840off the internet. OPC UA security protects sessions; it does not replace network segmentation, and an exposed server still reveals its endpoints and certificate to anyone who calls GetEndpoints.
By comparison, Modbus has no authentication or encryption at all, which is the main reason OPC UA is preferred when data has to cross from a control network to anything else. The comparison page covers the rest of the differences.
Common security errors
| Status code | Meaning | Usual fix |
|---|---|---|
BadSecurityChecksFailed | The server rejected the client’s certificate or signature | Trust the client certificate on the server |
BadCertificateUntrusted | The certificate is not in the trust list | Move it from rejected to trusted |
BadCertificateTimeInvalid | Expired or not yet valid | Check both clocks, then renew the certificate |
BadCertificateUriInvalid | Application URI mismatch | Regenerate the certificate with the application’s actual URI |
BadSecurityPolicyRejected | The server does not allow that policy | Choose a policy from the endpoint list |
BadIdentityTokenRejected | Token type or credentials refused | Check the user name, password and whether anonymous is allowed |
BadUserAccessDenied | The user has no right to that operation | Change the user’s role or the node’s permissions |
Where the ControlCom Edge Server sits
In a ControlCom deployment, the OPC UA session is opened by the ControlCom Edge Server, the on-site component, and ControlCom Connect, the hosted platform, never connects to the OPC UA server itself. The Edge Server’s OPC UA client is given the server’s OPC Endpoint URL, for example opc.tcp://192.168.1.100:4840, so the server only has to be reachable from the Edge Server on the plant network. Writing is off unless it is configured: each item’s Write Variable setting defaults to No Write Allowed.
The OPC UA client documentation lists the connection fields. Compare them with the security mode, policy and user identity your server requires before commissioning, and contact us if the documentation leaves a question about your server open.
The Edge Server opens the OPC UA connection on site and maps each node to a variable in ControlCom Connect, so the OPC UA server only has to be reachable from the Edge Server.