CertificatePolicy

S

Susan

My windows application contains a browser, which is used
to browse to HTTPS sites. The Security Alert dialog comes
up stating that the name on the certificate doesn't match
the name of the site. I have implemented a
CertificatePolicy that accepts all certificates by always
returning true, but the browser is using or getting access
to this policy. The Security Alert is still appearing.

Code:

'My class to override the existing Certificate Policy
'Accepts all certificates
Public Class AcceptAllPolicy
Implements System.Net.ICertificatePolicy

Public Function CheckValidationResult(ByVal srvPoint _
As ServicePoint, ByVal cert As X509Certificate, ByVal _
request As WebRequest, ByVal certificateProblem As _
Integer) As Boolean Implements _
ICertificatePolicy.CheckValidationResult

Return True

End Function
End Class



'The axwebbrowser uses the navigate() or navigate2()
'method to access the site. I have implemented the
'following code when the site is to be navigated to

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

webBrowser.show()
webBrowser.navigate(<https site>)

Any ideas/help/comments/suggestions?

Thanks!!
 
S

scorpion53061

Imports System
Imports System.IO
Imports System.Net
Imports System.Threading
Imports System.Text.RegularExpressions
Imports System.Text.Encoding
Imports System.Security.Cryptography.X509Certificates

Public Class TrustAllCertificatePolicy
Implements System.Net.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


Private Sub cmdGet_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdGet.Click
'Create(a) 'WebRequest' object with the specified url
System.Net.ServicePointManager.CertificatePolicy = New
TrustAllCertificatePolicy

Dim myWebRequest As WebRequest
'myWebRequest.Credentials = myCert.TrustAllCertificatePolicy
myWebRequest =
WebRequest.Create("https://sentri.us.nortel.com:8443/SENTRI/home.jsp")

' Send the 'WebRequest' and wait for response.
Dim myWebResponse As WebResponse
myWebResponse = myWebRequest.GetResponse()
' Call method 'GetResponseStream' to obtain stream associated with
the response object
Dim ReceiveStream As Stream
ReceiveStream = myWebResponse.GetResponseStream()

Dim encode As System.Text.Encoding
encode = GetEncoding("utf-8")

' Pipe the stream to a higher level stream reader with the required
encoding format.
Dim readStream As New StreamReader(ReceiveStream, encode)
'txtLog.Text = (ControlChars.CrLf + "Response stream received")
Dim read(1024) As [Char]

' Read 256 charcters at a time .
Dim count As Integer = readStream.Read(read, 0, 1024)
txtLog.Text = ""
'While count > 0
While readStream.Peek >= 0

' Dump the 256 characters on a string and display the string
onto the console.
Dim str As New [String](read, 0, count)
txtLog.Text = txtLog.Text & (str)
count = readStream.Read(read, 0, 1024)

End While
Dim str2 As New [String](read, 0, count)
txtLog.Text = txtLog.Text & (str2)
count = readStream.Read(read, 0, 1024)
'Console.WriteLine("")

' Release the resources of stream object.
readStream.Close()

' Release the resources of response object.
myWebResponse.Close()

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top