CURLOPT_PINNEDPUBLICKEY.3 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2021, 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 https://curl.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 \- pinned public key
  26. .SH SYNOPSIS
  27. .nf
  28. #include <curl/curl.h>
  29. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PINNEDPUBLICKEY,
  30. char *pinnedpubkey);
  31. .fi
  32. .SH DESCRIPTION
  33. Pass a pointer to a null-terminated string as parameter. The string can be the
  34. file name of your pinned public key. The file format expected is "PEM" or "DER".
  35. The string can also be any number of base64 encoded sha256 hashes preceded by
  36. "sha256//" and separated by ";"
  37. When negotiating a TLS or SSL connection, the server sends a certificate
  38. indicating its identity. A public key is extracted from this certificate and
  39. if it does not exactly match the public key provided to this option, curl will
  40. abort the connection before sending or receiving any data.
  41. On mismatch, \fICURLE_SSL_PINNEDPUBKEYNOTMATCH\fP is returned.
  42. The application does not have to keep the string around after setting this
  43. option.
  44. .SH DEFAULT
  45. NULL
  46. .SH PROTOCOLS
  47. All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
  48. .SH EXAMPLE
  49. .nf
  50. CURL *curl = curl_easy_init();
  51. if(curl) {
  52. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
  53. curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, "/etc/publickey.der");
  54. /* OR
  55. curl_easy_setopt(curl, CURLOPT_PINNEDPUBLICKEY, "sha256//YhKJKSzoTt2b5FP18fvpHo7fJYqQCjAa3HWY3tvRMwE=;sha256//t62CeU2tQiqkexU74Gxa2eg7fRbEgoChTociMee9wno=");
  56. */
  57. /* Perform the request */
  58. curl_easy_perform(curl);
  59. }
  60. .fi
  61. .SH PUBLIC KEY EXTRACTION
  62. If you do not have the server's public key file you can extract it from the
  63. server's certificate.
  64. .nf
  65. # retrieve the server's certificate if you do not already have it
  66. #
  67. # be sure to examine the certificate to see if it is what you expected
  68. #
  69. # Windows-specific:
  70. # - Use NUL instead of /dev/null.
  71. # - OpenSSL may wait for input instead of disconnecting. Hit enter.
  72. # - If you do not have sed, then just copy the certificate into a file:
  73. # Lines from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE-----.
  74. #
  75. openssl s_client -servername www.example.com -connect www.example.com:443 < /dev/null | sed -n "/-----BEGIN/,/-----END/p" > www.example.com.pem
  76. # extract public key in pem format from certificate
  77. openssl x509 -in www.example.com.pem -pubkey -noout > www.example.com.pubkey.pem
  78. # convert public key from pem to der
  79. openssl asn1parse -noout -inform pem -in www.example.com.pubkey.pem -out www.example.com.pubkey.der
  80. # sha256 hash and base64 encode der to string for use
  81. openssl dgst -sha256 -binary www.example.com.pubkey.der | openssl base64
  82. .fi
  83. The public key in PEM format contains a header, base64 data and a
  84. footer:
  85. .nf
  86. -----BEGIN PUBLIC KEY-----
  87. [BASE 64 DATA]
  88. -----END PUBLIC KEY-----
  89. .fi
  90. .SH AVAILABILITY
  91. PEM/DER support:
  92. 7.39.0: OpenSSL, GnuTLS
  93. 7.39.0-7.48.0,7.58.1+: GSKit
  94. 7.43.0: NSS and wolfSSL
  95. 7.47.0: mbedtls
  96. 7.54.1: SecureTransport on macOS 10.7+/iOS 10+
  97. 7.58.1: SChannel
  98. sha256 support:
  99. 7.44.0: OpenSSL, GnuTLS, NSS and wolfSSL
  100. 7.47.0: mbedtls
  101. 7.54.1: SecureTransport on macOS 10.7+/iOS 10+
  102. 7.58.1: SChannel Windows XP SP3+
  103. Other SSL backends not supported.
  104. .SH RETURN VALUE
  105. Returns CURLE_OK if TLS enabled, CURLE_UNKNOWN_OPTION if not, or
  106. CURLE_OUT_OF_MEMORY if there was insufficient heap space.
  107. .SH "SEE ALSO"
  108. .BR CURLOPT_SSL_VERIFYPEER "(3), "
  109. .BR CURLOPT_SSL_VERIFYHOST "(3), "
  110. .BR CURLOPT_CAINFO "(3), "
  111. .BR CURLOPT_CAPATH "(3), "