IMD SolutionComputing LibraryShop main store

Troubleshooting

Why the M262 MQTT client reports CertificateNoKey

Edge computing and IIoT Published 7 min read By IMD Solution engineering team

Short answer

CertificateNoKey is a local status: the controller found the client certificate in its trusted partition but no private key bound to it, and mutual TLS stops before the broker is contacted. Compare the certificate and key with OpenSSL, then import the pair through the store or CSR route your firmware documents, or end client authentication at an edge gateway.

On this page
  1. What does CertificateNoKey mean on an M262 MQTT client?
  2. How do you confirm the fault is the key and not the broker?
  3. Which three files does mutual TLS need, and which one does the M262 refuse?
  4. How do you prove the private key matches the client certificate?
  5. Where does the M262 store the client private key?
  6. Should you use the customer's key or a device-generated CSR?
  7. What is the procedure once the certificate has its key?
  8. Questions asked

CertificateNoKey on an M262 MQTT client is a local status, not a broker reply: the controller found the client certificate in its trusted partition but no private key bound to it, and a TLS client proves its identity by signing the handshake with that key, so the session never opens. The fix follows a fixed order: confirm the status is local, inventory the three files, prove the key matches the certificate, find the key store or the CSR route your firmware documents, then run a gated procedure to a verified publish.

What does CertificateNoKey mean on an M262 MQTT client? #

It means the controller found a client certificate in its credential store but no private key bound to that certificate, so the TLS handshake stops on the controller before any authentication request reaches the broker. The certificate alone is public data that anyone can copy, so it proves nothing on its own; in mutual TLS the client backs its certificate by signing the handshake with the matching private key, and with no key there is no signature and no session. You read the status in MainVisu, where the MQTT example reports it as CertificateNoKey. Treat it as a storage and binding fault on the controller, not as a network fault or a credential rejection by the broker.

How do you confirm the fault is the key and not the broker? #

Read the status in MainVisu: CertificateNoKey is raised on the controller before the broker is contacted, so broker address, port, CA trust and client policy cannot produce this status. Then branch:

  • Status reads CertificateNoKey: continue with the file inventory below.
  • Status shows a different connection or authentication error: the key pairing is not the cause. Check broker name resolution, the port, CA trust and the broker's client policy first.

Ask the customer one question before any import: does the broker policy actually require client certificates? TLS 1.2 lets a client send a certificate list of zero length when the server does not request one, as this mbedTLS discussion of RFC 5246 works through. If the answer is no, remove the client certificate from the MQTT configuration and connect with the CA certificate alone; nothing then asks for a key, so the status cannot appear.

Which three files does mutual TLS need, and which one does the M262 refuse? #

A mutual TLS package has three items: the CA certificate that lets the controller validate the broker, the client certificate that names the controller to the broker, and the client private key that signs the handshake. The reported behavior on this controller, under Machine Expert 2.0 (ME 2.0) with the vendor MQTT example modified to accept certificates:

Item Role Secret? Trusted partition on the M262
Server (CA) certificate Lets the controller validate the broker No Accepted
Client certificate Identifies the controller to the broker No Accepted
Client private key Signs the TLS handshake Yes Refused

Check the format of each file before you touch the controller. PEM files are text with -----BEGIN CERTIFICATE------style headers; DER files are binary; a PKCS#12 bundle (.p12 or .pfx) holds certificate and key together and normally asks for a password; a key whose PEM header contains the word ENCRYPTED needs its passphrase at every use. If the key arrives inside a bundle, split it into separate files on a trusted engineering PC, never a shared one, and note which format your firmware's import expects.

How do you prove the private key matches the client certificate? #

Compare the RSA modulus digest of both files with OpenSSL on an engineering PC: identical digests mean the pair is valid, and different digests mean the key belongs to another certificate. Run:

openssl x509 -in client.crt -noout -modulus | openssl md5
openssl rsa -in client.key -noout -modulus | openssl md5

Worked example, with example output: the certificate line prints MD5(stdin)= 4c1f9a07d3e2b8650aa6f1d2c9e7345b and the key line prints MD5(stdin)= 4c1f9a07d3e2b8650aa6f1d2c9e7345b. The two 128-bit digests are equal, so the key holds the private half of the certificate's key pair. Had the key line printed MD5(stdin)= b7e0251c44af9d3821cc6b0d5ef7a293, the digests would differ and the key would belong to some other certificate: stop and request the correct key instead of importing anything.

For an EC key there is no RSA modulus to compare; compare the public keys instead:

openssl x509 -in client.crt -pubkey -noout
openssl pkey -in client.key -pubout

Identical output blocks mean the pair matches. A match sends you to the key-location search next; a mismatch never reaches the controller.

Where does the M262 store the client private key? #

The MQTT manuals do not name a store for it, so the answer comes from the controller security documentation for your exact firmware, read in a fixed order before you touch the project:

  1. Record the firmware version from the controller's device information together with your ME 2.0 version. The credential model can differ between firmware releases, so every finding below is scoped to those two numbers.
  2. In ME 2.0, open the controller's device editor and find its certificate or security management page. Note every store it lists, the trusted partition and any device or own-certificate store, and whether any entry accepts a key file or a key-with-certificate pair.
  3. Read the certificate section of the controller programming guide and of the MQTT library guide shipped with your ME 2.0 version, applying the same checks as in controller MQTT TLS support: what the documentation must confirm.
  4. If the documents stay silent, open a case with Schneider Electric support through the official channel, quoting the controller reference, the firmware version, the ME 2.0 version and the exact status CertificateNoKey. Ask two questions: where is the client private key stored, and in what format.

