← history for iron/libexec/iron/iron-keystore
bb98ae1eiron/libexec/iron/iron-keystore73 lines⬡ raw↓ download
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /bin/bash 
# Usage: $iron keystore <create|show> <service> <client>
# 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 <service> <client-id>"
	echo "\$iron keystore show <service> <client-id>"
	exit -1
fi