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