client cert based authentication for a URL

This topic contains 2 replies, has 3 voices, and was last updated by  Joakim 3 years, 6 months ago.

  • Author
    Posts
  • #13314

    GoogleUser7
    Participant

    Hi,

    we want to check URL response of a .asmx URL which needs a client certificate for authenticating.
    I got the cert object and then passed it to invoke-webrequest cmdlet, but no matter what i try I always get this error
    "The underlying connection was closed".

    code1

    $WebClient = New-Object System.Net.WebClient
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
    $WebClient.DownloadString("https://server1/mywebservices/myser.asmx")

    code2
    $url="https://server1/mywebservices/myser.asmx"

    $cert=(Get-ChildItem cert: -Recurse | where {$_.Thumbprint -eq "abcdefgh3333.....something"}| Select -First 1)

    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
    #load my client certificate defined by thumbprint

    $HTTP_Request = [System.Net.WebRequest]::Create($url)
    $HTTP_Request.ClientCertificates.Add($cert )
    # We then get a response from the site.
    $HTTP_Response = $HTTP_Request.GetResponse()

    Can someone please help me.
    Thanks

  • #15379

    Don Jones
    Keymaster

    Unfortunately, the best place to troubleshoot this is probably on the web server, using its logs, and possibly writing a test Web page that can provide more information on what the server is receiving. It's impossible to tell, just from looking at your script, what might be wrong.

  • #15443

    Joakim
    Participant

    I would recommend you to install Fiddler. It is probably the quickest way to see what is going on. And it will help you determine if the error is with a local certificate or on the server side.

You must be logged in to reply to this topic.