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