113498266Sopenharmony_ciSSL Certificate Verification 213498266Sopenharmony_ci============================ 313498266Sopenharmony_ci 413498266Sopenharmony_ciSSL is TLS 513498266Sopenharmony_ci---------- 613498266Sopenharmony_ci 713498266Sopenharmony_ciSSL is the old name. It is called TLS these days. 813498266Sopenharmony_ci 913498266Sopenharmony_ciNative SSL 1013498266Sopenharmony_ci---------- 1113498266Sopenharmony_ci 1213498266Sopenharmony_ciIf libcurl was built with Schannel or Secure Transport support (the native SSL 1313498266Sopenharmony_cilibraries included in Windows and Mac OS X), then this does not apply to 1413498266Sopenharmony_ciyou. Scroll down for details on how the OS-native engines handle SSL 1513498266Sopenharmony_cicertificates. If you are not sure, then run "curl -V" and read the results. If 1613498266Sopenharmony_cithe version string says `Schannel` in it, then it was built with Schannel 1713498266Sopenharmony_cisupport. 1813498266Sopenharmony_ci 1913498266Sopenharmony_ciIt is about trust 2013498266Sopenharmony_ci----------------- 2113498266Sopenharmony_ci 2213498266Sopenharmony_ciThis system is about trust. In your local CA certificate store you have certs 2313498266Sopenharmony_cifrom *trusted* Certificate Authorities that you then can use to verify that 2413498266Sopenharmony_cithe server certificates you see are valid. They are signed by one of the 2513498266Sopenharmony_cicertificate authorities you trust. 2613498266Sopenharmony_ci 2713498266Sopenharmony_ciWhich certificate authorities do you trust? You can decide to trust the same 2813498266Sopenharmony_ciset of companies your operating system trusts, or the set one of the known 2913498266Sopenharmony_cibrowsers trust. That is basically trust via someone else you trust. You should 3013498266Sopenharmony_cijust be aware that modern operating systems and browsers are setup to trust 3113498266Sopenharmony_ci*hundreds* of companies and in recent years several certificate authorities 3213498266Sopenharmony_cihave been found untrustworthy. 3313498266Sopenharmony_ci 3413498266Sopenharmony_ciCertificate Verification 3513498266Sopenharmony_ci------------------------ 3613498266Sopenharmony_ci 3713498266Sopenharmony_cilibcurl performs peer SSL certificate verification by default. This is done 3813498266Sopenharmony_ciby using a CA certificate store that the SSL library can use to make sure the 3913498266Sopenharmony_cipeer's server certificate is valid. 4013498266Sopenharmony_ci 4113498266Sopenharmony_ciIf you communicate with HTTPS, FTPS or other TLS-using servers using 4213498266Sopenharmony_cicertificates in the CA store, you can be sure that the remote server really is 4313498266Sopenharmony_cithe one it claims to be. 4413498266Sopenharmony_ci 4513498266Sopenharmony_ciIf the remote server uses a self-signed certificate, if you do not install a CA 4613498266Sopenharmony_cicert store, if the server uses a certificate signed by a CA that is not 4713498266Sopenharmony_ciincluded in the store you use or if the remote host is an impostor 4813498266Sopenharmony_ciimpersonating your favorite site, and you want to transfer files from this 4913498266Sopenharmony_ciserver, do one of the following: 5013498266Sopenharmony_ci 5113498266Sopenharmony_ci 1. Tell libcurl to *not* verify the peer. With libcurl you disable this with 5213498266Sopenharmony_ci `curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);` 5313498266Sopenharmony_ci 5413498266Sopenharmony_ci With the curl command line tool, you disable this with `-k`/`--insecure`. 5513498266Sopenharmony_ci 5613498266Sopenharmony_ci 2. Get a CA certificate that can verify the remote server and use the proper 5713498266Sopenharmony_ci option to point out this CA cert for verification when connecting. For 5813498266Sopenharmony_ci libcurl hackers: `curl_easy_setopt(curl, CURLOPT_CAINFO, cacert);` 5913498266Sopenharmony_ci 6013498266Sopenharmony_ci With the curl command line tool: `--cacert [file]` 6113498266Sopenharmony_ci 6213498266Sopenharmony_ci 3. Add the CA cert for your server to the existing default CA certificate 6313498266Sopenharmony_ci store. The default CA certificate store can be changed at compile time with 6413498266Sopenharmony_ci the following configure options: 6513498266Sopenharmony_ci 6613498266Sopenharmony_ci `--with-ca-bundle=FILE`: use the specified file as the CA certificate 6713498266Sopenharmony_ci store. CA certificates need to be concatenated in PEM format into this 6813498266Sopenharmony_ci file. 6913498266Sopenharmony_ci 7013498266Sopenharmony_ci `--with-ca-path=PATH`: use the specified path as CA certificate store. CA 7113498266Sopenharmony_ci certificates need to be stored as individual PEM files in this directory. 7213498266Sopenharmony_ci You may need to run c_rehash after adding files there. 7313498266Sopenharmony_ci 7413498266Sopenharmony_ci If neither of the two options is specified, configure will try to 7513498266Sopenharmony_ci auto-detect a setting. It's also possible to explicitly not set any 7613498266Sopenharmony_ci default store but rely on the built in default the crypto library may 7713498266Sopenharmony_ci provide instead. You can achieve that by passing both 7813498266Sopenharmony_ci `--without-ca-bundle` and `--without-ca-path` to the configure script. 7913498266Sopenharmony_ci 8013498266Sopenharmony_ci If you use Internet Explorer, this is one way to get extract the CA cert 8113498266Sopenharmony_ci for a particular server: 8213498266Sopenharmony_ci 8313498266Sopenharmony_ci - View the certificate by double-clicking the padlock 8413498266Sopenharmony_ci - Find out where the CA certificate is kept (Certificate> 8513498266Sopenharmony_ci Authority Information Access>URL) 8613498266Sopenharmony_ci - Get a copy of the crt file using curl 8713498266Sopenharmony_ci - Convert it from crt to PEM using the OpenSSL tool: 8813498266Sopenharmony_ci `openssl x509 -inform DES -in yourdownloaded.crt -out outcert.pem -text` 8913498266Sopenharmony_ci - Add the `outcert.pem` to the CA certificate store or use it stand-alone 9013498266Sopenharmony_ci as described below. 9113498266Sopenharmony_ci 9213498266Sopenharmony_ci If you use the `openssl` tool, this is one way to get extract the CA cert 9313498266Sopenharmony_ci for a particular server: 9413498266Sopenharmony_ci 9513498266Sopenharmony_ci - `openssl s_client -showcerts -servername server -connect server:443 > cacert.pem` 9613498266Sopenharmony_ci - type "quit", followed by the "ENTER" key 9713498266Sopenharmony_ci - The certificate will have "BEGIN CERTIFICATE" and "END CERTIFICATE" 9813498266Sopenharmony_ci markers. 9913498266Sopenharmony_ci - If you want to see the data in the certificate, you can do: `openssl 10013498266Sopenharmony_ci x509 -inform PEM -in certfile -text -out certdata` where `certfile` is 10113498266Sopenharmony_ci the cert you extracted from logfile. Look in `certdata`. 10213498266Sopenharmony_ci - If you want to trust the certificate, you can add it to your CA 10313498266Sopenharmony_ci certificate store or use it stand-alone as described. Just remember that 10413498266Sopenharmony_ci the security is no better than the way you obtained the certificate. 10513498266Sopenharmony_ci 10613498266Sopenharmony_ci 4. If you are using the curl command line tool and the TLS backend is not 10713498266Sopenharmony_ci Schannel then you can specify your own CA cert file by setting the 10813498266Sopenharmony_ci environment variable `CURL_CA_BUNDLE` to the path of your choice. 10913498266Sopenharmony_ci 11013498266Sopenharmony_ci If you are using the curl command line tool on Windows, curl will search 11113498266Sopenharmony_ci for a CA cert file named "curl-ca-bundle.crt" in these directories and in 11213498266Sopenharmony_ci this order: 11313498266Sopenharmony_ci 1. application's directory 11413498266Sopenharmony_ci 2. current working directory 11513498266Sopenharmony_ci 3. Windows System directory (e.g. C:\windows\system32) 11613498266Sopenharmony_ci 4. Windows Directory (e.g. C:\windows) 11713498266Sopenharmony_ci 5. all directories along %PATH% 11813498266Sopenharmony_ci 11913498266Sopenharmony_ci 5. Get another CA cert bundle. One option is to extract the one a recent 12013498266Sopenharmony_ci Firefox browser uses by running 'make ca-bundle' in the curl build tree 12113498266Sopenharmony_ci root, or possibly download a version that was generated this way for you: 12213498266Sopenharmony_ci [CA Extract](https://curl.se/docs/caextract.html) 12313498266Sopenharmony_ci 12413498266Sopenharmony_ciNeglecting to use one of the above methods when dealing with a server using a 12513498266Sopenharmony_cicertificate that is not signed by one of the certificates in the installed CA 12613498266Sopenharmony_cicertificate store, will cause SSL to report an error ("certificate verify 12713498266Sopenharmony_cifailed") during the handshake and SSL will then refuse further communication 12813498266Sopenharmony_ciwith that server. 12913498266Sopenharmony_ci 13013498266Sopenharmony_ciCertificate Verification with Schannel and Secure Transport 13113498266Sopenharmony_ci----------------------------------------------------------- 13213498266Sopenharmony_ci 13313498266Sopenharmony_ciIf libcurl was built with Schannel (Microsoft's native TLS engine) or Secure 13413498266Sopenharmony_ciTransport (Apple's native TLS engine) support, then libcurl will still perform 13513498266Sopenharmony_cipeer certificate verification, but instead of using a CA cert bundle, it will 13613498266Sopenharmony_ciuse the certificates that are built into the OS. These are the same 13713498266Sopenharmony_cicertificates that appear in the Internet Options control panel (under Windows) 13813498266Sopenharmony_cior Keychain Access application (under OS X). Any custom security rules for 13913498266Sopenharmony_cicertificates will be honored. 14013498266Sopenharmony_ci 14113498266Sopenharmony_ciSchannel will run CRL checks on certificates unless peer verification is 14213498266Sopenharmony_cidisabled. Secure Transport on iOS will run OCSP checks on certificates unless 14313498266Sopenharmony_cipeer verification is disabled. Secure Transport on OS X will run either OCSP 14413498266Sopenharmony_cior CRL checks on certificates if those features are enabled, and this behavior 14513498266Sopenharmony_cican be adjusted in the preferences of Keychain Access. 14613498266Sopenharmony_ci 14713498266Sopenharmony_ciHTTPS proxy 14813498266Sopenharmony_ci----------- 14913498266Sopenharmony_ci 15013498266Sopenharmony_ciSince version 7.52.0, curl can do HTTPS to the proxy separately from the 15113498266Sopenharmony_ciconnection to the server. This TLS connection is handled separately from the 15213498266Sopenharmony_ciserver connection so instead of `--insecure` and `--cacert` to control the 15313498266Sopenharmony_cicertificate verification, you use `--proxy-insecure` and `--proxy-cacert`. 15413498266Sopenharmony_ciWith these options, you make sure that the TLS connection and the trust of the 15513498266Sopenharmony_ciproxy can be kept totally separate from the TLS connection to the server. 156