summaryrefslogtreecommitdiff
path: root/www/ap-ssl/patches/patch-ab
blob: b07a0f140525d7dfeea5d68ae50736828ebdbdb2 (plain)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
$NetBSD: patch-ab,v 1.2 2001/04/29 20:36:48 jlam Exp $

--- pkg.sslsup/mkcert.sh.in.orig	Sun Apr 16 05:21:24 2000
+++ pkg.sslsup/mkcert.sh.in
@@ -5,35 +5,53 @@
 ##
 
 #   parameters
-make="$1"
-mflags="$2"
-openssl="$3"
-support="$4"
-type="$5"
-algo="$6"
-crt="$7"
-key="$8"
-view="$9"
-
-#   we can operate only inside the Apache 1.3 source
-#   tree and only when mod_ssl+OpenSSL is actually configured.
-if [ ! -f "../README.configure" ]; then
-    echo "mkcert.sh:Error: Cannot operate outside the Apache 1.3 source tree." 1>&2
-    echo "mkcert.sh:Hint:  You have to stay inside apache_1.3.x/src." 1>&2
-    exit 1
-fi
-if [ ".$openssl" = . ]; then
-    echo "mkcert.sh:Error: mod_ssl/OpenSSL has to be configured before using this utility." 1>&2
-    echo "mkcert.sh:Hint:  Configure mod_ssl with --enable-module=ssl in APACI, first." 1>&2
-    exit 1
+parameters=`getopt a:c:t:k:v $*`
+if [ $# = 0 ]; then
+    cat << EOF
+Usage:
+        mkcert.sh [-t type] [-a algo] [-c crtfile ] [-k keyfile] [-v]
+
+Options:
+        -t type		Type of certificates to generate.  Valid types are:
+                            dummy      self-signed Snake Oil cert
+                            test       test cert signed by Snake Oil CA
+                            custom     custom cert signed by own CA
+                            existing   existing cert
+
+        -a algo         Signature algorithm for generated certificate.  Valid
+                        algorithms are RSA or DSA.
+
+        -c crtfile      Path to an existing certificate
+
+        -k keyfile      Path to an existing key file
+
+        -v              Display the certificate and key, then exit.
+
+EOF
+    exit 2
 fi
 
+set -- $parameters
+for param; do
+    case $param in
+        -a) algo=$2 ;;
+        -c) crt=$2 ;;
+        -t) type=$2 ;;
+        -k) key=$2 ;;
+        -v) view=1 ;;
+        --) break ;;
+    esac
+    shift
+done
+
+openssl="openssl"
+confdir=@APACHE_SYSCONFDIR@
+
 #   configuration
-#   WE ARE CALLED FROM THE PARENT DIR!
-sslcrtdir="../conf/ssl.crt"
-sslcsrdir="../conf/ssl.csr"
-sslkeydir="../conf/ssl.key"
-sslprmdir="../conf/ssl.prm"
+sslcrtdir="$confdir/ssl.crt"
+sslcsrdir="$confdir/ssl.csr"
+sslkeydir="$confdir/ssl.key"
+sslprmdir="$confdir/ssl.prm"
 
 #   some optional terminal sequences
 case $TERM in
@@ -93,11 +111,11 @@
 fi
 
 #   find some random files
-#   (do not use /dev/random here, because this device 
-#   doesn't work as expected on all platforms)
-randfiles=''
+#   We will always generate a /tmp/randfile using /dev/urandom
+#   before passing $randfile to openssl.
+randfiles='/tmp/randfile'
 for file in /var/log/messages /var/adm/messages /var/log/system.log /var/wtmp \
-            /kernel /kernel/genunix /vmunix /vmlinuz /mach \
+            /kernel /kernel/genunix /vmunix /vmlinuz /mach /netbsd \
             /etc/hosts /etc/group /etc/resolv.conf /bin/ls; do
     if [ -r $file ]; then
         if [ ".$randfiles" = . ]; then
@@ -112,7 +130,7 @@
 if [ -f $HOME/.rnd ]; then
     RANDFILE="$HOME/.rnd"
 else
-    RANDFILE=".mkcert.rnd"
+    RANDFILE="/tmp/.mkcert.rnd"
     (ps; date) >$RANDFILE
 fi
 export RANDFILE
