SSLCERTS 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. Peer SSL Certificate Verification
  2. =================================
  3. libcurl performs peer SSL certificate verification by default. This is done
  4. by using CA cert bundle that the SSL library can use to make sure the peer's
  5. server certificate is valid.
  6. If you communicate with HTTPS or FTPS servers using certificates that are
  7. signed by CAs present in the bundle, you can be sure that the remote server
  8. really is the one it claims to be.
  9. Until 7.18.0, curl bundled a severely outdated ca bundle file that was
  10. installed by default. These days, the curl archives include no ca certs at
  11. all. You need to get them elsewhere. See below for example.
  12. If the remote server uses a self-signed certificate, if you don't install a CA
  13. cert bundle, if the server uses a certificate signed by a CA that isn't
  14. included in the bundle you use or if the remote host is an impostor
  15. impersonating your favorite site, and you want to transfer files from this
  16. server, do one of the following:
  17. 1. Tell libcurl to *not* verify the peer. With libcurl you disable this with
  18. curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  19. With the curl command line tool, you disable this with -k/--insecure.
  20. 2. Get a CA certificate that can verify the remote server and use the proper
  21. option to point out this CA cert for verification when connecting. For
  22. libcurl hackers: curl_easy_setopt(curl, CURLOPT_CAPATH, capath);
  23. With the curl command line tool: --cacert [file]
  24. 3. Add the CA cert for your server to the existing default CA cert bundle.
  25. The default path of the CA bundle used can be changed by running configure
  26. with the --with-ca-bundle option pointing out the path of your choice.
  27. To do this, you need to get the CA cert for your server in PEM format and
  28. then append that to your CA cert bundle.
  29. If you use Internet Explorer, this is one way to get extract the CA cert
  30. for a particular server:
  31. o View the certificate by double-clicking the padlock
  32. o Find out where the CA certificate is kept (Certificate>
  33. Authority Information Access>URL)
  34. o Get a copy of the crt file using curl
  35. o Convert it from crt to PEM using the openssl tool:
  36. openssl x509 -inform DES -in yourdownloaded.crt \
  37. -out outcert.pem -text
  38. o Append the 'outcert.pem' to the CA cert bundle or use it stand-alone
  39. as described below.
  40. If you use the 'openssl' tool, this is one way to get extract the CA cert
  41. for a particular server:
  42. o openssl s_client -connect xxxxx.com:443 |tee logfile
  43. o type "QUIT", followed by the "ENTER" key
  44. o The certificate will have "BEGIN CERTIFICATE" and "END CERTIFICATE"
  45. markers.
  46. o If you want to see the data in the certificate, you can do: "openssl
  47. x509 -inform PEM -in certfile -text -out certdata" where certfile is
  48. the cert you extracted from logfile. Look in certdata.
  49. o If you want to trust the certificate, you can append it to your
  50. cert_bundle or use it stand-alone as described. Just remember that the
  51. security is no better than the way you obtained the certificate.
  52. 4. If you're using the curl command line tool, you can specify your own CA
  53. cert path by setting the environment variable CURL_CA_BUNDLE to the path
  54. of your choice.
  55. If you're using the curl command line tool on Windows, curl will search
  56. for a CA cert file named "curl-ca-bundle.crt" in these directories and in
  57. this order:
  58. 1. application's directory
  59. 2. current working directory
  60. 3. Windows System directory (e.g. C:\windows\system32)
  61. 4. Windows Directory (e.g. C:\windows)
  62. 5. all directories along %PATH%
  63. 5. Get a better/different/newer CA cert bundle! One option is to extract the
  64. one a recent Firefox browser uses by running 'make ca-bundle' in the curl
  65. build tree root, or possibly download a version that was generated this
  66. way for you:
  67. http://curl.haxx.se/docs/caextract.html
  68. Neglecting to use one of the above methods when dealing with a server using a
  69. certificate that isn't signed by one of the certificates in the installed CA
  70. cert bundle, will cause SSL to report an error ("certificate verify failed")
  71. during the handshake and SSL will then refuse further communication with that
  72. server.
  73. Peer SSL Certificate Verification with NSS
  74. ==========================================
  75. If libcurl is build with NSS support then depending on the OS distribution it
  76. is probably required to take some additional steps to use the system-wide CA
  77. cert db. RedHat ships with an additional module libnsspem.so which enables NSS
  78. to read the OpenSSL PEM CA bundle. With OpenSuSE this lib is missing, and NSS
  79. can only work with its own internal formats. Also NSS got a new database
  80. format:
  81. https://wiki.mozilla.org/NSS_Shared_DB
  82. Starting with version 7.19.7 libcurl will check for the NSS version it runs,
  83. and add automatically the 'sql:' prefix to the certdb directory (either the
  84. hardcoded default /etc/pki/nssdb or the directory configured with SSL_DIR
  85. environment variable) if a version 3.12.0 or later is detected.
  86. To check which certdb format your distribution provides examine the default
  87. certdb location /etc/pki/nssdb; the new certdb format can be identified by
  88. the filenames cert9.db, key4.db, pkcs11.txt; filenames of older versions are
  89. cert8.db, key3.db, modsec.db.
  90. Usually these cert databases are empty; but NSS also has built-in CAs which are
  91. provided through a shared library libnssckbi.so; if you want to use these
  92. built-in CAs then create a symlink to libnssckbi.so in /etc/pki/nssdb:
  93. ln -s /usr/lib[64]/libnssckbi.so /etc/pki/nssdb/libnssckbi.so