Skip to main content
MockServer uses port unification so HTTP and HTTPS are both handled on the same port. When a request arrives over TLS, MockServer detects and decrypts it automatically — no separate port is required. MockServer supports TLS in three areas:

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 Java keytool 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:
Do not add the built-in MockServer CA to your operating system trust store unless you have also enabled dynamicallyCreateCertificateAuthorityCertificate. The built-in CA private key is publicly available in the MockServer repository, which would expose your machine to man-in-the-middle attacks.

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:
The generated CA certificate and private key are saved to the specified directory. On subsequent restarts, MockServer reuses existing files rather than generating new ones.

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:
The private key must be in PKCS#8 or PKCS#1 PEM format. To convert a PKCS#1 key to PKCS#8:

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:
Both properties must be set together. The 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:

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