Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sobelfallcayor/b6bd25806a5a81ab72c54421f790fb18 to your computer and use it in GitHub Desktop.
Save sobelfallcayor/b6bd25806a5a81ab72c54421f790fb18 to your computer and use it in GitHub Desktop.
Create self-signed certificate for wiremock and configure a java client under test for HTTPS

1. Generate self-signed certificate

keytool -genkey -alias wiremock -keyalg RSA -keysize 1024 \
    -validity 365 -keypass password -keystore identity.jks -storepass password

Important: keypass must equal storepass, or else you'll receive java.io.IOException: !JsseListener: java.security.UnrecoverableKeyException: Cannot recover key

2. Start wiremock with the new keystore and HTTPS enabled

java -jar wiremock-1.54-standalone.jar --https-port 8081 --https-keystore ./identity.jks

3. Client

Run java with -Djavax.net.ssl.trustStore=/path/to/identity.jks and calls to https://localhost will succeed :-)

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment