GNURLOPT_SSL_VERIFYPEER(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

πŸ’… GNURLOPT_SSL_VERIFYPEER(3) πŸ’…

okay so real talk, this is a page out of the curl_easy_setopt options manual (gnurl flavor, bestie, GNURLOPT_SSL_VERIFYPEER(3)), and it's literally about one of the most important things you will ever set: do we actually check that the server's SSL certificate is real?


✨ NAME ✨

CURLOPT_SSL_VERIFYPEER β€” verify the peer's SSL certificate πŸŽ€


🌸 SYNOPSIS 🌸

#include <gnurl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSL_VERIFYPEER, long
verify);

πŸ¦‹ DESCRIPTION πŸ¦‹

You pass in a long and it's basically a yes/no switch, no cap.

This option is the whole vibe check for whether curl verifies the authenticity of the peer's certificate. A value of 1 means curl verifies; 0 (zero) means it doesn't. That's it, that's the toggle.

So picture this: when you're negotiating a TLS or SSL connection, the server sends over a certificate that says "hey, this is who I am." Curl then verifies whether that certificate is authentic β€” like, can you actually trust that the server is who the certificate claims to be? And the way that trust works is a chain of digital signatures, rooted in certification authority (CA) certificates you supply. curl ships with a default bundle of CA certificates (the path for that is determined at build time), and you can also specify alternate certificates with the CURLOPT_CAINFO(3) option or the CURLOPT_CAPATH(3) option. Options upon options, we love to see it πŸ’…

When CURLOPT_SSL_VERIFYPEER(3) is enabled and the verification fails to prove that the certificate is authentic, the connection fails. Brutal but fair. When the option is zero, the peer certificate verification succeeds regardless β€” like, it just doesn't care anymore, it's giving "no thoughts head empty" 😭

But here's the thing, and this is important: authenticating the certificate is not enough to be sure about the server. You typically also want to make sure the server is the actual server you meant to be talking to. Use CURLOPT_SSL_VERIFYHOST(3) for that. The check that the host name in the certificate is valid for the host name you're connecting to is done independently of the CURLOPT_SSL_VERIFYPEER(3) option. Two separate checks, two separate options, both iconic.

WARNING: disabling verification of the certificate allows bad guys to man-in-the-middle the communication without you knowing it. Disabling verification makes the communication insecure. Just having encryption on a transfer is not enough as you cannot be sure that you are communicating with the correct end-point. 🚨 Like genuinely, do not do this casually. This is the "leaving your front door open because the lock was annoying" of networking.
NOTE: even when this option is disabled, depending on the used TLS backend, curl may still load the certificate file specified in CURLOPT_CAINFO(3). curl default settings in some distributions might use quite a large file as a default setting for CURLOPT_CAINFO(3), so loading the file can be quite expensive, especially when dealing with many connections. Thus, in some situations, you might want to disable verification fully to save resources by setting CURLOPT_CAINFO(3) to NULL β€” but please also consider the warning above! πŸ™ˆ

πŸ’– DEFAULT πŸ’–

By default, curl assumes a value of 1. (Yes bestie, verification is ON out of the box, as it should be πŸ‘‘)


🌈 PROTOCOLS 🌈

All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.


⭐ EXAMPLE ⭐

CURL *curl = curl_easy_init();
if(curl) {
  curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");

  /* Set the default value: strict certificate check please */
  curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);

  curl_easy_perform(curl);
}

Look at that, setting it to 1L explicitly. Strict certificate check please, and honestly? Respect 🫢


🧚 AVAILABILITY 🧚

If built TLS enabled.


πŸ”₯ RETURN VALUE πŸ”₯

Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not. Simple as that πŸ’œ


πŸ“ SEE ALSO πŸ“


okay that's the whole page, go verify some certificates and stay safe out there πŸ’…βœ¨

libcurl 7.37.0 Β· 17 Jun 2014 Β· GNURLOPT_SSL_VERIFYPEER(3) β€” mwah, love u, bye πŸŽ€πŸ’–

πŸ“¦ where this page comes from