Magazine Informatica

curl: (60) SSL certificate problem

Creato il 05 agosto 2014 da Morganfw

A volte nell’utilizzo di cURL su siti https può capitare che venga restituito un messaggio simile al seguente

curl: (60) SSL certificate problem: self signed certificate in certificate chain
More details here: http://curl.haxx.se/docs/sslcerts.html
[...]

il problema si potrebbe aggirare aggiungendo l’opzione “-k” subito dopo il comando (come riportato nel messaggio), ma questo fa sì che non venga effettuata la verifica della CA (Certification Authority), quindi, non sarebbe il massimo connettersi a un sito “sicuro” non verificato, a questo punto vediamo un po’ di capire come eliminare il problema su Debian e derivate.
Innanzitutto verifichiamo dove si presenta il problema col comando “curl -v” (nell’esempio seguente effettuato su google.com)

curl -v https://www.google.com
* Rebuilt URL to: https://www.google.com/
* Hostname was NOT found in DNS cache
*   Trying 173.194.116.146...
* Connected to www.google.com (173.194.116.146) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS alert, Server hello (2):
* SSL certificate problem: self signed certificate in certificate chain
* Closing connection 0
curl: (60) SSL certificate problem: self signed certificate in certificate chain
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.

a quanto pare sembra che le CA non siano correttamente installate sulla nostra macchina, quindi verifichiamo ulteriormente.
Eseguiamo il seguente comando

sudo dpkg --list | grep "ca-certificates"

se viene restituita la seguente stringa con “ii” all’inizio, vuol dire che il package dei Certificati CA è correttamente installato

ii ca-certificates 20140325 all Common CA certificates

in caso contrario, provvediamo all’installazione

sudo apt-get install ca-certificates

oppure alla reinstallazione (perchè potrebbe essere non propriamente installato o altro)

sudo apt-get remove ca-certificates --purge & sudo apt-get install ca-certificates

una volta installato/reinstallato il package, verifichiamo nuovamente sempre utilizzando il comando “curl -v

curl -v https://www.google.com
* Rebuilt URL to: https://www.google.com/
* Hostname was NOT found in DNS cache
*   Trying 173.194.113.82...
* Connected to www.google.com (173.194.113.82) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
* 	 subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=www.google.com
* 	 start date: 2014-07-16 12:14:11 GMT
* 	 expire date: 2014-10-14 00:00:00 GMT
* 	 subjectAltName: www.google.com matched
* 	 issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
* 	 SSL certificate verify ok.
> GET / HTTP/1.1
> User-Agent: curl/7.37.1
> Host: www.google.com
> Accept: */*
>
< HTTP/1.1 302 Found
< Cache-Control: private
< Content-Type: text/html; charset=UTF-8
< Location: https://www.google.it/?gfe_rd=cr&ei=iInfU6_EGeKI8QfHvoGoBw
< Content-Length: 259
< Date: Mon, 04 Aug 2014 13:24:24 GMT
* Server GFE/2.0 is not blacklisted
< Server: GFE/2.0
< Alternate-Protocol: 443:quic
<
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="https://www.google.it/?gfe_rd=cr&amp;ei=iInfU6_EGeKI8QfHvoGoBw">here</A>.
</BODY></HTML>
* Connection #0 to host www.google.com left intact

se viene restituito un messaggio simile a quello sopra elencato, abbiamo brillantemente risolto (nella maggior parte dei casi si risolve semplicemente effettuando i passi sopra elencati, ovvero installando o reinstallando il package “ca-certificates” che contiene tutte le CA internazionali “Trusted”), in caso contrario bisogna verificare approfonditamente, quindi armiamoci di pazienza e procediamo.

Prendiamo come esempio la CA di google.com, quindi apriamo un browser (nel mio caso Google Chrome in lingua Inglese) e digitiamo “https://www.google.com/“, quindi facciamo click sul lucchetto a sx dell’URL, facciamo click su “Connection” e successivamete su “Certificate Information” si aprirà una finestrella in cui la seconda voce dall’alto sarà la CA utilizzata, che, nel caso di google.com è “GeoTrust Global CA“.

Una volta verificata la CA tramite browser, procediamo sulla nostra macchina, quindi recuperiamo la directory di installazione di OpenSSL

openssl version -d
OPENSSLDIR: "/usr/lib/ssl"

quindi entriamo nella directory indicata e verifichiamo cosa c’è al suo interno

cd /usr/lib/ssl
ls -la

troveremo una cartella chiamata “certs“, quindi entriamo in quest’ultima e verifichiamo dove sono salvati i certificati

cd certs
ls -la
[...]
lrwxrwxrwx 1 root root     86 Aug  4 14:49 VeriSign_Universal_Root_Certification_Authority.pem -> /usr/share/ca-certificates/mozilla/VeriSign_Universal_Root_Certification_Authority.crt
lrwxrwxrwx 1 root root     58 Aug  4 14:49 Visa_eCommerce_Root.pem -> /usr/share/ca-certificates/mozilla/Visa_eCommerce_Root.crt
lrwxrwxrwx 1 root root     84 Aug  4 14:49 WellsSecure_Public_Root_Certificate_Authority.pem -> /usr/share/ca-certificates/mozilla/WellsSecure_Public_Root_Certificate_Authority.crt
lrwxrwxrwx 1 root root     59 Aug  4 14:49 XRamp_Global_CA_Root.pem -> /usr/share/ca-certificates/mozilla/XRamp_Global_CA_Root.crt
[...]

da quel che si nota, sono presenti dei “symlink” e la maggior parte dei certificati è salvata all’interno della directory “/usr/share/ca-certificates/mozilla
quindi accediamo alla directory e verifichiamo che il nostro certificato sia presente

cd /usr/share/ca-certificates/mozilla
ls -la GeoTrust_Global_CA.crt
-rw-r--r-- 1 root root 1216 Mar 26 14:17 GeoTrust_Global_CA.crt

da quel che possiamo vedere, il certificato risulta presente, quindi non avremmo nessun problema con l’utilizzo di cURL su questo sito, mentre se non risulta presente, basterà importarlo

cd /usr/share/ca-certificates/mozilla
wget -O GeoTrust_Global_CA.crt https://www.geotrust.com/resources/root_certificates/certificates/GeoTrust_Global_CA.cer

successivamente bisognerà configurare il file “ca-certificates.conf

sudo vi /etc/ca-certificates.conf

inserendo il path al certificato appena scaricato (io l’ho inserito alla terza riga)

# This file lists certificates that you wish to use or to ignore to be
# installed in /etc/ssl/certs.
# update-ca-certificates(8) will update /etc/ssl/certs by reading this file.
#
# This is autogenerated by dpkg-reconfigure ca-certificates.
# Certificates should be installed under /usr/share/ca-certificates
# and files with extension '.crt' is recognized as available certs.
#
# line begins with # is comment.
# line begins with ! is certificate filename to be deselected.
#
mozilla/ACCVRAIZ1.crt
mozilla/ACEDICOM_Root.crt
mozilla/GeoTrust_Global_CA.crt
[...]

salvare ed uscire ed effettuare il reload dei certificati

sudo update-ca-certificates --fresh

una volta che il reload è andato a buon fine, non dovremmo più avere problemi di connessione tramite cURL.

La procedura sopra riportata è valida anche per l’importazione di eventuali Certificati CA “self-signed” che ovviamente non potranno mai essere presenti all’interno delle CA riconosciute.

curl


Potrebbero interessarti anche :

Ritornare alla prima pagina di Logo Paperblog

Possono interessarti anche questi articoli :