NOTE: Taken from https://blog.opensips.org/2022/10/31/how-to-generate-self-signed-stir-shaken-certificates/
- Guide for creating self-signed StirShaken Certificates
- Table of Contents
- Become a Certificate Authority (CA)
- Issue a certificate for a StirShaken Service Provider (SP)
Create a cert to act as our CA.
mkdir certificate-authority
cd certificate-authority
openssl ecparam -noout -name prime256v1 \
-genkey -out ca-key.pem
Note: Good for 100 years!
openssl req -new -x509 -days 36500 \
-key ca-key.pem -subj "/CN=stir-shaken-ca" \
-out ca-cert.pem
We're now a functioning Cert Authority!
mkdir service-provider
cd service-provider
openssl ecparam -noout -name prime256v1 \
-genkey -out sp-key.pem
Here is where STIR/SHAKEN comes into play, with its TNAuthList extension (1.3.6.1.5.5.7.1.26) to the X.509 certificate which we must include, otherwise the certificate is likely to be rejected by most STIR/SHAKEN software out there.
The steps below create the openssl.conf file and append the extension.
cat > TNAuthList.conf << EOF
asn1=SEQUENCE:tn_auth_list
[tn_auth_list]
field1=EXP:0,IA5:1001
EOF
openssl asn1parse -genconf TNAuthList.conf -out TNAuthList.der
cat > openssl.conf << EOF
[ req ]
distinguished_name = req_distinguished_name
req_extensions = v3_req
[ req_distinguished_name ]
commonName = "SHAKEN"
[ v3_req ]
EOF
od -An -t x1 TNAuthList.der | awk NF |sed -e 's/ /:/g' -e 's/^/1.3.6.1.5.5.7.1.26=DER/' >> openssl.conf
od
is a utility that dumps files in octal and other formats.
awk NF
removes blank lines.
sed
replaces spaces with colons and appends the OID, which is the StirShaken extension.
openssl req -new -nodes -key sp-key.pem -keyform PEM \
-subj '/C=US/ST=CO/L=Denver/O=DummyCompany Inc./OU=VOIP/CN=SHAKEN' \
-sha256 -config openssl.conf \
-out sp-csr.pem
Again, valid for 100 years.
openssl x509 -req -in sp-csr.pem \
-CA ../certificate-authority/ca-cert.pem -CAkey ../certificate-authority/ca-key.pem -CAcreateserial \
-days 36500 -sha256 -extfile openssl.conf -extensions v3_req -out sp-cert.pem
Note: Will have to wait 24 hours after creation to test expiration logic.
openssl x509 -req -in sp-csr.pem \
-CA ../certificate-authority/ca-cert.pem -CAkey ../certificate-authority/ca-key.pem -CAcreateserial \
-days 1 -sha256 -extfile openssl.conf -extensions v3_req -out sp-cert-expired.pem
openssl x509 -in sp-cert.pem -text -noout