Page tree
Skip to end of metadata
Go to start of metadata

Given certificates from a certificate authority, we are using the following script to create keystores for Jetty:

#! /bin/bash

if [ $# -ne 5 ]; then
   echo "Syntax: createKeystoreFromCertificates <key file> <certificate> <intermediate certificate> <keystore>"
   exit 1
fi
KEY_FILE="$1"
CERT_FILE="$2"
INTERM_CERT_FILE="$3"
KEYSTORE_FILE="$4"
CHAIN_FILE=$(mktemp tmpXXXXXX.chain)
PKCS_FILE=$(mktemp tmpXXXXXX.pkcs12)
JETTY_SNAPSHOT_DIR=/data/home/cifex/jetty_snapshot

cat $CERT_FILE $INTERM_CERT_FILE > $CHAIN_FILE
openssl pkcs12 -export -inkey $KEY_FILE -in $CHAIN_FILE -out $PKCS_FILE -passout pass:A
echo "Type 'A' for the first password"
java -classpath $JETTY_SNAPSHOT_DIR/jetty-util-6.1-SNAPSHOT.jar:$JETTY_SNAPSHOT_DIR/jetty-6.1-SNAPSHOT.jar org.mortbay.jetty.security.PKCS12Import $PKCS_FILE $KEYSTORE_FILE

# The alias "mykey" works fine for jetty - probably also "jetty" does as it is used in the documentation, but we didn't try.
keytool -keystore $KEYSTORE_FILE -changealias -alias 1 -destalias mykey

rm $CHAIN_FILE
rm $PKCS_FILE
  • Both certificates have to be in PEM format which is an ASCII format.
  • If the authorization authority is QuoVadis the intermediate certificate is probably the one which can be downloaded from here.
  • As of Jetty version 6.1.7, the PKCS12Import class is broken, so you need to use a current snapshot of 6.1 from http://snapshots.repository.codehaus.org/org/mortbay/jetty.
  • Since JDK 1.6 also keytool can be used instead of the PKCS12Import class. Syntax:

    keytool -importkeystore -srckeystore $PKCS_FILE -srcstoretype PKCS12 -destkeystore $KEYSTORE_FILE
    

    The first password you will be asked for is the keystore password (with verification) to create the keystore. For the second password request the password used by openssl (i.e. 'A') should be entered and the last password request type again the keystore password. The keystore password has to be the password found in jetty.xml (often 'changeit').

  • In order to check that the key in the keystore has a certificate chain of length 2 run the following command:

    keytool -v -keystore <keystore file> -list