Проверьте сертификат сервера, используя open_ssl и curl

У меня есть встроенное устройство (под управлением mbedTLS), которое может содержать только очень ограниченное количество сертификатов сервера, и я хочу проверить файл PEM, который я помещаю на устройство, с помощью curl. Я использую icanhazip.com (IPv6) для проверки. Для создания файла PEM я использую openSSL:

openssl s_client -connect icanhazip.com:443 -showcerts

И сохраняет часть сертификата в icanhazip_com.pem и пытается проверить с помощью curl:

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

Но я получаю сообщение об ошибке:

$ 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.

person thomas.fogh    schedule 20.06.2018    source источник


Ответы (1)


Какую часть сертификата вы сохранили? Я подозреваю, что вы поместили не тот сертификат в свой файл icanhazip_com.pem. Вы должны поставить сертификат CA, предоставленный эмитентом (т.е. Let's Encrypt).

Из вывода openssl s_client это второй, а не первый:

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-----

Вы также можете хранить все сертификаты, полученные с помощью команды openssl s_client, в одном файле пакета (openssl s_client -connect icanhazip.com:443 -showcerts > icanhazip_com.pem), но это не очень желательно, если ваше дисковое пространство ограничено.

person xhienne    schedule 26.06.2018
comment
Я вставляю оба и получаю указанную выше ошибку... Если я загружаю сертификаты вручную с веб-сайта Let's Encrypt, все работает нормально. - person thomas.fogh; 27.06.2018
comment
Что, если вы поместите в icanhazip_com.pem только сертификат Let’s Encrypt, а не оба? Может быть, ваша версия curl не поддерживает пакеты сертификатов? - person xhienne; 27.06.2018
comment
Я пробовал только со вторым сертификатом. Все та же ошибка. - person thomas.fogh; 29.06.2018