IMD SolutionComputing LibraryShop main store

Troubleshooting

Why MQTT over port 443 to a cloud needs ALPN

Edge computing and IIoT Published 8 min read

Short answer

AWS IoT Core accepts MQTT with TLS client authentication on port 443 only when the client sends the ALPN protocol name during the TLS handshake. An edge gateway whose MQTT interface has no ALPN setting cannot use 443, so keep outbound 8883 and scope the firewall rule to the gateway's source IP instead of enumerating the AWS address pool.

On this page
  1. Why does MQTT to AWS IoT Core work on 8883 but fail on 443?
  2. What is ALPN and where does it live in the connection?
  3. How do I check whether my gateway can send it?
  4. What exactly does AWS IoT Core accept on ports 443 and 8443?
  5. How do we open outbound 8883 without listing 100+ AWS addresses?
  6. How do I verify the session before calling it fixed?
  7. What if the customer network will never open 8883?
  8. Will a firmware or TLS library update add ALPN support?
  9. Questions asked

Keep the working session on outbound port 8883 and have the customer scope one egress firewall rule to the gateway's source address. AWS IoT Core accepts MQTT with TLS client authentication on port 443 only when the client sends an ALPN protocol name during the TLS handshake, and an edge gateway whose MQTT interface has no ALPN parameter cannot do that: switching the port alone yields a TCP connection that never becomes an MQTT session. Below is why 443 behaves differently, how to settle from the documentation whether a client can send ALPN, the single-rule firewall fix that replaces an unworkable list of 100-plus rotating AWS addresses, and what to put in front of the gateway when 8883 stays closed for good.

Why does MQTT to AWS IoT Core work on 8883 but fail on 443? #

Because port 443 carries the same MQTT-over-TLS traffic only when the TLS handshake presents AWS's ALPN protocol name; on 8883 no ALPN is required, so a gateway that never sends the extension connects on 8883 and fails on 443.

On 8883 the endpoint is dedicated to MQTT over TLS: a client with the root CA file, its device certificate and its private key negotiates TLS, sends CONNECT, and receives its CONNACK. On 443 the same endpoint also carries ordinary HTTPS, so the listener must tell the two apart before the first encrypted byte, and ALPN is how. No accepted protocol name in the ClientHello means the session never becomes MQTT.

The field symptom follows directly: the port is changed, the TCP three-way handshake completes, TLS starts, then the connection drops and the client retries in a loop. Nothing is wrong with the certificates, because the same credentials worked on 8883 minutes earlier. This is a handshake negotiation failure, not a certificate or policy failure; for the layer-by-layer method, see diagnosing MQTT connect failures when TCP still works.

What is ALPN and where does it live in the connection? #

ALPN — Application-Layer Protocol Negotiation, standardized in RFC 7301 — is a TLS extension listed in the ClientHello: the client offers protocol names, the server selects one in its ServerHello, and the negotiated session carries that protocol. It is the same mechanism a browser uses to obtain HTTP/2 over an HTTPS connection.

It sits below MQTT. Nothing in a topic, payload, client ID or username can substitute for it, because all of those travel after the TLS handshake completes. On AWS IoT Core's 443 listener, the protocol name is what routes the connection into the MQTT broker rather than the HTTPS front door; AWS documented this when it enabled MQTT with TLS client authentication on port 443, and its device communication protocols reference still states the condition. The name is an AWS-specific value published in that documentation, so copy it exactly, because the handshake matches it as an exact string.

How do I check whether my gateway can send it? #

Read the parameter list in the interface's current programming reference: the gateway discussed here exposes keys for port, keepalive, log, cafile, certfile and keyfile — and no ALPN key — which is the documented answer that this connection cannot be made to work on 443.

The documented setup, exactly as this class of interface accepts it, looks like this (DeviceID$ is the device identifier string the program already builds):

