0d4357ab1a3d7239ace1659b4beb709b743aaf90
[platform/upstream/curl.git] / docs / libcurl / opts / CURLOPT_PINNEDPUBLICKEY.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
9 .\" *
10 .\" * This software is licensed as described in the file COPYING, which
11 .\" * you should have received as part of this distribution. The terms
12 .\" * are also available at http://curl.haxx.se/docs/copyright.html.
13 .\" *
14 .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 .\" * copies of the Software, and permit persons to whom the Software is
16 .\" * furnished to do so, under the terms of the COPYING file.
17 .\" *
18 .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 .\" * KIND, either express or implied.
20 .\" *
21 .\" **************************************************************************
22 .\"
23 .TH CURLOPT_PINNEDPUBLICKEY 3 "27 Aug 2014" "libcurl 7.38.0" "curl_easy_setopt options"
24 .SH NAME
25 CURLOPT_PINNEDPUBLICKEY \- set pinned public key
26 .SH SYNOPSIS
27 #include <curl/curl.h>
28
29 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PINNEDPUBLICKEY, char *pinnedpubkey);
30 .SH DESCRIPTION
31 Pass a pointer to a zero terminated string as parameter. The string can be the
32 file name of your pinned public key. The file format expected is "PEM" or "DER".
33 The string can also be any number of base64 encoded sha256 hashes preceded by
34 "sha256//" and seperated by ";"
35
36 When negotiating a TLS or SSL connection, the server sends a certificate
37 indicating its identity. A public key is extracted from this certificate and
38 if it does not exactly match the public key provided to this option, curl will
39 abort the connection before sending or receiving any data.
40 .SH DEFAULT
41 NULL
42 .SH PROTOCOLS
43 All TLS based protocols: HTTPS, FTPS, IMAPS, POP3, SMTPS etc.
44 .SH EXAMPLE
45 .nf
46 CURL *curl = curl_easy_init();
47 if(curl) {
48   curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
49   curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, "/etc/publickey.der");
50   /* OR
51   curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, "sha256//YhKJKSzoTt2b5FP18fvpHo7fJYqQCjAa3HWY3tvRMwE=;sha256//t62CeU2tQiqkexU74Gxa2eg7fRbEgoChTociMee9wno=");
52   */
53
54   /* Perform the request */
55   curl_easy_perform(curl);
56 }
57 .fi
58 .SH PUBLIC KEY EXTRACTION
59 If you do not have the server's public key file you can extract it from the
60 server's certificate.
61 .nf
62 # extract public key in pem format from certificate
63 openssl x509 -in www.test.com.pem -pubkey -noout > www.test.com.pubkey.pem
64 # convert public key from pem to der
65 openssl asn1parse -noout -inform pem -in www.test.com.pubkey.pem -out www.test.com.pubkey.der
66 # sha256 hash and base64 encode der to string for use
67 openssl dgst -sha256 -binary www.test.com.pubkey.der | openssl base64
68 .fi
69 The public key in PEM format contains a header, base64 data and a
70 footer:
71 .nf
72 -----BEGIN PUBLIC KEY-----
73 [BASE 64 DATA]
74 -----END PUBLIC KEY-----
75 .fi
76 .SH AVAILABILITY
77 Added in 7.39.0 for OpenSSL, GnuTLS and GSKit. Added in 7.43.0 for
78 NSS and wolfSSL/CyaSSL. sha256 support added in 7.44.0 for OpenSSL,
79 GnuTLS, NSS and wolfSSL/CyaSSL. Other SSL backends not supported.
80 .SH RETURN VALUE
81 Returns CURLE_OK if TLS enabled, CURLE_UNKNOWN_OPTION if not, or
82 CURLE_OUT_OF_MEMORY if there was insufficient heap space.
83 .SH "SEE ALSO"
84 .BR CURLOPT_SSL_VERIFYPEER "(3), "
85 .BR CURLOPT_SSL_VERIFYHOST "(3), "
86 .BR CURLOPT_CAINFO "(3), "
87 .BR CURLOPT_CAPATH "(3), "