genroot.sh 2.1 KB

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