@@ -156,12 +174,12 @@
         fi
         echo "${T_MD}RESULT: Server Certification Files${T_ME}"
         echo ""
-        echo "o  ${T_MD}conf/ssl.key/server.key${T_ME}"
+        echo "o  ${T_MD}$confdir/ssl.key/server.key${T_ME}"
         echo "   The PEM-encoded $algo private key file which you configure"
         echo "   with the 'SSLCertificateKeyFile' directive (automatically done"
         echo "   when you install via APACI). ${T_MD}KEEP THIS FILE PRIVATE!${T_ME}"
         echo ""
-        echo "o  ${T_MD}conf/ssl.crt/server.crt${T_ME}"
+        echo "o  ${T_MD}$confdir/ssl.crt/server.crt${T_ME}"
         echo "   The PEM-encoded X.509 certificate file which you configure"
         echo "   with the 'SSLCertificateFile' directive (automatically done"
         echo "   when you install via APACI)."
@@ -211,6 +229,7 @@
         echo "______________________________________________________________________"
         echo ""
         echo "${T_MD}STEP 1: Generating $algo private key (1024 bit) [server.key]${T_ME}"
+        (umask 077; head -500 /dev/urandom > randfile)
         if [ ".$algo" = .RSA ]; then
             if [ ".$randfiles" != . ]; then
                 $openssl genrsa -rand $randfiles -out $sslkeydir/server.key 1024
@@ -238,10 +257,11 @@
                 exit 1
             fi
         fi
+        rm -f randfile
         echo "______________________________________________________________________"
         echo ""
         echo "${T_MD}STEP 2: Generating X.509 certificate signing request [server.csr]${T_ME}"
-        cat >.mkcert.cfg <<EOT
+        cat >/tmp/.mkcert.cfg <<EOT
 [ req ]
 default_bits                    = 1024
 distinguished_name              = req_DN
@@ -265,7 +285,7 @@
 emailAddress_max                = 40
 emailAddress_default            = www@snakeoil.dom
 EOT
-        $openssl req -config .mkcert.cfg \
+        $openssl req -config /tmp/.mkcert.cfg \
                      -new \
                      -key $sslkeydir/server.key \
                      -out $sslcsrdir/server.csr
@@ -273,7 +293,7 @@
             echo "mkcert.sh:Error: Failed to generate certificate signing request" 1>&2
             exit 1
         fi
-        rm -f .mkcert.cfg
+        rm -f /tmp/.mkcert.cfg
         prompt="8. Certificate Validity     (days)          [365]:"
         echo dummy | awk '{ printf("%s", prompt); }' "prompt=$prompt"
         read days
@@ -287,8 +307,8 @@
         read certversion
         extfile=""
         if [ ".$certversion" = .3 -o ".$certversion" = . ]; then
-            extfile="-extfile .mkcert.cfg"
-            cat >.mkcert.cfg <<EOT
+            extfile="-extfile /tmp/.mkcert.cfg"
+            cat >/tmp/.mkcert.cfg <<EOT
 extensions = x509v3
 [ x509v3 ]
 subjectAltName   = email:copy
@@ -296,13 +316,13 @@
 nsCertType       = server
 EOT
         fi
-        if [ ! -f .mkcert.serial ]; then
-            echo '01' >.mkcert.serial
+        if [ ! -f /tmp/.mkcert.serial ]; then
+            echo '01' >/tmp/.mkcert.serial
         fi
         if [ ".$algo" = .RSA ]; then
             $openssl x509 $extfile \
                           -days $days \
-                          -CAserial .mkcert.serial \
+                          -CAserial /tmp/.mkcert.serial \
                           -CA $sslcrtdir/snakeoil-ca-rsa.crt \
                           -CAkey $sslkeydir/snakeoil-ca-rsa.key \
                           -in $sslcsrdir/server.csr -req \
@@ -310,7 +330,7 @@
         else
             $openssl x509 $extfile \
                           -days $days \
-                          -CAserial .mkcert.serial \
+                          -CAserial /tmp/.mkcert.serial \
                           -CA $sslcrtdir/snakeoil-ca-dsa.crt \
                           -CAkey $sslkeydir/snakeoil-ca-dsa.key \
                           -in $sslcsrdir/server.csr -req \
