1 1.1 christos #!/bin/sh 2 1.1.1.2 christos # Copyright 2013-2022 The OpenSSL Project Authors. All Rights Reserved. 3 1.1.1.2 christos # 4 1.1.1.2 christos # Licensed under the OpenSSL license (the "License"). You may not use 5 1.1.1.2 christos # this file except in compliance with the License. You can obtain a copy 6 1.1.1.2 christos # in the file LICENSE in the source distribution or at 7 1.1.1.2 christos # https://www.openssl.org/source/license.html 8 1.1.1.2 christos 9 1.1 christos 10 1.1 christos # Utility to recreate S/MIME certificates 11 1.1 christos 12 1.1 christos OPENSSL=../../apps/openssl 13 1.1 christos OPENSSL_CONF=./ca.cnf 14 1.1 christos export OPENSSL_CONF 15 1.1 christos 16 1.1 christos # Root CA: create certificate directly 17 1.1 christos CN="Test S/MIME RSA Root" $OPENSSL req -config ca.cnf -x509 -nodes \ 18 1.1.1.2 christos -keyout smroot.pem -out smroot.pem -newkey rsa:2048 -days 36501 19 1.1 christos 20 1.1 christos # EE RSA certificates: create request first 21 1.1 christos CN="Test S/MIME EE RSA #1" $OPENSSL req -config ca.cnf -nodes \ 22 1.1 christos -keyout smrsa1.pem -out req.pem -newkey rsa:2048 23 1.1 christos # Sign request: end entity extensions 24 1.1.1.2 christos $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 36500 \ 25 1.1 christos -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smrsa1.pem 26 1.1 christos 27 1.1 christos CN="Test S/MIME EE RSA #2" $OPENSSL req -config ca.cnf -nodes \ 28 1.1 christos -keyout smrsa2.pem -out req.pem -newkey rsa:2048 29 1.1.1.2 christos $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 36500 \ 30 1.1 christos -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smrsa2.pem 31 1.1 christos 32 1.1 christos CN="Test S/MIME EE RSA #3" $OPENSSL req -config ca.cnf -nodes \ 33 1.1 christos -keyout smrsa3.pem -out req.pem -newkey rsa:2048 34 1.1.1.2 christos $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 36500 \ 35 1.1 christos -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smrsa3.pem 36 1.1 christos 37 1.1 christos # Create DSA parameters 38 1.1 christos 39 1.1 christos $OPENSSL dsaparam -out dsap.pem 2048 40 1.1 christos 41 1.1 christos CN="Test S/MIME EE DSA #1" $OPENSSL req -config ca.cnf -nodes \ 42 1.1 christos -keyout smdsa1.pem -out req.pem -newkey dsa:dsap.pem 43 1.1.1.2 christos $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 36500 \ 44 1.1 christos -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smdsa1.pem 45 1.1 christos CN="Test S/MIME EE DSA #2" $OPENSSL req -config ca.cnf -nodes \ 46 1.1 christos -keyout smdsa2.pem -out req.pem -newkey dsa:dsap.pem 47 1.1.1.2 christos $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 36500 \ 48 1.1 christos -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smdsa2.pem 49 1.1 christos CN="Test S/MIME EE DSA #3" $OPENSSL req -config ca.cnf -nodes \ 50 1.1 christos -keyout smdsa3.pem -out req.pem -newkey dsa:dsap.pem 51 1.1.1.2 christos $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 36500 \ 52 1.1 christos -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smdsa3.pem 53 1.1 christos 54 1.1 christos # Create EC parameters 55 1.1 christos 56 1.1 christos $OPENSSL ecparam -out ecp.pem -name P-256 57 1.1 christos $OPENSSL ecparam -out ecp2.pem -name K-283 58 1.1 christos 59 1.1 christos CN="Test S/MIME EE EC #1" $OPENSSL req -config ca.cnf -nodes \ 60 1.1 christos -keyout smec1.pem -out req.pem -newkey ec:ecp.pem 61 1.1.1.2 christos $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 36500 \ 62 1.1 christos -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smec1.pem 63 1.1 christos CN="Test S/MIME EE EC #2" $OPENSSL req -config ca.cnf -nodes \ 64 1.1 christos -keyout smec2.pem -out req.pem -newkey ec:ecp2.pem 65 1.1.1.2 christos $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 36500 \ 66 1.1 christos -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smec2.pem 67 1.1.1.2 christos CN="Test S/MIME EE EC #3" $OPENSSL req -config ca.cnf -nodes \ 68 1.1.1.2 christos -keyout smec3.pem -out req.pem -newkey ec:ecp.pem 69 1.1.1.2 christos $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 36500 \ 70 1.1.1.2 christos -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smec3.pem 71 1.1 christos # Create X9.42 DH parameters. 72 1.1 christos $OPENSSL genpkey -genparam -algorithm DH -pkeyopt dh_paramgen_type:2 \ 73 1.1 christos -out dhp.pem 74 1.1 christos # Generate X9.42 DH key. 75 1.1 christos $OPENSSL genpkey -paramfile dhp.pem -out smdh.pem 76 1.1 christos $OPENSSL pkey -pubout -in smdh.pem -out dhpub.pem 77 1.1 christos # Generate dummy request. 78 1.1 christos CN="Test S/MIME EE DH #1" $OPENSSL req -config ca.cnf -nodes \ 79 1.1 christos -keyout smtmp.pem -out req.pem -newkey rsa:2048 80 1.1 christos # Sign request but force public key to DH 81 1.1.1.2 christos $OPENSSL x509 -req -in req.pem -CA smroot.pem -days 36500 \ 82 1.1 christos -force_pubkey dhpub.pem \ 83 1.1 christos -extfile ca.cnf -extensions usr_cert -CAcreateserial >>smdh.pem 84 1.1 christos # Remove temp files. 85 1.1 christos rm -f req.pem ecp.pem ecp2.pem dsap.pem dhp.pem dhpub.pem smtmp.pem smroot.srl 86