Reputation: 963
I am trying to access data using httr library from server which expects certificate based authentication. I have certificate (cert.pem), key file (key.pem) and root certificate (caroot.pem)
Following curl works.
curl -H "userName:[email protected]" --cert cert.pem --key certkey.key --cacert caroot.pem https://api.somedomain.com/api/v1/timeseries/klog?limit=1
How can specify certkey.key and caroot.pem to httr GET request. I am trying with following R command but couldn't find option to specify cert key and caroot.
cafile=???? r<-GET("https://api.somedomain.com/api/v1/timeseries/klog", query = list(limit = 1), add_headers("userName"= "[email protected]"), config(cainfo = cafile, ssl_verifypeer=FALSE), verbose())
Thus I am looking for equivalent options of httr for (--cert, --key and --cacert) of curl.
Upvotes: 8
Views: 4443
Reputation: 21
As of April 2023 the get method returns an error:
schannel: Failed to import cert file cert.pem, last error is 0x80092002
This seems to be linked to the issue introduced in curl in 7.55.1 (see https://stackoverflow.com/a/71496170/5956120) In curl 8.0.1 using the certificate works again.
A workaround could be implemented in R:
# request via external tool curl (https://curl.se/windows/)
responseText <- system("<pathToCurl>/curl-8.0.1_6-win64-mingw/bin/curl.exe --cert cert.pem --key certkey.key https://api.somedomain.com/api/v1/timeseries/klog -sS", intern = TRUE)
responseJson <- paste(responseText, collapse = '')
Upvotes: 1
Reputation: 963
Based on curl docs, option for
As per that following command worked
cafile="ca.pem"
certfile="cert.pem"
keyfile="certkey.key"
r<-GET("https://api.somedomain.com/api/v1/timeseries/klog", query = list(limit = 1), add_headers("userName"= "[email protected]"), config(cainfo = cafile, sslcert = certfile, sslkey = keyfile))
Upvotes: 10