Inbound TLS
Accept HTTPS requests from clients connecting to MockServer.
Inbound mTLS
Require connecting clients to present a valid X.509 certificate.
Outbound TLS
Connect to HTTPS backends when forwarding or proxying requests.
Trusting MockServer’s certificate
MockServer dynamically generates its TLS certificates, signed by its own Certificate Authority (CA). HTTP clients must trust this CA to establish a TLS connection without errors.Add the CA to the JVM trust store
Use the Javakeytool command to import the MockServer CA certificate:
Configure the SSL socket factory in tests
For Java test suites, configure the default SSL socket factory to accept MockServer certificates:Inbound TLS configuration
Use a dynamically generated CA
By default, MockServer uses a fixed built-in CA. Enable this property to generate a unique CA certificate and private key on first startup instead:Use a custom CA certificate
To sign MockServer’s generated certificates with your own CA, provide both a private key and X.509 certificate in PEM format:Use a fixed server certificate
To use a specific certificate for all TLS connections into MockServer rather than having one generated, provide both the private key and X.509 certificate:certificateAuthorityCertificate must be the CA that signed this X.509 certificate.
Configure Subject Alternative Names
MockServer automatically updates the Subject Alternative Names (SANs) in its certificate as it sees new hostnames. To lock down SANs to a fixed list:Inbound mTLS (client certificate authentication)
Require all clients connecting to MockServer to present a valid certificate signed by a trusted CA:tlsMutualAuthenticationCertificateChain is the PEM file containing the CA (or chain) that signed trusted client certificates. Any client presenting a certificate not signed by this CA will be rejected.
When
tlsMutualAuthenticationRequired is enabled, the tlsMutualAuthenticationCertificateChain is also used by MockServerClient when it connects to MockServer over TLS.Outbound TLS (forwarding to HTTPS backends)
When MockServer forwards or proxies requests to HTTPS backends, it needs to establish its own TLS connection outbound.Configure which certificates to trust
Control which server certificates MockServer accepts for outbound connections using the trust manager type:| Value | Behavior |
|---|---|
ANY | Trust all certificates (default). No hostname verification. |
JVM | Trust certificates in the JVM’s default trust store. |
CUSTOM | Trust only certificates specified by forwardProxyTLSCustomTrustX509Certificates. |
Use a client certificate for outbound mTLS
If the backend requires MockServer to present a client certificate (mTLS), provide the private key and certificate chain for outbound connections:Reference: TLS properties
| Property | Environment variable | Default | Description |
|---|---|---|---|
mockserver.dynamicallyCreateCertificateAuthorityCertificate | MOCKSERVER_DYNAMICALLY_CREATE_CERTIFICATE_AUTHORITY_CERTIFICATE | false | Generate a unique CA on first startup |
mockserver.directoryToSaveDynamicSSLCertificate | MOCKSERVER_CERTIFICATE_DIRECTORY_TO_SAVE_DYNAMIC_SSL_CERTIFICATE | null | Directory to save the generated CA |
mockserver.certificateAuthorityPrivateKey | MOCKSERVER_CERTIFICATE_AUTHORITY_PRIVATE_KEY | null | Custom CA private key (PEM) |
mockserver.certificateAuthorityCertificate | MOCKSERVER_CERTIFICATE_AUTHORITY_X509_CERTIFICATE | null | Custom CA certificate (PEM) |
mockserver.privateKeyPath | MOCKSERVER_TLS_PRIVATE_KEY_PATH | null | Fixed server private key (PEM) |
mockserver.x509CertificatePath | MOCKSERVER_TLS_X509_CERTIFICATE_PATH | null | Fixed server certificate (PEM) |
mockserver.tlsMutualAuthenticationRequired | MOCKSERVER_TLS_MUTUAL_AUTHENTICATION_REQUIRED | false | Require client certificates on inbound connections |
mockserver.tlsMutualAuthenticationCertificateChain | MOCKSERVER_TLS_MUTUAL_AUTHENTICATION_CERTIFICATE_CHAIN | null | CA chain to validate client certificates |
mockserver.forwardProxyTLSX509CertificatesTrustManagerType | MOCKSERVER_FORWARD_PROXY_TLS_X509_CERTIFICATES_TRUST_MANAGER_TYPE | ANY | Trust policy for outbound connections |
mockserver.forwardProxyTLSCustomTrustX509Certificates | MOCKSERVER_FORWARD_PROXY_TLS_CUSTOM_TRUST_X509_CERTIFICATES | null | Custom trusted CAs for outbound connections |
mockserver.forwardProxyPrivateKey | MOCKSERVER_FORWARD_PROXY_TLS_PRIVATE_KEY | null | Client private key for outbound mTLS |
mockserver.forwardProxyCertificateChain | MOCKSERVER_FORWARD_PROXY_TLS_X509_CERTIFICATE_CHAIN | null | Client certificate for outbound mTLS |