CURLOPT_SSLCERT.md (2376B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_SSLCERT 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_KEYPASSWD (3) 9 - CURLOPT_SSLCERTTYPE (3) 10 - CURLOPT_SSLKEY (3) 11 Protocol: 12 - TLS 13 TLS-backend: 14 - OpenSSL 15 - GnuTLS 16 - mbedTLS 17 - Schannel 18 - wolfSSL 19 Added-in: 7.1 20 --- 21 22 # NAME 23 24 CURLOPT_SSLCERT - SSL client certificate 25 26 # SYNOPSIS 27 28 ~~~c 29 #include <curl/curl.h> 30 31 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSLCERT, char *cert); 32 ~~~ 33 34 # DESCRIPTION 35 36 Pass a pointer to a null-terminated string as parameter. The string should be 37 the filename of your client certificate. The default format is `PEM` but can 38 be changed with CURLOPT_SSLCERTTYPE(3). 39 40 (Schannel) Client certificates can be specified by a path expression to a 41 certificate store. (You can import *PFX* to a store first). You can use 42 "\<store location\>\\\<store name\>\\\<thumbprint\>" to refer to a certificate 43 in the system certificates store, for example, 44 **"CurrentUser\\MY\\934a7ac6f8a5d5"**. The thumbprint is usually a SHA-1 hex 45 string which you can see in certificate details. Following store locations are 46 supported: **CurrentUser**, **LocalMachine**, **CurrentService**, 47 **Services**, **CurrentUserGroupPolicy**, **LocalMachineGroupPolicy**, 48 **LocalMachineEnterprise**. Schannel also support P12 certificate file, with 49 the string `P12` specified with CURLOPT_SSLCERTTYPE(3). 50 51 When using a client certificate, you most likely also need to provide a 52 private key with CURLOPT_SSLKEY(3). 53 54 The application does not have to keep the string around after setting this 55 option. 56 57 Using this option multiple times makes the last set string override the 58 previous ones. Set it to NULL to disable its use again. 59 60 # DEFAULT 61 62 NULL 63 64 # %PROTOCOLS% 65 66 # EXAMPLE 67 68 ~~~c 69 int main(void) 70 { 71 CURL *curl = curl_easy_init(); 72 if(curl) { 73 CURLcode res; 74 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); 75 curl_easy_setopt(curl, CURLOPT_SSLCERT, "client.pem"); 76 curl_easy_setopt(curl, CURLOPT_SSLKEY, "key.pem"); 77 curl_easy_setopt(curl, CURLOPT_KEYPASSWD, "s3cret"); 78 res = curl_easy_perform(curl); 79 curl_easy_cleanup(curl); 80 } 81 } 82 ~~~ 83 84 # %AVAILABILITY% 85 86 # RETURN VALUE 87 88 curl_easy_setopt(3) returns a CURLcode indicating success or error. 89 90 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 91 libcurl-errors(3).