Advanced OAuth
Mutual-TLS client authentication
On this page
Introduction
Some applications are services that call Signari from servers of their own, such as a payments system. Each one has to prove who it is, and a shared secret can leak. Transport Layer Security (TLS) is the encryption behind every https address (see the glossary). "Mutual TLS" (mTLS), defined in RFC 8705, lets the application prove who it is with a certificate instead (see the glossary).
With mTLS, the application shows its certificate during the encrypted connection itself. Signari can then bind the application's access tokens to that certificate, so a stolen token is useless on its own.
You register how an application's certificate is matched with
signari client set-tls. The certificate authority Signari trusts is set with
SIGNARI_TLS_CLIENT_CA.
Registering a client
There are two ways to register one. With a "public key infrastructure" (PKI), an authority you trust issues the application's certificate. Without one, the application registers its own certificate. These commands show both:
Shell# PKI: certificates issued by an authority you trustsignari client set-tls -client-id payments -tls-san-dns payments.example.test \ -tls-bound-tokensSIGNARI_TLS_CLIENT_CA=/etc/signari/client-ca.pem signari serve ...# No PKI: the client registers its own certificatesignari client set-tls -client-id jobs -sp-cert ./jobs.crt -tls-bound-tokens
In this example, -tls-bound-tokens also binds each application's tokens to its
certificate, as described below.
Match on exactly one of -tls-subject-dn, -tls-san-dns, -tls-san-uri,
-tls-san-ip, -tls-san-email or a registered certificate. -tls-san-ip matches
an IP address in the certificate, and -tls-san-email an email address, as RFC
8705 allows. Two would have to be combined as AND, which is unexpected, or as
any-of, which is weaker. The database enforces it as a CHECK constraint.
Authentication and binding
Authentication: there is no shared secret to leak from a configuration file, a continuous integration (CI) log or an environment listing.
Binding: cnf.x5t#S256 ties the token to the certificate, so a stolen token
is useless without the private key. It is the same idea as Demonstrating Proof of
Possession (DPoP), which Signari also supports. mTLS suits
service-to-service callers with a PKI. DPoP suits browsers and mobile
applications.
Authenticating with a certificate and then issuing an unbound bearer token leaves
the token no harder to steal than before. With binding on, Signari binds the tokens
of the authorization-code grant and of client_credentials, the grant a service
uses.
Binding is a separate flag from authentication. An application can authenticate by certificate and still want plain tokens during a migration. Turning binding on breaks callers who do not present the certificate at the resource server. So it is a separate choice rather than a side effect.
How one listener accepts both methods
The listener uses tls.RequestClientCert: it asks for a certificate, and verifies
nothing during the handshake. The chain check happens in
VerifyClientCertificate, where it can depend on which method the application
registered.
The usual listener configuration, tls.VerifyClientCertIfGiven with a pool of
certificate authorities, cannot support both methods at once:
- with a pool, a self-signed client is refused during the handshake, before any application code runs;
- with no pool, every offered certificate fails the handshake. That breaks
self_signed_tls_client_auth, the method for applications with no certificate authority.
Both methods work on one listener:
| PKI client, correct SAN | 200, bound to its certificate |
| self-signed client, matching thumbprint | 200, bound to its certificate |
| self-signed certificate presented for the PKI client | refused: chains to nothing |
| PKI certificate presented for the self-signed client | refused: wrong thumbprint |
In this table, the SAN is the certificate's Subject Alternative Name, such as its Domain Name System (DNS) name.
What the chain check protects
Without it, a peer certificate is only something the application sent.
Matching a subject string against it would authenticate anybody who can write
that string into a certificate they signed themselves. A test checks this: a
self-signed certificate carrying the exact expected CN and SAN is refused.
ExtKeyUsageClientAuth is required too. Otherwise a certificate issued for
serving TLS would satisfy a client check.
With no authority configured, tls_client_auth is refused outright, rather
than downgraded to trusting whatever was presented. signari doctor reports that
combination as critical. Otherwise every request from those applications fails in
a way that looks like the application's fault.
Matching rules
- Subject DN: the certificate's distinguished name, in RFC 4514 string form, compared exactly. It is not normalised. DN equivalence depends on attribute order, case and encoding, and each of those rules is a way for two different names to compare equal.
- dNSName: case-insensitive, because DNS is. No wildcards: a wildcard in a client identity means a whole namespace can authenticate as that client.
- URI SAN: exact. It works with SPIFFE identifiers.
- Thumbprint: SHA-256 over the DER encoding, compared in constant time. A test registers one certificate, and presents a different certificate with the same common name. It is refused, because the match is on the credential, not on the name.
One binding per token
A token carries cnf.jkt or cnf.x5t#S256, never both. An application doing
DPoP and mTLS together would be asserting two possession proofs for one token.
A resource server has to know which to check.
DPoP takes precedence, because it is the proof the application constructed for that request. The certificate is a property of a connection the application may not know is mutually authenticated.
Both members are omitempty, so an unbound token carries no cnf at all, rather
than an empty object. A resource server checking for the claim finds no claim,
not an empty one.
Enforced at Signari's own resources
A "resource server" is the protocol's word for an API that accepts tokens. RFC 8705 §3 puts the other half on the resource:
"The protected resource MUST obtain, from its TLS implementation layer, the client certificate used for mutual TLS and MUST verify that the certificate matches the certificate associated with the access token. If they do not match, the resource access attempt MUST be rejected with an error, per [RFC6750], using an HTTP 401 status code and the "invalid_token" error code."
Signari is a resource for three things. The first is userinfo. The second is the credential endpoint of OpenID for Verifiable Credential Issuance (OID4VCI, see OID4VCI). The third is the token endpoint itself, when a token exchange or a transaction token request presents an access token as its subject.
Each one requires a certificate-bound token to arrive over a connection that
presents that same certificate. With no certificate, or a different one, userinfo
and the credential endpoint answer 401 with error="invalid_token". The token
endpoint refuses the subject token. DPoP-bound tokens get the same check against
the proof, through the same function.
A public client's refresh token is bound too
RFC 8705 §4 says:
"When the authorization server issues a refresh token to such a client, it SHOULD also bind the refresh token to the respective certificate and check the binding when the refresh token is presented to get new access tokens."
"Such a client" is §4's public client. It presents a certificate to obtain certificate-bound tokens, without using that certificate to authenticate.
§7.1 exempts confidential clients, whose refresh tokens are already "indirectly certificate-bound by way of the client ID and the associated requirement for (certificate-based) authentication". So the enforcement here is for public clients only, exactly as with DPoP.
This is a SHOULD, not a MUST. It is implemented anyway, because the alternative
is minting a certificate-bound access token from a refresh token that anybody
could present. That token's cnf.x5t#S256 tells every resource server it may only
be used by the holder of a particular certificate. Without the check, the refresh
token behind it would not be held to that binding.
Migration 0084 puts the binding on the family rather than the token, for the same reason as 0083. RFC 8705 §4's check happens "when the refresh token is presented", every time, not once.
Binding is chosen per application
The application must be registered for bound tokens. tls_bound_tokens is off
by default. Turning binding on breaks every caller not yet presenting its
certificate at the resource server, so it is a cutover, rather than a side effect
of turning on mutual TLS.
A certificate-bound token is still token_type: Bearer. Unlike DPoP, RFC 8705
signals the binding with the cnf.x5t#S256 claim, not the token type.
Mutation results
A "mutation test" breaks the code on purpose and checks that a test notices. Each of these deliberate breaks was caught:
TextCAUGHT cert binding never validated at rotationCAUGHT cert binding: no-certificate bypassCAUGHT cert binding lost after one rotationCAUGHT cert binding never recorded at issuance
Changed Signari v0.2