Bob Mottram 9 years ago
parent
commit
23eb5fac45
1 changed files with 17 additions and 12 deletions
  1. 17
    12
      src/freedombone-clientcert

+ 17
- 12
src/freedombone-clientcert View File

33
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
33
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
34
 
34
 
35
 USERNAME=
35
 USERNAME=
36
-CLIENT_CERT_PASSWORD=
37
 COUNTRY_CODE="US"
36
 COUNTRY_CODE="US"
38
 AREA="Free Speech Zone"
37
 AREA="Free Speech Zone"
39
 LOCATION="Freedomville"
38
 LOCATION="Freedomville"
49
     echo ''
48
     echo ''
50
     echo '     --help                  Show help'
49
     echo '     --help                  Show help'
51
     echo '  -u --username [name]       Username'
50
     echo '  -u --username [name]       Username'
52
-    echo '  -p --password [text]       Client certificate install password'
53
     echo ''
51
     echo ''
54
     exit 0
52
     exit 0
55
 }
53
 }
66
     shift
64
     shift
67
     USERNAME="$1"
65
     USERNAME="$1"
68
     ;;
66
     ;;
69
-    -p|--password)
70
-    shift
71
-    CLIENT_CERT_PASSWORD="$1"
72
-    ;;
73
     *)
67
     *)
74
     # unknown option
68
     # unknown option
75
     ;;
69
     ;;
113
 fi
107
 fi
114
 
108
 
115
 # create a certificate request
109
 # create a certificate request
116
-openssl req -new -sha256 -subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$USERNAME" -key /etc/ssl/private/$USERNAME.key -out /etc/ssl/requests/$USERNAME.csr
110
+openssl req -new -sha256 -subj \
111
+        "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$USERNAME" \
112
+        -key /etc/ssl/private/$USERNAME.key \
113
+        -out /etc/ssl/requests/$USERNAME.csr
117
 
114
 
118
 if [ ! -f /etc/ssl/requests/$USERNAME.csr ]; then
115
 if [ ! -f /etc/ssl/requests/$USERNAME.csr ]; then
119
     echo 'Certificate request was not created'
116
     echo 'Certificate request was not created'
123
 
120
 
124
 # sign the certificate request
121
 # sign the certificate request
125
 cd /etc/ssl
122
 cd /etc/ssl
126
-openssl ca -config /etc/ssl/dovecot-ca.cnf -in /etc/ssl/requests/$USERNAME.csr -out /etc/ssl/certs/$USERNAME.cer
123
+openssl ca -config /etc/ssl/dovecot-ca.cnf \
124
+        -in /etc/ssl/requests/$USERNAME.csr \
125
+        -out /etc/ssl/certs/$USERNAME.cer
127
 
126
 
128
 if [ ! -f /etc/ssl/certs/$USERNAME.cer ]; then
127
 if [ ! -f /etc/ssl/certs/$USERNAME.cer ]; then
129
     echo 'Authentication certificate was not created'
128
     echo 'Authentication certificate was not created'
137
 cp /etc/ssl/certs/dovecot-ca.crt /home/$USERNAME/emailcert
136
 cp /etc/ssl/certs/dovecot-ca.crt /home/$USERNAME/emailcert
138
 mv /etc/ssl/private/$USERNAME.key /home/$USERNAME/emailcert
137
 mv /etc/ssl/private/$USERNAME.key /home/$USERNAME/emailcert
139
 mv /etc/ssl/certs/$USERNAME.crt /home/$USERNAME/emailcert
138
 mv /etc/ssl/certs/$USERNAME.crt /home/$USERNAME/emailcert
140
-openssl pkcs12 -export -in /home/$USERNAME/emailcert/$USERNAME.cer -out /home/$USERNAME/emailcert/$USERNAME.p12 -inkey /home/$USERNAME/emailcert/$USERNAME.key -certfile /home/$USERNAME/emailcert/dovecot-ca.crt -password "$CLIENT_CERT_PASSWORD"
139
+openssl pkcs12 -export -in /home/$USERNAME/emailcert/$USERNAME.cer \
140
+        -out /home/$USERNAME/emailcert/$USERNAME.p12 \
141
+        -inkey /home/$USERNAME/emailcert/$USERNAME.key \
142
+        -certfile /home/$USERNAME/emailcert/dovecot-ca.crt \
143
+        -outpass pass:
141
 
144
 
142
 # make an install script
145
 # make an install script
143
 echo '#!/bin/bash' > /home/$USERNAME/emailcert/install.sh
146
 echo '#!/bin/bash' > /home/$USERNAME/emailcert/install.sh
144
-echo "sudo mv $USERNAME.crt /etc/ssl/certs" >> /home/$USERNAME/emailcert/install.sh
145
-echo "sudo mv $USERNAME.key /etc/ssl/private" >> /home/$USERNAME/emailcert/install.sh
147
+echo "sudo mv $USERNAME.crt /etc/ssl/certs" >> \
148
+     /home/$USERNAME/emailcert/install.sh
149
+echo "sudo mv $USERNAME.key /etc/ssl/private" >> \
150
+     /home/$USERNAME/emailcert/install.sh
146
 echo 'exit 0' >> /home/$USERNAME/emailcert/install.sh
151
 echo 'exit 0' >> /home/$USERNAME/emailcert/install.sh
147
 
152
 
148
 # set permissions for the user
153
 # set permissions for the user
154
 
159
 
155
 echo 'Email authentication certificate created. You can obtain it on the client with:'
160
 echo 'Email authentication certificate created. You can obtain it on the client with:'
156
 echo ''
161
 echo ''
157
-echo "      scp -P 2222 -r $USERNAME@mydomainname:/home/$USERNAME/emailcert ~/"
162
+echo "      scp -P 2222 -r $USERNAME@$HOSTNAME:/home/$USERNAME/emailcert ~/"
158
 echo ''
163
 echo ''
159
 
164
 
160
 exit 0
165
 exit 0