2024-01-17 18:32:44 +08:00
|
|
|
---
|
2024-02-28 18:28:10 +08:00
|
|
|
c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2024-01-17 18:32:44 +08:00
|
|
|
SPDX-License-Identifier: curl
|
|
|
|
Title: CURLOPT_PROXY_PINNEDPUBLICKEY
|
|
|
|
Section: 3
|
|
|
|
Source: libcurl
|
|
|
|
See-also:
|
|
|
|
- CURLOPT_PINNEDPUBLICKEY (3)
|
|
|
|
- CURLOPT_PROXY_CAINFO (3)
|
|
|
|
- CURLOPT_PROXY_CAPATH (3)
|
|
|
|
- CURLOPT_PROXY_SSL_VERIFYHOST (3)
|
|
|
|
- CURLOPT_PROXY_SSL_VERIFYPEER (3)
|
2024-03-21 18:50:20 +08:00
|
|
|
Protocol:
|
|
|
|
- TLS
|
2024-03-21 22:46:32 +08:00
|
|
|
TLS-backend:
|
|
|
|
- OpenSSL
|
|
|
|
- GnuTLS
|
|
|
|
- mbedTLS
|
|
|
|
- wolfSSL
|
2024-07-18 06:51:50 +08:00
|
|
|
Added-in: 7.52.0
|
2024-01-17 18:32:44 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
# NAME
|
|
|
|
|
|
|
|
CURLOPT_PROXY_PINNEDPUBLICKEY - pinned public key for https proxy
|
|
|
|
|
|
|
|
# SYNOPSIS
|
|
|
|
|
|
|
|
~~~c
|
2016-11-25 17:47:25 +08:00
|
|
|
#include <curl/curl.h>
|
|
|
|
|
2024-01-17 18:32:44 +08:00
|
|
|
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PROXY_PINNEDPUBLICKEY,
|
|
|
|
char *pinnedpubkey);
|
|
|
|
~~~
|
|
|
|
|
|
|
|
# DESCRIPTION
|
|
|
|
|
2020-06-25 17:38:25 +08:00
|
|
|
Pass a pointer to a null-terminated string as parameter. The string can be the
|
2024-01-23 22:12:09 +08:00
|
|
|
filename of your pinned public key. The file format expected is "PEM" or
|
2024-01-17 18:32:44 +08:00
|
|
|
"DER". The string can also be any number of base64 encoded sha256 hashes
|
|
|
|
preceded by "sha256//" and separated by ";"
|
2016-11-25 17:47:25 +08:00
|
|
|
|
|
|
|
When negotiating a TLS or SSL connection, the https proxy sends a certificate
|
|
|
|
indicating its identity. A public key is extracted from this certificate and
|
2023-08-22 23:40:39 +08:00
|
|
|
if it does not exactly match the public key provided to this option, libcurl
|
|
|
|
aborts the connection before sending or receiving any data.
|
2016-11-25 17:47:25 +08:00
|
|
|
|
2024-01-17 18:32:44 +08:00
|
|
|
On mismatch, *CURLE_SSL_PINNEDPUBKEYNOTMATCH* is returned.
|
2016-12-21 21:48:35 +08:00
|
|
|
|
|
|
|
The application does not have to keep the string around after setting this
|
|
|
|
option.
|
2024-01-17 18:32:44 +08:00
|
|
|
|
|
|
|
# DEFAULT
|
|
|
|
|
2016-11-25 17:47:25 +08:00
|
|
|
NULL
|
2024-01-17 18:32:44 +08:00
|
|
|
|
2024-07-19 07:06:06 +08:00
|
|
|
# %PROTOCOLS%
|
|
|
|
|
2024-01-17 18:32:44 +08:00
|
|
|
# EXAMPLE
|
|
|
|
|
|
|
|
~~~c
|
2023-12-04 17:50:42 +08:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
if(curl) {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy:443");
|
|
|
|
curl_easy_setopt(curl, CURLOPT_PROXY_PINNEDPUBLICKEY,
|
|
|
|
"sha256//YhKJKSzoTt2b5FP18fvpHo7fJYqQCjA"
|
|
|
|
"a3HWY3tvRMwE=;sha256//t62CeU2tQiqkexU74"
|
|
|
|
"Gxa2eg7fRbEgoChTociMee9wno=");
|
2017-05-31 17:56:28 +08:00
|
|
|
|
2023-12-04 17:50:42 +08:00
|
|
|
/* Perform the request */
|
|
|
|
curl_easy_perform(curl);
|
|
|
|
}
|
2017-05-31 17:56:28 +08:00
|
|
|
}
|
2024-01-17 18:32:44 +08:00
|
|
|
~~~
|
|
|
|
|
|
|
|
# PUBLIC KEY EXTRACTION
|
|
|
|
|
2016-11-25 17:47:25 +08:00
|
|
|
If you do not have the https proxy server's public key file you can extract it
|
|
|
|
from the https proxy server's certificate.
|
2024-01-17 18:32:44 +08:00
|
|
|
~~~c
|
2021-10-31 23:34:44 +08:00
|
|
|
# retrieve the server's certificate if you do not already have it
|
2016-11-25 17:47:25 +08:00
|
|
|
#
|
|
|
|
# be sure to examine the certificate to see if it is what you expected
|
|
|
|
#
|
|
|
|
# Windows-specific:
|
|
|
|
# - Use NUL instead of /dev/null.
|
|
|
|
# - OpenSSL may wait for input instead of disconnecting. Hit enter.
|
2021-10-31 23:34:44 +08:00
|
|
|
# - If you do not have sed, then just copy the certificate into a file:
|
2016-11-25 17:47:25 +08:00
|
|
|
# Lines from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE-----.
|
|
|
|
#
|
2024-01-17 18:32:44 +08:00
|
|
|
openssl s_client -servername www.example.com -connect www.example.com:443 \
|
|
|
|
< /dev/null | sed -n "/-----BEGIN/,/-----END/p" > www.example.com.pem
|
2016-11-25 17:47:25 +08:00
|
|
|
|
|
|
|
# extract public key in pem format from certificate
|
|
|
|
openssl x509 -in www.example.com.pem -pubkey -noout > www.example.com.pubkey.pem
|
|
|
|
|
|
|
|
# convert public key from pem to der
|
2024-01-17 18:32:44 +08:00
|
|
|
openssl asn1parse -noout -inform pem -in www.example.com.pubkey.pem \
|
|
|
|
-out www.example.com.pubkey.der
|
2016-11-25 17:47:25 +08:00
|
|
|
|
|
|
|
# sha256 hash and base64 encode der to string for use
|
|
|
|
openssl dgst -sha256 -binary www.example.com.pubkey.der | openssl base64
|
2024-01-17 18:32:44 +08:00
|
|
|
~~~
|
2016-11-25 17:47:25 +08:00
|
|
|
The public key in PEM format contains a header, base64 data and a
|
|
|
|
footer:
|
2024-01-17 18:32:44 +08:00
|
|
|
~~~c
|
2016-11-25 17:47:25 +08:00
|
|
|
-----BEGIN PUBLIC KEY-----
|
|
|
|
[BASE 64 DATA]
|
|
|
|
-----END PUBLIC KEY-----
|
2024-01-17 18:32:44 +08:00
|
|
|
~~~
|
|
|
|
|
2024-07-19 07:06:06 +08:00
|
|
|
# HISTORY
|
2024-01-17 18:32:44 +08:00
|
|
|
|
2016-11-25 17:47:25 +08:00
|
|
|
PEM/DER support:
|
|
|
|
|
2024-01-17 18:32:44 +08:00
|
|
|
7.52.0: GnuTLS, OpenSSL, mbedTLS, wolfSSL
|
2016-11-25 17:47:25 +08:00
|
|
|
|
|
|
|
sha256 support:
|
|
|
|
|
2024-01-17 18:32:44 +08:00
|
|
|
7.52.0: GnuTLS, OpenSSL, mbedTLS, wolfSSL
|
2016-11-25 17:47:25 +08:00
|
|
|
|
|
|
|
Other SSL backends not supported.
|
2024-01-17 18:32:44 +08:00
|
|
|
|
2024-07-19 07:06:06 +08:00
|
|
|
# %AVAILABILITY%
|
|
|
|
|
2024-01-17 18:32:44 +08:00
|
|
|
# RETURN VALUE
|
|
|
|
|
2016-11-25 17:47:25 +08:00
|
|
|
Returns CURLE_OK if TLS enabled, CURLE_UNKNOWN_OPTION if not, or
|
|
|
|
CURLE_OUT_OF_MEMORY if there was insufficient heap space.
|