#!/sbin/sh
####################################
#  Product: HPUXOpenSSL
#  Fileset: Latest
#  configure
#  (c) Copyright Hewlett-Packard Company
####################################
UTILS="/usr/lbin/sw/control_utils"
if [[ ! -f $UTILS ]]
then
        echo "ERROR:    Cannot find $UTILS"
        exit 1
fi
. $UTILS
exitval=$SUCCESS
####################################
# Start prngd daemon
####################################
if [ ! -d /var/run ]
then
	mkdir /var/run
	chmod 555 /var/run
	chown bin:bin /var/run
fi

ch_rc -a -p PRNGD_START=0 /etc/rc.config.d/prngd > /dev/null

if [ ! -e /dev/urandom ]
then
	ch_rc -a -p PRNGD_START=1 /etc/rc.config.d/prngd > /dev/null
	/sbin/init.d/prngd.rc start 1>/dev/null 2>/dev/null
	sleep 5
fi
####################################
# Set up the man pages
####################################

	mod_pathfile -a MP /opt/openssl/fips/0.9.7/man
#	mod_pathfile -a MP /opt/openssl/prngd/man

####################################
# Add long filenames
####################################
	. $SW_CONTROL_DIRECTORY/add_long_filenames $SW_CONTROL_DIRECTORY/openssl_filename_index.txt
####################################
# Create self signed certificate
####################################

if [[ ! -f /opt/openssl/certs/host.pem || ! -f /opt/openssl/private/hostkey.pem ]]
then
	/opt/openssl/fips/0.9.7/bin/openssl req -new -x509 -out /opt/openssl/certs/host.pem -keyout /opt/openssl/private/hostkey.pem -nodes -subj /C=US/ST=CA/L=City/O=Company/CN=localhost/emailAddress=www@localhost >/tmp/fips_hostcert.out 2>&1
	if [ $? -ne 0 ]
	then
		echo "\nNOTE:   Unable to create self-signed host certificate." 

		ps -ea|grep prngd  2> /dev/null 1> /dev/null
		prngd_status=$?
		if [ ! -e /dev/urandom -a $prngd_status -ne 0 ]
		then
			echo "        The prngd server failed to start."
		fi
		echo "        See the file /tmp/fips_hostcert.out for details." 
         else
		rm -f /tmp/fips_hostcert.out
		chmod 600 /opt/openssl/private/hostkey.pem
	fi
fi

####################################
exit $exitval
####################################
