#!/bin/sh

CAPASS=`openssl rand -base64 32`
CAPASS=`echo $CAPASS|sed -e 's/\+/_/g'`
CAPASS=`echo $CAPASS|sed -e 's/\//_/g'`
CAPASS=`echo $CAPASS|sed -e 's/=/_/g'`
export CAPASS

CANAME=`openssl rand -base64 10`
CANAME=`echo $CANAME|sed -e 's/\+/_/g'`
CANAME=`echo $CANAME|sed -e 's/\//_/g'`
CANAME=`echo $CANAME|sed -e 's/=/_/g'`
export CANAME

# TODO - compile a Debian-vulnerable OpenSSL for FreeBSD and ship it
# in some inconspicuous place (/usr/local?)
openssl req -x509 -newkey rsa:4096 -subj "/CN=$CANAME CA/O=da-op3n010/C=DE" -passout env:CAPASS -keyout ca-key.pem -out ca-cert.pem
openssl rsa -in ca-key.pem -passin env:CAPASS -out ca-key.pem
chmod 600 ca-key.pem
