rem ------------------------------------------------------------------------------
rem --  Use this batch file to build a request before addressing the CA (Thawte)
rem --   	and to convert the generated certificate 
rem --		to the format required by C/SSL.
rem --
rem --  Parameters:
rem --     %1 - operation (request | convert)
rem --     %2 - password phrase (must match the value in mgreq.ini)
rem ------------------------------------------------------------------------------

if "%1" == "request" goto :request
goto :convert


rem --  --------------------------------------------------------
rem --  Phase 1 - Preparing a request for a certificate :
rem --  --------------------------------------------------------
:request

certreq -alg rsa -str 512 -dn cn=bob -enc pem -req a.req -prv a.p8 -pass "%2"

goto :end


rem --  --------------------------------------------------------
rem --  Phase 2 - Obtaining the test certificate from Thawte :
rem --  --------------------------------------------------------
rem --  Go to: https://www.thawte.com/cgi/server/test.exe
rem --  Copy the contents of the file a.req into the CSR box.
rem --  Choose the "standard" output format. It's a radio button in the page.
rem --  Press "Generate Test Certificate".
rem --  Copy the result into a file called a.crt.


rem --  ---------------------------------------------------------------
rem --  Phase 3 - Converting the certificate before activating Magic :
rem --  ---------------------------------------------------------------
:convert

convert -certificate a.crt -pkcs8 a.p8 "%2" toPEM -pkcs12 a.p12 "%2"
Copy a.p12 ..\personal\thawte\StrongServerRsa.pem
Copy a.p12 ..\personal\thawte\StrongClientRsa.pem

del a.crt
del a.*

:end

