2015-03-08 8 views
7

Sto cercando di eseguire il seguente comando CURL ma sto ottenendo un errore di certificato SSL:comando Curl per HTTPS (SSL)

curl https://example.com:8443/cli/agentCLI -u username:password 

Errore:

curl: (60) SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 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). The default bundle is named curl-ca-bundle.crt; 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.

Come dovrei risolvere questo problema per consentire URL SSL?

+0

Vedi anche (https://stackoverflow.com/q/27611193/608639) – jww

risposta

9

se si sta utilizzando un certificato auto firmato sul server, è possibile utilizzare:

curl -k https://example.com:8443/cli/agentCLI -u username:password 

ma sappiate che allora è meglio che usare connessione non SSL al server, come la vostra comunicazione ha vinto' essere più sicuro, abilitando tutti i tipi di attacchi uomo nel mezzo.

Anche se il mio consiglio per voi è quello di scaricare il .pem dal server:

utilizzando:

echo "HEAD/HTTP/1.0\n Host: example.com\n\n EOT\n" | openssl s_client -prexit -connect example.com:8443 > cert.pem 

a voi r computer, mantenere solo la parte compresa tra BEGIN CERTIFICATE e END CERTIFICATE all'interno del file (comprese le linee BEGIN/END) e assegnarla come parametro all'opzione --cacert, è anche possibile scaricarla. Quindi potrai autenticare il tuo server ogni volta che ti connetti!

curl --cacert cert.pem https://example.com:8443/cli/agentCLI -u username:password 

test sul mio server auto-firmato, sta funzionando benissimo:

% openssl s_client -showcerts -connect example.com:443 </dev/null 2>/dev/null | sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' | grep -m1 -B-1 -- '-----END CERTIFICATE-----' > cert.pem 
% curl --cacert cert.pem https://example.com 

per un esempio che dovrebbe funzionare:

% openssl s_client -showcerts -connect git.cryptolib.org:443 </dev/null 2>/dev/null | sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' | grep -m1 -B-1 -- '-----END CERTIFICATE-----' > cert.pem 
% curl --cacert cert.pem https://git.cryptolib.org 
curl: (51) SSL: certificate verification failed (result: 5) 

ma purtroppo non è.

Ho anche cercato di fare, come suggerito here:

% openssl x509 -inform PEM -in cert.pem -text -out certdata.pem 
% curl --cacert certdata.pem https://git.cryptolib.org 

che non sta funzionando, perché quel sito (git.cryptolib.org) che sto utilizzando per il test non è auto-firmato, ma è dalla catena CACert, che può essere risolta utilizzando i certificati radice CACert, seguendo questo FAQ.


alcune risorse a scavare:

Ma nessuna risposta definitiva finora: [? Usa certificato auto firmato con l'arricciatura] -s

+0

Grazie Zmo..i hanno scaricato .pem eseguendo il comando echo "HEAD/HTTP/1.0 \ n Host: example.com \ n \ n EOT \ n" | openssl s_client -prexit -connect example.com:8443> cert.pem. Ma sto facendo lo stesso errore quando im eseguo il secondo comando che hai dato qui – Kalaiyarasan

+0

Ciao zmo..dopo aver scaricato cret.pem, ho eseguito curl -k https://example.com:8443/cli/agentCLI -u utente: pass. Ora sto ottenendo output..Grazie .. Ma ho ottenuto output illeggibile ... Puoi dirmi che riceverò output come row .. – Kalaiyarasan

+0

'curl -k' è la mia prima risposta e ti sta dando una connessione https insicura al server. Lo sta facendo funzionare, ma non lo rende autenticato. – zmo