Skip to content

Instantly share code, notes, and snippets.

@imZack
Last active October 28, 2020 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imZack/0c15be35d6c0d6621e00049c7ecf48ef to your computer and use it in GitHub Desktop.
Save imZack/0c15be35d6c0d6621e00049c7ecf48ef to your computer and use it in GitHub Desktop.
#!/bin/bash
for i in {1..10};
do
openssl req -x509 -new -sha256 -nodes \
-out "cert-$i.der" \
-outform DER \
-newkey rsa:2048 \
-keyout "cert-$i.key" \
-config <(
cat <<-EOF
[req]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
x509_extensions = v3_req
distinguished_name = dn
[ dn ]
C=TW
ST=TW
L=Xindian
O=Moxa
OU=Testing Domain
emailAddress=test@test.com
CN = cert-$i.test.com
[ req_ext ]
subjectAltName = @alt_names
[ alt_names ]
DNS.1 = test.com
DNS.2 = www.test.com
[ v3_req ]
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
EOF
)
openssl x509 -inform DER -outform PEM -in "cert-$i.der" -out "cert-$i.crt.pem"
cat "cert-$i.crt.pem" "cert-$i.key" > "cert-$i-with-privatekey.pem"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment