Java Keytool is a PKI toolkit for Java environments, used which manage Sun JKS keystores - a small mini-database consisting of a single file used to store PKI properties such as certificates and private files. This toolkit is important because it used to create files used by JSSE (Java Secure Socket Extension), the javax.net.ssl classes used for SSL/TLS authentication.
The complete manual is available at http://download.oracle.com/javase/7/docs/technotes/tools/windows/keytool.html.
This examples creates a SSL/TLS javax.net.ssl.keyStore containing the client identity (Private Key, Certificate and Certificate Chain / Path) for a client used in SSL/TLS Mutual Authentication.
Note: This step is only intended for SSL/TLS Client Authentication (aka Mutual Authentication, aka Two-Way Authentication). If you are only interested in Server Authentication, this is not what you want to do.
Parameters used in example:
Parameter | Meaning / Context | Value used in example |
---|---|---|
keystore | Filename of SSL/TLS javax.net.ssl.keyStore file | keystore |
dname | Distinguished name identifying the certificate, set according to CA requirements. | "CN=Test, OU=Test, O=Test, L=Test, S=Test, C=Test" |
alias | Alias used to store private key and client certificate in keystore | keyAlias |
alias | Alias used to store certificate chain / path in keystore | ca0, ca1, ca2, ... |
keypass | Password used to protect key | password |
storepass | Password used to protect keystore (use same as keypass!) | password |
file | Certificate Signing Request (CSR) file to be sent to CA. | keyAlias.csr |
file | Client certificate file | keyAlias.cer |
file | Client certificate chain / path certificate files | ca-root.cer, ca-int-1.cer, ca-int-2.cer, ... |
keytool -genkey -dname "CN=Test, OU=Test, O=Test, L=Test, S=Test, C=Test" -alias
keyAlias
-keypass password -storepass password -keystore KeyStore
keytool -certreq -alias keyAlias -file keyAlias.csr -keypass password -storepass password -keystore
KeyStore
keytool -import -alias ca0 -file ca-root.cer -trustcacerts -storepass
password -keystore KeyStore
keytool -import -alias ca1 -file ca-int-1.cer -trustcacerts -storepass
password -keystore KeyStore
keytool -import -alias ca2 -file ca-int-2.cer -trustcacerts -storepass
password -keystore KeyStore
keytool -import -alias keyAlias -file keyAlias.cer -storepass
password -keystore KeyStore
Java Keytool JKS keystore is a proprietary format with little or no support outside of the Java world. For verification / test / backup purposes, it is very useful to be able to convert client identity contained in a javax.net.ssl.keyStore into the more popular Personal Information Exchange (PKCS12) file format.
Note: This is an optional thing to do. You do not have to create PKCS12 files unless you have specific reason to do so.
%JAVA_HOME%\bin\javac ExportPriv.java
java ExportPriv KeyStore keyAlias password > exported-pkcs8.key
keytool -export -rfc -alias keyAlias -file exported.crt -keystore KeyStore
openssl pkcs12 -export -out exported.pfx -inkey exported-pkcs8.key -in exported.crt