2009-08-12 05:48:58 +08:00
|
|
|
#!/bin/bash
|
2022-09-02 20:24:25 +08:00
|
|
|
#***************************************************************************
|
|
|
|
# _ _ ____ _
|
|
|
|
# Project ___| | | | _ \| |
|
|
|
|
# / __| | | | |_) | |
|
|
|
|
# | (__| |_| | _ <| |___
|
|
|
|
# \___|\___/|_| \_\_____|
|
|
|
|
#
|
2023-01-02 20:51:48 +08:00
|
|
|
# Copyright (C) EdelWeb for EdelKey and OpenEvidence
|
2022-09-02 20:24:25 +08:00
|
|
|
#
|
|
|
|
# This software is licensed as described in the file COPYING, which
|
|
|
|
# you should have received as part of this distribution. The terms
|
|
|
|
# are also available at https://curl.se/docs/copyright.html.
|
|
|
|
#
|
|
|
|
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
# copies of the Software, and permit persons to whom the Software is
|
|
|
|
# furnished to do so, under the terms of the COPYING file.
|
|
|
|
#
|
|
|
|
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, either express or implied.
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: curl
|
|
|
|
#
|
|
|
|
###########################################################################
|
2009-08-12 05:48:58 +08:00
|
|
|
|
|
|
|
OPENSSL=openssl
|
|
|
|
if [ -f /usr/local/ssl/bin/openssl ] ; then
|
|
|
|
OPENSSL=/usr/local/ssl/bin/openssl
|
|
|
|
fi
|
|
|
|
|
|
|
|
USAGE="echo Usage is genroot.sh \<name\>"
|
|
|
|
|
|
|
|
HOME=`pwd`
|
|
|
|
cd $HOME
|
|
|
|
|
|
|
|
KEYSIZE=2048
|
|
|
|
DURATION=6000
|
2018-09-19 15:04:48 +08:00
|
|
|
# The -sha256 option was introduced in OpenSSL 1.0.1
|
|
|
|
DIGESTALGO=-sha256
|
2009-08-12 05:48:58 +08:00
|
|
|
|
|
|
|
PREFIX=$1
|
|
|
|
if [ ".$PREFIX" = . ] ; then
|
2018-09-24 06:24:02 +08:00
|
|
|
echo No configuration prefix
|
|
|
|
NOTOK=1
|
2009-08-12 05:48:58 +08:00
|
|
|
else
|
2018-09-24 06:24:02 +08:00
|
|
|
if [ ! -f $PREFIX-ca.prm ] ; then
|
|
|
|
echo No configuration file $PREFIX-ca.prm
|
|
|
|
NOTOK=1
|
|
|
|
fi
|
2009-08-12 05:48:58 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ".$NOTOK" != . ] ; then
|
2018-09-24 06:24:02 +08:00
|
|
|
echo "Sorry, I can't do that for you."
|
|
|
|
$USAGE
|
|
|
|
exit
|
2009-08-12 05:48:58 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
GETSERIAL="\$t = time ;\$d = \$t . substr(\$t+$$ ,-4,4)-1;print \$d"
|
|
|
|
SERIAL=`/usr/bin/env perl -e "$GETSERIAL"`
|
|
|
|
|
2022-11-25 21:00:48 +08:00
|
|
|
# exit on first fail
|
|
|
|
set -e
|
|
|
|
|
2010-02-15 03:40:18 +08:00
|
|
|
echo SERIAL=$SERIAL PREFIX=$PREFIX DURATION=$DURATION KEYSIZE=$KEYSIZE
|
2009-08-12 05:48:58 +08:00
|
|
|
|
2022-12-23 20:34:49 +08:00
|
|
|
echo "openssl genrsa -out $PREFIX-ca.key -passout XXX $KEYSIZE"
|
|
|
|
openssl genrsa -out $PREFIX-ca.key -passout pass:secret $KEYSIZE
|
2010-05-28 05:33:19 +08:00
|
|
|
|
|
|
|
echo "openssl req -config $PREFIX-ca.prm -new -key $PREFIX-ca.key -out $PREFIX-ca.csr"
|
|
|
|
$OPENSSL req -config $PREFIX-ca.prm -new -key $PREFIX-ca.key -out $PREFIX-ca.csr -passin pass:secret
|
2009-08-12 05:48:58 +08:00
|
|
|
|
2018-09-19 15:04:48 +08:00
|
|
|
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 "
|
2009-08-12 05:48:58 +08:00
|
|
|
|
2018-09-19 15:04:48 +08:00
|
|
|
$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
|
2009-08-12 05:48:58 +08:00
|
|
|
|
2015-03-21 21:23:00 +08:00
|
|
|
echo "openssl x509 -text -in $PREFIX-$SERIAL-ca.cacert -nameopt multiline > $PREFIX-ca.cacert "
|
|
|
|
$OPENSSL x509 -text -in $PREFIX-$SERIAL-ca.cacert -nameopt multiline > $PREFIX-ca.cacert
|
2009-08-12 05:48:58 +08:00
|
|
|
|
|
|
|
echo "openssl x509 -in $PREFIX-ca.cacert -outform der -out $PREFIX-ca.der "
|
2010-02-15 03:40:18 +08:00
|
|
|
$OPENSSL x509 -in $PREFIX-ca.cacert -outform der -out $PREFIX-ca.der
|
2009-08-12 05:48:58 +08:00
|
|
|
|
2015-03-21 21:23:00 +08:00
|
|
|
echo "openssl x509 -in $PREFIX-ca.cacert -text -nameopt multiline > $PREFIX-ca.crt "
|
2009-08-12 05:48:58 +08:00
|
|
|
|
2015-03-21 21:23:00 +08:00
|
|
|
$OPENSSL x509 -in $PREFIX-ca.cacert -text -nameopt multiline > $PREFIX-ca.crt
|
2009-08-12 05:48:58 +08:00
|
|
|
|
|
|
|
echo "openssl x509 -noout -text -in $PREFIX-ca.cacert -nameopt multiline"
|
|
|
|
$OPENSSL x509 -noout -text -in $PREFIX-ca.cacert -nameopt multiline
|
|
|
|
|
|
|
|
#$OPENSSL rsa -in ../keys/$PREFIX-ca.key -text -noout -pubout
|