Last active
January 13, 2026 15:19
-
-
Save AfroThundr3007730/c8db93ecacb9930e1e85ead283c79071 to your computer and use it in GitHub Desktop.
Generating x509 PKI certs inline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| config=' | |
| [ca_cert] | |
| basicConstraints=critical,CA:true,pathlen:1 | |
| authorityKeyIdentifier=keyid:always,issuer | |
| subjectKeyIdentifier=hash | |
| keyUsage=critical,keyCertSign,cRLSign | |
| [sign_cert] | |
| basicConstraints=critical,CA:false | |
| subjectKeyIdentifier=hash | |
| keyUsage=critical,digitalSignature | |
| extendedKeyUsage=codeSigning | |
| [san_cert] | |
| basicConstraints=critical,CA:false | |
| subjectKeyIdentifier=hash | |
| keyUsage=critical,digitalSignature | |
| extendedKeyUsage=serverAuth | |
| subjectAltName=@alt_names | |
| [alt_names] | |
| DNS.1=foo.example.com | |
| DNS.2=bar.example.com | |
| ' | |
| # The Root Cert | |
| openssl req -x509 -days 3660 -sha384 -utf8 -noenc \ | |
| -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 \ | |
| -keyout /etc/keys/ca.key -out /etc/keys/ca.crt \ | |
| -config <(printf "$config") -extensions ca_cert \ | |
| -subj '/CN=My CA Cert' | |
| # The Leaf Cert (code signing) | |
| openssl req -x509 -days 730 -sha384 -utf8 -noenc \ | |
| -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 \ | |
| -keyout /etc/keys/db.key -out /etc/keys/db.crt \ | |
| -CAkey /etc/keys/ca.key -CA /etc/keys/ca.crt \ | |
| -config <(printf "$config") -extensions sign_cert \ | |
| -subj '/CN=MY Leaf Cert' | |
| # The Leaf Cert (SAN inline) | |
| openssl req -x509 -days 730 -sha384 -utf8 -noenc \ | |
| -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 \ | |
| -keyout /etc/keys/db.key -out /etc/keys/db.crt \ | |
| -CAkey /etc/keys/ca.key -CA /etc/keys/ca.crt \ | |
| -config <(printf "$config") -extensions san_cert \ | |
| -subj '/' -addext 'subjectAltNames=DNS.1:foo.bar.baz' | |
| # The Leaf Cert (SAN full) | |
| openssl req -x509 -days 730 -sha384 -utf8 -noenc \ | |
| -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 \ | |
| -keyout /etc/keys/db.key -out /etc/keys/db.crt \ | |
| -CAkey /etc/keys/ca.key -CA /etc/keys/ca.crt \ | |
| -config <(printf "$config") -extensions san_cert \ | |
| -subj '/' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment