Re: SSL for dummies... how to generate X509Certificate (*.DER) files?
- From: "Joe Kaplan" <joseph.e.kaplan@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 4 Oct 2007 22:27:30 -0500
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
.
- Follow-Ups:
- Re: SSL for dummies... how to generate X509Certificate (*.DER) files?
- From: James Crosswell
- Re: SSL for dummies... how to generate X509Certificate (*.DER) files?
- References:
- SSL for dummies... how to generate X509Certificate (*.DER) files?
- From: James Crosswell
- SSL for dummies... how to generate X509Certificate (*.DER) files?
- Prev by Date: SSL for dummies... how to generate X509Certificate (*.DER) files?
- Next by Date: Re: SSL for dummies... how to generate X509Certificate (*.DER) files?
- Previous by thread: SSL for dummies... how to generate X509Certificate (*.DER) files?
- Next by thread: Re: SSL for dummies... how to generate X509Certificate (*.DER) files?
- Index(es):
Relevant Pages
|