The OPC UA server in Crimson 3.2 identifies itself to OPC UA clients with a certificate. By default the device creates that certificate itself and signs it with the C3.2 Local Root, a certificate authority (CA) built into Crimson, which OPC UA clients don't trust. This article shows how to give the OPC UA server a certificate issued by your own CA, and how to make an OPC UA client trust it, so that clients connect with a secure policy such as Basic256Sha256 with Sign & Encrypt.
The procedure was tested on a FlexEdge™ DA30D with Crimson 3.2.1060.0 and device firmware 3.2.1060.0 (18), using a scripted OPC UA client. The UaExpert steps come from earlier tests on the same device, and from a later run of UaExpert 2.0.2 on Windows against the same device. Only the FlexEdge DA30D was tested; other models are not covered by this article.
Preparation
-
Software and device:
- Crimson 3.2 and a device you can download a database to. The procedure was tested on a FlexEdge DA30D with Crimson 3.2.1060.0; no other model or build was tested.
- An OPC UA client, such as UaExpert.
-
A server certificate for the device, issued by your CA:
- An RSA 2048-bit key. In testing on 3.2.1060.0 (18), a 3072-bit key did not work with the OPC UA server (see Part 5).
- The private key in PKCS#1 format: the key file starts with -----BEGIN RSA PRIVATE KEY-----. A key in PKCS#8 format (-----BEGIN PRIVATE KEY-----) is accepted by Crimson, but in testing on 3.2.1060.0 (18) secure connections to the OPC UA server then failed. Part 1 shows how to convert it.
- Subject Alternative Names (SANs) that list the server's Application URI and every DNS name and IP address clients use to reach the device. With default naming, the server's Application URI has the form urn:hostname.local:server (for example urn:red-08-b8-68.local:server), and the certificate's CN is hostname.local. The certificate tested had a URI SAN matching the Application URI, a DNS SAN with the hostname (hostname.local) and an IP SAN with the device's address, and a strict client accepted it. Match all three as tested. The Application URI comes from the device's own name: in testing, setting Endpoint Host to a DNS name changed the endpoint URLs and the Application Name to that name, but the Application URI stayed urn:hostname.local:server, so keep that URI SAN in the certificate. To avoid the .local name, set Endpoint Host to a DNS name your clients can resolve and add that name as a DNS SAN (and the device's IP address, if clients connect by IP). Setting Server Name itself was not tested.
- An unencrypted private key (no password). The tested keys were unencrypted; an encrypted key with a Key Password was not tested.
-
Your CA certificates and CRLs, for the client:
- The root CA certificate, and the issuing (intermediate) CA certificate if your CA uses one.
- A certificate revocation list (CRL) from each CA, in DER format. UaExpert reports BadCertificateRevocationUnknown without them.
-
Time synchronization:
- The device's clock must be correct. OPC UA depends on accurate timestamps, and certificates are only valid between their start and end dates. Set up time synchronization under Device Configuration > System Configuration > Services > Time Sync; see the Time Sync section of the Crimson 3.2 Software Guide (System Configuration > Services), which notes that an accurate clock is needed for X509 certificate validation.
Part 1: Prepare the Certificate and Key
Step 1: Check the Key Format
- Open the private key file in a text editor.
- Check the first line:
- -----BEGIN RSA PRIVATE KEY-----: PKCS#1. Continue with Step 2.
-
-----BEGIN PRIVATE KEY----- or -----BEGIN ENCRYPTED PRIVATE KEY-----: PKCS#8. Convert it with OpenSSL 3.x:
- openssl rsa -in server.key -traditional -out server-pkcs1.key
- Check the key size: openssl rsa -in server-pkcs1.key -noout -text shows Private-Key: (2048 bit, 2 primes) on its first line. If it shows 3072 or 4096 bit, issue a new certificate with a 2048-bit key.
Note: The key must be unencrypted for this procedure, so keep it as safe as the original and delete copies you no longer need.
Step 2: Build the Certificate File
- If your CA uses an issuing (intermediate) CA, make one PEM file that holds the device certificate first, followed by the issuing CA certificate. The device then sends both to the client.
- Adding the root CA certificate at the end of the file is optional. Both a file with the device and issuing CA certificates, and one with the device, issuing CA and root certificates, worked in testing. A device with the first kind of file sends the device and issuing CA certificates, not the root, so clients need the root CA certificate in their trusted store.
Part 2: Load the Certificate into Crimson
Step 1: Set the Default Certificate
- Open your database in Crimson 3.2.
- Navigate to Device Configuration > System Configuration > Network > Identity, Naming Tab.
- Set the following:
- Default Cert: Specified Below.
- Cert File: the certificate file from Part 1, Step 2. Drop the file onto the field, or use the upload button beside it.
- Key File: the PKCS#1 private key from Part 1, Step 1.
- Key Password: leave empty. The tested keys were unencrypted.
Note: The Default Cert is also the device's certificate for the System Web Server, and for other services that are set to use it, such as the TLS Server and the Crimson Web Server. Make sure the certificate's names also suit those services.
Part 3: Configure the OPC UA Server
Step 1: Enable the Server
- Navigate to Communications > Services > OPC UA Server, Service Tab.
- Set the following:
- Enable Server: Yes.
- Server Name and Endpoint Host: leave them at Default, or enter the name clients use. If Endpoint Host is left blank, the server uses the device's name, which defaults to the red-xx-yy-zz.local form.
- Anonymous Access: Disabled, if clients must log on. Then set User Name and Password.
- Tag Writes: Enabled only if clients need to write to tags.
Step 2: Select the Server Certificate
- Open the Network Tab.
- Set the following:
- Listen on Port: 4840, the OPC UA default, unless your clients use another port.
- Server Certificate: Default Identity, which is the certificate set in Network > Identity, the one you loaded in Part 2.
Step 3: Choose the Tags
- On the Public Data and Private Data tabs, select the tags the server exposes.
Part 4: Download and Connect
Step 1: Download the Database
- Save the database.
- Download it to the device with Link > Send.
- The device restarts after the download and then uses the new certificate.
Step 2: Make the Client Trust Your CA (UaExpert)
UaExpert validates the server's certificate chain and checks revocation for each CA in it. Copy your CA files into UaExpert's PKI folders. On Windows, the PKI folder is %APPDATA%\unifiedautomation\uaexpert\PKI, for example C:\Users\user\AppData\Roaming\unifiedautomation\uaexpert\PKI. To open the folders from UaExpert, choose Settings > Manage Certificates…, select the Default Certificate Store tab (the dialog may first open on a GDS Server tab), and on the Trusted, Issuers or TLS Issuers sub-tab click Open. The folders are:
- trusted/certs: your root CA certificate (DER format worked in testing).
- trusted/crl: the root CA's CRL, in DER format, with a .crl extension.
- issuers/certs: the issuing (intermediate) CA certificate (DER format worked in testing).
- issuers/crl: the issuing CA's CRL, in DER format, with a .crl extension.
Note: Name the CRL files with a .crl extension. In testing, UaExpert ignored CRLs named .crl.der and reported BadCertificateRevocationUnknown.
You don't need to put the device certificate itself in the trusted folder, and you don't need to accept it temporarily.
Step 3: Connect
- Before connecting, set Endpoint Host (Part 3, Step 1) to a name your PC can resolve, and add that name as a DNS SAN in the certificate. Without it, the server's endpoints advertise the device's .local name (opc.tcp://hostname.local:4840), not its IP address. With Endpoint Host set, all endpoint URLs use that name (opc.tcp://name:4840).
- In UaExpert, add a server with the endpoint URL opc.tcp://name:4840, using the Endpoint Host name.
- If you leave Endpoint Host blank and your PC can't resolve the .local name, UaExpert may report that GetEndpoints failed with BadHostUnknown and show two prompts. Answer Yes to Replace Hostname (try the URL with the IP address) and Yes to Replaced Hostname (replace the hostnames of the endpoint URLs). If you connect by IP address, the certificate needs an IP SAN.
- Select the endpoint:
- Security Policy: Basic256Sha256.
- Message Security Mode: Sign & Encrypt.
- Connect, with anonymous logon or the user name and password from Part 3.
- With the CA files in place, UaExpert showed no certificate dialog in testing: it checked the server certificate against the CA files silently, and the status changed to Connected. The device accepted UaExpert's own self-signed client certificate with no change on the device. The first time UaExpert starts, it runs its own one-time setup, which asks for an Organization and creates UaExpert's own application instance certificate (defaults: RSA 2048, SHA-256, 5 years). That setup comes from UaExpert, not from the device.
UaExpert connected, with no certificate warning.
Part 5: Frequently Asked Questions (FAQ)
Question: The client fails at OpenSecureChannel with a Bad status, but Security Policy None works. What is wrong?
Answer: Check the private key's format. In testing on 3.2.1060.0 (18), with a PKCS#8 key the server presented its certificate and the None policy worked, but the server refused the secure OpenSecureChannel with a generic Bad status. Convert the key to PKCS#1 (Part 1, Step 1), load it again in Key File, and download the database. Debug Output on the OPC UA server shows nothing for these failures.
Question: The secure channel opens, but CreateSession fails or gets no answer. Why?
Answer: The key is probably larger than 2048 bits (a client may report InvalidSignature or just time out). In testing on 3.2.1060.0 (18), with a 3072-bit PKCS#1 key the certificate validated and the secure channel opened, but the server did not answer CreateSession within 30 seconds (on earlier firmware the client rejected the reply with InvalidSignature). The OPC UA server may stop answering for a while after failed attempts. Issue a new certificate with an RSA 2048-bit key.
Question: UaExpert reports BadCertificateChainIncomplete or BadCertificateRevocationUnknown. What should I check?
Answer: BadCertificateChainIncomplete means UaExpert is missing a CA certificate: put the root in trusted/certs and the issuing CA in issuers/certs. BadCertificateRevocationUnknown means a CRL is missing or misnamed: each CA needs a DER CRL with a .crl extension (Part 4, Step 2).
Question: With the default certificate, UaExpert reports BadCertificateBasicConstraintsMissing. Is a custom certificate the fix?
Answer: Yes. The certificate the device creates by default is issued by the C3.2 Local Root and has no Basic Constraints extension, which strict clients reject. The missing Basic Constraints extension was seen on a DA30D with 3.2.1060.0 (18) and on an earlier firmware. The UaExpert error was seen on 3.2.1060.0 (18) only: UaExpert 2.0.2 refused the certificate with BadCertificateBasicConstraintsMissing (the details also listed BadCertificateRevocationUnknown and BadCertificateUntrusted, because the client has no CRL for, and doesn't trust, the C3.2 Local Root). A scripted client completed a secure session with it only when told to accept an untrusted certificate, so the certificate works cryptographically but strict clients reject it. A certificate from your own CA, with Basic Constraints, avoids the error: with the CA-issued certificate, UaExpert connected without any certificate error.
Question: Which security policies does the OPC UA server support?
Answer: On the DA30D with 3.2.1060.0 (18) the server offered seven endpoints: None (for lab use only), and Sign and Sign & Encrypt for each of Basic256Sha256, Aes128_Sha256_RsaOaep and Aes256_Sha256_RsaPss. It offers no Basic128Rsa15 or Basic256 endpoints. A Basic256Sha256 Sign & Encrypt session with anonymous logon completed in testing, and earlier tests completed secure sessions on the other policies too. With the test database, anonymous logon was offered on every endpoint. The Crimson 3.2 Software Guide says the server uses the None security profile, but current firmware offers the secure policies.
Question: Can I limit which clients connect by their certificates?
Answer: No. The OPC UA server accepts any client certificate that is within its dates and correctly signed, including self-signed certificates, and its only certificate setting is Server Certificate. To restrict access, set Anonymous Access to Disabled and set a User Name and Password, and limit which networks can reach port 4840. The None endpoint stays offered and can't be turned off, so a client can log on over it without encryption.
Disclaimer
It is the customer's responsibility to review the advice provided herein and its applicability to the system. Red Lion makes no representation about specific knowledge of the customer's system or the specific performance of the system. Red Lion is not responsible for any damage to equipment or connected systems. The use of this document is at your own risk. Red Lion standard product warranty applies.
HMS Technical Support
If you have any questions or trouble contact HMS Technical Support by clicking here.