.NETGURU
HttpWebRequest and X509Certificates...anyone?
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngsec' list.


Paul Tillotson
Has anyone had luck accessing a secured SSL site using HttpWebRequest and
the X509Certificate class. I keep getting the error "Could not establish
trust relationship with remote server.I have successfully exported a .pfx
file to a DES 509 certificate .cer file.
I then read in the certificate file with the code below and TRY to post data
to HTTPS server.
Here is my code.
Thanks much Paul

////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////

X509Certificate x509
=509Certificate.CreateFromCertFile(@"c:\\MyDES509File.cer");
StreamWriter myWriter = null;
System.Net.HttpWebRequest objRequest;
objRequest =
(HttpWebRequest)System.Net.HttpWebRequest.Create(https://somesecuredServer/t
est.aspx);
objRequest.ClientCertificates.Add(x509);
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
try
{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write("Test data to SSL port...");
}
catch (Exception err)
{
string someerror=err.Message.ToString();
ResultsBox.Text = "Error="+ someerror;
return ;
}
myWriter.Flush();
myWriter.Close();

Reply to this message...
 
    
Remas Wojciechowski
Paul,

I recall having that issue every now and then, but I forgot exactly when and
why. Try this wide shot, maybe it will turn out a hit:

1. Have you installed the certificate an the machine that sends the request?
My experience with SSL comes from windows services and there I even had to
create a user for the service to run under and install the certificate for
that user.

Could proxy be an issue (I doubt). One thing to remember about HTTPS proxy -
due to a bug, the Proxy class must be instantiated like this:
WebProxy("proxy.domain.com", 443)
(no https:// in the server part

hth
Remas
http://www.aspalliance.com/remas

----- Original Message -----
From: "Paul Tillotson" <Click here to reveal e-mail address>
To: "aspngsec" <Click here to reveal e-mail address>
Sent: Tuesday, July 16, 2002 9:42 AM
Subject: [aspngsec] HttpWebRequest and X509Certificates...anyone?

[Original message clipped]

Reply to this message...
 
 
System.IO.StreamWriter
System.Net.HttpWebRequest
System.Net.WebProxy
System.Security.Cryptography.X509Certificates.X509Certificate




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification