genroot.sh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) EdelWeb for EdelKey and OpenEvidence
  10. #
  11. # This software is licensed as described in the file COPYING, which
  12. # you should have received as part of this distribution. The terms
  13. # are also available at https://curl.se/docs/copyright.html.
  14. #
  15. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # copies of the Software, and permit persons to whom the Software is
  17. # furnished to do so, under the terms of the COPYING file.
  18. #
  19. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # KIND, either express or implied.
  21. #
  22. # SPDX-License-Identifier: curl
  23. #
  24. ###########################################################################
  25. OPENSSL=openssl
  26. if [ -f /usr/local/ssl/bin/openssl ] ; then
  27. OPENSSL=/usr/local/ssl/bin/openssl
  28. fi
  29. USAGE="echo Usage is genroot.sh \<name\>"
  30. HOME=`pwd`
  31. cd $HOME
  32. KEYSIZE=2048
  33. DURATION=6000
  34. # The -sha256 option was introduced in OpenSSL 1.0.1
  35. DIGESTALGO=-sha256
  36. PREFIX=$1
  37. if [ ".$PREFIX" = . ] ; then
  38. echo No configuration prefix
  39. NOTOK=1
  40. else
  41. if [ ! -f $PREFIX-ca.prm ] ; then
  42. echo No configuration file $PREFIX-ca.prm
  43. NOTOK=1
  44. fi
  45. fi
  46. if [ ".$NOTOK" != . ] ; then
  47. echo "Sorry, I can't do that for you."
  48. $USAGE
  49. exit
  50. fi
  51. GETSERIAL="\$t = time ;\$d = \$t . substr(\$t+$$ ,-4,4)-1;print \$d"
  52. SERIAL=`/usr/bin/env perl -e "$GETSERIAL"`
  53. # exit on first fail
  54. set -e
  55. echo SERIAL=$SERIAL PREFIX=$PREFIX DURATION=$DURATION KEYSIZE=$KEYSIZE
  56. echo "openssl genrsa -out $PREFIX-ca.key -passout XXX $KEYSIZE"
  57. openssl genrsa -out $PREFIX-ca.key -passout pass:secret $KEYSIZE
  58. echo "openssl req -config $PREFIX-ca.prm -new -key $PREFIX-ca.key -out $PREFIX-ca.csr"
  59. $OPENSSL req -config $PREFIX-ca.prm -new -key $PREFIX-ca.key -out $PREFIX-ca.csr -passin pass:secret
  60. 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 $DIGESTALGO "
  61. $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
  62. echo "openssl x509 -text -in $PREFIX-$SERIAL-ca.cacert -nameopt multiline > $PREFIX-ca.cacert "
  63. $OPENSSL x509 -text -in $PREFIX-$SERIAL-ca.cacert -nameopt multiline > $PREFIX-ca.cacert
  64. echo "openssl x509 -in $PREFIX-ca.cacert -outform der -out $PREFIX-ca.der "
  65. $OPENSSL x509 -in $PREFIX-ca.cacert -outform der -out $PREFIX-ca.der
  66. echo "openssl x509 -in $PREFIX-ca.cacert -text -nameopt multiline > $PREFIX-ca.crt "
  67. $OPENSSL x509 -in $PREFIX-ca.cacert -text -nameopt multiline > $PREFIX-ca.crt
  68. echo "openssl x509 -noout -text -in $PREFIX-ca.cacert -nameopt multiline"
  69. $OPENSSL x509 -noout -text -in $PREFIX-ca.cacert -nameopt multiline
  70. #$OPENSSL rsa -in ../keys/$PREFIX-ca.key -text -noout -pubout