-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwso2runjavaciphertool.sh
executable file
·155 lines (131 loc) · 5.21 KB
/
wso2runjavaciphertool.sh
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
# -------------------------------------------------------------- #
# wso2runjavaciphertool.sh v 1.0 #
# #
# run the the ciphertool utility to encrypt the plaintext #
# passwords in the wso2 secure vault ciphertext-properties #
# configuration file of an installed product and replace the #
# plaintext passwords in the wso2 configuration files by #
# an alias reference to the encrypted password. #
# #
# -------------------------------------------------------------- #
# #
# Options : #
# #
# -h print help #
# -change execute the ciphertool for 'change' #
# #
# -------------------------------------------------------------- #
# #
# Parameters : #
# #
# ${1} CARBON_HOME directory of installed product #
# #
# -------------------------------------------------------------- #
# #
# Environment Variables #
# #
# JAVA_HOME optional, if undefined the script tries to #
# derive JAVA_HOME from the location of the #
# 'java' executable. #
# #
# -------------------------------------------------------------- #
# #
# return codes : #
# #
# 0 operation successful #
# 1 operation not started #
# -4 parameters invalid #
# -8 no java installation found #
# 16 operation of ciphertool utility was aborted #
# #
# -------------------------------------------------------------- #
#set -vx
export usage="usage: $(basename ${0}) [-change] [-p <storekeypassword>] <carbonhome>"
export hostname=$(hostname -f)
##
# process options
##
opisupdate=''
while [[ "${1}" =~ ^-.* ]];
do
case "${1}" in
-change) opisupdate='yes';
shift
;;
-h) echo "$usage";
exit 1
;;
-p) storekeypass="-Dpassword=${2}";
shift;
shift;
;;
*) shift
;;
esac
done
carbonhome="${1}"
##
# verify existence of directories
##
if [ x"${carbonhome}" == x ]; then
echo "<carbonhome> is not defined"
echo "$usage";
exit 1
fi
if [ ! -d "${carbonhome}" ]; then
echo "CARBON_HOME directory ${carbonhome} does not exist"
exit -4
fi
##
# update environment variables
##
export CARBON_HOME=${carbonhome}
if [ x"${JAVA_HOME}" == x ]; then
javabin=$(which java)
if [ ! x"${javabin}" == x ]; then
echo "no 'java' executable found"
exit -8
fi
javabin=$(dirname $(readlink -f $javabin))
export JAVA_HOME=$(readlink -f "$javabin/..")
fi
export PATH=${JAVA_BASE}/bin:${CARBON_HOME}/bin:$PATH
# CAVEAT: As reported in https://wso2.org/jira/browse/IDENTITY-4276,
# there are problems with processing the plaintext passwords from
#
# ${CARBON_HOME}/repository/conf/identity/EndpointConfig.properties
#
# INTERMEDITATE RESOLUTION
#
# use the sed commands below to replace the plaintext passwords by alias references
endpointconfig="repository/conf/identity/EndpointConfig.properties"
sed -i -e "s/\(Carbon.Security.KeyStore.Password\)=.*$/\1=secretAlias:\1/g" "${CARBON_HOME}"/$endpointconfig
sed -i -e "s/\(Carbon.Security.TrustStore.Password\)=.*$/\1=secretAlias:\1/g" "${CARBON_HOME}"/$endpointconfig
##
# collect the jars required to run the ciphertool utility in the classpath
##
CARBON_CLASSPATH=""
for f in "$CARBON_HOME"/lib/org.wso2.ciphertool*.jar
do
CARBON_CLASSPATH=$CARBON_CLASSPATH:$f
done
for h in "$CARBON_HOME"/repository/components/plugins/*.jar
do
CARBON_CLASSPATH=$CARBON_CLASSPATH:$h
done
CARBON_CLASSPATH=$CARBON_CLASSPATH:$CLASSPATH
echo "CARBONHOME : ${CARBON_HOME}"
echo "JAVA_HOME : $JAVA_HOME"
##
# execute the ciphertool utility.
##
ciphertooloperation='configure'
if [ x$opisupdate != x ]; then
ciphertooloperation='change'
fi
$JAVA_HOME/bin/java -Dcarbon.home="$CARBON_HOME" -classpath "$CARBON_CLASSPATH" org.wso2.ciphertool.CipherTool -D${ciphertooloperation} $storekeypass
if [ $? -ne 0 ]; then
exit 16
fi
exit 0