@@ -320,7 +340,7 @@
             echo "mkcert.sh:Error: Failed to generate X.509 certificate" 1>&2
             exit 1
         fi
-        rm -f .mkcert.cfg
+        rm -f /tmp/.mkcert.cfg
         echo "Verify: matching certificate & key modulus"
         modcrt=`$openssl x509 -noout -modulus -in $sslcrtdir/server.crt | sed -e 's;.*Modulus=;;'`
         if [ ".$algo" = .RSA ]; then
@@ -387,22 +407,22 @@
         echo ""
         echo "${T_MD}RESULT: Server Certification Files${T_ME}"
         echo ""
-        echo "o  ${T_MD}conf/ssl.key/server.key${T_ME}"
+        echo "o  ${T_MD}$confdir/ssl.key/server.key${T_ME}"
         echo "   The PEM-encoded $algo private key file which you configure"
         echo "   with the 'SSLCertificateKeyFile' directive (automatically done"
         echo "   when you install via APACI). ${T_MD}KEEP THIS FILE PRIVATE!${T_ME}"
         echo ""
-        echo "o  ${T_MD}conf/ssl.crt/server.crt${T_ME}"
+        echo "o  ${T_MD}$confdir/ssl.crt/server.crt${T_ME}"
         echo "   The PEM-encoded X.509 certificate file which you configure"
         echo "   with the 'SSLCertificateFile' directive (automatically done"
         echo "   when you install via APACI)."
         echo ""
-        echo "o  ${T_MD}conf/ssl.csr/server.csr${T_ME}"
+        echo "o  ${T_MD}$confdir/ssl.csr/server.csr${T_ME}"
         echo "   The PEM-encoded X.509 certificate signing request file which" 
         echo "   you can send to an official Certificate Authority (CA) in order"
         echo "   to request a real server certificate (signed by this CA instead"
         echo "   of our demonstration-only Snake Oil CA) which later can replace"
-        echo "   the conf/ssl.crt/server.crt file."
+        echo "   the $confdir/ssl.crt/server.crt file."
         echo ""
         echo "WARNING: Do not use this for real-life/production systems"
         echo ""
@@ -448,6 +468,7 @@
         echo "______________________________________________________________________"
         echo ""
         echo "${T_MD}STEP 1: Generating $algo private key for CA (1024 bit) [ca.key]${T_ME}"
+        (umask 077; head -500 /dev/urandom > randfile)
         if [ ".$algo" = .RSA ]; then
             if [ ".$randfiles" != . ]; then
                 $openssl genrsa -rand $randfiles -out $sslkeydir/ca.key 1024
@@ -475,10 +496,11 @@
                 exit 1
             fi
         fi
+        rm -f randfile
         echo "______________________________________________________________________"
         echo ""
         echo "${T_MD}STEP 2: Generating X.509 certificate signing request for CA [ca.csr]${T_ME}"
-        cat >.mkcert.cfg <<EOT
+        cat >/tmp/.mkcert.cfg <<EOT
 [ req ]
 default_bits                    = 1024
 distinguished_name              = req_DN
@@ -502,7 +524,7 @@
 emailAddress_max                = 40
 emailAddress_default            = ca@snakeoil.dom
 EOT
-        $openssl req -config .mkcert.cfg \
+        $openssl req -config /tmp/.mkcert.cfg \
                      -new \
                      -key $sslkeydir/ca.key \
                      -out $sslcsrdir/ca.csr
@@ -510,7 +532,7 @@
             echo "mkcert.sh:Error: Failed to generate certificate signing request" 1>&2
             exit 1
         fi
-        rm -f .mkcert.cfg
+        rm -f /tmp/.mkcert.cfg
         prompt="8. Certificate Validity     (days)          [365]:"
         echo dummy | awk '{ printf("%s", prompt); }' "prompt=$prompt"
         read days
@@ -524,8 +546,8 @@
         read certversion
         extfile=""
         if [ ".$certversion" = .3 -o ".$certversion" = . ]; then
