Subversion Repositories DevTools

Rev

Blame | Last modification | View Log | RSS feed

#! /bin/bash

ROOTCA=VixPulseManifestRootCA
CLIENT=VixPulseManifest
CLIENT_FQDN=Vix.Pulse.Manifest

# Generate a config file for creating the csr (cert signing Request)
cat << EOF > ${CLIENT}.cnf
FQDN = ${CLIENT_FQDN}

# the name of your organization
ORGNAME = Vix Technology

# --- no modifications required below ---
[ req ]
default_bits = 2048
default_md = sha256
prompt = no
encrypt_key = no

distinguished_name = dn
req_extensions = req_ext
x509_extensions     = x509_ext

[ x509_ext ]
keyUsage            = digitalSignature, keyEncipherment

[ dn ]
C = AU
O = \$ORGNAME
CN = \$FQDN

[ req_ext ]

EOF

echo Gen client certificate request
openssl genrsa -out ${CLIENT}.key 2048 2> /dev/null
openssl req -new -key ${CLIENT}.key -out ${CLIENT}.csr -config  ${CLIENT}.cnf

echo Sign with CA
openssl x509 -req -in ${CLIENT}.csr -CA ${ROOTCA}.crt -CAkey ${ROOTCA}.key -CAcreateserial -out ${CLIENT}.crt -days 36500 -sha256

echo Verify key
openssl verify -CAfile ${ROOTCA}.crt ${CLIENT}.crt

echo Generate signature
#set -x
TESTFILE=${CLIENT}.cnf
openssl dgst -sha1 -sign ${CLIENT}.key  -out file.out ${TESTFILE}

echo "Verify file signature - from certificate"
openssl x509  -in ${CLIENT}.crt -pubkey -noout >${CLIENT}.pubkey
openssl dgst -sha1 -verify ${CLIENT}.pubkey  -signature file.out ${TESTFILE}
rm -f file.out

echo Generated: ${CLIENT}.key
echo Generated: ${CLIENT}.crt  FQDN: \(${CLIENT_FQDN}\)


# Clean up unneeded files
rm -f *.pubkey
rm -f *.srl
rm -f *.csr