4

I have an embedded device (running mbedTLS) which can contain only a very limited number of server certificates and I want to verify the PEM file I'm putting on the device with curl. I'm using icanhazip.com (IPv6) to verify. To create the PEM file I use openSSL:

openssl s_client -connect icanhazip.com:443 -showcerts

And stores the certificate part in icanhazip_com.pem and try to verify with curl:

curl --verbose --cacert icanhazip_com.pem https://icanhazip.com

But I get an error:

$ curl --verbose --cacert icanhazip_com.pem https://icanhazip.com
* Rebuilt URL to: https://icanhazip.com/
* timeout on name lookup is not supported
*   Trying 2607:ff68:116:f33d::13...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to icanhazip.com (2607:ff68:116:f33d::13) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: icanhazip_com.pem
  CApath: none
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
} [5 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* TLSv1.2 (IN), TLS handshake, Server hello (2):
{ [108 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [2792 bytes data]
* TLSv1.2 (OUT), TLS alert, Server hello (2):
} [2 bytes data]
* SSL certificate problem: unable to get issuer certificate
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Closing connection 0
} [5 bytes data]
* TLSv1.2 (OUT), TLS alert, Client hello (1):
} [2 bytes data]
curl: (60) SSL certificate problem: unable to get issuer certificate
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.
thomas.fogh
  • 369
  • 1
  • 4
  • 17

1 Answers1

0

Which certificate part did you store? I suspect you didn't put the right certificate in your file icanhazip_com.pem. You must put the CA certificate, the one provided by the issuer (i.e. Let's Encrypt).

From the output of openssl s_client, this is the second one, not the first one :

Certificate chain
0 s:/CN=icanhazip.com
i:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
-----BEGIN CERTIFICATE-----
        ...
(icanhazip.com certificate)
        ...
-----END CERTIFICATE-----
1 s:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
i:/O=Digital Signature Trust Co./CN=DST Root CA X3
-----BEGIN CERTIFICATE-----
        ...
(Let's Encrypt CA certificate)
        ...
-----END CERTIFICATE-----

You may also choose to store all the certificates yielded by the openssl s_client command in one single bundle file (openssl s_client -connect icanhazip.com:443 -showcerts > icanhazip_com.pem) but this is not really desirable if your disk space is limited.

xhienne
  • 5,738
  • 1
  • 15
  • 34
  • I put in both and I get the error above... If I download the certificates manually from the Let's Encrypt website it works fine. – thomas.fogh Jun 27 '18 at 05:30
  • What if you put only the Let's Encrypt certificate, and not both, in icanhazip_com.pem? Maybe your version of curl doesn't support certificate bundles? – xhienne Jun 27 '18 at 15:51
  • I tried with just the second certificate. Still same error. – thomas.fogh Jun 29 '18 at 07:51