Skip to content

Instantly share code, notes, and snippets.

@rhenning
Last active October 14, 2015 15:13
Show Gist options
  • Save rhenning/bde6c4e4051c8e87fa83 to your computer and use it in GitHub Desktop.
Save rhenning/bde6c4e4051c8e87fa83 to your computer and use it in GitHub Desktop.
Quick CSR to Certificate with fake CA
#!/usr/bin/env bash
set -e
if [[ "$#" != "1" ]]; then
echo usage: $0 /path/to/file.csr
exit 1
fi
invoke_dir=$(pwd)
path_to_csr=$1
ca_tempdir=$(mktemp -d -t csr2crt)
cd $ca_tempdir
openssl genrsa 2048 > ca.key
openssl req \
-x509 \
-new \
-nodes \
-key ca.key \
-days 3650 \
-subj '/C=US/ST=Pennsylvania/L=Philadelphia/O=WebLinc/CN=www.weblinc.com' \
-out ca.crt
openssl x509 \
-req \
-in ${invoke_dir}/${path_to_csr} \
-CA ca.crt \
-CAkey ca.key \
-CAcreateserial \
-out ${invoke_dir}/site.crt \
-days 365
echo 'Wrote certificate to site.crt!'
rm -r $ca_tempdir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment