Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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