-            extfile="-extfile .mkcert.cfg"
-            cat >.mkcert.cfg <<EOT
+            extfile="-extfile /tmp/.mkcert.cfg"
+            cat >/tmp/.mkcert.cfg <<EOT
 extensions = x509v3
 [ x509v3 ]
 subjectAltName   = email:copy
@@ -543,7 +565,7 @@
             echo "mkcert.sh:Error: Failed to generate self-signed CA certificate" 1>&2
             exit 1
         fi
-        rm -f .mkcert.cfg
+        rm -f /tmp/.mkcert.cfg
         echo "Verify: matching certificate & key modulus"
         modcrt=`$openssl x509 -noout -modulus -in $sslcrtdir/ca.crt | sed -e 's;.*Modulus=;;'`
         if [ ".$algo" = .RSA ]; then
@@ -564,6 +586,7 @@
         echo "______________________________________________________________________"
         echo ""
         echo "${T_MD}STEP 4: Generating $algo private key for SERVER (1024 bit) [server.key]${T_ME}"
+        (umask 077; head -500 /dev/urandom > randfile)
         if [ ".$algo" = .RSA ]; then
             if [ ".$randfiles" != . ]; then
                 $openssl genrsa -rand $randfiles -out $sslkeydir/server.key 1024
@@ -588,10 +611,11 @@
                 exit 1
             fi
         fi
+        rm -f randfile
         echo "______________________________________________________________________"
         echo ""
         echo "${T_MD}STEP 5: Generating X.509 certificate signing request for SERVER [server.csr]${T_ME}"
-        cat >.mkcert.cfg <<EOT
+        cat >/tmp/.mkcert.cfg <<EOT
 [ req ]
 default_bits                    = 1024
 distinguished_name              = req_DN
@@ -615,7 +639,7 @@
 emailAddress_max                = 40
 emailAddress_default            = www@snakeoil.dom
 EOT
-        $openssl req -config .mkcert.cfg \
+        $openssl req -config /tmp/.mkcert.cfg \
                      -new \
                      -key $sslkeydir/server.key \
                      -out $sslcsrdir/server.csr
@@ -623,7 +647,7 @@
             echo "mkcert.sh:Error: Failed to generate certificate signing request" 1>&2
             exit 1
         fi
-        rm -f .mkcert.cfg
+        rm -f /tmp/.mkcert.cfg
         prompt="8. Certificate Validity     (days)          [365]:"
         echo dummy | awk '{ printf("%s", prompt); }' "prompt=$prompt"
         read days
@@ -637,8 +661,8 @@
         read certversion
         extfile=""
         if [ ".$certversion" = .3 -o ".$certversion" = . ]; then
-            extfile="-extfile .mkcert.cfg"
-            cat >.mkcert.cfg <<EOT
+            extfile="-extfile /tmp/.mkcert.cfg"
+            cat >/tmp/.mkcert.cfg <<EOT
 extensions = x509v3
 [ x509v3 ]
 subjectAltName   = email:copy
@@ -646,12 +670,12 @@
 nsCertType       = server
 EOT
         fi
-        if [ ! -f .mkcert.serial ]; then
-            echo '01' >.mkcert.serial
+        if [ ! -f /tmp/.mkcert.serial ]; then
+            echo '01' >/tmp/.mkcert.serial
         fi
         $openssl x509 $extfile \
                       -days $days \
-                      -CAserial .mkcert.serial \
+                      -CAserial /tmp/.mkcert.serial \
                       -CA    $sslcrtdir/ca.crt \
                       -CAkey $sslkeydir/ca.key \
                       -in    $sslcsrdir/server.csr -req \
@@ -660,7 +684,7 @@
             echo "mkcert.sh:Error: Failed to generate X.509 certificate" 1>&2
             exit 1
         fi
-        rm -f .mkcert.cfg
+        rm -f /tmp/.mkcert.cfg
         echo "Verify: matching certificate & key modulus"
         modcrt=`$openssl x509 -noout -modulus -in $sslcrtdir/server.crt | sed -e 's;.*Modulus=;;'`
         if [ ".$algo" = .RSA ]; then
@@ -764,31 +788,31 @@
         echo ""
         echo "${T_MD}RESULT: CA and Server Certification Files${T_ME}"
         echo ""
