Automatically Generate a self signed Certificate and load in adkeystore.dat using Shell Script


If we want to generate self signed certificate we can do manually. I have tried to do the same via a script and tested for Oracle Apps jar signing.

Before running the script please make necessary changes as per your need.

Script:

[applmgr@funebs122 admin]$ cat gen_self_sign.sh  
#!/bin/bash
#
# CN = Common Name
# OU = Organization Unit
# O  = Organization
# C  = Country code
#
# Certificate settings:
# These are used to generate the initial signing certificate
# Change them to suite your organisation
#
DN_CN="funoracleapps"
DN_OU="IT Lab"
DN_O=Noida
DN_C=India
#
# Give your keystore file
KEYSTORE=$APPL_TOP/admin/adkeystore.dat
#
# If KEYSTORE already exists, old KEYSTORE_PASSWORD for the keystore file must
# be correctly given here. If KEYSTORE does not already exist, any password
# given here will be taken for the new KEYSTORE file to be created.
#
# *** Remove the text after the '=' below and replace with your password. ***
KEYSTORE_PASSWORD=puneet
#
# Give your alias for key here.
#
JAR_KEY=fun_lab_cer
#
# Key Password for the given key to be used for signing.
#
# *** Remove the text after the '=' below and replace with your password. ***
JAR_KEY_PASSWORD=myxuan

#
# Number of days before this certificate expires
#
VALIDDAYS=1000


#
# Self Signing script starts here...
#

echo "Generating a self signing certificate for key=$JAR_KEY..."
error_text=`keytool -genkey -dname "CN=$DN_CN, OU=$DN_OU, O=$DN_O, C=$DN_C" \
       -alias $JAR_KEY -keypass $JAR_KEY_PASSWORD -keystore $KEYSTORE \
       -storepass $KEYSTORE_PASSWORD -validity $VALIDDAYS`
# Check for any error
found=`echo "$error_text" | grep -c "already exists"`
isError=`echo "$error_text" | grep -c "error"`

if test $found -ne 0
then
# Let us show this as warning.
 echo "Warning: $JAR_KEY already present in $KEYSTORE"
elif test $isError -ne 0
then
 echo $error_text
else
 echo "...successfully done."
fi






If you like please follow and comment