• Updated
mTLS (mutual TLS): How it works, with diagram
Mutual TLS (mTLS) is TLS where the client and the server each prove who they are with a certificate. In standard TLS, only the server proves itself. In mTLS, the client proves itself right back.
This mutual authentication is what separates mTLS from standard TLS. It’s built for machine-to-machine communication: service meshes like Istio and Linkerd turn it on by default, and API gateways, IoT devices, and zero trust architectures use it too.
What is TLS, and why isn’t it enough?
Before understanding mTLS, it helps to understand what standard TLS does, and what it leaves out.
TLS (Transport Layer Security) is the protocol that secures most internet traffic today. When your browser connects to https://ngrok.com, TLS is doing two things: authenticating the server (via its certificate) and encrypting the connection so nobody can read the data in transit.
That authentication is one-directional. The server proves its identity to you, but you don’t prove your identity to the server. For a public website, that’s fine: the server doesn’t need to know who you are just to serve a web page. Application-layer authentication (username and password) handles that.
For service-to-service communication, the situation is different. There’s no human logging in. TLS already tells Service A that it’s talking to the real Service B. It tells Service B nothing about who’s calling: the request could come from Service A, or from an attacker who has compromised the network. A shared secret or API key helps, but the caller sends it with every request, so a log or a proxy can leak it, and an attacker can replay it. A private key never leaves the service that owns it, and a certificate from a certificate authority that Service B trusts ties that key to Service A’s identity.
That’s the gap mTLS fills.
How does mTLS work?
The mTLS handshake extends the standard TLS handshake by adding a client certificate exchange step. Here’s the full sequence in TLS 1.3:
1. Hellos and key exchange
The client sends a ClientHello with the TLS versions and cipher suites it supports, plus a key share: a one-time public key made for this connection. The server answers with a ServerHello that picks the version and cipher suite and carries its own key share.
Each side combines its own one-time private key with the other’s key share, using a key agreement algorithm such as ECDHE, and arrives at the same secret without ever sending it. The session keys come from that secret. Everything after the ServerHello is encrypted, including both certificates. In TLS 1.2, encryption starts only after the ChangeCipherSpec message near the end of the handshake, so both certificates cross the network unencrypted.
2. The server asks for a certificate and proves itself
The server sends a CertificateRequest, which asks the client to present a certificate. This is the message a standard TLS handshake leaves out.
Then the server sends:
- Its
Certificate, which holds its public key and a signature from a certificate authority (CA). - A
CertificateVerify, a signature over the handshake so far, made with the private key that matches the certificate. - A
Finishedmessage, which confirms that nobody tampered with the handshake.
A certificate is a name and a public key, signed by the CA’s private key:
3. The client checks the server
The client checks that:
- The certificate chains to a CA it trusts, hasn’t expired, and names the host it meant to reach.
- The signature in
CertificateVerifymatches the public key in the certificate.
The second check is the one that proves identity. A certificate isn’t a secret, so anyone can copy one. Only the holder of the matching private key can produce the signature. Standard TLS runs this same check, and it’s what stops an attacker from impersonating the server.
4. The client proves itself
The client sends its own Certificate, signed by a CA the server trusts, followed by its own CertificateVerify and Finished. In standard TLS, the client sends only Finished.
5. The server checks the client
The server runs the same checks on the client: the certificate must chain to a CA the server trusts, and the signature must match the certificate’s public key. If the client sent no certificate, a certificate from a CA the server doesn’t trust, or a signature made with another key, a server that requires mTLS sends a TLS alert and closes the connection.
This is the check mTLS adds. An attacker who copies a client’s certificate can’t produce the signature without the client’s private key, and an attacker with their own key pair can’t get a certificate from your private CA.
A TLS 1.3 client can start sending application data right after its Finished, so it may find out about the rejection only when it reads the alert. The server discards anything a rejected client sent, so none of it reaches your application.
If both checks pass, application data flows in both directions, encrypted with the session keys from step 1. Those keys came from one-time key shares, not from the keys in the certificates, so someone who records the traffic and later steals a certificate’s private key still can’t decrypt it.
The mTLS handshake diagram
Put the five steps together and you get the whole handshake. The numbers match the steps above, and the rows in bold blue are the ones mTLS adds to TLS.
Grab the diagram as a PNG, a light SVG, or a dark SVG.
Want to see this handshake succeed and fail for real? Skip to the hands-on walkthrough: you’ll generate a CA and client certificate, put an mTLS-protected endpoint in front of a local service, and watch curl get rejected without a certificate.
mTLS vs TLS: key differences
The core trade-off is complexity vs. assurance. Standard TLS is simpler to operate because only server certificates need managing. mTLS requires issuing, rotating, and revoking client certificates too, but in return you get cryptographic proof that both parties are who they claim to be.
mTLS authentication: how certificates work
The foundation of mTLS is X.509 digital certificates. Understanding these explains why mTLS is stronger than shared secrets or API keys.
Certificate authorities (CAs) are the root of trust. A CA is an entity that issues certificates, signing each one with its private key to vouch for the certificate holder’s identity. In an mTLS setup, you run your own private CA, because you don’t want arbitrary clients on the internet to be able to obtain a certificate. Public CAs have also stopped issuing client certificates: Let’s Encrypt, for example, removed the client authentication EKU from its certificates in 2026.
Certificate issuance works like this: a service generates a key pair (public + private), creates a Certificate Signing Request (CSR) containing its public key and identity information, and submits it to the CA. The CA verifies the identity and signs the certificate. The private key never leaves the service.
Certificate verification at handshake time asks: does this certificate chain back to a CA I trust? Is it expired? Has it been revoked?
Revocation is the Achilles heel of certificate-based auth. If a service’s private key is compromised, you need to revoke its certificate quickly. Two mechanisms handle revocation:
- OCSP (Online Certificate Status Protocol) lets the verifier query the CA in real time for a certificate’s current status.
- CRL (Certificate Revocation List) is a list of revoked certificates that the CA publishes and verifiers download periodically.
For production mTLS, rotate short-lived certificates that expire every few hours or days automatically. Rotation limits the blast radius of a compromised key without depending on revocation infrastructure being available, or on the verifier checking revocation at all.
What is an mTLS client certificate?
An mTLS client certificate is the certificate a client presents in step 4 of the handshake. It’s an ordinary X.509 certificate: nothing in its format is specific to mTLS. The server checks it in step 5 the same way the client checked the server’s certificate in step 3, except there’s no hostname to match.
What makes it a client certificate is what’s inside it:
- The subject, or a subject alternative name (SAN), names the client, such as a service, a device, or a customer.
- The issuer is the CA the server trusts for clients, usually your private CA.
- The public key matches a private key that stays on the client.
- The extended key usage (EKU) extension usually lists
clientAuth, which marks the certificate for client authentication. A server certificate listsserverAuthinstead.
To try one, generate a CA and a client certificate with openssl, then pass it to curl with --cert and --key.
When to use mTLS
mTLS shines in environments where all participants are machines and you can control certificate issuance:
Microservices and service meshes. Service meshes like Istio and Linkerd use mTLS by default for all intra-cluster traffic. Every service gets a certificate, and mutual authentication happens transparently at the sidecar proxy layer.
API gateways. When your API gateway receives requests from partner services or internal clients, mTLS gives you cryptographic proof of which client is connecting. That’s stronger than API keys, which can be shared or leaked. See how ngrok works as an API gateway with mTLS for exactly this pattern.
Zero trust networks. Zero trust security assumes no implicit trust based on network location: every connection must be authenticated regardless of whether it’s internal or external. mTLS is the standard mechanism for enforcing this for machine identities.
IoT devices. Devices in the field can hold a certificate provisioned at manufacture time. When they connect home, mTLS verifies the device is genuine, not an attacker who has taken over the device’s IP address.
Webhooks and callbacks. If your service sends webhooks to customer endpoints, your service is the client. TLS already verifies the customer’s endpoint for you. mTLS adds the other direction: the customer’s endpoint verifies that each webhook came from your service, and rejects anyone else who finds the URL.
mTLS is generally not used for browser-to-server connections, because distributing client certificates to end users at scale is operationally difficult. For human-facing authentication, OAuth 2.0 and OpenID Connect are the standard choice.
mTLS challenges and limitations
Weigh these costs before you roll out mTLS:
Certificate lifecycle management. Every service needs a certificate, and certificates expire. Automating issuance and rotation is critical, because manual certificate management at scale is a source of outages, not security.
Debugging. Encrypted connections with mutual auth are harder to inspect than plain HTTP. Tools like ngrok’s Traffic Inspector help here by capturing the decrypted request/response at the gateway layer before forwarding to your upstream.
CA infrastructure. Running a private CA requires operational care. If an attacker gets the CA’s private key, you can’t trust any certificate it has signed. Keep CA keys in a hardware security module (HSM) or a secrets manager with tight access controls.
Performance. The additional certificate verification during the handshake adds a few milliseconds of latency compared to standard TLS. For long-lived connections this is negligible; for high-frequency short-lived connections it can accumulate.
How to implement mTLS with ngrok
ngrok’s terminate-tls Traffic Policy action puts mTLS in front of any service without changing your application code. ngrok verifies the client certificate in the ngrok cloud, rejects anything not signed by your CA, and forwards only authenticated traffic to your upstream. It’s the same building block behind ngrok’s secure customer connectivity, where mutual TLS authenticates both ends of a private link.
The whole thing takes about five minutes. You’ll need openssl, curl, and an ngrok account on the Pay-as-you-go plan, which is where mTLS is available. Its monthly fee counts as a credit against usage, so trying this costs effectively nothing.
1. Generate a CA and a client certificate
If you already run a private CA, skip this and use your existing CA certificate.
2. Write the Traffic Policy
Paste the contents of ca.crt into policy.yml. The min_version line accepts only TLS 1.3, the handshake this post describes. The second rule is optional: it passes the verified client’s identity to your upstream as a header, which ngrok doesn’t do on its own.
3. Start an mTLS-protected endpoint
Point ngrok at any local service, for example one on port 8080:
4. Test it
Use the URL ngrok prints. Without a client certificate, the handshake fails before any request reaches your service:
With the certificate signed by your CA, the request goes through, and your service sees x-client-cn: ExampleClient:
That’s mutual TLS end to end: your CA decides who gets in, and the ngrok network enforces it.
ngrok doesn’t check CRLs or OCSP, so revoking a client certificate at your CA doesn’t block it at ngrok. To cut off a leaked certificate, deny its serial number with a Traffic Policy rule on conn.tls.client.serial_number, or replace the CA and reissue every client certificate. Short-lived client certificates limit how long a leaked one stays useful.
For uploading your CA to the dashboard instead of inlining it, matching on other certificate fields, and terminating mTLS at the agent instead of in the ngrok cloud, see the mTLS termination docs. To put mTLS in front of an API, see mTLS for API gateways.
Ready to try it? Create an ngrok account and you’ll have an mTLS-protected endpoint running in minutes.
Frequently asked questions
mTLS (mutual TLS) is TLS where the client and the server each prove who they are with a certificate. In standard TLS, only the server proves its identity. In mTLS, the client also presents a certificate and proves it holds the matching private key, and the server rejects any client that can't.
Standard TLS is one-way: only the server presents a certificate. mTLS is two-way: both the client and the server exchange and verify certificates against a trusted certificate authority. That makes mTLS a good fit for machine-to-machine communication, where no user logs in to prove who the caller is.
In TLS 1.3, the mTLS handshake works in five steps: (1) the client and server trade hellos that carry one-time key shares, and derive the keys that encrypt the rest of the handshake, (2) the server requests the client's certificate, then sends its own certificate and a signature made with its private key, (3) the client verifies the server's certificate against a trusted certificate authority and checks the signature, (4) the client sends its own certificate and signature, and (5) the server runs the same checks on the client and rejects the connection if either one fails.
An mTLS diagram maps the mutual TLS handshake flow: the two hellos that set up encryption, the server's CertificateRequest, the server's certificate and signature, the client's certificate and signature, and each side checking the other against a trusted certificate authority. Seeing the flow visually makes clear why a client without a CA-signed certificate and its private key never gets a request through to the application.
Yes, in both directions. Standard TLS already stops an attacker from impersonating the server, because the server must sign the handshake with the private key that matches its CA-signed certificate. mTLS applies the same check to the client. An attacker who copies a client's certificate can't produce that signature without the client's private key, so the server rejects the connection.
Yes, as long as each private key stays secret. The protocol itself is sound; the main risk is operational: certificate lifecycle management. If a private key leaks, revoke its certificate right away. Not every verifier checks revocation, though (ngrok doesn't), so short-lived certificates with automated rotation are the surer way to limit how long a leaked key stays useful.
mTLS is best suited for service-to-service communication where both sides are machines: microservices architectures, API-to-API calls, zero trust network access, IoT device authentication, and service mesh environments. It isn't typically used for browser-to-server connections because distributing client certificates to end users is operationally complex.
The main benefits of mTLS are: mutual authentication (both sides are cryptographically verified), protection against impersonation of the client as well as the server, a credential that never travels with a request, alignment with zero trust security principles, and an auditable certificate record for compliance.
mTLS authentication is the process by which both the client and server verify each other's identity using X.509 digital certificates issued by a trusted certificate authority. Unlike password-based authentication, mTLS uses asymmetric cryptography: each party proves it holds a private key without ever sending it, so there's no secret on the wire to intercept or replay.
An mTLS client certificate is an ordinary X.509 certificate that a client presents to prove its identity in the mTLS handshake. It names the client, carries a signature from a certificate authority the server trusts (usually a private CA), and holds a public key that matches a private key that never leaves the client. It usually lists clientAuth in its extended key usage, which marks it for client authentication.
Answers come from ngrok.com and the ngrok docs, and can be wrong. Check the linked pages before you rely on one.
Related posts
Terminate TLS however (and wherever) you want with Traffic Policy
Need custom certs? Want fast mTLS setup? ngrok’s terminate-tls action gives you complete TLS control from one declarative config.
Authentication with ngrok
Add authentication to any ngrok endpoint in minutes with Traffic Policy. Choose Basic Auth, OAuth login, OpenID Connect, or JWT validation, no code required.