1#!/bin/sh 2 3# Recreate the demo certificates in the apps directory. 4 5opensslcmd() { 6 LD_LIBRARY_PATH=../../.. ../../../apps/openssl $@ 7} 8 9opensslcmd version 10 11# Root CA: create certificate directly 12CN="OpenSSL Test Root CA" opensslcmd req -config apps.cnf -x509 -nodes \ 13 -keyout root.pem -out root.pem -key rootkey.pem -new -days 3650 14# Intermediate CA: request first 15CN="OpenSSL Test Intermediate CA" opensslcmd req -config apps.cnf -nodes \ 16 -key intkey.pem -out intreq.pem -new 17# Sign request: CA extensions 18opensslcmd x509 -req -in intreq.pem -CA root.pem -CAkey rootkey.pem -days 3630 \ 19 -extfile apps.cnf -extensions v3_ca -CAcreateserial -out intca.pem 20# Client certificate: request first 21CN="Test Client Cert" opensslcmd req -config apps.cnf -nodes \ 22 -key ckey.pem -out creq.pem -new 23# Sign using intermediate CA 24opensslcmd x509 -req -in creq.pem -CA intca.pem -CAkey intkey.pem -days 3600 \ 25 -extfile apps.cnf -extensions usr_cert -CAcreateserial | \ 26 opensslcmd x509 -nameopt oneline -subject -issuer >client.pem 27# Server certificate: request first 28CN="Test Server Cert" opensslcmd req -config apps.cnf -nodes \ 29 -key skey.pem -out sreq.pem -new 30# Sign using intermediate CA 31opensslcmd x509 -req -in sreq.pem -CA intca.pem -CAkey intkey.pem -days 3600 \ 32 -extfile apps.cnf -extensions usr_cert -CAcreateserial | \ 33 opensslcmd x509 -nameopt oneline -subject -issuer >server.pem 34# Server certificate #2: request first 35CN="Test Server Cert #2" opensslcmd req -config apps.cnf -nodes \ 36 -key skey2.pem -out sreq2.pem -new 37# Sign using intermediate CA 38opensslcmd x509 -req -in sreq2.pem -CA intca.pem -CAkey intkey.pem -days 3600 \ 39 -extfile apps.cnf -extensions usr_cert -CAcreateserial | \ 40 opensslcmd x509 -nameopt oneline -subject -issuer >server2.pem 41 42# Append keys to file. 43 44cat skey.pem >>server.pem 45cat skey2.pem >>server2.pem 46cat ckey.pem >>client.pem 47 48opensslcmd verify -CAfile root.pem -untrusted intca.pem \ 49 server2.pem server.pem client.pem 50