#! /bin/bash # Usage: $iron keystore # Summary: create and show contents of java keystore # Help: This command groups commands used to create java keystore from pkcs#12 APPNAME="iron" CURRDIR=$(pwd) RCDIR=$HOME/.$APPNAME test -d $RCDIR || mkdir -p $RCDIR CURRENT_TSTAMP=$(date '+%Y%m%d%H%M') function certificate_create() { service=$1 client=$2 CLIENT_CERTPATH=$RCDIR/$service/certs CP=$CLIENT_CERTPATH/$client test -d ${CP} || mkdir -p ${CP} openssl x509 -req -days 365 -CA $CAPATH/ca.crt -CAkey $CAPATH/ca.key -CAcreateserial -in $CP/$client.csr -out $CP/$client.crt test -f $CP/$client.crt && echo "Created certificate in [$CP/$client.crt]" } function keystore_show() { service=$1 client=$2 CLIENT_CERTPATH=$RCDIR/$service/certs CP=$CLIENT_CERTPATH/$client test -d ${CP} || mkdir -p ${CP} echo "Showing content of KeyStore: [$CP/client.keystore]" keytool -keystore $CP/client.keystore -list -v } function keystore_create() { service=$1 client=$2 CLIENT_CERTPATH=$RCDIR/$service/certs CP=$CLIENT_CERTPATH/$client test -d ${CP} || mkdir -p ${CP} echo "Insert PKCS#12 (*.p12) keystore password:" read keystore_password keytool -importkeystore \ -deststorepass "${keystore_password}" -destkeypass "${keystore_password}" -destkeystore $CP/client.keystore \ -srckeystore $CP/${client}.p12 -srcstoretype PKCS12 -srcstorepass "${keystore_password}" \ -alias "${client}" test -f $CP/client.keystore && echo "Created Java Keystore in [$CP/client.keystore]" } if [ "$#" = 3 ];then operation=$1 service=$2 CA_RCFILE="$HOME/"."$APPNAME/default-ca"".env" source ${CA_RCFILE} if [ "$operation" = "create" ]; then client=$3 keystore_create $service $client fi if [ "$operation" = "show" ]; then client=$3 keystore_show $service $client fi else echo "Usage:" echo "\$iron keystore create " echo "\$iron keystore show " exit -1 fi # This file is part of Iron # Copyright (c) 2016-2024 Paolo Lulli. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 3. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see .