|
| 1 | +#!/bin/bash |
| 2 | +#------------------------------------------------------------------------------ |
| 3 | +# cleanup any previously created files |
| 4 | +rm -f exampleca.* example.* cert.h private_key.h |
| 5 | + |
| 6 | +#------------------------------------------------------------------------------ |
| 7 | +# create a CA called "myca" |
| 8 | + |
| 9 | +# create a private key |
| 10 | +openssl genrsa -out exampleca.key 1024 |
| 11 | + |
| 12 | +# create certificate |
| 13 | +cat > exampleca.conf << EOF |
| 14 | +[ req ] |
| 15 | +distinguished_name = req_distinguished_name |
| 16 | +prompt = no |
| 17 | +[ req_distinguished_name ] |
| 18 | +C = DE |
| 19 | +ST = HE |
| 20 | +L = Darmstadt |
| 21 | +O = MyCompany |
| 22 | +CN = myca.local |
| 23 | +EOF |
| 24 | +openssl req -new -x509 -days 3650 -key exampleca.key -out exampleca.crt -config exampleca.conf |
| 25 | +# create serial number file |
| 26 | +echo "01" > exampleca.srl |
| 27 | + |
| 28 | +#------------------------------------------------------------------------------ |
| 29 | +# create a certificate for the ESP (hostname: "myesp") |
| 30 | + |
| 31 | +# create a private key |
| 32 | +openssl genrsa -out example.key 1024 |
| 33 | +# create certificate signing request |
| 34 | +cat > example.conf << EOF |
| 35 | +[ req ] |
| 36 | +distinguished_name = req_distinguished_name |
| 37 | +prompt = no |
| 38 | +[ req_distinguished_name ] |
| 39 | +C = DE |
| 40 | +ST = HE |
| 41 | +L = Darmstadt |
| 42 | +O = MyCompany |
| 43 | +CN = esp32.local |
| 44 | +EOF |
| 45 | +openssl req -new -key example.key -out example.csr -config example.conf |
| 46 | + |
| 47 | +# have myca sign the certificate |
| 48 | +openssl x509 -days 3650 -CA exampleca.crt -CAkey exampleca.key -in example.csr -req -out example.crt |
| 49 | + |
| 50 | +# verify |
| 51 | +openssl verify -CAfile exampleca.crt example.crt |
| 52 | + |
| 53 | +# convert private key and certificate into DER format |
| 54 | +openssl rsa -in example.key -outform DER -out example.key.DER |
| 55 | +openssl x509 -in example.crt -outform DER -out example.crt.DER |
| 56 | + |
| 57 | +# create header files |
| 58 | +xxd -i example.crt.DER > ../../data/cert/cert.h |
| 59 | +xxd -i example.key.DER > ../../data/cert/private_key.h |
0 commit comments