TLS/HTTPS Configuration
mockd supports HTTPS for both the mock server and proxy modes. This guide covers certificate generation, configuration, and common use cases.
Mock Server HTTPS
Section titled “Mock Server HTTPS”Quick Start
Section titled “Quick Start”Enable HTTPS with auto-generated certificates:
mockd start --config mocks.json --httpsmockd generates a self-signed certificate and starts on port 8443.
Custom Port
Section titled “Custom Port”mockd start --config mocks.json --https --port 443With Your Own Certificates
Section titled “With Your Own Certificates”mockd start --config mocks.json \ --cert ./certs/server.crt \ --key ./certs/server.keyConfiguration File
Section titled “Configuration File”{ "server": { "port": 8443, "tls": { "enabled": true, "certFile": "./certs/server.crt", "keyFile": "./certs/server.key" } }, "mocks": [...]}Certificate Generation
Section titled “Certificate Generation”Self-Signed (Development)
Section titled “Self-Signed (Development)”Generate a self-signed certificate:
mockd cert generate --name localhost --days 365Output:
Generated certificate: ./certs/localhost.crtGenerated private key: ./certs/localhost.keyWith Subject Alternative Names:
mockd cert generate \ --name localhost \ --san "127.0.0.1" \ --san "::1" \ --san "myapp.local"CA Certificate (For Proxy)
Section titled “CA Certificate (For Proxy)”Generate a CA for MITM proxying:
mockd cert generate-ca --name "mockd CA" --days 3650Output:
Generated CA certificate: ./certs/mockd-ca.crtGenerated CA private key: ./certs/mockd-ca.keyProxy HTTPS
Section titled “Proxy HTTPS”MITM Proxy Setup
Section titled “MITM Proxy Setup”For the proxy to intercept HTTPS traffic, clients must trust the mockd CA.
- Generate CA Certificate:
mockd cert generate-ca- Start Proxy:
mockd proxy --target https://api.example.com \ --ca-cert ./certs/mockd-ca.crt \ --ca-key ./certs/mockd-ca.key- Install CA on Client:
See Installing CA Certificates below.
Proxy Configuration
Section titled “Proxy Configuration”{ "proxy": { "target": "https://api.example.com", "tls": { "caCertFile": "./certs/mockd-ca.crt", "caKeyFile": "./certs/mockd-ca.key", "certCacheDir": "./certs/generated" } }}| Field | Description |
|---|---|
caCertFile | CA certificate for signing |
caKeyFile | CA private key |
certCacheDir | Cache for generated certs |
Installing CA Certificates
Section titled “Installing CA Certificates”# Add to system keychainsudo security add-trusted-cert -d -r trustRoot \ -k /Library/Keychains/System.keychain \ ./certs/mockd-ca.crt
# Or for current user onlysecurity add-trusted-cert -r trustRoot \ -k ~/Library/Keychains/login.keychain \ ./certs/mockd-ca.crt# Copy certificatesudo cp ./certs/mockd-ca.crt /usr/local/share/ca-certificates/mockd-ca.crt
# Update certificate storesudo update-ca-certificatesWindows
Section titled “Windows”# Import to Trusted Root Certification AuthoritiesImport-Certificate -FilePath .\certs\mockd-ca.crt ` -CertStoreLocation Cert:\LocalMachine\RootNode.js
Section titled “Node.js”export NODE_EXTRA_CA_CERTS=./certs/mockd-ca.crtnode app.jsPython (requests)
Section titled “Python (requests)”import requestsrequests.get('https://localhost:8443', verify='./certs/mockd-ca.crt')curl --cacert ./certs/mockd-ca.crt https://localhost:8443/api/usersDocker
Section titled “Docker”Mount the CA certificate:
docker run -v $(pwd)/certs/mockd-ca.crt:/etc/ssl/certs/mockd-ca.crt \ myappTLS Options
Section titled “TLS Options”Minimum TLS Version
Section titled “Minimum TLS Version”{ "server": { "tls": { "enabled": true, "minVersion": "1.2" } }}Supported: 1.0, 1.1, 1.2, 1.3
Cipher Suites
Section titled “Cipher Suites”{ "server": { "tls": { "enabled": true, "cipherSuites": [ "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" ] } }}Client Certificate Authentication (mTLS)
Section titled “Client Certificate Authentication (mTLS)”Require client certificates:
{ "server": { "tls": { "enabled": true, "certFile": "./certs/server.crt", "keyFile": "./certs/server.key", "clientAuth": "require", "clientCAs": ["./certs/client-ca.crt"] } }}Client auth modes:
none- No client cert requiredrequest- Request but don’t requirerequire- Require valid client cert
Mixed HTTP/HTTPS
Section titled “Mixed HTTP/HTTPS”Serve both protocols:
{ "server": { "port": 4280, "tls": { "enabled": true, "port": 8443, "certFile": "./certs/server.crt", "keyFile": "./certs/server.key" } }}Both endpoints serve the same mocks:
http://localhost:4280https://localhost:8443
HTTPS Redirect
Section titled “HTTPS Redirect”Redirect HTTP to HTTPS:
{ "server": { "port": 4280, "httpsRedirect": true, "tls": { "enabled": true, "port": 8443 } }}Common Issues
Section titled “Common Issues”Certificate Not Trusted
Section titled “Certificate Not Trusted”Symptom: CERT_AUTHORITY_INVALID or similar errors
Solution: Install the CA certificate as described above, or use --insecure flags for testing:
curl -k https://localhost:8443/api/usersCertificate Hostname Mismatch
Section titled “Certificate Hostname Mismatch”Symptom: HOSTNAME_MISMATCH error
Solution: Generate certificate with correct SANs:
mockd cert generate --name localhost --san "myapp.local"Certificate Expired
Section titled “Certificate Expired”Symptom: CERT_HAS_EXPIRED error
Solution: Regenerate with longer validity:
mockd cert generate --name localhost --days 3650Permission Denied (Port 443)
Section titled “Permission Denied (Port 443)”Symptom: Cannot bind to port 443
Solution: Use a high port or grant capability:
# Use high portmockd start --https --port 8443
# Or grant capability (Linux)sudo setcap 'cap_net_bind_service=+ep' $(which mockd)Security Considerations
Section titled “Security Considerations”-
Never use self-signed certs in production - They’re for development only
-
Protect private keys - Restrict file permissions:
Terminal window chmod 600 ./certs/*.key -
Short-lived certificates - Use shorter validity for development certs
-
Don’t commit certs - Add to
.gitignore:certs/*.crt*.key*.pem
Next Steps
Section titled “Next Steps”- Proxy Recording - HTTPS proxy setup
- CLI Reference - Certificate commands
- Configuration Reference - Full TLS options