Skip to content

Instantly share code, notes, and snippets.

@friendlyanon
Created March 3, 2025 21:01
Show Gist options
  • Save friendlyanon/6656752c956e431586bbcaef95492ded to your computer and use it in GitHub Desktop.
Save friendlyanon/6656752c956e431586bbcaef95492ded to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
key='-algorithm EC -pkeyopt ec_paramgen_curve:secp384r1'
enc=-aes256
x509=-days\ 825\ -sha512
subj=-subj\ /C=XX/O=XXX/OU=XXX/CN
domain=xxx.lan
req="\
basicConstraints = critical, CA:false
keyUsage = critical, digitalSignature, keyAgreement
extendedKeyUsage = critical, serverAuth
subjectAltName = @alts
[alts]
DNS.1 = $domain
DNS.2 = *.$domain
IP.1 = 10.255.255.255
"
conf="\
[req]
x509_extensions = ca_ext
req_extensions = srv_ext
[ca_ext]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always, issuer
basicConstraints = critical, CA:true, pathlen:0
keyUsage = critical, keyCertSign
subjectAltName = @alts
[srv_ext]
$req\
"
openssl genpkey $key -out ca.key $enc
openssl req -x509 -new -key ca.key $x509 -out ca.pem -config <(printf %s "$conf") $subj=XXX\ CA
openssl genpkey $key -out server.key
openssl req -new -key server.key -out server.csr -config <(printf %s "$conf") $subj=$domain
openssl x509 -req -in server.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out server.crt $x509 -extfile <(printf %s "$req")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment