1#!/bin/bash 2 3# (c) CopyRight EdelWeb for EdelKey and OpenEvidence, 2000-2004, 2009 4# Author: Peter Sylvester 5 6# "libre" for integration with curl 7 8OPENSSL=openssl 9if [ -f /usr/local/ssl/bin/openssl ] ; then 10OPENSSL=/usr/local/ssl/bin/openssl 11fi 12 13USAGE="echo Usage is genroot.sh \<name\>" 14 15HOME=`pwd` 16cd $HOME 17 18KEYSIZE=2048 19DURATION=6000 20 21PREFIX=$1 22if [ ".$PREFIX" = . ] ; then 23 echo No configuration prefix 24 NOTOK=1 25else 26 if [ ! -f $PREFIX-ca.prm ] ; then 27 echo No configuration file $PREFIX-ca.prm 28 NOTOK=1 29 fi 30fi 31 32if [ ".$NOTOK" != . ] ; then 33 echo "Sorry, I can't do that for you." 34 $USAGE 35 exit 36fi 37 38GETSERIAL="\$t = time ;\$d = \$t . substr(\$t+$$ ,-4,4)-1;print \$d" 39SERIAL=`/usr/bin/env perl -e "$GETSERIAL"` 40 41echo SERIAL=$SERIAL PREFIX=$PREFIX DURATION=$DURATION KEYSIZE=$KEYSIZE 42 43echo "openssl genrsa -out $PREFIX-ca.key $KEYSIZE -passout XXX" 44openssl genrsa -out $PREFIX-ca.key $KEYSIZE -passout pass:secret 45 46echo "openssl req -config $PREFIX-ca.prm -new -key $PREFIX-ca.key -out $PREFIX-ca.csr" 47$OPENSSL req -config $PREFIX-ca.prm -new -key $PREFIX-ca.key -out $PREFIX-ca.csr -passin pass:secret 48 49echo "openssl x509 -set_serial $SERIAL -extfile $PREFIX-ca.prm -days $DURATION -req -signkey $PREFIX-ca.key -in $PREFIX-ca.csr -out $PREFIX-$SERIAL.ca-cacert -sha1 " 50 51$OPENSSL x509 -set_serial $SERIAL -extfile $PREFIX-ca.prm -days $DURATION -req -signkey $PREFIX-ca.key -in $PREFIX-ca.csr -out $PREFIX-$SERIAL-ca.cacert -sha1 52 53echo "openssl x509 -text -in $PREFIX-$SERIAL-ca.cacert -nameopt multiline > $PREFIX-ca.cacert " 54$OPENSSL x509 -text -in $PREFIX-$SERIAL-ca.cacert -nameopt multiline > $PREFIX-ca.cacert 55 56echo "openssl x509 -in $PREFIX-ca.cacert -outform der -out $PREFIX-ca.der " 57$OPENSSL x509 -in $PREFIX-ca.cacert -outform der -out $PREFIX-ca.der 58 59echo "openssl x509 -in $PREFIX-ca.cacert -text -nameopt multiline > $PREFIX-ca.crt " 60 61$OPENSSL x509 -in $PREFIX-ca.cacert -text -nameopt multiline > $PREFIX-ca.crt 62 63echo "openssl x509 -noout -text -in $PREFIX-ca.cacert -nameopt multiline" 64$OPENSSL x509 -noout -text -in $PREFIX-ca.cacert -nameopt multiline 65 66#$OPENSSL rsa -in ../keys/$PREFIX-ca.key -text -noout -pubout 67