MQTT "open", DeviceID$, Endpoint$
MQTT "setparam", "port", "443"
MQTT "setparam", "keepalive", "300"
MQTT "setparam", "cafile", "/usr/AmazonRootCA1.pem"
MQTT "setparam", "certfile", "/usr/" + DeviceID$ + ".crt"
MQTT "setparam", "keyfile", "/usr/" + DeviceID$ + ".key"
MQTT "connect"

Every TLS credential is present — root CA, device certificate, private key — and the port can be set to 443 with one line. What is not present is any key that carries a protocol name into the ClientHello. If your client's documentation names no ALPN or protocol-name setting, stop testing 443 on that device: you are not missing a hidden option, the interface cannot express the requirement. A capture showing a ClientHello with no ALPN extension confirms it, but the parameter list already settles the question.

What exactly does AWS IoT Core accept on ports 443 and 8443? #

On 443 the device data endpoint accepts MQTT over TLS with client certificates when the ClientHello carries the AWS ALPN protocol name, and it accepts ordinary HTTPS; port 8443 is another HTTPS port, and the AWS protocol matrix lists the Jobs endpoint as not offering MQTT on 443 at all.

Port What AWS IoT Core accepts Condition for MQTT
8883 MQTT over TLS with client certificates Certificates only, no ALPN needed
443 MQTT over TLS with client certificates ClientHello must carry the AWS ALPN protocol name
443 HTTPS to the AWS IoT endpoints Not MQTT, no ALPN involved
8443 HTTPS Not an MQTT port

For a client that cannot send ALPN, the table reduces to one usable port, and that is the number to give the customer's network team: the conversation is not "which AWS server IP" but "one host, one outbound port".

How do we open outbound 8883 without listing 100+ AWS addresses? #

Write one egress rule keyed on the gateway's source address and destination port 8883 — permit TCP from that single host to any destination on 8883 — and the customer's list of 100-plus rotating AWS addresses stops mattering.

  1. Reserve the gateway's address, by DHCP reservation or static assignment, so the rule has an object that does not drift.
  2. Request the rule as egress-only: source the gateway's address, destination any, destination port 8883/TCP. The gateway is always the client, and return traffic rides the stateful flow.
  3. Offer MAC-based matching only if the firewall sits on the gateway's own Layer-2 segment; past the first router the source MAC is gone, so on a routed plant network the IP is the workable key.
  4. Answer the destination question directly: the pool behind the endpoint counted more than 100 addresses and rotates, so a hand-built destination list is stale before it is installed. Scope by source instead.

This is also the tighter rule from the IT side — one host on one outbound port — compared with a port-443 path every device on the plant network already uses. If the security team wants less than "any destination", the honest answer is that the service's rotating pool makes destination enumeration unworkable.

How do I verify the session before calling it fixed? #

Confirm four layers in order — DNS resolves the endpoint, TCP connects, TLS completes with the client certificate, and the broker returns an MQTT CONNACK followed by a message you can see published — because a completed TCP handshake proves reachability and nothing else.

  • Name resolution: the endpoint hostname resolves; getting a different pool member than yesterday is normal.
  • Transport: the TCP three-way handshake to port 8883 completes.
  • TLS: the handshake finishes with the device certificate and no alert.
  • MQTT: CONNACK comes back, and a test message appears on the topic in the cloud console or on a subscribed client.

Then turn the keepalive into numbers. This gateway requests a keepalive of 300 seconds — the keepalive key above — which is the longest the TCP flow may sit idle. A full day therefore contains 86,400 s ÷ 300 s = 288 keepalive exchanges. A 24-hour log showing roughly 288 keepalive request/response pairs plus the publishes says the firewall is passing the established flow; a far lower count paired with repeated new TCP connections says the flow state is being dropped. That fault is on the firewall side: every stateful device on the path must idle out above 300 s, or the gateway's keepalive must be lowered below the shortest timeout on the path.

What if the customer network will never open 8883? #

