CURLOPT_SSH_HOSTKEYFUNCTION.3 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 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. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLOPT_SSH_HOSTKEYFUNCTION 3 "4 Nov 2021" libcurl libcurl
  26. .SH NAME
  27. CURLOPT_SSH_HOSTKEYFUNCTION \- callback to check host key
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. int keycallback(void *clientp,
  32. int keytype,
  33. const char *key,
  34. size_t keylen);
  35. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSH_HOSTKEYFUNCTION,
  36. keycallback);
  37. .fi
  38. .SH DESCRIPTION
  39. Pass a pointer to your callback function, which should match the prototype
  40. shown above. It overrides \fICURLOPT_SSH_KNOWNHOSTS(3)\fP.
  41. This callback gets called when the verification of the SSH host key is needed.
  42. \fBkey\fP is \fBkeylen\fP bytes long and is the key to check. \fBkeytype\fP
  43. says what type it is, from the \fBCURLKHTYPE_*\fP series in the
  44. \fBcurl_khtype\fP enum.
  45. \fBclientp\fP is a custom pointer set with \fICURLOPT_SSH_HOSTKEYDATA(3)\fP.
  46. The callback MUST return one of the following return codes to tell libcurl how
  47. to act:
  48. .IP CURLKHMATCH_OK
  49. The host key is accepted, the connection should continue.
  50. .IP CURLKHMATCH_MISMATCH
  51. the host key is rejected, the connection is canceled.
  52. .SH DEFAULT
  53. NULL
  54. .SH PROTOCOLS
  55. SCP and SFTP
  56. .SH EXAMPLE
  57. .nf
  58. int hostkeycb(void *clientp, /* passed with CURLOPT_SSH_HOSTKEYDATA */
  59. int keytype, /* CURLKHTYPE */
  60. const char * key, /* host key to check */
  61. size_t keylen); /* length of the key */
  62. {
  63. /* 'clientp' points to the callback_data struct */
  64. /* investigate the situation and return the correct value */
  65. return CURLKHMATCH_OK;
  66. }
  67. {
  68. curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/thisfile.txt");
  69. curl_easy_setopt(curl, CURLOPT_SSH_HOSTKEYFUNCTION, hostkeycb);
  70. curl_easy_setopt(curl, CURLOPT_SSH_HOSTKEYDATA, &callback_data);
  71. curl_easy_perform(curl);
  72. }
  73. .fi
  74. .SH AVAILABILITY
  75. Added in 7.84.0 , work only with libssh2 backend.
  76. .SH RETURN VALUE
  77. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  78. .SH "SEE ALSO"
  79. .BR CURLOPT_SSH_HOSTKEYDATA "(3), "
  80. .BR CURLOPT_SSH_KNOWNHOSTS "(3), "