CURLOPT_SSLKEYTYPE(3)
π CURLOPT_SSLKEYTYPE(3) π
okay so this is from the Library Functions Manual bestie, and it's literally all about telling curl what format your private key file is in π
β¨ NAME β¨
CURLOPT_SSLKEYTYPE β the type of the private key file, like, what flavor your key is π
π SYNOPSIS π
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSLKEYTYPE, char *type);
π¦ DESCRIPTION π¦
You pass in a pointer to a null-terminated string as the parameter, and that string should be the format of your private key, no cap. The supported formats are "PEM", "DER", "ENG" and "PROV" β¨
The "ENG" format is what lets you load the private key from a crypto engine β very main character energy tbh. When you do that, CURLOPT_SSLKEY(3) gets used as an identifier that's passed to the engine, and you have to set the crypto engine with CURLOPT_SSLENGINE(3) π
The "PROV" format lets you load the private key from a crypto provider (this was added in 8.12.0, iykyk). Same deal here: CURLOPT_SSLKEY(3) is used as an identifier passed to the provider π«Ά
β οΈ Heads up bestie: the "DER" format does not work with OpenSSL. Not me warning you twice, but likeβ¦ it doesn't.
Good news though β your application does not have to keep the string around after setting this option, so you can yeet it as soon as you're done π
And if you use this option multiple times? The last set string overrides the previous ones, periodt. Set it to NULL to restore the internal default π
π DEFAULT π
"PEM" β the standard, the icon, the moment β
π PROTOCOLS π
This functionality affects all TLS based protocols, fr fr: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc. πΈ
This option works only with the following TLS backends: OpenSSL and wolfSSL β that's the vibe check and those two passed π§
πΈ EXAMPLE πΈ
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem");
curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem");
curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, "PEM");
curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret");
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
look at that little certified slay of a program π₯
β AVAILABILITY β
Added in curl 7.9.3 β she's been around for a minute, an absolute veteran π
π RETURN VALUE π
curl_easy_setopt(3) returns a CURLcode that indicates success or error, that's it, that's the whole thing π
CURLE_OK (0) means everything was OK πβ€οΈ, and non-zero means an error occurred β go check libcurl-errors(3) for the deets.
π«Ά SEE ALSO π«Ά
go read those next bestie, they're all connected, it's giving lore π¦
mwah π that's the whole page β brought to you by libcurl, dated 2026-10-12, and yes that date is in the future, don't question it, she's iconic like that π
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms