By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,025 Members | 2,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,025 IT Pros & Developers. It's quick & easy.

Connect to web site using SSL & Client Certificates

P: n/a
Well, I got it working when running against my test server (IIS5 W2K
svr, I will attach a sample of the code at the bottom of this
message), but now I'm connecting to our client (Apache) I'm getting
the following error:

An unhandled exception of type 'System.Net.WebException' occurred in
system.dll

Additional information: The underlying connection was closed: Unable
to connect to the remote server.
This exception is thrown when the GetRequestStream() method is
called and I am using a client cert that was issued to us from their
internal CA (they are using OpenSSL).

Any help'd be much appreciated!

Regards,kg.
public void Connect()
{
// Doesn't work
X509Certificate cert =
X509Certificate.CreateFromCertFile("c:\\Certificat es\\client_cert.cer");
WebRequest request = GetWebRequest(new
Uri("https://client_web/methodserver.php"));

// Works
//X509Certificate cert =
X509Certificate.CreateFromCertFile("c:\\Certificat es\\verisign_cert.cer");
//WebRequest request = GetWebRequest(new
Uri("https://server.com/testpage.aspx"));
request.ContentType = "text/xml";
request.Method = "POST";

HttpWebRequest httpRequest = (HttpWebRequest)request;
httpRequest.UserAgent = "Exel Test";
httpRequest.Headers = new WebHeaderCollection();
httpRequest.ClientCertificates.Add(cert);

request = (WebRequest)httpRequest;

// This is where it breaks...
Stream reqStream = request.GetRequestStream();
reqStream.Close();

WebResponse resp = GetWebResponse(request);
Stream respStream = resp.GetResponseStream();

TextReader tr = new StreamReader(respStream, new UTF8Encoding(), true,
4096);

string certInfo = tr.ReadToEnd();

System.Diagnostics.Debug.WriteLine(certInfo);
}
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Okey dokey, well only a little embarrassed! I didn't have the
private key for the Client Cert that our client gave us, therefor it
wasn't properly loaded in my Personal Cert store, therefor when the
connection was being negotiated it crashed... I got the full key
pair from them and voila!

Hope this helps anyone!

Krishna.

kr*********@hotmail.com (Krishna) wrote in message news:<76**************************@posting.google. com>...
Well, I got it working when running against my test server (IIS5 W2K
svr, I will attach a sample of the code at the bottom of this
message), but now I'm connecting to our client (Apache) I'm getting
the following error:

An unhandled exception of type 'System.Net.WebException' occurred in
system.dll

Additional information: The underlying connection was closed: Unable
to connect to the remote server.
This exception is thrown when the GetRequestStream() method is
called and I am using a client cert that was issued to us from their
internal CA (they are using OpenSSL).

Any help'd be much appreciated!

Regards,kg.
public void Connect()
{
// Doesn't work
X509Certificate cert =
X509Certificate.CreateFromCertFile("c:\\Certificat es\\client_cert.cer");
WebRequest request = GetWebRequest(new
Uri("https://client_web/methodserver.php"));

// Works
//X509Certificate cert =
X509Certificate.CreateFromCertFile("c:\\Certificat es\\verisign_cert.cer");
//WebRequest request = GetWebRequest(new
Uri("https://server.com/testpage.aspx"));
request.ContentType = "text/xml";
request.Method = "POST";

HttpWebRequest httpRequest = (HttpWebRequest)request;
httpRequest.UserAgent = "Exel Test";
httpRequest.Headers = new WebHeaderCollection();
httpRequest.ClientCertificates.Add(cert);

request = (WebRequest)httpRequest;

// This is where it breaks...
Stream reqStream = request.GetRequestStream();
reqStream.Close();

WebResponse resp = GetWebResponse(request);
Stream respStream = resp.GetResponseStream();

TextReader tr = new StreamReader(respStream, new UTF8Encoding(), true,
4096);

string certInfo = tr.ReadToEnd();

System.Diagnostics.Debug.WriteLine(certInfo);
}

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.