1

I'm having problems with reading a API with a pkcs12 certificate. I can read the certificate with openssl, but I can't figure out how to pass the certificate to the GET command.

library(openssl)
library(httr)

pkcs12_name <- "path_to_certificate.p12"
pkcs12_pwd <- "password"

url <- "theAPIURL"

cert <- read_p12(pkcs12_name,pkcs12_pwd)

This works fine, but the following GET doesn't work:

GET(url1,config(cainfo=cert$ca,sslcert=cert$cert,sslkey=cert$key))

Error in curl::handle_setopt(handle, .list = req$options) : 
  Value for option cainfo (10065) must be a string or raw vector.

cert$ca is a list with two elements. If I just take cert$ca[[1]] or cert$ca[[2]] I get

Error in curl::curl_fetch_memory(url, handle = handle) : 
  Problem with the local SSL certificate

Any suggestions?

Tobias D
  • 345
  • 2
  • 12
  • Is there any diagnostic output to help understand what is going wrong? Have you installed a response callback so that you can read `res$status_code` to see what happened? See the example on page 14 of [the httr manual](https://cran.r-project.org/web/packages/httr/httr.pdf) – lockcmpxchg8b Aug 05 '18 at 01:06
  • Sorry, I could have been much more precise. See above edit. – Tobias D Aug 06 '18 at 06:34
  • Ah. In that light, [This answer](https://stackoverflow.com/questions/37273819/how-to-specify-certificate-key-and-root-certificate-with-httr-for-certificate-b) seems to address the problem. (i.e., the CA/cert/key params take filenames, not literal certificate objects) You might have to play around a bit to see if they can accept .p12 files rather than the other answer's PEM files, but I suspect that if curl successfully uses .p12s, then this API will as well. If this is the solution, then we should mark this question as a duplicate. – lockcmpxchg8b Aug 07 '18 at 07:36

0 Answers0