Re: SSL for dummies... how to generate X509Certificate (*.DER) files?



Do you need to do client certificate authentication or just do SSL server
auth? If you don't need client certificate auth, then you don't specify a
client certificate in your HttpWebRequest. Just make sure you have your
server configured for SSL.

If you do need to do client cert auth, then you can get the DER version of a
certificate simply by exporting the certificate from the local machine
store. Note that you must have a private key installed for the client
certificate if you wish to do client certificate auth. Supplying the file
tells Windows which cert to use, but it must be able to use that cert to
look up the stored private key on the system in order for things to actually
work.

I hope that helps a bit. Go back and ask more questions if that didn't
explain enough of the basics.

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
"James Crosswell" <james@xxxxxxxxxxxxxx> wrote in message
news:e8aiCdsBIHA.5960@xxxxxxxxxxxxxxxxxxxxxxx
I need to establish an SSL connection to a web site, do an HTTP post and
retrieve the response. I currently have the following code (based on
something I found in a blog somewhere - can't remember where):

public string PostData(byte[] postData, string serverAddress,
string certificatePath)
{
// Set up a Post request to be sent to the IFEP interface
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create(serverAddress);

// read DER encoded client certificate and attach it to
request object
// so it can be passed to the gateway as part of the SSL
handshake
X509Certificate clientcert =
X509Certificate.CreateFromCertFile(certificatePath);
req.ClientCertificates.Add(clientcert);

// Set the content type of the data being posted.
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = postData.Length;

//Send the request
using (Stream streamOut = req.GetRequestStream())
{
streamOut.Write(postData, 0, postData.Length);
}

// Read the response
string strResponse;
using (StreamReader streamIn = new
StreamReader(req.GetResponse().GetResponseStream()))
{
strResponse = streamIn.ReadToEnd();
}

// Spit out the results to the console
return strResponse;
}

This looks like it would work fine but I don't know how to generate the
DER file that is required for X509Certificate.CreateFromCertFile. I'm
using Vista as my development machine, by the way, so I need to be able to
generate this certificate for my Vista box.

TIA for any help.

Best Regards,

James Crosswell
Microforge.net LLC
http://www.microforge.net


.



Relevant Pages

  • RE: The remote certificate is invalid according to the validation proc
    ... the webservice is protected through https/ssl. ... you also add client certificate in your ... try accessing the server service to see ... SSL certificate or the servername you used to access the server. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: regarding client certificates.
    ... between the client and the server. ... For this you don't need to enable Clients certificate requirement and should ... SSL protected and click on Directory Security. ... > How to go about to create a client certificate. ...
    (microsoft.public.inetserver.iis.security)
  • Re: SSL for dummies... how to generate X509Certificate (*.DER) files?
    ... If you don't need client certificate auth, then you don't specify a client certificate in your HttpWebRequest. ... I need to establish an SSL connection to a remote web server. ... So it seems to be complaining about the remote certificate, ...
    (microsoft.public.dotnet.security)
  • Re: Simple Single Sign-On
    ... > Doesn't SSL do this, even if it is not usually used that way? ... > recall that SSL can authenticate both the server AND the client, ... client certificate, which is currently a tricky and browser-specific ... to do just by clicking on browser links. ...
    (sci.crypt)
  • Re: question about SSL certificates and PHP
    ... > the current client certificate on the server? ... > environmental variable that holds the entire certificate, ... > the numerous SSL env variables that hold all the certificate piece ...
    (comp.lang.php)