1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_SSL_VERIFYHOST
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_CAINFO (3)
9  - CURLOPT_PINNEDPUBLICKEY (3)
10  - CURLOPT_SSL_VERIFYPEER (3)
11---
12
13# NAME
14
15CURLOPT_SSL_VERIFYHOST - verify the certificate's name against host
16
17# SYNOPSIS
18
19~~~c
20#include <curl/curl.h>
21
22CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSL_VERIFYHOST, long verify);
23~~~
24
25# DESCRIPTION
26
27Pass a long as parameter specifying what to *verify*.
28
29This option determines whether libcurl verifies that the server cert is for
30the server it is known as.
31
32When negotiating TLS and SSL connections, the server sends a certificate
33indicating its identity.
34
35When CURLOPT_SSL_VERIFYHOST(3) is 2, that certificate must indicate that
36the server is the server to which you meant to connect, or the connection
37fails. Simply put, it means it has to have the same name in the certificate as
38is in the URL you operate against.
39
40Curl considers the server the intended one when the Common Name field or a
41Subject Alternate Name field in the certificate matches the hostname in the
42URL to which you told Curl to connect.
43
44If *verify* value is set to 1:
45
46In 7.28.0 and earlier: treated as a debug option of some sorts, not supported
47anymore due to frequently leading to programmer mistakes.
48
49From 7.28.1 to 7.65.3: setting it to 1 made curl_easy_setopt(3) return
50an error and leaving the flag untouched.
51
52From 7.66.0: treats 1 and 2 the same.
53
54When the *verify* value is 0, the connection succeeds regardless of the
55names in the certificate. Use that ability with caution!
56
57The default value for this option is 2.
58
59This option controls checking the server's certificate's claimed identity.
60The server could be lying. To control lying, see CURLOPT_SSL_VERIFYPEER(3).
61
62WARNING: disabling verification of the certificate allows bad guys to
63man-in-the-middle the communication without you knowing it. Disabling
64verification makes the communication insecure. Just having encryption on a
65transfer is not enough as you cannot be sure that you are communicating with
66the correct end-point.
67
68When libcurl uses secure protocols it trusts responses and allows for example
69HSTS and Alt-Svc information to be stored and used subsequently. Disabling
70certificate verification can make libcurl trust and use such information from
71malicious servers.
72
73# LIMITATIONS
74
75Secure Transport: If *verify* value is 0, then SNI is also disabled. SNI is
76a TLS extension that sends the hostname to the server. The server may use that
77information to do such things as sending back a specific certificate for the
78hostname, or forwarding the request to a specific origin server. Some hostnames
79may be inaccessible if SNI is not sent.
80
81# DEFAULT
82
832
84
85# PROTOCOLS
86
87All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
88
89# EXAMPLE
90
91~~~c
92int main(void)
93{
94  CURL *curl = curl_easy_init();
95  if(curl) {
96    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
97
98    /* Set the default value: strict name check please */
99    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
100
101    curl_easy_perform(curl);
102  }
103}
104~~~
105
106# AVAILABILITY
107
108If built TLS enabled.
109
110# RETURN VALUE
111
112Returns CURLE_OK if TLS is supported, and CURLE_UNKNOWN_OPTION if not.
113
114If 1 is set as argument, *CURLE_BAD_FUNCTION_ARGUMENT* is returned.
115