Skip to content

Instantly share code, notes, and snippets.

@BryceCicada
Created February 4, 2014 16:45
Show Gist options
  • Select an option

  • Save BryceCicada/8807484 to your computer and use it in GitHub Desktop.

Select an option

Save BryceCicada/8807484 to your computer and use it in GitHub Desktop.

Revisions

  1. Chris Nix created this gist Feb 4, 2014.
    27 changes: 27 additions & 0 deletions ImportCertificate
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/bin/bash

    if [ -z $1 ]; then
    echo "Usage: importcert.sh <CA cert PEM file>"
    exit 1
    fi

    CACERT=$1
    BCJAR=bcprov-jdk16-149.jar

    TRUSTSTORE=mytruststore.bks
    ALIAS=`openssl x509 -inform PEM -subject_hash -noout -in $CACERT`

    if [ -f $TRUSTSTORE ]; then
    rm $TRUSTSTORE || exit 1
    fi

    echo "Adding certificate to $TRUSTSTORE..."
    keytool -import -v -trustcacerts -alias $ALIAS \
    -file $CACERT \
    -keystore $TRUSTSTORE -storetype BKS \
    -providerclass org.bouncycastle.jce.provider.BouncyCastleProvider \
    -providerpath $BCJAR \
    -storepass secret

    echo ""
    echo "Added '$CACERT' with alias '$ALIAS' to $TRUSTSTORE..."