How to specify certificate, key and root certificate with httr for certificate based authentication?

荒凉一梦 提交于 2019-12-30 10:35:42

问题


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:sriharsha@rpc.com" --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"= "sriharsha@rpc.com"), config(cainfo = cafile, ssl_verifypeer=FALSE), verbose())

Thus I am looking for equivalent options of httr for (--cert, --key and --cacert) of curl.


回答1:


Based on curl docs, option for

  1. ssl certificate is sslcert
  2. ssl key is sslkey
  3. ssl ca is cainfo

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"= "sriharsha@rpc.com"), config(cainfo = cafile, sslcert = certfile, sslkey = keyfile))



来源:https://stackoverflow.com/questions/37273819/how-to-specify-certificate-key-and-root-certificate-with-httr-for-certificate-b

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