IMD SolutionComputing LibraryShop main store

Explainer

What actually links x.crt and y.key to an MQTT client block

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

Short answer

An MQTT client block never receives x.crt or y.key as a file path. The certificate and its private key are imported or registered into the controller runtime's certificate store by the vendor's documented procedure, the block gets a reference to that store entry, and the only proof that the pairing works is a confirmed TLS session in which the broker authenticates the client certificate.

On this page
  1. The block takes a store reference, not a path
  2. What the standards require of the pair
  3. Check the pair before it reaches the controller
  4. Register the pair through the documented procedure
  5. Prove the pairing with a confirmed session
  6. Test against a broker you control
  7. What is fixed and what only your installed version decides
  8. Questions asked

An MQTT client block never receives x.crt or y.key as a file path. The two files are a matched X.509 certificate and its private key, and a controller runtime accepts them only through its certificate store: you import or register the pair using the vendor's documented procedure, and the function block receives a reference to that store entry through its TLS configuration. The proof that the link is right is not a clean compile or a connected flag — it is a confirmed TLS session in which the broker authenticates the client certificate and logs its subject. This article walks that chain from matched files to a confirmed session on the MQTT_Client block of the CODESYS MQTT Client SL library, and it is explicit about what only your installed library and runtime versions decide.

The block takes a store reference, not a path #

File names describe where the pair lives on an engineering workstation. On the controller, the runtime keeps certificate and key material in a certificate store of its own, outside the application program, and a client block selects an entry from that store through its TLS configuration. The design is deliberate: the private key must not become application data, or it travels inside every project archive and backup copy.

For the MQTT_Client block of MQTT Client SL — part of the IIoT Libraries SL package, which sends messages from a CODESYS controller to an MQTT broker and subscribes to topics — the general product material documents the publish and subscribe side, not the certificate inputs. Those depend on the installed library and runtime versions, so record both before selecting any input. If the library is not yet on the controller, its setup comes first in Set up the MQTT Client SL library on a CODESYS controller. And before selecting inputs at all, confirm from your runtime documentation that TLS with client authentication is supported on the target — that documentation check is exactly what Controller MQTT TLS support: what the documentation must confirm walks through.

What the standards require of the pair #

Three standards define what the pair is and what the handshake does with it.

RFC 5280 defines the X.509 certificate in x.crt: a public key bound to a subject name, signed by an issuing CA. RFC 7468 defines PEM, the text armor most .crt and .key files carry; the extensions are naming conventions, and the bytes underneath can equally be the binary DER form. TLS — RFC 5246 for version 1.2, RFC 8446 for version 1.3 — defines client authentication: the broker sends a certificate request listing acceptable issuers, the client answers with its certificate chain, and the client proves possession of the key by signing handshake material that the broker verifies against the certificate's public key.

Two consequences matter for the pairing question. The signature proof succeeds only when the key on the controller corresponds to the certificate's public key — a mismatched key is rejected at the handshake, never at compile time. And the broker must hold the issuing CA in its own trust list, because a chain it cannot trace to a trusted CA is rejected no matter how correctly the client store is configured.

Check the pair before it reaches the controller #

Two faults masquerade as configuration faults, and both are cheapest to kill on the workstation.

Format first. Open x.crt in a text editor: a file beginning with -----BEGIN CERTIFICATE----- is PEM per RFC 7468; a binary file is DER. A store that documents one form refuses the other at import, and that refusal reads like a pairing failure.

Match second. Extract the public key from the certificate and from the key file independently, then compare the two fingerprints byte for byte: identical fingerprints mean one pair; differing fingerprints mean the key was regenerated after the certificate was signed, and no store configuration will make them a pair.

Worked example, with illustrative values: the plant CA signs a client certificate with subject CN=plc-line-1 on 2 June 2025, valid for 365 days, for a 2048-bit RSA key pair. The validity arithmetic runs 2 June 2025 plus 365 days, which lands on 2 June 2026 — so a session attempted on 10 July 2026 fails certificate validation at the broker before key possession is ever proven, with a symptom identical to a mismatched pair. The pairing check is the fingerprint comparison, the freshness check is that date window, and the chain check is the issuing CA's name appearing in the broker's trust list. Kill all three on the workstation and whatever fails afterwards is genuinely a runtime or configuration fault.

One safety line belongs here: the private key leaves the workstation exactly once, on its way into the store — a leaked client key lets anyone impersonate the controller to the broker.

Register the pair through the documented procedure #

For the CODESYS IIoT Libraries SL path, the vendor publishes a description titled Usage of client certificates from an external certification authority. That is the documented procedure for importing or registering a client certificate and its key from an external CA, and it is the authority on what representation the runtime expects — follow it rather than assuming that file paths can be wired to MQTT_Client.

Where the store documents a combined bundle import, with certificate and key carried together under one password, prefer it: the pairing question disappears because the two files travel as one object and the store enforces their correspondence.

A key that refuses to import belongs to the format and encoding fault family, not the pairing family; on a PC-side gateway that same family has its own troubleshooting path in Fixing an edge gateway MQTT TLS private key load failure. And when the documented fields do not match the interface your installed MQTT_Client exposes, stop there: the version mismatch is the fault, and no certificate procedure repairs it.

