Skip to content

Commit 52b1d03

Browse files
committed
Force version 3 leaf certificates with a subjectKeyIdentifier
openssl emits a version 1 leaf without a subjectKeyIdentifier when x509 -req runs without extensions on openssl 3.0.x, while newer builds add one by default. The WSSE SubjectKeyIdentifier and IssuerSerial key references require it, so signing an RSA or EC leaf now passes an extfile that sets basicConstraints, subjectKeyIdentifier and keyUsage, making the certificates identical across platform openssl versions.
1 parent 55562c9 commit 52b1d03

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

certs/generate.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,25 @@ gen_ca() { # <name> <cn>
5959
-out "${name}.crt"
6060
}
6161

62+
# v3 leaf extensions. The WSSE SubjectKeyIdentifier and IssuerSerial key references need a version 3
63+
# certificate that carries a subjectKeyIdentifier. Without explicit extensions openssl may emit a version 1
64+
# leaf without one, and the default varies by platform openssl, so the extensions are forced here to keep
65+
# the certs identical everywhere.
66+
LEAF_EXT="${CERT_DIR}/leaf.ext"
67+
cat > "${LEAF_EXT}" <<'EXT'
68+
basicConstraints = CA:FALSE
69+
subjectKeyIdentifier = hash
70+
keyUsage = digitalSignature, keyEncipherment
71+
EXT
72+
6273
gen_leaf() { # <name> <cn> <ca>
6374
local name="$1" cn="$2" ca="$3"
6475
openssl genrsa -out "${name}.key" 2048
6576
openssl req -new -key "${name}.key" \
6677
-subj "/C=BE/O=php-soap interop/CN=${cn}" \
6778
-out "${name}.csr"
6879
openssl x509 -req -in "${name}.csr" -CA "${ca}.crt" -CAkey "${ca}.key" -CAcreateserial \
69-
-days "${DAYS}" -sha256 -out "${name}.crt"
80+
-days "${DAYS}" -sha256 -extfile "${LEAF_EXT}" -out "${name}.crt"
7081
rm -f "${name}.csr"
7182
}
7283

@@ -77,7 +88,7 @@ gen_ec_leaf() { # <name> <cn> <ca> — EC P-256 leaf for the ECDSA-SHA256 inter
7788
-subj "/C=BE/O=php-soap interop/CN=${cn}" \
7889
-out "${name}.csr"
7990
openssl x509 -req -in "${name}.csr" -CA "${ca}.crt" -CAkey "${ca}.key" -CAcreateserial \
80-
-days "${DAYS}" -sha256 -out "${name}.crt"
91+
-days "${DAYS}" -sha256 -extfile "${LEAF_EXT}" -out "${name}.crt"
8192
rm -f "${name}.csr"
8293
}
8394

@@ -148,6 +159,8 @@ cat untrusted-client.crt untrusted-client.key untrusted-ca.crt > untrusted-clien
148159
openssl pkcs12 -export -inkey untrusted-client.key -in untrusted-client.crt -certfile untrusted-ca.crt \
149160
-name untrusted-client -passout "pass:${STOREPASS}" -out untrusted.p12
150161

162+
rm -f "${LEAF_EXT}"
163+
151164
echo
152165
echo "Done. Files in ${CERT_DIR}:"
153166
ls -1 "${CERT_DIR}" | grep -vE '\.srl$'

0 commit comments

Comments
 (0)