CURLOPT_PROXY_PINNEDPUBLICKEY.3 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. .\" generated by cd2nroff 0.1 from CURLOPT_PROXY_PINNEDPUBLICKEY.md
  2. .TH CURLOPT_PROXY_PINNEDPUBLICKEY 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_PROXY_PINNEDPUBLICKEY \- pinned public key for https proxy
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PROXY_PINNEDPUBLICKEY,
  9. char *pinnedpubkey);
  10. .fi
  11. .SH DESCRIPTION
  12. Pass a pointer to a null\-terminated string as parameter. The string can be the
  13. filename of your pinned public key. The file format expected is "PEM" or
  14. \&"DER". The string can also be any number of base64 encoded sha256 hashes
  15. preceded by "sha256//" and separated by ";"
  16. When negotiating a TLS or SSL connection, the https proxy sends a certificate
  17. indicating its identity. A public key is extracted from this certificate and
  18. if it does not exactly match the public key provided to this option, libcurl
  19. aborts the connection before sending or receiving any data.
  20. On mismatch, \fICURLE_SSL_PINNEDPUBKEYNOTMATCH\fP is returned.
  21. The application does not have to keep the string around after setting this
  22. option.
  23. .SH DEFAULT
  24. NULL
  25. .SH PROTOCOLS
  26. This functionality affects all TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
  27. This option works only with the following TLS backends:
  28. GnuTLS, OpenSSL, mbedTLS and wolfSSL
  29. .SH EXAMPLE
  30. .nf
  31. int main(void)
  32. {
  33. CURL *curl = curl_easy_init();
  34. if(curl) {
  35. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  36. curl_easy_setopt(curl, CURLOPT_PROXY, "https://proxy:443");
  37. curl_easy_setopt(curl, CURLOPT_PROXY_PINNEDPUBLICKEY,
  38. "sha256//YhKJKSzoTt2b5FP18fvpHo7fJYqQCjA"
  39. "a3HWY3tvRMwE=;sha256//t62CeU2tQiqkexU74"
  40. "Gxa2eg7fRbEgoChTociMee9wno=");
  41. /* Perform the request */
  42. curl_easy_perform(curl);
  43. }
  44. }
  45. .fi
  46. .SH PUBLIC KEY EXTRACTION
  47. If you do not have the https proxy server\(aqs public key file you can extract it
  48. from the https proxy server\(aqs certificate.
  49. .nf
  50. # retrieve the server's certificate if you do not already have it
  51. #
  52. # be sure to examine the certificate to see if it is what you expected
  53. #
  54. # Windows-specific:
  55. # - Use NUL instead of /dev/null.
  56. # - OpenSSL may wait for input instead of disconnecting. Hit enter.
  57. # - If you do not have sed, then just copy the certificate into a file:
  58. # Lines from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE-----.
  59. #
  60. openssl s_client -servername www.example.com -connect www.example.com:443 \\
  61. < /dev/null | sed -n "/-----BEGIN/,/-----END/p" > www.example.com.pem
  62. # extract public key in pem format from certificate
  63. openssl x509 -in www.example.com.pem -pubkey -noout > www.example.com.pubkey.pem
  64. # convert public key from pem to der
  65. openssl asn1parse -noout -inform pem -in www.example.com.pubkey.pem \\
  66. -out www.example.com.pubkey.der
  67. # sha256 hash and base64 encode der to string for use
  68. openssl dgst -sha256 -binary www.example.com.pubkey.der | openssl base64
  69. .fi
  70. The public key in PEM format contains a header, base64 data and a
  71. footer:
  72. .nf
  73. -----BEGIN PUBLIC KEY-----
  74. [BASE 64 DATA]
  75. -----END PUBLIC KEY-----
  76. .fi
  77. .SH HISTORY
  78. PEM/DER support:
  79. 7.52.0: GnuTLS, OpenSSL, mbedTLS, wolfSSL
  80. sha256 support:
  81. 7.52.0: GnuTLS, OpenSSL, mbedTLS, wolfSSL
  82. Other SSL backends not supported.
  83. .SH AVAILABILITY
  84. Added in curl 7.52.0
  85. .SH RETURN VALUE
  86. Returns CURLE_OK if TLS enabled, CURLE_UNKNOWN_OPTION if not, or
  87. CURLE_OUT_OF_MEMORY if there was insufficient heap space.
  88. .SH SEE ALSO
  89. .BR CURLOPT_PINNEDPUBLICKEY (3),
  90. .BR CURLOPT_PROXY_CAINFO (3),
  91. .BR CURLOPT_PROXY_CAPATH (3),
  92. .BR CURLOPT_PROXY_SSL_VERIFYHOST (3),
  93. .BR CURLOPT_PROXY_SSL_VERIFYPEER (3)