Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. WebBrowser control, HTTPS SSL certificate security dialog

WebBrowser control, HTTPS SSL certificate security dialog

Scheduled Pinned Locked Moved Visual Basic
securitycsharpcomcryptography
5 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    akuma6099
    wrote on last edited by
    #1

    I'm writing a util that uses a hidden webbrowser control to traverse through a few .aspx pages. These are through an SSL enabled site. I want to accept the certificate and or install it locally instead of the end user clicking on "yes" to accept it. I've googled for quite some time and found 2 different methods. One for .NET 1.1 and .NET 2.0. I cannot get either to work. The dialog still pops up. I am trying to put this into a module. Here's what I have tried.

    Imports System.Net
    Imports System.Net.Security
    Imports System.Security.Cryptography.X509Certificates
    Imports System.Security.Policy

    Module VWeb

    Dim WithEvents WB As New WebBrowser
    Dim ASPComplete As Integer = 0
    Dim LoginURI As New Uri("https://XXX.com/Login.aspx")
    Dim OpenCallsURI As New Uri("https://XXX.com/openCallReport.aspx")
    Dim MainPage As New Uri("https://XXX.com/Default.aspx")
    Dim TestTimer As New Timer()
    

    Public Function LoginAsTech(ByVal UserID As String, ByVal Pass As String) As Boolean
    Dim MyDoc As New mshtml.HTMLDocument
    Dim DocElements As mshtml.IHTMLElementCollection = Nothing
    Dim LoginForm As mshtml.HTMLFormElement = Nothing

        ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
        
        ASPComplete = 0
        WB.Navigate(LoginURI)
        BrowserLoop()
    
        MyDoc = WB.Document.DomDocument
        DocElements = MyDoc.getElementsByTagName("input")
        For Each i As mshtml.IHTMLElement In DocElements
    
            Select Case i.name
                Case "seLogin$UserName"
                    i.value = UserID
                Case "seLogin$Password"
                    i.value = Pass
                Case Else
                    Exit Select
            End Select
    
            frmServiceCalls.txtOut.Text &= i.name & " : " & i.value & " : " & i.type & vbCrLf
        Next i
        'WB.Document.Forms("form1").InvokeMember("submit")
    
    
        LoginForm = MyDoc.forms.item("form1")
        LoginForm.item("seLogin$LoginButton").click()
        ASPComplete = 0
        BrowserLoop()
    
    
    
        MyDoc = WB.Document.DomDocument
        DocElements = MyDoc.getElementsByTagName("input")
        For Each j As mshtml.IHTMLElement In DocElements
            frmServiceCalls.txtOut.Text &= j.name & " : " & j.value & " : " & j.type & vbCrLf
    
        Next j
    
        frmServiceCalls.txtOut.Text &= vbCrLf & vbCrLf & WB.Url.AbsoluteUri & vbCrLf
    
    S B 2 Replies Last reply
    0
    • A akuma6099

      I'm writing a util that uses a hidden webbrowser control to traverse through a few .aspx pages. These are through an SSL enabled site. I want to accept the certificate and or install it locally instead of the end user clicking on "yes" to accept it. I've googled for quite some time and found 2 different methods. One for .NET 1.1 and .NET 2.0. I cannot get either to work. The dialog still pops up. I am trying to put this into a module. Here's what I have tried.

      Imports System.Net
      Imports System.Net.Security
      Imports System.Security.Cryptography.X509Certificates
      Imports System.Security.Policy

      Module VWeb

      Dim WithEvents WB As New WebBrowser
      Dim ASPComplete As Integer = 0
      Dim LoginURI As New Uri("https://XXX.com/Login.aspx")
      Dim OpenCallsURI As New Uri("https://XXX.com/openCallReport.aspx")
      Dim MainPage As New Uri("https://XXX.com/Default.aspx")
      Dim TestTimer As New Timer()
      

      Public Function LoginAsTech(ByVal UserID As String, ByVal Pass As String) As Boolean
      Dim MyDoc As New mshtml.HTMLDocument
      Dim DocElements As mshtml.IHTMLElementCollection = Nothing
      Dim LoginForm As mshtml.HTMLFormElement = Nothing

          ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
          
          ASPComplete = 0
          WB.Navigate(LoginURI)
          BrowserLoop()
      
          MyDoc = WB.Document.DomDocument
          DocElements = MyDoc.getElementsByTagName("input")
          For Each i As mshtml.IHTMLElement In DocElements
      
              Select Case i.name
                  Case "seLogin$UserName"
                      i.value = UserID
                  Case "seLogin$Password"
                      i.value = Pass
                  Case Else
                      Exit Select
              End Select
      
              frmServiceCalls.txtOut.Text &= i.name & " : " & i.value & " : " & i.type & vbCrLf
          Next i
          'WB.Document.Forms("form1").InvokeMember("submit")
      
      
          LoginForm = MyDoc.forms.item("form1")
          LoginForm.item("seLogin$LoginButton").click()
          ASPComplete = 0
          BrowserLoop()
      
      
      
          MyDoc = WB.Document.DomDocument
          DocElements = MyDoc.getElementsByTagName("input")
          For Each j As mshtml.IHTMLElement In DocElements
              frmServiceCalls.txtOut.Text &= j.name & " : " & j.value & " : " & j.type & vbCrLf
      
          Next j
      
          frmServiceCalls.txtOut.Text &= vbCrLf & vbCrLf & WB.Url.AbsoluteUri & vbCrLf
      
      S Offline
      S Offline
      sph3rex
      wrote on last edited by
      #2

      You still can process the output of webrequest or httpwebrequest with webbrowser control using WebBrowser.DocumentStream property ... so for test purposes make the request with a webrequest and redirect the incoming stream to documentstream property. Additionally ServicePointManager serves for managed code usage, while webbrowser is a wrapper around the shdocwhatever.

      1 Reply Last reply
      0
      • A akuma6099

        I'm writing a util that uses a hidden webbrowser control to traverse through a few .aspx pages. These are through an SSL enabled site. I want to accept the certificate and or install it locally instead of the end user clicking on "yes" to accept it. I've googled for quite some time and found 2 different methods. One for .NET 1.1 and .NET 2.0. I cannot get either to work. The dialog still pops up. I am trying to put this into a module. Here's what I have tried.

        Imports System.Net
        Imports System.Net.Security
        Imports System.Security.Cryptography.X509Certificates
        Imports System.Security.Policy

        Module VWeb

        Dim WithEvents WB As New WebBrowser
        Dim ASPComplete As Integer = 0
        Dim LoginURI As New Uri("https://XXX.com/Login.aspx")
        Dim OpenCallsURI As New Uri("https://XXX.com/openCallReport.aspx")
        Dim MainPage As New Uri("https://XXX.com/Default.aspx")
        Dim TestTimer As New Timer()
        

        Public Function LoginAsTech(ByVal UserID As String, ByVal Pass As String) As Boolean
        Dim MyDoc As New mshtml.HTMLDocument
        Dim DocElements As mshtml.IHTMLElementCollection = Nothing
        Dim LoginForm As mshtml.HTMLFormElement = Nothing

            ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
            
            ASPComplete = 0
            WB.Navigate(LoginURI)
            BrowserLoop()
        
            MyDoc = WB.Document.DomDocument
            DocElements = MyDoc.getElementsByTagName("input")
            For Each i As mshtml.IHTMLElement In DocElements
        
                Select Case i.name
                    Case "seLogin$UserName"
                        i.value = UserID
                    Case "seLogin$Password"
                        i.value = Pass
                    Case Else
                        Exit Select
                End Select
        
                frmServiceCalls.txtOut.Text &= i.name & " : " & i.value & " : " & i.type & vbCrLf
            Next i
            'WB.Document.Forms("form1").InvokeMember("submit")
        
        
            LoginForm = MyDoc.forms.item("form1")
            LoginForm.item("seLogin$LoginButton").click()
            ASPComplete = 0
            BrowserLoop()
        
        
        
            MyDoc = WB.Document.DomDocument
            DocElements = MyDoc.getElementsByTagName("input")
            For Each j As mshtml.IHTMLElement In DocElements
                frmServiceCalls.txtOut.Text &= j.name & " : " & j.value & " : " & j.type & vbCrLf
        
            Next j
        
            frmServiceCalls.txtOut.Text &= vbCrLf & vbCrLf & WB.Url.AbsoluteUri & vbCrLf
        
        B Offline
        B Offline
        BimJeam
        wrote on last edited by
        #3

        The answer from sph3rex is an entirely valid one, however if you still want to do it using your hidden window I have a solution that will assist you. It is part of an article detailing various WebBrowser/Security 'tricks' that I have employed that I am currently writing up. It should be published here on Code Project shortly (i.e. in the next week) and I will notify you when it is ready. BimJeam

        A 1 Reply Last reply
        0
        • B BimJeam

          The answer from sph3rex is an entirely valid one, however if you still want to do it using your hidden window I have a solution that will assist you. It is part of an article detailing various WebBrowser/Security 'tricks' that I have employed that I am currently writing up. It should be published here on Code Project shortly (i.e. in the next week) and I will notify you when it is ready. BimJeam

          A Offline
          A Offline
          akuma6099
          wrote on last edited by
          #4

          I look forward to it. I'm sure it will help others. I'm experimenting with the DocumentStream property. So far it's been ok. Not getting what I wanted but still tweaking about. Thanks.

          B 1 Reply Last reply
          0
          • A akuma6099

            I look forward to it. I'm sure it will help others. I'm experimenting with the DocumentStream property. So far it's been ok. Not getting what I wanted but still tweaking about. Thanks.

            B Offline
            B Offline
            BimJeam
            wrote on last edited by
            #5

            Ok, it is up - see http://www.codeproject.com/KB/shell/WebBrowserControlDialogs.aspx[^] Hopefully this helps.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups