2012-07-23 44 views

回答

3

也作爲https://gist.github.com/3164098(補丁歡迎)


#!/bin/bash 
REMHOST=$1 
REMPORT=${2:-443} 

KEYSTORE_PASS=changeit 
KEYTOOL=/opt/jira/jre/bin/keytool 

# FYI: the default keystore is located in ~/.keystore 

if [ -z "$REMHOST" ] 
    then 
    echo "ERROR: Please specify the server name to import the certificatin from, eventually followed by the port number, if other than 443." 
    exit 1 
    fi 

set -e 

rm -f $REMHOST.pem 

echo -n | openssl s_client -connect $REMHOST:$REMPORT 2>/dev/null $REMHOST.pem 

if $KEYTOOL -list -storepass ${KEYSTORE_PASS} -alias $REMHOST >/dev/null 
    then 
    echo "Key of $REMHOST already found, skipping it." 
    else 
    $KEYTOOL -import -trustcacerts -noprompt -storepass ${KEYSTORE_PASS} -alias $REMHOST -file $REMHOST.pem 
    fi 

相關問題