@echo off

rem Update History...................
rem    Mar 5, 2002 - add support for environments with no domain name configured
rem

rem ...................................................
rem This batch file creates and install 2 certificates. 
rem This first is a server certificate used by Callpilot Servers to identify themselves.
rem The second is a user certificate that is imported to Netscape certificate database
rem
rem
rem Usage: MakeCertificate [host name] [domain name]
rem
rem Example: MakeCertificate CallPilot1 company.com
rem


echo WARNING: 
echo    RUNNING THIS WILL OVERWRITE EXISTING CALLPILOT SERVER CERTIFICATES

if "%1"=="" goto error

d:
cd \nortel\ssl

date /T
time /T

if exist cert7.db del cert7.db
if exist key3.db del key3.db
if exist secmod.db del secmod.db

set CERTFILE="CallPilot.cer"
if exist %CERTFILE% del %CERTFILE%
if exist SelfSigned.cer del SelfSigned.cer

if "%2"=="" goto noDomainName

rem FULL Host and Domain Name available

rem the following generates an CA certificate file and inserts into the certificate database 
cc cn=%1.%2.authority -u 31 -m 240 -sl ROOT m -r

rem the following generates a user certificate file that can be imported to Netscape certificate database
cc cn=%1.%2 -u 31 -m 240 -sl MY u -is %1.%2.authority ROOT m -r

goto netscape

:noDomainName

rem HOST Name only
rem the following generates an CA certificate file and inserts into the certificate database 
cc cn=%1.authority -u 31 -m 240 -sl ROOT m -r

rem the following generates a user certificate file that can be imported to Netscape certificate database
cc cn=%1 -u 31 -m 240 -sl MY u -is %1.authority ROOT m -r


:netscape
rem Create Netscape certificate database files required for SSL access to server with Netscape SDK

rem Generate the Database
modutil -create -dbdir . -force

rem Set default database password
modutil -dbdir . -changepw "Communicator Certificate DB" -newpwfile pwd.txt -force

rem Install CallPilot certificate into netscape certificate database
certutil -A -n %1 -t "P,," -d . -i %CERTFILE% -f pwd.txt

goto end

:error   
echo Usage:  MakeCertificate [host name] [domain name]

:end