-        echo "o  ${T_MD}conf/ssl.key/ca.key${T_ME}"
+        echo "o  ${T_MD}$confdir/ssl.key/ca.key${T_ME}"
         echo "   The PEM-encoded $algo private key file of the CA which you can"
         echo "   use to sign other servers or clients. ${T_MD}KEEP THIS FILE PRIVATE!${T_ME}"
         echo ""
-        echo "o  ${T_MD}conf/ssl.crt/ca.crt${T_ME}"
+        echo "o  ${T_MD}$confdir/ssl.crt/ca.crt${T_ME}"
         echo "   The PEM-encoded X.509 certificate file of the CA which you use to"
         echo "   sign other servers or clients. When you sign clients with it (for"
         echo "   SSL client authentication) you can configure this file with the"
         echo "   'SSLCACertificateFile' directive."
         echo ""
-        echo "o  ${T_MD}conf/ssl.key/server.key${T_ME}"
+        echo "o  ${T_MD}$confdir/ssl.key/server.key${T_ME}"
         echo "   The PEM-encoded $algo private key file of the server which you configure"
         echo "   with the 'SSLCertificateKeyFile' directive (automatically done"
         echo "   when you install via APACI). ${T_MD}KEEP THIS FILE PRIVATE!${T_ME}"
         echo ""
-        echo "o  ${T_MD}conf/ssl.crt/server.crt${T_ME}"
+        echo "o  ${T_MD}$confdir/ssl.crt/server.crt${T_ME}"
         echo "   The PEM-encoded X.509 certificate file of the server which you configure"
         echo "   with the 'SSLCertificateFile' directive (automatically done"
         echo "   when you install via APACI)."
         echo ""
-        echo "o  ${T_MD}conf/ssl.csr/server.csr${T_ME}"
+        echo "o  ${T_MD}$confdir/ssl.csr/server.csr${T_ME}"
         echo "   The PEM-encoded X.509 certificate signing request of the server file which" 
         echo "   you can send to an official Certificate Authority (CA) in order"
         echo "   to request a real server certificate (signed by this CA instead"
-        echo "   of our own CA) which later can replace the conf/ssl.crt/server.crt"
+        echo "   of our own CA) which later can replace the $confdir/ssl.crt/server.crt"
         echo "   file."
         echo ""
         echo "Congratulations that you establish your server with real certificates."
@@ -808,14 +832,26 @@
             echo "mkcert.sh: Cannot find certificate file: $crt" 1>&2
             exit 1
         fi
+        if [ $crt -ef $sslcrtdir/server.crt ]; then
+            mv -f $crt $crt.backup
+            crt="$crt.backup"
+        fi
         if [ ".$key" != . ]; then
             if [ ! -f "$key" ]; then
                 echo "mkcert.sh: Cannot find private key file: $key" 1>&2
                 exit 1
             fi
+            if [ $key -ef $sslkeydir/server.key ]; then
+                mv -f $key $key.backup
+                key="$key.backup"
+            fi
             cp $crt $sslcrtdir/server.crt
             (umask 077; cp $key $sslkeydir/server.key)
         else
+            if [ $crt -ef $sslcrtdir/server.crt ]; then
+                mv -f $crt $crt.backup
+                crt="$crt.backup"
+            fi
             key=$crt
             umask 077
             touch $sslkeydir/server.key
@@ -836,12 +872,12 @@
         fi
         echo "${T_MD}RESULT: Server Certification Files${T_ME}"
         echo ""
-        echo "o  ${T_MD}conf/ssl.key/server.key${T_ME}"
+        echo "o  ${T_MD}$confdir/ssl.key/server.key${T_ME}"
         echo "   The PEM-encoded $algo private key file which you configure"
         echo "   with the 'SSLCertificateKeyFile' directive (automatically done"
         echo "   when you install via APACI). ${T_MD}KEEP THIS FILE PRIVATE!${T_ME}"
         echo ""
-        echo "o  ${T_MD}conf/ssl.crt/server.crt${T_ME}"
+        echo "o  ${T_MD}$confdir/ssl.crt/server.crt${T_ME}"
         echo "   The PEM-encoded X.509 certificate file which you configure"
         echo "   with the 'SSLCertificateFile' directive (automatically done"
         echo "   when you install via APACI)."