Put an ALPN-capable MQTT client in front of the gateway: a small edge computer on the plant network terminates TLS to AWS on 443 with the protocol name set, while the gateway publishes to it locally where no firewall stands between them.

The pattern is a local bridge: the gateway's MQTT target becomes the edge computer's address on the LAN, and the edge computer's client — a Mosquitto bridge, a Node-RED flow or a vendor IoT SDK — holds the device certificate and sets ALPN on the outbound 443 session. The same shape is used when bridging PLC data to MQTT with an edge PC, and the certificate handling for one common stack is covered in configuring MQTT TLS certificates in Node-RED on an edge PC. Where the front end is hardware you specify rather than reuse, a fanless mini PC in the same cabinet is the usual choice. Treat the certificate and private key on that computer as plant credentials: bind the local listener to the plant VLAN and restrict which hosts may publish through it.

Will a firmware or TLS library update add ALPN support? #

Not unless the vendor adds the parameter: ALPN has been part of OpenSSL since version 1.0.2, so the TLS library under a current firmware almost certainly already has the capability — what is missing is the MQTT interface's willingness to pass the name, and that is application code the vendor controls.

That is what happened here. A later firmware refreshed the TLS library, ALPN looked plausible again, and the re-check against the interface documentation still found no parameter; the vendor confirmed the MQTT function does not support ALPN and had nothing on its roadmap. Treat the documented parameter list as the contract. Raise the enhancement request through the vendor's sales channel so it counts as demand, and design around it today — the 8883 rule or the front-end computer — instead of retesting 443 after every release.

Questions asked

Is there any other port AWS IoT Core serves MQTT on?

No. MQTT with TLS client authentication runs on 8883, and on 443 only with the ALPN protocol name in the handshake; 8443 is HTTPS. For a client that cannot send ALPN, 8883 is the one usable port, which is why the firewall rule is the fix rather than another port change.

Can MQTT username and password settings stand in for ALPN?

No. ALPN is an extension of the TLS handshake itself, sent before any MQTT bytes. Username, password and client ID are MQTT-level fields that travel after TLS completes, so if the interface has no ALPN parameter, no MQTT-side setting can supply the missing protocol name.

Does the firewall also need an inbound rule for port 8883?

No. The gateway is the client: it initiates the outbound TCP connection, and the firewall's stateful inspection carries the return traffic on the same flow. The rule to request is egress-only, one source address to destination port 8883.

Can several gateways share one source-address rule?

Only if they leave through the same address. If the site NATs the plant network to one egress IP, the firewall sees that single address and one rule covers every gateway behind it; per-device control then has to come from unique device certificates at the broker, not from the firewall.

Keep reading

  • How-to

    Bridge a cellular tracker's TCP stream into MQTT for AWS IoT Core

    Build a small ingest service on your edge PC: it terminates the tracker's raw TCP session, decodes each stored record, and republishes one MQTT message per fix over TLS on port 8883. Acknowledge a packet only after every publish is confirmed, or a coverage-gap batch is silently lost.

    Edge computing and IIoT

  • Troubleshooting

    Fixing MQTT cloud broker data not reaching SCADA tags

    Get the gate right first: MQTT over TLS belongs on port 8883, with the TLS mode and client identity the broker actually requires. An independent client such as MQTT Explorer on the same PC proves only its own settings, not the driver's. If the driver cannot perform the service-specific handshake Azure IoT Hub needs, no tag mapping will ever fill.

    Edge computing and IIoT

  • Troubleshooting

    Fixing X.509 certificate auth to Azure IoT Hub over MQTT

    The controller fails because the selected .key file is only half an X.509 credential: TLS client authentication must present the device certificate and its chain, so the key passes file validation and the handshake still has nothing to send. Convert the test certificates to PEM, import the leaf-plus-chain with its matching key as one pair, make the hub's device ID or thumbprint match, and verify with a real MQTT connection.

    Edge computing and IIoT