curl_easy_ssls_import(3)

πŸ’– curl_easy_ssls_import β€” like, the "import SSL sessions" page πŸ’–

okay bestie, welcome to the libcurl section of the manual (yes, that's the manual name, we're being official now ✨). This is curl_easy_ssls_import(3) and it's honestly kinda iconic: it's the little function that lets you bring an SSL session back home.


✨ NAME ✨

curl_easy_ssls_import β€” import SSL sessions πŸŽ€ like, re-import them, the ones you exported earlier, no cap


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <curl/curl.h>

CURLcode curl_easy_ssls_import(CURL *handle,
                               const char *session_key,
                               const unsigned char *shmac, size_t shmac_len,
                               const unsigned char *sdata, size_t sdata_len);

🌸 DESCRIPTION 🌸

So here's the vibe 🫢: this function imports a previously exported SSL session ticket. That's it, that's the whole personality.

The tea β˜•: sdata and sdata_len must always be provided. Non-negotiable, periodt. But if session_key is NULL, then shmac and shmac_len must be given exactly as they were received during the export. Curious about what those even are? Go peek at curl_easy_ssls_export(3) β€” it describes them properly, iykyk.

⚠️ Lowkey important: importing session tickets from other curl versions may fail, because the handling of shmac or sdata can change between versions. Not a bug, just how it is 😭.

And if a session ticket has already expired? It gets silently discarded. No error, no drama, it just ✨ evaporates ✨. Very main character energy honestly.


πŸ’… PROTOCOLS πŸ’…

This functionality affects all TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc. The whole squad 🌈.

This option works only with the following TLS backends: GnuTLS, OpenSSL, mbedTLS and wolfSSL. Those four, no substitutes 😌.


πŸŽ€ EXAMPLE πŸŽ€

Here's the whole thing in action, copy-paste ready, bestie:

int main(void)
{
  CURLSHcode sh;
  CURLSH *share = curl_share_init();
  CURLcode result;
  CURL *curl;

  sh = curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
  if(sh)
    printf("Error: %s\n", curl_share_strerror(sh));

  curl = curl_easy_init();
  if(curl) {
    extern unsigned char *shmac, *sdata;
    size_t hlen = 4, slen = 5;

    curl_easy_setopt(curl, CURLOPT_SHARE, share);

    /* read shmac and sdata from storage */
    result = curl_easy_ssls_import(curl, NULL, shmac, hlen, sdata, slen);

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  curl_share_cleanup(share);
}

Notice the /* read shmac and sdata from storage */ comment β€” that's you, that's your job, curl isn't gonna fetch those for you πŸ’€.


⭐ AVAILABILITY ⭐

Added in curl 8.12.0 β€” so if you're on something ancient, this is your sign to upgrade 🧚


πŸ”₯ RETURN VALUE πŸ”₯

This function returns a CURLcode indicating success or error.

  • CURLE_OK (0) means everything was, like, totally fine πŸ’–
  • non-zero means an error occurred β€” go check libcurl-errors(3) for the full lore

And here's a handy tip πŸ‘‘: if CURLOPT_ERRORBUFFER(3) was set with curl_easy_setopt(3), there can be an error message stored in the error buffer when non-zero is returned. So you might get actual words explaining the problem, which is honestly so thoughtful of it.


🌈 SEE ALSO 🌈


πŸ’€ real talk: keep your sdata and sdata_len around, keep your shmac matching the export if session_key is NULL, and don't expect expired tickets to do anything but ghost you.

okay that's the whole page, bestie, you ate that πŸ“πŸ’œ β€” this was libcurl, dated 2026-10-12, and the page you just read is curl_easy_ssls_import(3). mwah πŸ’‹

πŸ“¦ where this page comes from