Prove the pairing with a confirmed session #

The proof is a TLS session to a broker that requires client authentication, with the broker's handshake log naming the certificate subject. Set the listener to require a client certificate before you test, because a session that succeeds without one proves nothing about your store entry — the reasons a client still connects clean with no certificate are covered in Why an MQTT client connects without its TLS client certificate.

Read where the handshake fails, because the location splits the fault in two. A rejection at the broker's trust decision is peer verification of certificates, a separate axis from your pairing, covered in Fix CODESYS MQTT TLS peer verification handshake failure. A rejection during the client's proof of key possession points back at the store entry: wrong key, unreadable key, or a reference that resolves to nothing.

If the pair sits registered in the store and the session still fails, hunt on the verification side before touching the certificates. Certificate validation is clock-sensitive: a controller clock outside the validity window fails trust checks that mimic pairing faults — the failure mode behind TLS error 8089 on an S7-1500 CPU, walked through in S7-1500 MQTT TLS error 8089: check CPU clock and certificate trust.

Test against a broker you control #

A public broker cannot supply the pair you want to test with. Client certificates come out of a CA's enrollment process, and a public test broker runs no enrollment for anonymous users, so it issues neither certificate nor key. The fast public test does not exist; build the equivalent.

Run your own lab broker with TLS and a listener that requires client authentication, register your test CA on it, and enroll a test pair from that CA. The complete TLS broker setup on a PC is walked through in Run a secure Mosquitto MQTT lab broker with Node-RED. Against a broker you control, every variable the handshake touches — required issuer, validity window, trust list — is yours to set, which is exactly what a public endpoint never offers.

What is fixed and what only your installed version decides #

Item Status Decision it drives
x.crt, y.key Named pair; the names fix no encoding Check PEM or DER against the store's documented import format
MQTT_Client Function block of MQTT Client SL in IIoT Libraries SL Its certificate inputs come from the installed library version
Usage of client certificates from an external certification authority Documented vendor description The import and registration procedure to follow
Library and runtime versions Not fixed by the general material Record both before selecting any input
Issuing CA on the broker Not part of the client pairing Register the CA in the broker's trust list

The decision, for every case: import the pair through the runtime's certificate store with the documented procedure, reference that entry from the block's TLS configuration, and accept nothing short of a broker-authenticated TLS session as proof of the link. Mismatched fingerprints are a workstation problem; a refused import is a format or version problem; a refused session with a registered, matching, in-window pair is a trust or clock problem. Public brokers are not certificate suppliers — your own lab broker is the test rig.

Questions asked

Can I paste the certificate and key contents into string variables on the block?

No supported route does that, and it is a bad trade even where a runtime tolerates it: key material inside the application ends up in the project file and every archive and backup of it. Keep the private key in the runtime certificate store and let the block carry only the store reference. The store exists precisely so the key never becomes application data.

Must the files be converted before import?

Convert only if the store's documented input format differs from what you hold. A text file beginning with the certificate begin line is PEM; a binary file is DER; some stores also accept a combined bundle that carries certificate and key together under one password, which removes the pairing step entirely. The installed runtime's import documentation decides, not the file names.

What log line proves the broker accepted the client certificate?

The broker's TLS handshake log naming the client certificate subject, recorded on a listener that requires client authentication. A successful publish is weaker evidence: on a broker that permits anonymous TLS, a client can connect and publish with no certificate at all. Confirm the enforcement first, then read the subject line.

The session succeeds — what does the broker authorize the client on?

On the certificate subject, usually the common name in x.crt. Brokers that enforce client authentication typically map that subject to access rules for topics and listeners, so the subject is part of your security design: keep it stable across renewals, or update the broker's authorization mapping with every re-issue. A renewed certificate with a changed subject arrives as an unknown client.

Keep reading

  • Explainer

    Securing ctrlX MQTT data paths to AWS or GCP

    Yes — Node-RED plus Mosquitto can carry ctrlX Data Layer values under X.509 authentication and TLS 1.2, but each of the three connections (publisher to broker, device to broker, uploader to cloud) needs its own trust and client-certificate configuration. DeviceBridge joins only when the chosen AWS or GCP service's protocol calls for it.

    Edge computing and IIoT

  • How-to

    Configuring MQTT TLS certificates in Node-RED on an edge PC

    Configure the MQTT node's own TLS inputs: the broker's CA chain always, the client certificate and private key when the broker requires mutual TLS. A platform certificate store is invisible to Node-RED until the installed integration exposes it, so use persistent files unless store support is verified, and renew in a staged 30-day window.

    Edge computing and IIoT

  • Troubleshooting

    What the trustAnchors parameter must be non-empty MQTT error means

    The trustAnchors parameter must be non-empty exception is the Java TLS engine reporting that the trust store your MQTT client opened holds no certificates, so it cannot validate the broker. Fix it on the client host: import the broker's public server certificate and its CA into that client-side trust store, restart the client, and reconnect. A certificate installed only on the broker never populates the client's store.

    Edge computing and IIoT

Failed to load node catalog: check the gateway and DNS first