Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / November 2004

Tip: Looking for answers? Try searching our database.

Secure Connection HTTPWebrequest.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Matthew - 25 Oct 2004 19:10 GMT
Hi!

Hoping for some help here re client certificates and SSL The following
method:

========================================================================
Public Sub SimpleXMLSendReceive()

       Try

           m_StartTime = Now

           Dim FileName As String
           Dim Request = CreateWebRequest()

--crashes-> m_XmlIn.Save(Request.GetRequestStream())
           
Private Function CreateWebRequest() As HttpWebRequest

       Dim objRequest As HttpWebRequest = WebRequest.Create(m_URL &
"/" & m_Operation)

       SetProxy(objRequest.Proxy)

       objRequest.Method = "POST"
       objRequest.ContentType = "application/x-www-form-urlencoded"
       objRequest.Timeout = 300000

       Dim certStore As X509CertificateStore
       certStore = X509CertificateStore.CurrentUserStore(X509CertificateStore.RootStore.ToString)
       certStore.OpenRead()

       Dim cert As X509Certificates.X509Certificate
       If certStore.FindCertificateBySubjectString("XYZ").Count > 0
Then
           cert = certStore.FindCertificateBySubjectString("XYZ")(0)
       End If

       objRequest.ClientCertificates.Add(cert)

       Return objRequest

   End Function

========================================================================
I am attaching the cert ok, and I have IIS configured to require a
secure connection, and require a client cert The URl for the post is a
HTTPS address. When I hit the GetRequestStream call I get;

"The underlying connection was closed: could not establish a secure
connection."

I am using test certificates and when I change to another one the
error becomes could not establish a trust relationship ( I think this
may be related to the Untrusted Root Authority error).

I have tried implementing a custom ICertificatePolicy as follows :

========================================================================
Public Enum CertificateProblem As Long

   CertEXPIRED = 2148204801
   CertVALIDITYPERIODNESTING = 2148204802
   CertROLE = 2148204803
   CertPATHLENCONST = 2148204804
   CertCRITICAL = 2148204805
   CertPURPOSE = 2148204806
   CertISSUERCHAINING = 2148204807
   CertMALFORMED = 2148204808
   CertUNTRUSTEDROOT = 2148204809
   CertCHAINING = 2148204810
   CertREVOKED = 2148204812
   CertUNTRUSTEDTESTROOT = 2148204813
   CertREVOCATION_FAILURE = 2148204814
   CertCN_NO_MATCH = 2148204815
   CertWRONG_USAGE = 2148204816
   CertUNTRUSTEDCA = 2148204818
End Enum

Class CertPol
   Implements ICertificatePolicy

   Public Function CheckValidationResult(ByVal srvPoint As
System.Net.ServicePoint, ByVal certificate As
System.Security.Cryptography.X509Certificates.X509Certificate, ByVal
request As System.Net.WebRequest, ByVal certificateProblem As Integer)
As Boolean Implements
System.Net.ICertificatePolicy.CheckValidationResult
       Return True
   End Function
End Class

========================================================================

And registed it with ServicePointManager prior to the problem call:

========================================================================

System.Net.ServicePointManager.CertificatePolicy = New CertPol()

========================================================================

to attempt and override the issue... but no dice...

Any ideas would be much appreciated.

THanks,

Matt
lilryno - 13 Nov 2004 21:57 GMT
I'm having the same kind of trouble trying to automate the downloading
of files on secure servers.  I'm trying to use the
webclient.downloadfile on a secure server with no dice.  That trust
relationship is foiling my schemes...

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.