GNURLOPT_SSLKEY_BLOB(3)

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

πŸ’œ GNURLOPT_SSLKEY_BLOB β€” the manual page, but make it make sense

okay so this is a page from the gnurl manual (the curl_easy_setopt options corner of it, to be exact) and bestie, it's all about handing libcurl your private key straight from memory instead of making it go dig around in your filesystem. obsessed. let's get into it 🫢


✨ NAME ✨

CURLOPT_SSLKEY_BLOB β€” literally just: the private key for your client cert, but coming at you from a memory blob πŸ’…


🌸 SYNOPSIS 🌸

#include <gnurl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSLKEY_BLOB,
                          struct curl_blob *blob);

πŸ¦‹ DESCRIPTION πŸ¦‹

So you pass in a pointer to a curl_blob structure, and that struct is carrying the info for a private key β€” as in, a pointer and a size, the whole package πŸ’–. This one is compatible with OpenSSL. And the format (like "PEM") has to be specified with CURLOPT_SSLKEYTYPE(3) β€” no guessing games, you have to tell it.

Here's the cute part: if the blob is initialized with the flags member of struct curl_blob set to CURL_BLOB_COPY, then the application does not have to keep the buffer around after setting this. it made its own copy, you're free πŸ•ŠοΈ

This option is an alternative to CURLOPT_SSLKEY(3), which instead expects a file name as input. same energy, different delivery method fr fr.


πŸŽ€ DEFAULT πŸŽ€

NULL

(nothing's set until you set it, iconic behavior)


🌈 PROTOCOLS 🌈

All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc. β€” the whole secure squad πŸ‘‘


⭐ EXAMPLE ⭐

CURL *curl = curl_easy_init();
if(curl) {
  struct curl_blob blob;
  curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
  blob.data = certificateData;
  blob.len = filesize;
  blob.flags = CURL_BLOB_COPY;
  curl_easy_setopt(curl, CURLOPT_SSLCERT_BLOB, &blob);
  curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, "PEM");

  blob.data = privateKeyData;
  blob.len = privateKeySize;
  curl_easy_setopt(curl, CURLOPT_SSLKEY_BLOB, &blob);
  curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
  curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, "PEM");
  ret = curl_easy_perform(curl);
  curl_easy_cleanup(curl);
}

like, look at it. cert blob, key blob, password "s3cret", type "PEM", done. main character energy honestly πŸ”₯


🧚 AVAILABILITY 🧚

Added in libcurl 7.71.0. This option is supported by the OpenSSL backends.


πŸ’€ RETURN VALUE πŸ’€

  • Returns CURLE_OK if TLS enabled
  • CURLE_UNKNOWN_OPTION if not
  • or CURLE_OUT_OF_MEMORY if there was insufficient heap space 😭 (heap said no πŸ’”)

πŸ”₯ SEE ALSO πŸ”₯


ngl bestie, read those two too β€” they're the supporting cast and they ate πŸ’…

okay that's the whole page!! no cap, you got this πŸ“

β€” with love, from libcurl 7.71.0, dated 24 Jun 2020 (yes that's the version and the date, i would never gatekeep a citation from you) πŸŽ€βœ¨

πŸ“¦ where this page comes from