Skip to content

Instantly share code, notes, and snippets.

@wsargent
Last active May 7, 2021 15:16
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save wsargent/11062032 to your computer and use it in GitHub Desktop.
Save wsargent/11062032 to your computer and use it in GitHub Desktop.
Generate a certificate authority and trust anchor keystore, using only keytool
#!/bin/bash
export PW=`cat password`
# Create a self signed key pair root CA certificate.
keytool -genkeypair -v \
-alias exampleca \
-dname "CN=exampleCA, OU=Example Org, O=Example Company, L=San Francisco, ST=California, C=US" \
-keystore exampleca.jks \
-keypass:env PW \
-storepass:env PW \
-keyalg RSA \
-keysize 4096 \
-ext KeyUsage="keyCertSign" \
-ext BasicConstraints:"critical=ca:true" \
-validity 9999
# Export the exampleCA public certificate so that it can be used in trust stores..
keytool -export -v \
-alias exampleca \
-file exampleca.crt \
-keypass:env PW \
-storepass:env PW \
-keystore exampleca.jks \
-rfc
@marcosdemelo
Copy link

Thanks man!

@heregear
Copy link

When I run this I get an Illegal Option -ext from keytool.

What version of java does this run under?

@heregear
Copy link

My bad - nevermind - just realized the VM i was on was running java 1.6...doooop. Time for donut. Thanks!

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