Process untrusted, expired or not-match certificates with HttpWebRequest and ASP.Net
ActiveX RegEdit.   ActiveX User account Manager   Pure-ASP Upload
Export MDB/DBF from ASP   Active LogFile   WebChecker   ActiveX/ASP Multi Dictionary object
 See 
 also 
 IISTracer, real-time IIS monitor and logging tool.
 Huge ASP file upload with progress bar. 



Do you like this article?
Please, rate it
and write review!
Rated:
by Aspin.com users
What do you think?
 Top messages
 22.3.2003 19:18:41 
 Read and write SQL image data, store binary file to sql table. (nbsp;WSHDatabaseConversionVBScript)
 4.5.2002 9:16:43 
 Send an email from ASP (WSH) using VBSscript, CDONTS and Outlook. (nbsp;ASP / ASP.NetWSHVBScriptEmail)
 12.6.2003 9:14:29 
 Download multiple files in one http request (nbsp;File & data transferVBScript)

 Process untrusted, expired or not-match certificates with HttpWebRequest and ASP.Net 

 Areas>Languages>VB.Net
 Areas>ASP / ASP.Net>Networking
      Sometimes you will need to process secure web request to a site with certificate, which does not exactly match default security policy. The server certificate can be expired site host does not match cn, the server certificate can be issued by untrusted authority. If you access the ssl URL by Internet Explorer or other browser, you will usually ge the message with security warning.
      If you want to process such URL with VB Net, you have to specify own ICertificatePolicy:
Imports System.Net
Imports System.Web
Imports System.Security.Cryptography.X509Certificates
Imports System.Runtime.InteropServices

Public Class MyAcceptCertificatePolicy
  Implements ICertificatePolicy

  Private Enum eCertificateProblem As Integer
    CertNone = 0
    CertEXPIRED = &H800B0101
    CertVALIDITYPERIODNESTING = &H800B0102
    CertROLE = &H800B0103
    CertPATHLENCONST = &H800B0104
    CertCRITICAL = &H800B0105
    CertPURPOSE = &H800B0106
    CertISSUERCHAINING = &H800B0107
    CertMALFORMED = &H800B0108
    CertUNTRUSTEDROOT = &H800B0109
    CertCHAINING = &H800B010A
    CertREVOKED = &H800B010C
    CertUNTRUSTEDTESTROOT = &H800B010D
    CertREVOCATION_FAILURE = &H800B010E
    CertCN_NO_MATCH = &H800B010F
    CertWRONG_USAGE = &H800B0110
    CertUNTRUSTEDCA = &H800B0112
  End Enum

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

    Dim cp As eCertificateProblem = certificateProblem

    'this accepts certificates with untrusted root, 
    '  And If cn does Not match host name
    Select Case cp
      Case eCertificateProblem.CertUNTRUSTEDROOT, _
           eCertificateProblem.CertCN_NO_MATCH
        Return True
      Case eCertificateProblem.CertNone
        Return True
    End Select
    Return False
  End Function
End Class

Public Class Conector
  Public Shared Function GetEncodingFromCT(ByRef ContentType As String) As String
    On Error Resume Next
    Return Split(ContentType, "charset=", 2, CompareMethod.Text)(1).Trim("""")
  End Function

  Public Function GetWebData(ByVal URL As String) As String
    ServicePointManager.CertificatePolicy = New MyAcceptCertificatePolicy

    'create a web request To the URL
    Dim Req As HttpWebRequest = HttpWebRequest.Create(URL)

    'get a response from web site
    Dim Response As HttpWebResponse = Req.GetResponse()

    'check encoding of the response.
    Dim sEncoding As String = response.ContentEncoding
    If Len(sEncoding) = 0 Then sEncoding = GetEncodingFromCT(Response.ContentType)

    'read the response stream To end using the response stream
    Dim Reader As New StreamReader(Response.GetResponseStream(), _
      System.Text.Encoding.GetEncoding(sEncoding))
    Dim sResponse As String = Reader.ReadToEnd()

    'close handles
    Reader.Close()
    Response.Close()
  End Function
End Class

 
 

See also for 'Process untrusted, expired or not-match certificates with HttpWebRequest and ASP.Net' article:


If you like this page, please include next link on your pages:



     IISTracer - IIS ISAPI real-time monitor IISTracer is a real-time monitoring tool for Microsoft IIS, which will show/log you what is happenning on IIS server right now. It let's you reveal problems with long-running scripts (.asp, .cgi, cfm...), hang-up states and low resource situations and lets you stop long-running requests (uploads/downloads).      ActiveX User account Manager - Set of simple objects for creating, deleting, and managing user accounts, groups, servers and domains in the Windows NT environment.
     Active log file - Hi-performance text file logging for ASP/VBS/VBA applications. Lets you create daily/weekly/monthly log files with variable number of logged values and extra timing and performance info.      ActiveX windows registry editor - Intuitive, easy to use COM interface to windows registry. Set of classes to read/enumerate/modify windows registry keys and values from ASP, VBS and T-SQL.
     ActiveX/ASP Multi Dictionary object - Free-threaded hi-speed dictionary algorithm with unique/nonunique keys (map/multimap). Connect to another dictionary object in the same process. Lock and Unlock methods to synchronize tasks (application scope). Share ASP Application/Session objects.      Export DBF/MDB from ASP - Conversion from recordset to MDB/DBF. Direct binary output of MDB or DBF files from ASP pages with one row of code.
     Pure-ASP upload - lets you upload files using Pure ASP VBS code (using multipart/form-data and input type=file).      ByteArray - Works with safearray binary data (VT_UI1 | VT_ARRAY) - save/restore binary data from disk, find, work with code pages, convert to string/hexstring(SQL).
     WebChecker - Checks http, https, ftp and gopher internet connections in regular intervals. Lets you monitor web site functionality (uptime). Enables restart or notification on problems.      HTTPLog ISAPI filter - Lets you log incomming/outgoing http header and document data to separate files. Monitor of IIS service input/output.

© 1996 – 2010 Antonin Foller, PSTRUH Software, e-mail help@pstruh.cz