kuksa-val: add regenerated server certificate
[AGL/meta-agl-demo.git] / recipes-connectivity / kuksa-val / kuksa-val / 0001-genCerts.sh-add-Subject-Alt-Name-extension-to-server.patch
1 From da4e6c439921b3225ae1af172185d709a368e4b1 Mon Sep 17 00:00:00 2001
2 From: Scott Murray <scott.murray@konsulko.com>
3 Date: Mon, 11 Jul 2022 16:23:56 -0400
4 Subject: [PATCH] genCerts.sh: add Subject Alt Name extension to server
5  certificate
6
7 With the newer Python and OpenSSL in Yocto kirkstone, it seems that
8 server certificates need to have a valid Subject Alt Name extension
9 field, or trying to connect fails with errors of the form:
10
11   certificate verify failed: IP address mismatch, certificate is not valid for localhost
12
13 To fix this, the generated server certificate should not rely on the
14 long deprecated CN field and add the now required extension field.
15 To facilitate this, the genCerts.sh script has been enhanced to
16 add a Subject Alt Name extension field of "DNS:localhost" (or
17 optionally some other hostname) to the server certificate, and to
18 also add the commonly used keyUsage and extendedKeyUsage extension
19 fields with appropriate values.
20
21 Signed-off-by: Scott Murray <scott.murray@konsulko.com>
22 ---
23  kuksa_certificates/genCerts.sh | 19 ++++++++++++++++++-
24  1 file changed, 18 insertions(+), 1 deletion(-)
25
26 diff --git a/kuksa_certificates/genCerts.sh b/kuksa_certificates/genCerts.sh
27 index d0ef767..dfb9458 100755
28 --- a/kuksa_certificates/genCerts.sh
29 +++ b/kuksa_certificates/genCerts.sh
30 @@ -1,5 +1,11 @@
31  #!/bin/sh
32  
33 +# Optional first argument is server hostname
34 +if [ $# -eq 1 ]; then
35 +    HOST=$1
36 +else
37 +    HOST="localhost"
38 +fi
39  
40  genCACert() {
41      openssl genrsa -out CA.key 2048
42 @@ -10,7 +16,18 @@ genCACert() {
43  genCert() {
44      openssl genrsa -out $1.key 2048
45      openssl req -new -key $1.key -out $1.csr -passin pass:"temp" -subj "/C=DE/ST=BW/L=Rng/O=Robert Bosch GmbH/OU=CR/CN=$1/emailAddress=CI.Hotline@de.bosch.com"
46 -    openssl x509 -req -in $1.csr -CA CA.pem -CAkey CA.key -CAcreateserial -days 365 -out $1.pem
47 +    if [ "$1" = "Server" ]; then
48 +        extfile=`mktemp -p .`
49 +        cat > $extfile <<-EOF
50 +       subjectAltName=DNS:${HOST}
51 +       keyUsage=digitalSignature
52 +       extendedKeyUsage=serverAuth
53 +EOF
54 +        openssl x509 -req -in $1.csr -CA CA.pem -CAkey CA.key -CAcreateserial -days 365 -out $1.pem -extfile $extfile
55 +        rm -f $extfile
56 +    else
57 +        openssl x509 -req -in $1.csr -CA CA.pem -CAkey CA.key -CAcreateserial -days 365 -out $1.pem
58 +    fi
59      openssl verify -CAfile CA.pem $1.pem
60  }
61  
62 -- 
63 2.35.3
64