-
Notifications
You must be signed in to change notification settings - Fork 10
/
make_certificate_file
executable file
·80 lines (68 loc) · 2.6 KB
/
make_certificate_file
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
#! /bin/bash
globus_exists(){
echo "Check for the $HOME/.globus folder ... "
if [ ! -d "$HOME/.globus" ]; then
echo -e "\tCouldn't find the ${HOME}/.globus folder."
return 0
fi
return 1
}
certs_exist(){
cert_dir=$(dirname "${1}")
cert_file=$(basename "${1}")
echo "Check for $cert_file in $cert_dir ... "
if [ ! -e "${1}" ]; then
echo -e "\tUnable to find the file ${1}."
echo -e "\tNOTE: The home character \"~\" is not expanded and must not be used."
return 0
fi
if [ ! -e "${2}" ]; then
echo -e"\tUnable to find the file ${2}."
echo -e "\tNOTE: The home character \"~\" is not expanded and must not be used."
return 0
fi
echo -e "\tFound both the usercert and userkey files."
return 1
}
read -d '' USAGE <<EOF
\\t\\t\\t=================================================================================
\\t\\t\\tThis script checks if you have globus certificates (defaults: usercert.pem and
\\t\\t\\tuserkey.pem). If you do it will create a p12 file based on them (default: mycert.p12)
\\t\\t\\t=================================================================================\\n\\n
EOF
echo -e "$USAGE"
if globus_exists; then
exit 1
fi
usercert='${HOME}/.globus/usercert.pem'
userkey='${HOME}/.globus/userkey.pem'
read -e -p "Enter the full path of the usercert file: " -i "${HOME}/.globus/usercert.pem" input
usercert="${input:-$name}"
read -e -p "Enter the full path of the userkey file: " -i "${HOME}/.globus/userkey.pem" input
userkey="${input:-$name}"
if certs_exist "$usercert" "$userkey"; then
exit 2
fi
mycert="${HOME}/.globus/mycert.p12"
desc="my browser cert for <year>"
read -e -p "Enter the output path and name to the p12 certificate file: " -i "${HOME}/.globus/mycert.p12" input
mycert="${input:-$name}"
read -e -p "Enter a description of this certificate file: " -i "my browser cert for <year>" input
desc="${input:-$name}"
if [ ! -e "$(dirname "${mycert}")" ]; then
echo -e "\tUnable to find the output path for the certificate file."
exit 3
fi
echo -e "Running the command \`openssl pkcs12 -export -in ${usercert} -inkey ${userkey} -out ${mycert} -name \"${desc}\"\`"
openssl pkcs12 -export -in "${usercert}" -inkey "${userkey}" -out "${mycert}" -name "${desc}"
res=$?
if [ "$res" = "0" ]; then
echo -e "\nAll Done..."
echo -e "You can now import the file ${mycert} into your browser.\n"
else
echo -e "\nThere were problems creating the file ${mycert}."
echo -e "Please, check the directions at "
echo -e " https://twiki.cern.ch/twiki/bin/view/CMSPublic/WorkBookStartingGrid#ObtainingCert"
echo -e " and try the process manually."
fi
exit ${res}