1 $! CA - wrapper around ca to make it easier to use ... basically ca requires
2 $! some setup stuff to be done before you can use it and this makes
3 $! things easier between now and when Eric is convinced to fix it :-)
5 $! CA -newca ... will setup the right stuff
6 $! CA -newreq ... will generate a certificate request
7 $! CA -sign ... will sign the generated request and output
9 $! At the end of that grab newreq.pem and newcert.pem (one has the key
10 $! and the other the certificate) and cat them together and that is what
11 $! you want/need ... I'll make even this a little cleaner later.
14 $! 12-Jan-96 tjh Added more things ... including CA -signcert which
15 $! converts a certificate to a request and then signs it.
16 $! 10-Jan-96 eay Fixed a few more bugs and added the SSLEAY_CONFIG
17 $! environment variable so this can be driven from
19 $! 25-Jul-96 eay Cleaned up filenames some more.
20 $! 11-Jun-96 eay Fixed a few filename missmatches.
21 $! 03-May-96 eay Modified to use 'openssl cmd' instead of 'cmd'.
22 $! 18-Apr-96 tjh Original hacking
28 $! default ssleay.cnf file has setup as per the following
29 $! demoCA ... where everything is stored
31 $ IF F$TYPE(SSLEAY_CONFIG) .EQS. "" THEN SSLEAY_CONFIG := SSLLIB:SSLEAY.CNF
34 $ REQ = openssl + " req " + SSLEAY_CONFIG
35 $ CA = openssl + " ca " + SSLEAY_CONFIG
36 $ VERIFY = openssl + " verify"
37 $ X509 = openssl + " x509"
38 $ PKCS12 = openssl + " pkcs12"
39 $ echo = "write sys$Output"
41 $ s = F$PARSE(F$ENVIRONMENT("DEFAULT"),"[]") - "].;"
44 $ CACERT := ]cacert.pem
46 $ __INPUT := SYS$COMMAND
51 $ if i .gt. 8 then goto opt_loop_end
53 $ prog_opt = F$EDIT(P'i',"lowercase")
55 $ IF (prog_opt .EQS. "?" .OR. prog_opt .EQS. "-h" .OR. prog_opt .EQS. "-help")
57 $ echo "usage: CA -newcert|-newreq|-newca|-sign|-verify"
61 $ IF (prog_opt .EQS. "-input")
63 $ ! Get input from somewhere other than SYS$COMMAND
66 $ GOTO opt_loop_continue
69 $ IF (prog_opt .EQS. "-newcert")
71 $ ! Create a certificate.
72 $ DEFINE/USER SYS$INPUT '__INPUT'
73 $ REQ -new -x509 -keyout newreq.pem -out newreq.pem 'DAYS'
75 $ echo "Certificate (and private key) is in newreq.pem"
76 $ GOTO opt_loop_continue
79 $ IF (prog_opt .EQS. "-newreq")
81 $ ! Create a certificate request
82 $ DEFINE/USER SYS$INPUT '__INPUT'
83 $ REQ -new -keyout newreq.pem -out newreq.pem 'DAYS'
85 $ echo "Request (and private key) is in newreq.pem"
86 $ GOTO opt_loop_continue
89 $ IF (prog_opt .EQS. "-newca")
91 $ ! If explicitly asked for or it doesn't exist then setup the directory
92 $ ! structure that Eric likes to manage things.
93 $ IF F$SEARCH(CATOP+"]serial.") .EQS. ""
95 $ CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP']
96 $ CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP'.certs]
97 $ CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP'.crl]
98 $ CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP'.newcerts]
99 $ CREATE /DIR /PROTECTION=OWNER:RWED 'CATOP'.private]
101 $ OPEN /WRITE ser_file 'CATOP']serial.
102 $ WRITE ser_file "01"
104 $ APPEND/NEW NL: 'CATOP']index.txt
106 $ ! The following is to make sure access() doesn't get confused. It
107 $ ! really needs one file in the directory to give correct answers...
108 $ COPY NLA0: 'CATOP'.certs].;
109 $ COPY NLA0: 'CATOP'.crl].;
110 $ COPY NLA0: 'CATOP'.newcerts].;
111 $ COPY NLA0: 'CATOP'.private].;
114 $ IF F$SEARCH(CATOP+".private"+CAKEY) .EQS. ""
116 $ READ '__INPUT' FILE -
117 /PROMT="CA certificate filename (or enter to create)"
118 $ IF F$SEARCH(FILE) .NES. ""
120 $ COPY 'FILE' 'CATOP'.private'CAKEY'
123 $ echo "Making CA certificate ..."
124 $ DEFINE/USER SYS$INPUT '__INPUT'
125 $ REQ -new -x509 -keyout 'CATOP'.private'CAKEY' -
126 -out 'CATOP''CACERT' 'DAYS'
130 $ GOTO opt_loop_continue
133 $ IF (prog_opt .EQS. "-pkcs12")
137 $ IF cname .EQS. "" THEN cname = "My certificate"
138 $ PKCS12 -in newcert.pem -inkey newreq.pem -certfile 'CATOP''CACERT -
139 -out newcert.p12 -export -name "''cname'"
144 $ IF (prog_opt .EQS. "-xsign")
147 $ DEFINE/USER SYS$INPUT '__INPUT'
148 $ CA -policy policy_anything -infiles newreq.pem
150 $ GOTO opt_loop_continue
153 $ IF ((prog_opt .EQS. "-sign") .OR. (prog_opt .EQS. "-signreq"))
156 $ DEFINE/USER SYS$INPUT '__INPUT'
157 $ CA -policy policy_anything -out newcert.pem -infiles newreq.pem
160 $ echo "Signed certificate is in newcert.pem"
161 $ GOTO opt_loop_continue
164 $ IF (prog_opt .EQS. "-signcert")
167 $ echo "Cert passphrase will be requested twice - bug?"
168 $ DEFINE/USER SYS$INPUT '__INPUT'
169 $ X509 -x509toreq -in newreq.pem -signkey newreq.pem -out tmp.pem
170 $ DEFINE/USER SYS$INPUT '__INPUT'
171 $ CA -policy policy_anything -out newcert.pem -infiles tmp.pem
175 $ echo "Signed certificate is in newcert.pem"
176 $ GOTO opt_loop_continue
179 $ IF (prog_opt .EQS. "-verify")
185 $ DEFINE/USER SYS$INPUT '__INPUT'
186 $ VERIFY "-CAfile" 'CATOP''CACERT' newcert.pem
190 $ IF j .GT. 8 THEN GOTO verify_opt_loop_end
193 $ DEFINE/USER SYS$INPUT '__INPUT'
195 $ VERIFY "-CAfile" 'CATOP''CACERT' '__tmp'
197 $ IF tmp .NE. 0 THEN RET=tmp
200 $ GOTO verify_opt_loop
201 $ verify_opt_loop_end:
207 $ IF (prog_opt .NES. "")
210 $ echo "Unknown argument ''prog_opt'"