• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# The -sha256 option was introduced in OpenSSL 1.0.1
21DIGESTALGO=-sha256
22
23PREFIX=$1
24if [ ".$PREFIX" = . ] ; then
25   echo No configuration prefix
26   NOTOK=1
27else
28   if [ ! -f $PREFIX-ca.prm ] ; then
29      echo No configuration file $PREFIX-ca.prm
30      NOTOK=1
31   fi
32fi
33
34if [ ".$NOTOK" != . ] ; then
35   echo "Sorry, I can't do that for you."
36   $USAGE
37   exit
38fi
39
40GETSERIAL="\$t = time ;\$d =  \$t . substr(\$t+$$ ,-4,4)-1;print \$d"
41SERIAL=`/usr/bin/env perl -e "$GETSERIAL"`
42
43echo SERIAL=$SERIAL PREFIX=$PREFIX DURATION=$DURATION KEYSIZE=$KEYSIZE
44
45echo "openssl genrsa -out $PREFIX-ca.key $KEYSIZE -passout XXX"
46openssl genrsa -out $PREFIX-ca.key $KEYSIZE -passout pass:secret
47
48echo "openssl req -config $PREFIX-ca.prm -new -key $PREFIX-ca.key -out $PREFIX-ca.csr"
49$OPENSSL req -config $PREFIX-ca.prm -new -key $PREFIX-ca.key -out $PREFIX-ca.csr -passin pass:secret
50
51echo "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 $DIGESTALGO "
52
53$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 $DIGESTALGO
54
55echo "openssl x509 -text -in $PREFIX-$SERIAL-ca.cacert -nameopt multiline > $PREFIX-ca.cacert "
56$OPENSSL x509 -text -in $PREFIX-$SERIAL-ca.cacert -nameopt multiline > $PREFIX-ca.cacert
57
58echo "openssl x509 -in $PREFIX-ca.cacert -outform der -out $PREFIX-ca.der "
59$OPENSSL x509 -in $PREFIX-ca.cacert -outform der -out $PREFIX-ca.der
60
61echo "openssl x509 -in $PREFIX-ca.cacert -text -nameopt multiline > $PREFIX-ca.crt "
62
63$OPENSSL x509 -in $PREFIX-ca.cacert -text -nameopt multiline > $PREFIX-ca.crt
64
65echo "openssl x509 -noout -text -in $PREFIX-ca.cacert -nameopt multiline"
66$OPENSSL x509 -noout -text -in $PREFIX-ca.cacert -nameopt multiline
67
68#$OPENSSL rsa -in ../keys/$PREFIX-ca.key -text -noout -pubout
69