Imported Upstream version 7.48.0
[platform/upstream/curl.git] / docs / libcurl / opts / CURLOPT_PINNEDPUBLICKEY.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2  "http://www.w3.org/TR/html4/loose.dtd">
3 <html><head>
4 <title>CURLOPT_PINNEDPUBLICKEY man page</title>
5 <meta name="generator" content="roffit">
6 <STYLE type="text/css">
7 pre {
8   overflow: auto;
9   margin: 0;
10 }
11
12 P.level0, pre.level0 {
13  padding-left: 2em;
14 }
15
16 P.level1, pre.level1 {
17  padding-left: 4em;
18 }
19
20 P.level2, pre.level2 {
21  padding-left: 6em;
22 }
23
24 span.emphasis {
25  font-style: italic;
26 }
27
28 span.bold {
29  font-weight: bold;
30 }
31
32 span.manpage {
33  font-weight: bold;
34 }
35
36 h2.nroffsh {
37  background-color: #e0e0e0;
38 }
39
40 span.nroffip {
41  font-weight: bold;
42  font-size: 120%;
43  font-family: monospace;
44 }
45
46 p.roffit {
47  text-align: center;
48  font-size: 80%;
49 }
50 </STYLE>
51 </head><body>
52
53 <p class="level0"><a name="NAME"></a><h2 class="nroffsh">NAME</h2>
54 <p class="level0">CURLOPT_PINNEDPUBLICKEY - set pinned public key <a name="SYNOPSIS"></a><h2 class="nroffsh">SYNOPSIS</h2>
55 <p class="level0">&#35;include &lt;curl/curl.h&gt; 
56 <p class="level0">CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PINNEDPUBLICKEY, char *pinnedpubkey); <a name="DESCRIPTION"></a><h2 class="nroffsh">DESCRIPTION</h2>
57 <p class="level0">Pass a pointer to a zero terminated string as parameter. The string can be the file name of your pinned public key. The file format expected is "PEM" or "DER". The string can also be any number of base64 encoded sha256 hashes preceded by "sha256//" and separated by ";" 
58 <p class="level0">When negotiating a TLS or SSL connection, the server sends a certificate indicating its identity. A public key is extracted from this certificate and if it does not exactly match the public key provided to this option, curl will abort the connection before sending or receiving any data. 
59 <p class="level0">On mismatch, <span Class="emphasis">CURLE_SSL_PINNEDPUBKEYNOTMATCH</span> is returned. <a name="DEFAULT"></a><h2 class="nroffsh">DEFAULT</h2>
60 <p class="level0">NULL <a name="PROTOCOLS"></a><h2 class="nroffsh">PROTOCOLS</h2>
61 <p class="level0">All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc. <a name="EXAMPLE"></a><h2 class="nroffsh">EXAMPLE</h2>
62 <p class="level0"><pre class="level0">
63 CURL *curl = curl_easy_init();
64 if(curl) {
65 &nbsp; curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
66 &nbsp; curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, "/etc/publickey.der");
67 &nbsp; /* OR
68 &nbsp; curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, "sha256//YhKJKSzoTt2b5FP18fvpHo7fJYqQCjAa3HWY3tvRMwE=;sha256//t62CeU2tQiqkexU74Gxa2eg7fRbEgoChTociMee9wno=");
69 &nbsp; */
70 &nbsp;
71 &nbsp; /* Perform the request */
72 &nbsp; curl_easy_perform(curl);
73 }
74 </pre>
75
76 <p class="level0"><a name="PUBLIC"></a><h2 class="nroffsh">PUBLIC KEY EXTRACTION</h2>
77 <p class="level0">If you do not have the server's public key file you can extract it from the server's certificate. <pre class="level0">
78 &#35; retrieve the server's certificate if you don't already have it
79 &#35;
80 &#35; be sure to examine the certificate to see if it is what you expected
81 &#35;
82 &#35; Windows-specific:
83 &#35; - Use NUL instead of /dev/null.
84 &#35; - OpenSSL may wait for input instead of disconnecting. Hit enter.
85 &#35; - If you don't have sed, then just copy the certificate into a file:
86 &#35;   Lines from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE-----.
87 &#35;
88 openssl s_client -servername www.example.com -connect www.example.com:443 &lt; /dev/null | sed -n "/-----BEGIN/,/-----END/p" &gt; www.example.com.pem
89 &nbsp;
90 &#35; extract public key in pem format from certificate
91 openssl x509 -in www.example.com.pem -pubkey -noout &gt; www.example.com.pubkey.pem
92 &nbsp;
93 &#35; convert public key from pem to der
94 openssl asn1parse -noout -inform pem -in www.example.com.pubkey.pem -out www.example.com.pubkey.der
95 &nbsp;
96 &#35; sha256 hash and base64 encode der to string for use
97 openssl dgst -sha256 -binary www.example.com.pubkey.der | openssl base64
98 </pre>
99
100 <p class="level0">The public key in PEM format contains a header, base64 data and a footer: <pre class="level0">
101 -----BEGIN PUBLIC KEY-----
102 [BASE 64 DATA]
103 -----END PUBLIC KEY-----
104 </pre>
105
106 <p class="level0"><a name="AVAILABILITY"></a><h2 class="nroffsh">AVAILABILITY</h2>
107 <p class="level0">Added in 7.39.0 for OpenSSL, GnuTLS and GSKit. Added in 7.43.0 for NSS and wolfSSL/CyaSSL. Added for mbedtls in 7.47.0, sha256 support added in 7.44.0 for OpenSSL, GnuTLS, NSS and wolfSSL/CyaSSL. Other SSL backends not supported. <a name="RETURN"></a><h2 class="nroffsh">RETURN VALUE</h2>
108 <p class="level0">Returns CURLE_OK if TLS enabled, CURLE_UNKNOWN_OPTION if not, or CURLE_OUT_OF_MEMORY if there was insufficient heap space. <a name="SEE"></a><h2 class="nroffsh">SEE ALSO</h2>
109 <p class="level0"><a Class="manpage" href="./CURLOPT_SSL_VERIFYPEER.html">CURLOPT_SSL_VERIFYPEER</a>, <a Class="manpage" href="./CURLOPT_SSL_VERIFYHOST.html">CURLOPT_SSL_VERIFYHOST</a>, <a Class="manpage" href="./CURLOPT_CAINFO.html">CURLOPT_CAINFO</a>, <a Class="manpage" href="./CURLOPT_CAPATH.html">CURLOPT_CAPATH</a><p class="roffit">
110  This HTML page was made with <a href="http://daniel.haxx.se/projects/roffit/">roffit</a>.
111 </body></html>