Three outcomes decide the branch:

  • A store accepts certificate plus key, or a bundle: import the pair there and go to the procedure.
  • The controller generates its own key pair and exports a certificate signing request: take the CSR route in the next section.
  • Neither exists on your firmware: it cannot present a client certificate at all. Update firmware only from the manufacturer's official download channel, or terminate the client-authenticated TLS on an edge gateway, a fanless mini PC running an MQTT bridge with certificates set up as in configuring MQTT TLS certificates in Node-RED on an edge PC, so the controller-to-gateway hop stays inside the control network.

Should you use the customer's key or a device-generated CSR? #

Prefer the device-generated route: if your firmware can generate a key pair and export a certificate signing request, the private key never leaves the controller and the customer signs only the request. Most brokers and cloud endpoints register a certificate that was signed from a CSR, so this route loses nothing and removes the weakest step, moving a key file between parties. If your firmware has no CSR generation, a customer-supplied key must travel over a protected channel and enter only through the import path your firmware documents. Never paste a key into the trusted partition or rename it to look like a certificate: the store validates the object type of everything it accepts, and the refusal you saw is that validation doing its job.

What is the procedure once the certificate has its key? #

Run five gated steps: trust the CA, bind the pair, name the certificate in the MQTT example, set the controller clock, then confirm one published value arrives on the broker.

  1. Import the CA certificate into the trusted store. Gate: it appears in the list with the subject you expected.
  2. Import the client certificate together with its key through the store and method your firmware documents, or receive the signed certificate back on the CSR route. Gate: the entry shows as a certificate with a key, never a certificate alone.
  3. In the MQTT example, reference the client certificate by the exact name the store shows. Set the broker address, the TLS port the customer specifies, 8883 being the common MQTT-over-TLS port but the customer's value deciding, and a client ID the broker policy permits, because brokers that enforce policies reject client IDs and topics outside them.
  4. Check the controller clock against the certificate's validity dates. Validation is date-bound, and a controller that lost its time fails with perfectly good files.
  5. Download, run and watch MainVisu. Gate: CertificateNoKey clears and the status reaches connected. Publish one test value and confirm it on the customer's subscriber on the agreed topic; that confirmed payload, not the connected flag, ends the job.

If the status now turns into a certificate validation error, the usual next cause is the name inside the certificate, the case where a Flexy certificate lacks the broker DNS name.

Decision by case:

  • Digests match and a documented store accepts the pair: import it and run the five steps.
  • The firmware generates a key pair and a CSR: generate on the controller, let the customer's CA sign it, import only the returned certificate.
  • No key store and no CSR exist on your firmware: the controller cannot do client-certificate authentication; terminate TLS at a gateway or update firmware from the official channel.
  • The broker policy requires no client certificate: drop the client certificate and connect with the CA certificate alone.

Questions asked

How do I tell whether the key file is passphrase-protected before import?

Open the file in a text editor and read its first line. A header reading BEGIN ENCRYPTED PRIVATE KEY means every use of the key asks for the passphrase, and a PKCS#12 bundle prompts for its password when opened. Decrypt or unpack it on the trusted engineering PC with the passphrase the customer supplied, import the form your firmware documents, and delete the working copies.

Does the same failure apply when the broker is AWS IoT?

Yes, and it cannot be avoided there: AWS IoT requires a client certificate for every connecting device, so a certificate without its key can never connect. AWS IoT also registers device certificates signed from a CSR, so when your firmware generates a key pair and a signing request, the controller keeps its private key and you register only the signed certificate.

How do I read the validity dates to check the controller clock?

Run openssl x509 -in client.crt -noout -dates on the engineering PC. It prints a notBefore line and a notAfter line, for example notBefore=Mar 1 00:00:00 2025 GMT and notAfter=Mar 1 00:00:00 2026 GMT. Set the controller clock inside that window before connecting; a clock outside it fails validation even with correct files.

How do I prove the broker used the certificate I imported?

Ask the customer to read the broker connect log while your controller connects. Brokers that request client certificates can log the subject or common name of the certificate that authenticated each session, so the entry for your client ID should carry your controller certificate name. A matching name in that log proves the stored pair is the one signing the handshake.

Keep reading

  • Troubleshooting

    Fix CODESYS MQTT TLS peer verification handshake failure

    Enabling peer verification in the MQTT client's TLS context fails because the controller has no trust anchor for the broker's certificate chain. Import the issuing CA certificate into the runtime's trusted certificate area through the security screen; the client identity .pfx does not provide that trust. A TCP_Init error is an earlier socket-layer fault, so check endpoint settings before touching certificates.

    Edge computing and IIoT

  • Troubleshooting

    Why an MQTT client connects without its TLS client certificate

    An mqtts branch that assigns Certificates = null enables TLS but presents no client certificate, so AWS IoT's mutual TLS check ends the handshake before CONNECT. Build a certificate object from the thing certificate and its private key, assign it to the TLS options, keep chain validation on, and confirm with a captured CONNECT result.

    Edge computing and IIoT

  • How-to

    Set up the MQTT Client SL library on a CODESYS controller

    MQTT Client SL is part of the CODESYS IIoT Libraries SL package. Verify the exact controller runtime and its license, pin the library version, batch JSON per asset, and set the controller clock before opening a TLS session.

    Edge computing and IIoT

Sending Sparkplug B payloads over an MQTT WebSocket client