Skip to content

Commit dd2e3da

Browse files
committed
Add IP subject alt name to cert gen
1 parent bd42d3c commit dd2e3da

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

scripts/gen_certs.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44
CERT_BASE="certs"
55

66
if [ -z $1 ]; then
7-
echo "Usage: gen_certs.sh <hostname> [<password>]"
7+
echo "Usage: gen_certs.sh <hostname> <ip> [<password>]"
88
exit 1
99
fi
1010

1111
mkdir -p $CERT_BASE
1212

1313
# Setting up a CA
1414
openssl genrsa -out $CERT_BASE/rootCA.key 2048
15-
openssl req -subj /C=/ST=/L=/O=/CN=rootCA -x509 -new -nodes -key $CERT_BASE/rootCA.key -sha256 -out $CERT_BASE/rootCA.pem
15+
openssl req -subj /C=/ST=/L=/O=/CN=rootCA -x509 -new -nodes -key $CERT_BASE/rootCA.key -sha256 -days 1095 -out $CERT_BASE/rootCA.pem
1616

1717
# Setting up device cert and key
1818
openssl genrsa -out $CERT_BASE/device.key 2048
1919
openssl req -subj /C=/ST=/L=/O=/CN=$1 -new -key $CERT_BASE/device.key -out $CERT_BASE/device.csr
20-
openssl x509 -req -in $CERT_BASE/device.csr -CA $CERT_BASE/rootCA.pem -CAkey $CERT_BASE/rootCA.key -CAcreateserial -out $CERT_BASE/device.crt -sha256
20+
openssl x509 -req -in $CERT_BASE/device.csr -CA $CERT_BASE/rootCA.pem -CAkey $CERT_BASE/rootCA.key -CAcreateserial -out $CERT_BASE/device.crt -days 1095 -sha256 -extfile <(printf "%s" "subjectAltName=DNS:$1,IP:$2")
2121

2222
# Encrypt device key - needed for input to IOS
23-
if [ ! -z $2 ]; then
23+
if [ ! -z $3 ]; then
2424
openssl rsa -des3 -in $CERT_BASE/device.key -out $CERT_BASE/device.des3.key -passout pass:$2
2525
else
2626
echo "Skipping device key encryption."
@@ -29,4 +29,4 @@ fi
2929
# Setting up client cert and key
3030
openssl genrsa -out $CERT_BASE/client.key 2048
3131
openssl req -subj /C=/ST=/L=/O=/CN=gnmi_client -new -key $CERT_BASE/client.key -out $CERT_BASE/client.csr
32-
openssl x509 -req -in $CERT_BASE/client.csr -CA $CERT_BASE/rootCA.pem -CAkey $CERT_BASE/rootCA.key -CAcreateserial -out $CERT_BASE/client.crt -sha256
32+
openssl x509 -req -in $CERT_BASE/client.csr -CA $CERT_BASE/rootCA.pem -CAkey $CERT_BASE/rootCA.key -CAcreateserial -out $CERT_BASE/client.crt -days 1095 -sha256

0 commit comments

Comments
 (0)