Results 1 to 7 of 7

Thread: SSL Error

  1. #1

    Thread Starter
    Addicted Member Dmyze's Avatar
    Join Date
    Mar 2002
    Location
    Seattle
    Posts
    160

    SSL Error

    I keep getting the following error message when trying to make an SSL Connection via VB.NET's WebRequest:

    The underlying connection was closed: Could not establish trust relationship with remote server.

    VB Code:
    1. Private Function SendXML(ByVal xml As String) As String
    2.  
    3.         Dim aURL As String
    4.  
    5.         aURL = "https://www.site.com:10027"
    6.  
    7.         Dim wr As HttpWebRequest = Net.WebRequest.Create(aURL)
    8.  
    9.         Dim cert As System.Security.Cryptography.X509Certificates.X509Certificate
    10.         cert = System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromSignedFile("C:\cert\ca.cer")
    11.         wr.ClientCertificates.Add(cert)
    12.  
    13.         wr.ContentType = "text/xml"
    14.         wr.KeepAlive = False
    15.  
    16.         wr.Method = "POST"
    17.  
    18.         Dim sw As StreamWriter
    19.  
    20.         Try
    21.             sw = New StreamWriter(wr.GetRequestStream())
    22.             sw.Flush()
    23.             sw.AutoFlush = True
    24.         Catch ex As Exception
    25.             Return False
    26.         End Try
    27.  
    28.         Try
    29.             sw.Write(xml)
    30.             sw.Flush()
    31.             sw.Close()
    32.  
    33.         Catch ex As Exception
    34.             Return False
    35.         End Try
    36.  
    37.         wr.Timeout = 900000
    38.         Dim wres As HttpWebResponse = wr.GetResponse
    39.  
    40.         Dim s As IO.Stream
    41.         s = wres.GetResponseStream
    42.  
    43.         Dim sr As IO.StreamReader
    44.         sr = New IO.StreamReader(s)
    45.  
    46.         Return sr.ReadToEnd
    47.  
    48.     End Function
    -Daryl
    "Two More Rolls of Duct tape, and the world is mine!"
    VB.NET Guru

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm I need to send some things (like on a submit form) and then download the output(just registering in a forum and then retrieving the "you are being logged in blablabla" but in a site which is https(SSL).

    I am facing the same trouble, anyway to go over it?
    \m/\m/

  3. #3

    Thread Starter
    Addicted Member Dmyze's Avatar
    Join Date
    Mar 2002
    Location
    Seattle
    Posts
    160
    Here is how I got it to work, note that first line:

    Code:
            ServicePointManager.CertificatePolicy = New MyPolicy
    
            Dim sURL As String =  "https://www.site.com:10027"
    
            Dim uUri As Uri = New Uri(sURL)
    
            Dim wr As HttpWebRequest = Net.WebRequest.Create(uUri)
    
            Dim cert As System.Security.Cryptography.X509Certificates.X509Certificate
            cert = System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromCertFile("C:\Cert\ca.cer")
    
            wr.ClientCertificates.Add(cert)
    
            wr.ContentType = "text/xml"
            wr.KeepAlive = False
    
            wr.Method = "POST"
    
            Dim sw As StreamWriter
    
            Try
                sw = New StreamWriter(wr.GetRequestStream())
                sw.Flush()
                sw.AutoFlush = True
            Catch ex As Exception
                Throw ex
            End Try
    
            Try
                sw.Write(xml)
                sw.Flush()
                sw.Close()
    
            Catch ex As Exception
                Throw ex
            End Try
    
            wr.Timeout = 120000
            Try
                Dim wres As HttpWebResponse = wr.GetResponse
    
    
                Dim s As IO.Stream
                s = wres.GetResponseStream
    
                Dim sr As IO.StreamReader
                sr = New IO.StreamReader(s)
    
                Return sr.ReadToEnd
    
            Catch ex As Exception
                Throw ex
            End Try
    -Daryl
    "Two More Rolls of Duct tape, and the world is mine!"
    VB.NET Guru

  4. #4

    Thread Starter
    Addicted Member Dmyze's Avatar
    Join Date
    Mar 2002
    Location
    Seattle
    Posts
    160
    Oh yeah, Here's MyPolicy


    Code:
    Imports System.Net
    Imports System.Security.Cryptography.X509Certificates
    Public Class MyPolicy
        Implements ICertificatePolicy
        Public Function CheckValidationResult(ByVal srvPoint As ServicePoint, ByVal cert As X509Certificate, ByVal request As WebRequest, ByVal problem As Integer) As Boolean Implements ICertificatePolicy.CheckValidationResult
            Return True
        End Function
    End Class
    -Daryl
    "Two More Rolls of Duct tape, and the world is mine!"
    VB.NET Guru

  5. #5
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    and this?
    cert = System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromCertFile("C:\Cert\ca.cer")
    What does the file have inside?
    \m/\m/

  6. #6

    Thread Starter
    Addicted Member Dmyze's Avatar
    Join Date
    Mar 2002
    Location
    Seattle
    Posts
    160
    ca.cer is a file the web site emailed to me to use with their site. It is their SSL Certificate File. I think there is a way you can find it in your browser's cache if you visit the site.

    In IE look at -Tools -Internet Options -Content -Certificates

    Hope that Helps.
    Last edited by Dmyze; May 17th, 2004 at 07:33 PM.
    -Daryl
    "Two More Rolls of Duct tape, and the world is mine!"
    VB.NET Guru

  7. #7
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Hey, I tried finding the .CER file but I couldn't :S

    People over here http://www.vbforums.com/showthread.p...hreadid=290738 say that i must buy a certificate in order to use it...do I?!

    I could try to make like you and mail the guys from the webpage im trying to access but I guess they simply won't answer :S

    Any ideas?
    \m/\m/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width