I expect a client cert will return after starting System.Net.HttpListener in "Negotiate" mode

I want to write a HttpListener requires browser to submit its client cert before response.  When start following code, the browser prompts for password only and nothing is returned in the server side statement .GetClientCertificate() .  Instead, the response headers("Authorization") has a long base64 string [Negotiate TlRMTVNTUAADA...].  I suspect it is the client cert that I want.  However, I fail to create the cert from it.

What is wrong

Imports System.Security.Cryptography.X509Certificates
Module modClientCert
    Private xListener As New System.Net.HttpListener
    Public Sub Main()
        xListener.Prefixes.Add("http://192.168.2.103/")
        xListener.AuthenticationSchemes = AuthenticationSchemes.Negotiate
        xListener.Start()

        Dim mContext As HttpListenerContext = xListener.GetContext
        With mContext.Request
            Dim mIsAuth As Boolean = .IsAuthenticated ' Return True
            Dim mCert As X509Certificate2 = .GetClientCertificate() ' Return nothing
            Dim mCertErr As Integer = .ClientCertificateError ' Return 0
            Dim mNegotiate As string = .Headers("Authorization") ' Return Negotiate TlRMTVNTUAADAAAAGAAYAI4AAAAYABgApgAAABoAGgBIAAAAGAAYAGIAAAAUABQAegAAAAAAAAC+AAAABYKIogUBKAoAAAAPMQA5ADIALgAxADYAOAAuADIALgAxADAAMwBhAGQAbQBpAG4AcwB0AHIAYQB0AG8AcgBKAE8ASABOAFMATwBOAFQANAAzAGD3k7ByYKqeAAAAAAAAAAAAAAAAAAAAAIK+w+qKJqwaXCPR6Lxtmei3e7Pwy337rQ==
            Dim mCert_Raw() As Byte = System.Convert.FromBase64String(Mid(mNegotiate, 11))
            Dim mCert_x As New X509Certificate2(mCert_Raw) ' Throw System.Security.Cryptography.CryptographicException : Cannot find the requested object.
        End With
   
    End Sub
End Module



Answer this question

I expect a client cert will return after starting System.Net.HttpListener in "Negotiate" mode

  • FREDYCOREA

    Here is a blog that points to some tools for associating server certificate with an HttpListener server.

    http://blogs.msdn.com/mahjayar/archive/2004/11/30/272638.aspx


  • Seraph_78

    The Negotiate string you are trying to use has nothing to do with certificates, but is related to the process of proving the client's identity without the use of certifcates.  If you want to use client certificates you have to use an https prefix so that SSL is enabled.  I will look up some blogs that talk about this and post them in few minutes..



  • I expect a client cert will return after starting System.Net.HttpListener in "Negotiate" mode