Skip to content

Instantly share code, notes, and snippets.

@yaegashi
Created January 31, 2015 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaegashi/fafef425fc2080b2ced4 to your computer and use it in GitHub Desktop.
Save yaegashi/fafef425fc2080b2ced4 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
if test $# -lt 2; then
echo "Usage: $0 <common name> <output> [<start> <end>]" >&2
exit 1
fi
cn=$1
out=$2
start=${3-now}
end=${4-30 days}
dir=$(mktemp -d)
trap "rm -rf $dir" EXIT
cat <<EOF >$dir/certtool.cfg
cn = "$cn"
activation_date = "$start"
expiration_date = "$end"
EOF
certtool --generate-privkey --outfile $dir/key.pem
certtool --generate-self-signed --load-privkey $dir/key.pem --outfile $dir/cert.pem --template $dir/certtool.cfg
cat $dir/key.pem $dir/cert.pem | sed -ne '/^-----/,$p' >$out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment