Friday, 10 February 2012

Creating your own certificate for a test SSL server

I've just needed to spoof an SSL server that one of my client apps connects to, in order to setup some test cases for specific responses.

The TcpListener needs an X509Certificate to use for encryption. An easy way to set this up is to use the makecert.exe utility from Mircosoft.

First, you create a trusted root certificate:
makecert -pe -n "CN=Test And Dev Root Authority" -ss my -sr LocalMachine  -sky signature 
-r "Test And Dev Root Authority.cer"
,Then you use this created cert to create a certificate for encryption:
makecert -pe -n "CN=apptest.com" -ss my -sr LocalMachine -sky exchange -eku 1.3.6.1.5.5.7.3.1 -is MY -ir LocalMachine  
-sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 apptest.com.cer

Be sure to copy the root authority certificate into you trusted root store.

An example of setting up a server is below, copied directly from here.