xref: /aosp_15_r20/external/curl/docs/SSLCERTS.md (revision 6236dae45794135f37c4eb022389c904c8b0090d)
1*6236dae4SAndroid Build Coastguard Worker<!--
2*6236dae4SAndroid Build Coastguard WorkerCopyright (C) Daniel Stenberg, <[email protected]>, et al.
3*6236dae4SAndroid Build Coastguard Worker
4*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl
5*6236dae4SAndroid Build Coastguard Worker-->
6*6236dae4SAndroid Build Coastguard Worker
7*6236dae4SAndroid Build Coastguard Worker# TLS Certificate Verification
8*6236dae4SAndroid Build Coastguard Worker
9*6236dae4SAndroid Build Coastguard Worker## Native vs file based
10*6236dae4SAndroid Build Coastguard Worker
11*6236dae4SAndroid Build Coastguard WorkerIf curl was built with Schannel or Secure Transport support, then curl uses
12*6236dae4SAndroid Build Coastguard Workerthe system native CA store for verification. All other TLS libraries use a
13*6236dae4SAndroid Build Coastguard Workerfile based CA store by default.
14*6236dae4SAndroid Build Coastguard Worker
15*6236dae4SAndroid Build Coastguard Worker## Verification
16*6236dae4SAndroid Build Coastguard Worker
17*6236dae4SAndroid Build Coastguard WorkerEvery trusted server certificate is digitally signed by a Certificate
18*6236dae4SAndroid Build Coastguard WorkerAuthority, a CA.
19*6236dae4SAndroid Build Coastguard Worker
20*6236dae4SAndroid Build Coastguard WorkerIn your local CA store you have a collection of certificates from *trusted*
21*6236dae4SAndroid Build Coastguard Workercertificate authorities that TLS clients like curl use to verify servers.
22*6236dae4SAndroid Build Coastguard Worker
23*6236dae4SAndroid Build Coastguard Workercurl does certificate verification by default. This is done by verifying the
24*6236dae4SAndroid Build Coastguard Workersignature and making sure the certificate was crafted for the server name
25*6236dae4SAndroid Build Coastguard Workerprovided in the URL.
26*6236dae4SAndroid Build Coastguard Worker
27*6236dae4SAndroid Build Coastguard WorkerIf you communicate with HTTPS, FTPS or other TLS-using servers using
28*6236dae4SAndroid Build Coastguard Workercertificates signed by a CA whose certificate is present in the store, you can
29*6236dae4SAndroid Build Coastguard Workerbe sure that the remote server really is the one it claims to be.
30*6236dae4SAndroid Build Coastguard Worker
31*6236dae4SAndroid Build Coastguard WorkerIf the remote server uses a self-signed certificate, if you do not install a
32*6236dae4SAndroid Build Coastguard WorkerCA cert store, if the server uses a certificate signed by a CA that is not
33*6236dae4SAndroid Build Coastguard Workerincluded in the store you use or if the remote host is an impostor
34*6236dae4SAndroid Build Coastguard Workerimpersonating your favorite site, the certificate check fails and reports an
35*6236dae4SAndroid Build Coastguard Workererror.
36*6236dae4SAndroid Build Coastguard Worker
37*6236dae4SAndroid Build Coastguard WorkerIf you think it wrongly failed the verification, consider one of the following
38*6236dae4SAndroid Build Coastguard Workersections.
39*6236dae4SAndroid Build Coastguard Worker
40*6236dae4SAndroid Build Coastguard Worker### Skip verification
41*6236dae4SAndroid Build Coastguard Worker
42*6236dae4SAndroid Build Coastguard WorkerTell curl to *not* verify the peer with `-k`/`--insecure`.
43*6236dae4SAndroid Build Coastguard Worker
44*6236dae4SAndroid Build Coastguard WorkerWe **strongly** recommend this is avoided and that even if you end up doing
45*6236dae4SAndroid Build Coastguard Workerthis for experimentation or development, **never** skip verification in
46*6236dae4SAndroid Build Coastguard Workerproduction.
47*6236dae4SAndroid Build Coastguard Worker
48*6236dae4SAndroid Build Coastguard Worker### Use a custom CA store
49*6236dae4SAndroid Build Coastguard Worker
50*6236dae4SAndroid Build Coastguard WorkerGet a CA certificate that can verify the remote server and use the proper
51*6236dae4SAndroid Build Coastguard Workeroption to point out this CA cert for verification when connecting - for this
52*6236dae4SAndroid Build Coastguard Workerspecific transfer only.
53*6236dae4SAndroid Build Coastguard Worker
54*6236dae4SAndroid Build Coastguard WorkerWith the curl command line tool: `--cacert [file]`
55*6236dae4SAndroid Build Coastguard Worker
56*6236dae4SAndroid Build Coastguard WorkerIf you use the curl command line tool without a native CA store, then you can
57*6236dae4SAndroid Build Coastguard Workerspecify your own CA cert file by setting the environment variable
58*6236dae4SAndroid Build Coastguard Worker`CURL_CA_BUNDLE` to the path of your choice.
59*6236dae4SAndroid Build Coastguard Worker
60*6236dae4SAndroid Build Coastguard WorkerIf you are using the curl command line tool on Windows, curl searches for a CA
61*6236dae4SAndroid Build Coastguard Workercert file named `curl-ca-bundle.crt` in these directories and in this order:
62*6236dae4SAndroid Build Coastguard Worker  1. application's directory
63*6236dae4SAndroid Build Coastguard Worker  2. current working directory
64*6236dae4SAndroid Build Coastguard Worker  3. Windows System directory (e.g. C:\Windows\System32)
65*6236dae4SAndroid Build Coastguard Worker  4. Windows Directory (e.g. C:\Windows)
66*6236dae4SAndroid Build Coastguard Worker  5. all directories along %PATH%
67*6236dae4SAndroid Build Coastguard Worker
68*6236dae4SAndroid Build Coastguard Workercurl 8.11.0 added a build-time option to disable this search behavior, and
69*6236dae4SAndroid Build Coastguard Workeranother option to restrict search to the application's directory.
70*6236dae4SAndroid Build Coastguard Worker
71*6236dae4SAndroid Build Coastguard Worker### Use the native store
72*6236dae4SAndroid Build Coastguard Worker
73*6236dae4SAndroid Build Coastguard WorkerIn several environments, in particular on Windows, you can ask curl to use the
74*6236dae4SAndroid Build Coastguard Workersystem's native CA store when verifying the certificate.
75*6236dae4SAndroid Build Coastguard Worker
76*6236dae4SAndroid Build Coastguard WorkerWith the curl command line tool: `--ca-native`.
77*6236dae4SAndroid Build Coastguard Worker
78*6236dae4SAndroid Build Coastguard Worker### Modify the CA store
79*6236dae4SAndroid Build Coastguard Worker
80*6236dae4SAndroid Build Coastguard WorkerAdd the CA cert for your server to the existing default CA certificate store.
81*6236dae4SAndroid Build Coastguard Worker
82*6236dae4SAndroid Build Coastguard WorkerUsually you can figure out the path to the local CA store by looking at the
83*6236dae4SAndroid Build Coastguard Workerverbose output that `curl -v` shows when you connect to an HTTPS site.
84*6236dae4SAndroid Build Coastguard Worker
85*6236dae4SAndroid Build Coastguard Worker### Change curl's default CA store
86*6236dae4SAndroid Build Coastguard Worker
87*6236dae4SAndroid Build Coastguard WorkerThe default CA certificate store curl uses is set at build time. When you
88*6236dae4SAndroid Build Coastguard Workerbuild curl you can point out your preferred path.
89*6236dae4SAndroid Build Coastguard Worker
90*6236dae4SAndroid Build Coastguard Worker### Extract CA cert from a server
91*6236dae4SAndroid Build Coastguard Worker
92*6236dae4SAndroid Build Coastguard Worker    curl -w %{certs} https://example.com > cacert.pem
93*6236dae4SAndroid Build Coastguard Worker
94*6236dae4SAndroid Build Coastguard WorkerThe certificate has `BEGIN CERTIFICATE` and `END CERTIFICATE` markers.
95*6236dae4SAndroid Build Coastguard Worker
96*6236dae4SAndroid Build Coastguard Worker### Get the Mozilla CA store
97*6236dae4SAndroid Build Coastguard Worker
98*6236dae4SAndroid Build Coastguard WorkerDownload a version of the Firefox CA store converted to PEM format on the [CA
99*6236dae4SAndroid Build Coastguard WorkerExtract](https://curl.se/docs/caextract.html) page. It always features the
100*6236dae4SAndroid Build Coastguard Workerlatest Firefox bundle.
101*6236dae4SAndroid Build Coastguard Worker
102*6236dae4SAndroid Build Coastguard Worker## Native CA store
103*6236dae4SAndroid Build Coastguard Worker
104*6236dae4SAndroid Build Coastguard WorkerIf curl was built with Schannel, Secure Transport or were instructed to use
105*6236dae4SAndroid Build Coastguard Workerthe native CA Store, then curl uses the certificates that are built into the
106*6236dae4SAndroid Build Coastguard WorkerOS. These are the same certificates that appear in the Internet Options
107*6236dae4SAndroid Build Coastguard Workercontrol panel (under Windows) or Keychain Access application (under macOS).
108*6236dae4SAndroid Build Coastguard WorkerAny custom security rules for certificates are honored.
109*6236dae4SAndroid Build Coastguard Worker
110*6236dae4SAndroid Build Coastguard WorkerSchannel runs CRL checks on certificates unless peer verification is disabled.
111*6236dae4SAndroid Build Coastguard WorkerSecure Transport on iOS runs OCSP checks on certificates unless peer
112*6236dae4SAndroid Build Coastguard Workerverification is disabled. Secure Transport on macOS runs either OCSP or CRL
113*6236dae4SAndroid Build Coastguard Workerchecks on certificates if those features are enabled, and this behavior can be
114*6236dae4SAndroid Build Coastguard Workeradjusted in the preferences of Keychain Access.
115*6236dae4SAndroid Build Coastguard Worker
116*6236dae4SAndroid Build Coastguard Worker## HTTPS proxy
117*6236dae4SAndroid Build Coastguard Worker
118*6236dae4SAndroid Build Coastguard Workercurl can do HTTPS to the proxy separately from the connection to the server.
119*6236dae4SAndroid Build Coastguard WorkerThis TLS connection is handled and verified separately from the server
120*6236dae4SAndroid Build Coastguard Workerconnection so instead of `--insecure` and `--cacert` to control the
121*6236dae4SAndroid Build Coastguard Workercertificate verification, you use `--proxy-insecure` and `--proxy-cacert`.
122*6236dae4SAndroid Build Coastguard WorkerWith these options, you make sure that the TLS connection and the trust of the
123*6236dae4SAndroid Build Coastguard Workerproxy can be kept totally separate from the TLS connection to the server.
124