Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Svastikkka/99eb9a55390d28318c07d85d77bed76d to your computer and use it in GitHub Desktop.
Save Svastikkka/99eb9a55390d28318c07d85d77bed76d to your computer and use it in GitHub Desktop.
Curl with Java KeyStore

Curl with Java KeyStore

Curl doesn't have support for java keystore file, so therefor the file should be converted to a PEM format. It consists of the following multiple steps:

  1. Convert keystore to p12 file
  2. Convert p12 file to pem file
  3. Run curl command with pem files

Convert keystore to p12 file

keytool -importkeystore -srckeystore truststore.jks -destkeystore truststore.p12 -srcstoretype JKS -deststoretype PKCS12

Convert p12 file to pem file

openssl pkcs12 -in truststore.p12 -out truststore.pem

Run curl command with pem files

Example curl request with loading trusted certificates:

curl secret --cacert truststore.pem https://localhost:8443/api/hello

Example curl request for mutual authentication, loading trusted certificates and loading private and public key of the client:

Repeat step 1 (if applicable) and step 2 for the identity.jks which contains the keypair.

curl --cert identity.pem --cacert truststore.pem https://localhost:8443/api/hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment