Skip to content

Commit e210cf2

Browse files
author
Derrek Young
committed
v0.8, cert validation, minor refactoring
1 parent 8629796 commit e210cf2

File tree

3 files changed

+112
-66
lines changed

3 files changed

+112
-66
lines changed

build.sh

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
#!/bin/bash
22

3-
VERSION="v0.7-BETA"
3+
VERSION="0.8-BETA"
44

5+
6+
################################################
7+
# Do not edit below this line
58
DIST_DIR="./dist"
6-
DIST_TOP_FOLDER="appd-ssl-cert-utils-$VERSION"
9+
DIST_TOP_FOLDER="appd-ssl-certs-utils-$VERSION"
710
DISTRIBUTABLE_NAME="$DIST_TOP_FOLDER.zip"
811

9-
if [ -d "$DIST_DIR" ]; then
10-
echo "Cleaning dist/ directory..."
11-
rm -R $DIST_DIR
12-
fi
12+
dist()
13+
{
14+
if [ -d "$DIST_DIR" ]; then
15+
echo "Cleaning dist/ directory..."
16+
rm -R $DIST_DIR
17+
fi
18+
19+
if [ ! -d "$DIST_DIR" ]; then
20+
echo "Making dist/ directory..."
21+
mkdir $DIST_DIR
22+
fi
23+
24+
# Create a top-level folder for when unzipping the archive
25+
mkdir $DIST_DIR/$DIST_TOP_FOLDER
1326

14-
if [ ! -d "$DIST_DIR" ]; then
15-
echo "Making dist/ directory..."
16-
mkdir $DIST_DIR
17-
fi
27+
cp controller-ssl-certs-util.sh $DIST_DIR/$DIST_TOP_FOLDER/controller-ssl-certs-util-$VERSION.sh
28+
cp eum-ssl-certs-util.sh $DIST_DIR/$DIST_TOP_FOLDER/eum-ssl-certs-util-$VERSION.sh
1829

19-
# Create a top-level folder for when unzipping the archive
20-
mkdir $DIST_DIR/$DIST_TOP_FOLDER
21-
cp *-ssl-certs-util.sh $DIST_DIR/$DIST_TOP_FOLDER/
30+
echo "Creating the Zip file..."
2231

23-
echo "Creating the Zip file..."
24-
#zip $DIST_DIR/$DISTRIBUTABLE_NAME controller-ssl-certs-util.sh eum-ssl-certs-util.sh
25-
cd $DIST_DIR/
26-
zip -r $DISTRIBUTABLE_NAME $DIST_TOP_FOLDER/
32+
cd $DIST_DIR/
33+
zip -r $DISTRIBUTABLE_NAME $DIST_TOP_FOLDER/
34+
}
2735

28-
#unzip -l $DISTRIBUTABLE_NAME
36+
dist

controller-ssl-certs-util.sh

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# Generate new certs, import them, list keystore contents and disable the HTTP port.
77
#
8-
# Version: 0.7
8+
# Version: 0.8
99
#
1010
#--------------------------------------------------------------------------------------------------
1111

@@ -27,12 +27,6 @@ KEYTOOL_HOME=$CONTROLLER_HOME/jre/bin
2727
KEYTOOL=$KEYTOOL_HOME/keytool
2828
KEYSTORE_BACKUP="./$KEYSTORE_NAME-$DATETIME.bak"
2929

30-
# For localhost, manual testing
31-
#CONFIG_HOME=$CONTROLLER_HOME
32-
#KEYTOOL_HOME=$CONTROLLER_HOME
33-
#KEYTOOL=keytool
34-
#CONTROLLER_HOME=.
35-
3630
#1
3731
generate-csr()
3832
{
@@ -93,10 +87,7 @@ import-signed-cert()
9387
echo "Importing a signed certificate..."
9488
read -rp $'Certificate filename: ' cert
9589

96-
if [ -z "$cert" ]; then
97-
echo "Required: certificate file name"
98-
exit
99-
fi
90+
validate-certificate $cert
10091

10192
echo "Importing $cert into $KEYSTORE_PATH for alias $SIGNED_CERT_ALIAS_NAME"
10293
$KEYTOOL -import -trustcacerts -keystore $KEYSTORE_PATH -file $cert -alias $SIGNED_CERT_ALIAS_NAME -storepass $KEYSTORE_PASSWORD
@@ -115,17 +106,12 @@ import-cert-chain()
115106
echo "Importing a root or intermediate certificate..."
116107
read -rp $'Certificate filename: ' cert
117108

118-
if [ -z "$cert" ]; then
119-
echo "Required: certificate file name"
120-
exit
121-
fi
109+
validate-certificate $cert
122110

123-
local fullfile=$cert
124-
local filename="${fullfile##*/}"
125-
local alias=$(echo $filename | cut -f 1 -d '.') #File name without the extension
111+
local alias=$(get-alias $cert)
126112

127113
echo "Importing $cert into $KEYSTORE_PATH for alias $alias"
128-
$KEYTOOL -import -trustcacerts -alias $alias -keystore $KEYSTORE_PATH -storepass $KEYSTORE_PASSWORD -file $cert
114+
$KEYTOOL -import -trustcacerts -keystore $KEYSTORE_PATH -file $cert -alias $alias -storepass $KEYSTORE_PASSWORD
129115

130116
if [ $? -gt 0 ] ; then
131117
echo "ERROR: unable to import the certificate"
@@ -141,7 +127,38 @@ list()
141127
$KEYTOOL -list -keystore $KEYSTORE_PATH -storepass $KEYSTORE_PASSWORD | more
142128
}
143129

144-
validate()
130+
get-alias()
131+
{
132+
local fullfile=$1
133+
local filename="${fullfile##*/}"
134+
local alias=$(echo $filename | cut -f 1 -d '.') #File name without the extension
135+
136+
echo "$alias"
137+
}
138+
139+
validate-certificate()
140+
{
141+
local cert=$1
142+
143+
if [ -z "$cert" ]; then
144+
echo "Required: certificate file name"
145+
exit 1
146+
fi
147+
148+
if [[ $cert == *.p12 || $cert == *.P12 ]]; then
149+
echo "ERROR: This script does not support p12 certificates. Please refer to the official docs."
150+
echo " "
151+
echo "https://docs.appdynamics.com/display/latest/Controller+SSL+and+Certificates"
152+
exit 1
153+
fi
154+
155+
if [ ! -f $cert ]; then
156+
echo "ERROR: File not found, $1"
157+
exit 1
158+
fi
159+
}
160+
161+
validate-install()
145162
{
146163
if [ ! -d "$CONTROLLER_HOME" ]; then
147164
echo "ERROR: Unable to find $CONTROLLER_HOME. Set the variable in this script."
@@ -157,18 +174,23 @@ validate()
157174
fi
158175
}
159176

160-
main()
177+
disclaimer-controller()
161178
{
162179
echo " "
163180
echo "This script helps working with SSL certificates, but it's not a total replacement for keytool."
164181
echo "Think of this as the Basic interface to keystores and keytool is the Advanced one."
165182
echo "Read the full Controller+SSL docs at "
183+
echo " "
166184
echo "https://docs.appdynamics.com/display/latest/Controller+SSL+and+Certificates "
167185
echo " "
168-
echo "ATTENTION: This is an *unofficial* script so consider it to be Alpha--not GA."
186+
echo "ATTENTION: This is an *unofficial* script; it is not GA. Read the docs above."
169187
echo " "
188+
read -p "Press [Enter] to continue..."
170189
echo " "
190+
}
171191

192+
main-controller()
193+
{
172194
while true; do
173195
echo "[1] Generate a certificate signing request"
174196
echo "[2] Import a root or intermediate certificate"
@@ -206,5 +228,6 @@ main()
206228
done
207229
}
208230

209-
validate
210-
main
231+
disclaimer-controller
232+
validate-install
233+
main-controller

eum-ssl-certs-util.sh

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# Generate new certs, import them, and list keystore contents.
77
#
8-
# Version: 0.7
8+
# Version: 0.8
99
#
1010
#--------------------------------------------------------------------------------------------------
1111

@@ -27,12 +27,6 @@ KEYTOOL_HOME=$EUM_HOME/jre/bin
2727
KEYTOOL=$KEYTOOL_HOME/keytool
2828
KEYSTORE_BACKUP="./$KEYSTORE_NAME-$DATETIME.bak"
2929

30-
# For localhost, manual testing
31-
#CONFIG_HOME=$CONTROLLER_HOME
32-
#KEYTOOL_HOME=$CONTROLLER_HOME
33-
#KEYTOOL=keytool
34-
#CONTROLLER_HOME=.
35-
3630
#1
3731
generate-csr()
3832
{
@@ -82,10 +76,7 @@ import-signed-cert()
8276
echo "Importing a signed certificate..."
8377
read -rp $'Certificate filename: ' cert
8478

85-
if [ -z "$cert" ]; then
86-
echo "Required: certificate file name"
87-
exit
88-
fi
79+
validate-certificate $cert
8980

9081
echo "Importing $cert into $KEYSTORE_PATH for alias $SIGNED_CERT_ALIAS_NAME"
9182
$KEYTOOL -import -trustcacerts -keystore $KEYSTORE_PATH -file $cert -alias $SIGNED_CERT_ALIAS_NAME -storepass $KEYSTORE_PASSWORD
@@ -107,17 +98,14 @@ import-cert-chain()
10798
echo "Importing a root or intermediate certificate..."
10899
read -rp $'Certificate filename: ' cert
109100

110-
if [ -z "$cert" ]; then
111-
echo "Required: certificate file name"
112-
exit
113-
fi
101+
validate-certificate $cert
114102

115103
local fullfile=$cert
116104
local filename="${fullfile##*/}"
117105
local alias=$(echo $filename | cut -f 1 -d '.') #File name without the extension
118106

119107
echo "Importing $cert into $KEYSTORE_PATH for alias $alias"
120-
$KEYTOOL -import -trustcacerts -alias $alias -keystore $KEYSTORE_PATH -storepass $KEYSTORE_PASSWORD -file $cert
108+
$KEYTOOL -import -trustcacerts -keystore $KEYSTORE_PATH -file $cert -alias $alias -storepass $KEYSTORE_PASSWORD
121109

122110
if [ $? -gt 0 ] ; then
123111
echo "ERROR: unable to import the certificate"
@@ -133,7 +121,29 @@ list()
133121
$KEYTOOL -list -keystore $KEYSTORE_PATH -storepass $KEYSTORE_PASSWORD
134122
}
135123

136-
validate()
124+
validate-certificate()
125+
{
126+
local cert=$1
127+
128+
if [ -z "$cert" ]; then
129+
echo "Required: certificate file name"
130+
exit 1
131+
fi
132+
133+
if [[ $cert == *.p12 || $cert == *.P12 ]]; then
134+
echo "ERROR: This script does not support p12 certificates. Please refer to the official docs."
135+
echo " "
136+
echo "https://docs.appdynamics.com/display/latest/Install+and+Configure+the+On-Premise+EUM+Server"
137+
exit 1
138+
fi
139+
140+
if [ ! -f $cert ]; then
141+
echo "ERROR: File not found, $1"
142+
exit 1
143+
fi
144+
}
145+
146+
validate-install()
137147
{
138148
if [ ! -d "$EUM_HOME" ]; then
139149
echo "ERROR: Unable to find $EUM_HOME. Set this variable in this script."
@@ -149,19 +159,23 @@ validate()
149159
fi
150160
}
151161

152-
153-
main()
162+
disclaimer-eum()
154163
{
155164
echo " "
156165
echo "This script helps working with SSL certificates, but it's not a total replacement for keytool."
157166
echo "Think of this as the Basic interface to keystores and keytool is the Advanced one."
158-
echo "Read the full EUM Server+SSL docs at "
159-
echo "https://docs.appdynamics.com/display/latest/Install+and+Configure+the+On-Premise+EUM+Server "
167+
echo "Read the full Controller+SSL docs at "
160168
echo " "
161-
echo "ATTENTION: This is an *unofficial* script so consider it to be Alpha--not GA."
169+
echo "https://docs.appdynamics.com/display/latest/Controller+SSL+and+Certificates "
162170
echo " "
171+
echo "ATTENTION: This is an *unofficial* script; it is not GA. Read the docs above."
163172
echo " "
173+
read -p "Press [Enter] to continue..."
174+
echo " "
175+
}
164176

177+
main-eum()
178+
{
165179
while true; do
166180
echo "[1] Generate a certificate signing request"
167181
echo "[2] Import a root or intermediate cert"
@@ -199,5 +213,6 @@ main()
199213
done
200214
}
201215

202-
validate
203-
main
216+
disclaimer-eum
217+
validate-install
218+
main-eum

0 commit comments

Comments
 (0)