1CURLOPT_PINNEDPUBLICKEY(3) curl_easy_setopt options CURLOPT_PINNEDPUBLICKEY(3)
2
3
4

NAME

6       CURLOPT_PINNEDPUBLICKEY - pinned public key
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PINNEDPUBLICKEY,
12                                 char *pinnedpubkey);
13

DESCRIPTION

15       Pass a pointer to a null-terminated string as parameter. The string can
16       be the file name of your pinned public key. The file format expected is
17       "PEM"  or  "DER".   The string can also be any number of base64 encoded
18       sha256 hashes preceded by "sha256//" and separated by ";"
19
20       When negotiating a TLS or SSL connection, the server sends  a  certifi‐
21       cate  indicating its identity. A public key is extracted from this cer‐
22       tificate and if it does not exactly match the public  key  provided  to
23       this option, curl will abort the connection before sending or receiving
24       any data.
25
26       On mismatch, CURLE_SSL_PINNEDPUBKEYNOTMATCH is returned.
27
28       The application does not have to keep the string around  after  setting
29       this option.
30

DEFAULT

32       NULL
33

PROTOCOLS

35       All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
36

EXAMPLE

38       CURL *curl = curl_easy_init();
39       if(curl) {
40         curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
41         curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, "/etc/publickey.der");
42         /* OR
43         curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, "sha256//YhKJKSzoTt2b5FP18fvpHo7fJYqQCjAa3HWY3tvRMwE=;sha256//t62CeU2tQiqkexU74Gxa2eg7fRbEgoChTociMee9wno=");
44         */
45
46         /* Perform the request */
47         curl_easy_perform(curl);
48       }
49

PUBLIC KEY EXTRACTION

51       If you do not have the server's public key file you can extract it from
52       the server's certificate.
53       # retrieve the server's certificate if you do not already have it
54       #
55       # be sure to examine the certificate to see if it is what you expected
56       #
57       # Windows-specific:
58       # - Use NUL instead of /dev/null.
59       # - OpenSSL may wait for input instead of disconnecting. Hit enter.
60       # - If you do not have sed, then just copy the certificate into a file:
61       #   Lines from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE-----.
62       #
63       openssl s_client -servername www.example.com -connect www.example.com:443 < /dev/null | sed -n "/-----BEGIN/,/-----END/p" > www.example.com.pem
64
65       # extract public key in pem format from certificate
66       openssl x509 -in www.example.com.pem -pubkey -noout > www.example.com.pubkey.pem
67
68       # convert public key from pem to der
69       openssl asn1parse -noout -inform pem -in www.example.com.pubkey.pem -out www.example.com.pubkey.der
70
71       # sha256 hash and base64 encode der to string for use
72       openssl dgst -sha256 -binary www.example.com.pubkey.der | openssl base64
73       The public key in PEM format contains  a  header,  base64  data  and  a
74       footer:
75       -----BEGIN PUBLIC KEY-----
76       [BASE 64 DATA]
77       -----END PUBLIC KEY-----
78

AVAILABILITY

80       PEM/DER support:
81
82         7.39.0: OpenSSL, GnuTLS
83
84         7.39.0-7.48.0,7.58.1+: GSKit
85
86         7.43.0: NSS and wolfSSL
87
88         7.47.0: mbedtls
89
90         7.54.1: SecureTransport on macOS 10.7+/iOS 10+
91
92         7.58.1: SChannel
93
94       sha256 support:
95
96         7.44.0: OpenSSL, GnuTLS, NSS and wolfSSL
97
98         7.47.0: mbedtls
99
100         7.54.1: SecureTransport on macOS 10.7+/iOS 10+
101
102         7.58.1: SChannel Windows XP SP3+
103
104       Other SSL backends not supported.
105

RETURN VALUE

107       Returns  CURLE_OK  if  TLS  enabled,  CURLE_UNKNOWN_OPTION  if  not, or
108       CURLE_OUT_OF_MEMORY if there was insufficient heap space.
109

SEE ALSO

111       CURLOPT_SSL_VERIFYPEER(3),       CURLOPT_SSL_VERIFYHOST(3),        CUR‐
112       LOPT_CAINFO(3), CURLOPT_CAPATH(3),
113
114
115
116libcurl 7.82.0                 November 26, 2021    CURLOPT_PINNEDPUBLICKEY(3)
Impressum