3

I'm using MSXML2.ServerXMLHTTP in JScript / VBA and want to set the client certificate path. In WinHTTP.WinHTTPRequest I could use the option '.setClientCertificate', but this seems absent in MSXML2.ServerXMLHTTP.

Is there any argument I can use for this to get the same effect? I need to use MSXML2.ServerXMLHTTP as I'm using it a-synchronously and WinHTTP doesn't support that.

Example code JScript/VBA:

var H = new ActiveXObject('MSXML2.ServerXMLHTTP.6.0')
    H.open('GET', 'https://stackoverflow.com/', true)
    H.setRequestHeader('Cookie', 'yesplease')
    H.setClientCertificate('CURRENT_USER\MY\USERNAME')  <-- this line doesn't work
    H.send

So the above errors on the setClientCertificate line. However, the below would work (but as mentioned I can't use WinHTTP)

var H = new ActiveXObject('WinHTTP.WinHTTPRequest.5.1')
    H.open('GET', 'https://stackoverflow.com/', true)
    H.setRequestHeader('Cookie', 'yesplease')
    H.setClientCertificate('CURRENT_USER\MY\USERNAME')  <-- this line DOES work
    H.send

Is there a way I can use the setClientCertificate with the MSXML2.ServerHTTP object?

QHarr
  • 83,427
  • 12
  • 54
  • 101
JasperD
  • 152
  • 1
  • 3
  • 15
  • 1
    https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms763811(v%3Dvs.85) – QHarr Sep 13 '19 at 08:39
  • 1
    SXH_OPTION_SELECT_CLIENT_SSL_CERT = 3 '&H3 – QHarr Sep 13 '19 at 08:45
  • Thank you, @QHarr !! This ultimately gave me the answer; H.setOption(3, 'CURRENT_USER\\MY\\USERNAME') - can you submit it as an answer, so I can accept it? – JasperD Sep 14 '19 at 05:09
  • 1
    hi, sure thing. Added. Please edit as required. I don't think you need the () i.e. .setOption 3, "\value\......." – QHarr Sep 14 '19 at 05:49
  • @JasperD would you please explain this part 'CURRENT_USER\\MY\\USERNAME' a bit more? Is this the actual path of the certificate stored in local? Or this is the path of the cert in the IE registry? Or would you mind sharing how do you find it. Thanks! – Gin Jul 03 '20 at 03:57

1 Answers1

2

You want

.setOption 3, "\value\......."

It is detailed here:

https://learn.microsoft.com/en-us/previous-versions/windows/desktop/ms763811(v%3Dvs.85) under `SXH_OPTION_SELECT_CLIENT_SSL_CERT`

Syntax

oServerXMLHTTPRequest.setOption option, value

As per your code

H.setOption 3, "CURRENT_USER\\MY\\USERNAME"

For the constant

SXH_OPTION_SELECT_CLIENT_SSL_CERT = 3 '&H3
QHarr
  • 83,427
  • 12
  • 54
  • 101
  • would you please explain this part 'CURRENT_USER\\MY\\USERNAME' a bit more? Is this the actual path of the certificate stored in local? Or this is the path of the cert in the IE registry? Or would you mind sharing how do you find it. Thanks! – Gin Jul 03 '20 at 04:28
  • It was used in the question but should be a cert path – QHarr Jul 03 '20 at 09:51