1999-05-13 11:37:32 +00:00
|
|
|
$! CA - wrapper around ca to make it easier to use ... basically ca requires
|
|
|
|
$! some setup stuff to be done before you can use it and this makes
|
|
|
|
$! things easier between now and when Eric is convinced to fix it :-)
|
|
|
|
$!
|
|
|
|
$! CA -newca ... will setup the right stuff
|
|
|
|
$! CA -newreq ... will generate a certificate request
|
|
|
|
$! CA -sign ... will sign the generated request and output
|
|
|
|
$!
|
|
|
|
$! At the end of that grab newreq.pem and newcert.pem (one has the key
|
|
|
|
$! and the other the certificate) and cat them together and that is what
|
|
|
|
$! you want/need ... I'll make even this a little cleaner later.
|
|
|
|
$!
|
|
|
|
$!
|
|
|
|
$! 12-Jan-96 tjh Added more things ... including CA -signcert which
|
|
|
|
$! converts a certificate to a request and then signs it.
|
|
|
|
$! 10-Jan-96 eay Fixed a few more bugs and added the SSLEAY_CONFIG
|
|
|
|
$! environment variable so this can be driven from
|
|
|
|
$! a script.
|
|
|
|
$! 25-Jul-96 eay Cleaned up filenames some more.
|
|
|
|
$! 11-Jun-96 eay Fixed a few filename missmatches.
|
|
|
|
$! 03-May-96 eay Modified to use 'openssl cmd' instead of 'cmd'.
|
|
|
|
$! 18-Apr-96 tjh Original hacking
|
|
|
|
$!
|
|
|
|
$! Tim Hudson
|
|
|
|
$! tjh@cryptsoft.com
|
|
|
|
$!
|
|
|
|
$!
|
|
|
|
$! default ssleay.cnf file has setup as per the following
|
|
|
|
$! demoCA ... where everything is stored
|
|
|
|
$
|
|
|
|
$ IF F$TYPE(SSLEAY_CONFIG) .EQS. "" THEN SSLEAY_CONFIG := SSLLIB:SSLEAY.CNF
|
|
|
|
$
|
|
|
|
$ DAYS = "-days 365"
|
|
|
|
$ REQ = openssl + " req " + SSLEAY_CONFIG
|
|
|
|
$ CA = openssl + " ca " + SSLEAY_CONFIG
|
|
|
|
$ VERIFY = openssl + " verify"
|
|
|
|
$ X509 = openssl + " x509"
|
2000-01-28 12:15:20 +00:00
|
|
|
$ PKCS12 = openssl + " pkcs12"
|
1999-05-13 11:37:32 +00:00
|
|
|
$ echo = "write sys$Output"
|
2011-03-25 16:20:35 +00:00
|
|
|
$ RET = 1
|
|
|
|
$!
|
|
|
|
$! 2010-12-20 SMS.
|
|
|
|
$! Use a concealed logical name to reduce command line lengths, to
|
|
|
|
$! avoid DCL errors on VAX:
|
|
|
|
$! %DCL-W-TKNOVF, command element is too long - shorten
|
|
|
|
$! (Path segments like "openssl-1_0_1-stable-SNAP-20101217" accumulate
|
|
|
|
$! quickly.)
|
|
|
|
$!
|
|
|
|
$ CATOP = F$PARSE( F$ENVIRONMENT( "DEFAULT"), "[]")- "].;"+ ".demoCA.]"
|
|
|
|
$ define /translation_attributes = concealed CATOP 'CATOP'
|
1999-05-13 11:37:32 +00:00
|
|
|
$!
|
2011-03-25 16:20:35 +00:00
|
|
|
$ on error then goto clean_up
|
|
|
|
$ on control_y then goto clean_up
|
|
|
|
$!
|
|
|
|
$ CAKEY = "CATOP:[private]cakey.pem"
|
|
|
|
$ CACERT = "CATOP:[000000]cacert.pem"
|
1999-05-13 11:37:32 +00:00
|
|
|
$
|
|
|
|
$ __INPUT := SYS$COMMAND
|
|
|
|
$!
|
|
|
|
$ i = 1
|
|
|
|
$opt_loop:
|
|
|
|
$ if i .gt. 8 then goto opt_loop_end
|
|
|
|
$
|
|
|
|
$ prog_opt = F$EDIT(P'i',"lowercase")
|
|
|
|
$
|
|
|
|
$ IF (prog_opt .EQS. "?" .OR. prog_opt .EQS. "-h" .OR. prog_opt .EQS. "-help")
|
|
|
|
$ THEN
|
|
|
|
$ echo "usage: CA -newcert|-newreq|-newca|-sign|-verify"
|
2011-03-25 16:20:35 +00:00
|
|
|
$ goto clean_up
|
1999-05-13 11:37:32 +00:00
|
|
|
$ ENDIF
|
|
|
|
$!
|
|
|
|
$ IF (prog_opt .EQS. "-input")
|
|
|
|
$ THEN
|
|
|
|
$ ! Get input from somewhere other than SYS$COMMAND
|
|
|
|
$ i = i + 1
|
|
|
|
$ __INPUT = P'i'
|
|
|
|
$ GOTO opt_loop_continue
|
|
|
|
$ ENDIF
|
|
|
|
$!
|
|
|
|
$ IF (prog_opt .EQS. "-newcert")
|
|
|
|
$ THEN
|
|
|
|
$ ! Create a certificate.
|
2011-03-25 16:20:35 +00:00
|
|
|
$ DEFINE /USER_MODE SYS$INPUT '__INPUT'
|
1999-05-13 11:37:32 +00:00
|
|
|
$ REQ -new -x509 -keyout newreq.pem -out newreq.pem 'DAYS'
|
|
|
|
$ RET=$STATUS
|
|
|
|
$ echo "Certificate (and private key) is in newreq.pem"
|
|
|
|
$ GOTO opt_loop_continue
|
|
|
|
$ ENDIF
|
|
|
|
$!
|
|
|
|
$ IF (prog_opt .EQS. "-newreq")
|
|
|
|
$ THEN
|
|
|
|
$ ! Create a certificate request
|
2011-03-25 16:20:35 +00:00
|
|
|
$ DEFINE /USER_MODE SYS$INPUT '__INPUT'
|
1999-05-13 11:37:32 +00:00
|
|
|
$ REQ -new -keyout newreq.pem -out newreq.pem 'DAYS'
|
|
|
|
$ RET=$STATUS
|
|
|
|
$ echo "Request (and private key) is in newreq.pem"
|
|
|
|
$ GOTO opt_loop_continue
|
|
|
|
$ ENDIF
|
|
|
|
$!
|
|
|
|
$ IF (prog_opt .EQS. "-newca")
|
|
|
|
$ THEN
|
|
|
|
$ ! If explicitly asked for or it doesn't exist then setup the directory
|
|
|
|
$ ! structure that Eric likes to manage things.
|
2011-03-25 16:20:35 +00:00
|
|
|
$ IF F$SEARCH( "CATOP:[000000]serial.") .EQS. ""
|
1999-05-13 11:37:32 +00:00
|
|
|
$ THEN
|
2011-03-25 16:20:35 +00:00
|
|
|
$ CREATE /DIRECTORY /PROTECTION=OWNER:RWED CATOP:[000000]
|
|
|
|
$ CREATE /DIRECTORY /PROTECTION=OWNER:RWED CATOP:[certs]
|
|
|
|
$ CREATE /DIRECTORY /PROTECTION=OWNER:RWED CATOP:[crl]
|
|
|
|
$ CREATE /DIRECTORY /PROTECTION=OWNER:RWED CATOP:[newcerts]
|
|
|
|
$ CREATE /DIRECTORY /PROTECTION=OWNER:RWED CATOP:[private]
|
2000-02-11 18:12:47 +00:00
|
|
|
$
|
2011-03-25 16:20:35 +00:00
|
|
|
$ OPEN /WRITE ser_file CATOP:[000000]serial.
|
1999-05-13 11:37:32 +00:00
|
|
|
$ WRITE ser_file "01"
|
|
|
|
$ CLOSE ser_file
|
2011-03-25 16:20:35 +00:00
|
|
|
$ APPEND /NEW_VERSION NL: CATOP:[000000]index.txt
|
2000-02-11 18:12:47 +00:00
|
|
|
$
|
|
|
|
$ ! The following is to make sure access() doesn't get confused. It
|
|
|
|
$ ! really needs one file in the directory to give correct answers...
|
2011-03-25 16:20:35 +00:00
|
|
|
$ COPY NLA0: CATOP:[certs].;
|
|
|
|
$ COPY NLA0: CATOP:[crl].;
|
|
|
|
$ COPY NLA0: CATOP:[newcerts].;
|
|
|
|
$ COPY NLA0: CATOP:[private].;
|
1999-05-13 11:37:32 +00:00
|
|
|
$ ENDIF
|
|
|
|
$!
|
2011-03-25 16:20:35 +00:00
|
|
|
$ IF F$SEARCH( CAKEY) .EQS. ""
|
1999-05-13 11:37:32 +00:00
|
|
|
$ THEN
|
|
|
|
$ READ '__INPUT' FILE -
|
2011-03-25 16:20:35 +00:00
|
|
|
/PROMPT="CA certificate filename (or enter to create): "
|
2011-03-19 10:58:14 +00:00
|
|
|
$ IF (FILE .NES. "") .AND. (F$SEARCH(FILE) .NES. "")
|
1999-05-13 11:37:32 +00:00
|
|
|
$ THEN
|
2011-03-25 16:20:35 +00:00
|
|
|
$ COPY 'FILE' 'CAKEY'
|
|
|
|
$ RET=$STATUS
|
1999-05-13 11:37:32 +00:00
|
|
|
$ ELSE
|
|
|
|
$ echo "Making CA certificate ..."
|
2011-03-25 16:20:35 +00:00
|
|
|
$ DEFINE /USER_MODE SYS$INPUT '__INPUT'
|
|
|
|
$ REQ -new -x509 -keyout 'CAKEY' -out 'CACERT' 'DAYS'
|
|
|
|
$ RET=$STATUS
|
1999-05-13 11:37:32 +00:00
|
|
|
$ ENDIF
|
|
|
|
$ ENDIF
|
|
|
|
$ GOTO opt_loop_continue
|
|
|
|
$ ENDIF
|
|
|
|
$!
|
2000-01-28 12:15:20 +00:00
|
|
|
$ IF (prog_opt .EQS. "-pkcs12")
|
|
|
|
$ THEN
|
|
|
|
$ i = i + 1
|
|
|
|
$ cname = P'i'
|
|
|
|
$ IF cname .EQS. "" THEN cname = "My certificate"
|
2011-03-25 16:20:35 +00:00
|
|
|
$ PKCS12 -in newcert.pem -inkey newreq.pem -certfile 'CACERT' -
|
|
|
|
-out newcert.p12 -export -name "''cname'"
|
2000-01-28 12:15:20 +00:00
|
|
|
$ RET=$STATUS
|
2011-03-25 16:20:35 +00:00
|
|
|
$ goto clean_up
|
2000-01-28 12:15:20 +00:00
|
|
|
$ ENDIF
|
|
|
|
$!
|
1999-05-13 11:37:32 +00:00
|
|
|
$ IF (prog_opt .EQS. "-xsign")
|
|
|
|
$ THEN
|
|
|
|
$!
|
2011-03-25 16:20:35 +00:00
|
|
|
$ DEFINE /USER_MODE SYS$INPUT '__INPUT'
|
1999-05-13 11:37:32 +00:00
|
|
|
$ CA -policy policy_anything -infiles newreq.pem
|
|
|
|
$ RET=$STATUS
|
|
|
|
$ GOTO opt_loop_continue
|
|
|
|
$ ENDIF
|
|
|
|
$!
|
|
|
|
$ IF ((prog_opt .EQS. "-sign") .OR. (prog_opt .EQS. "-signreq"))
|
|
|
|
$ THEN
|
|
|
|
$!
|
2011-03-25 16:20:35 +00:00
|
|
|
$ DEFINE /USER_MODE SYS$INPUT '__INPUT'
|
1999-05-13 11:37:32 +00:00
|
|
|
$ CA -policy policy_anything -out newcert.pem -infiles newreq.pem
|
|
|
|
$ RET=$STATUS
|
|
|
|
$ type newcert.pem
|
|
|
|
$ echo "Signed certificate is in newcert.pem"
|
|
|
|
$ GOTO opt_loop_continue
|
|
|
|
$ ENDIF
|
|
|
|
$!
|
|
|
|
$ IF (prog_opt .EQS. "-signcert")
|
|
|
|
$ THEN
|
|
|
|
$!
|
|
|
|
$ echo "Cert passphrase will be requested twice - bug?"
|
2011-03-25 16:20:35 +00:00
|
|
|
$ DEFINE /USER_MODE SYS$INPUT '__INPUT'
|
1999-05-13 11:37:32 +00:00
|
|
|
$ X509 -x509toreq -in newreq.pem -signkey newreq.pem -out tmp.pem
|
2011-03-25 16:20:35 +00:00
|
|
|
$ DEFINE /USER_MODE SYS$INPUT '__INPUT'
|
1999-05-13 11:37:32 +00:00
|
|
|
$ CA -policy policy_anything -out newcert.pem -infiles tmp.pem
|
|
|
|
y
|
|
|
|
y
|
|
|
|
$ type newcert.pem
|
|
|
|
$ echo "Signed certificate is in newcert.pem"
|
|
|
|
$ GOTO opt_loop_continue
|
|
|
|
$ ENDIF
|
|
|
|
$!
|
|
|
|
$ IF (prog_opt .EQS. "-verify")
|
|
|
|
$ THEN
|
|
|
|
$!
|
|
|
|
$ i = i + 1
|
|
|
|
$ IF (p'i' .EQS. "")
|
|
|
|
$ THEN
|
2011-03-25 16:20:35 +00:00
|
|
|
$ DEFINE /USER_MODE SYS$INPUT '__INPUT'
|
|
|
|
$ VERIFY "-CAfile" 'CACERT' newcert.pem
|
1999-05-13 11:37:32 +00:00
|
|
|
$ ELSE
|
|
|
|
$ j = i
|
|
|
|
$ verify_opt_loop:
|
|
|
|
$ IF j .GT. 8 THEN GOTO verify_opt_loop_end
|
|
|
|
$ IF p'j' .NES. ""
|
|
|
|
$ THEN
|
2011-03-25 16:20:35 +00:00
|
|
|
$ DEFINE /USER_MODE SYS$INPUT '__INPUT'
|
1999-05-13 11:37:32 +00:00
|
|
|
$ __tmp = p'j'
|
2011-03-25 16:20:35 +00:00
|
|
|
$ VERIFY "-CAfile" 'CACERT' '__tmp'
|
1999-05-13 11:37:32 +00:00
|
|
|
$ tmp=$STATUS
|
|
|
|
$ IF tmp .NE. 0 THEN RET=tmp
|
|
|
|
$ ENDIF
|
|
|
|
$ j = j + 1
|
|
|
|
$ GOTO verify_opt_loop
|
|
|
|
$ verify_opt_loop_end:
|
|
|
|
$ ENDIF
|
|
|
|
$
|
|
|
|
$ GOTO opt_loop_end
|
|
|
|
$ ENDIF
|
|
|
|
$!
|
|
|
|
$ IF (prog_opt .NES. "")
|
|
|
|
$ THEN
|
|
|
|
$!
|
|
|
|
$ echo "Unknown argument ''prog_opt'"
|
2011-03-25 16:20:35 +00:00
|
|
|
$ RET = 3
|
|
|
|
$ goto clean_up
|
1999-05-13 11:37:32 +00:00
|
|
|
$ ENDIF
|
|
|
|
$
|
|
|
|
$opt_loop_continue:
|
|
|
|
$ i = i + 1
|
|
|
|
$ GOTO opt_loop
|
|
|
|
$
|
|
|
|
$opt_loop_end:
|
2011-03-25 16:20:35 +00:00
|
|
|
$!
|
|
|
|
$clean_up:
|
|
|
|
$!
|
|
|
|
$ if f$trnlnm( "CATOP", "LNM$PROCESS") .nes. "" then -
|
|
|
|
deassign /process CATOP
|
|
|
|
$!
|
1999-05-13 11:37:32 +00:00
|
|
|
$ EXIT 'RET'
|