Identifying correct client certificate for ServerXMLHTTP.SetOption

白昼怎懂夜的黑 提交于 2019-12-24 14:24:03

问题


I have three client certificates installed in Windows 7 and need to use a specific one to authenticate a ServerXMLHTTP60 call using VBA.

Calling ServerXMLHTTP60.SetOption with the friendly name of the certificate returns with no error. But the subsequent .send fails with "A certificate is required to complete client authentication".

Code example:

    Public Sub TestCert()
    Dim myHTTP as New ServerXMLHTTP60
    Dim myURL as String

        ' Open the connection to the secure server
         myHTTP.Open "GET", "https://server/finalpath", False

        ' Attempt to set the correct client certificate
        ' I have also tried just the friendly name as well as 
        ' LOCAL_MACHINE\My\cert friendly name'
        myHTTP.SetOption 3, "CURRENT_USER\My\cert friendly name"

        ' Send request fails with "A certificate is required ..."
        myHTTP.Send
    End Sub

The specified certificate is working fine via IE or Firefox with this site. I must be using an incorrect pathname for the certificate. Is there a way to determine the correct client certificate pathname to ensure success?


回答1:


This drove me mad for a couple of days but... Assuming you install your client to default store under current user and your certificate has subject cn=mycert then this seems to work. Running office16, windows 10, winhttp5.1

Dim apiConnection As New WinHttp.WinHttpRequest

' Set the authentication settings
apiConnection.SetClientCertificate "mycert"

apiConnection.Open "Get", "https://localhost:8443", False
apiConnection.Send


来源:https://stackoverflow.com/questions/31942165/identifying-correct-client-certificate-for-serverxmlhttp-setoption

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!