CURLOPT_SSH_HOSTKEYFUNCTION.3 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. .\" generated by cd2nroff 0.1 from CURLOPT_SSH_HOSTKEYFUNCTION.md
  2. .TH CURLOPT_SSH_HOSTKEYFUNCTION 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_SSH_HOSTKEYFUNCTION \- callback to check host key
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. int keycallback(void *clientp,
  9. int keytype,
  10. const char *key,
  11. size_t keylen);
  12. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSH_HOSTKEYFUNCTION,
  13. keycallback);
  14. .fi
  15. .SH DESCRIPTION
  16. Pass a pointer to your callback function, which should match the prototype
  17. shown above. It overrides \fICURLOPT_SSH_KNOWNHOSTS(3)\fP.
  18. This callback gets called when the verification of the SSH host key is needed.
  19. \fBkey\fP is \fBkeylen\fP bytes long and is the key to check. \fBkeytype\fP
  20. says what type it is, from the \fBCURLKHTYPE_\fP* series in the
  21. \fBcurl_khtype\fP enum.
  22. \fBclientp\fP is a custom pointer set with \fICURLOPT_SSH_HOSTKEYDATA(3)\fP.
  23. The callback MUST return one of the following return codes to tell libcurl how
  24. to act:
  25. .IP CURLKHMATCH_OK
  26. The host key is accepted, the connection should continue.
  27. .IP CURLKHMATCH_MISMATCH
  28. the host key is rejected, the connection is canceled.
  29. .SH DEFAULT
  30. NULL
  31. .SH PROTOCOLS
  32. This functionality affects scp and sftp
  33. .SH EXAMPLE
  34. .nf
  35. struct mine {
  36. void *custom;
  37. };
  38. int hostkeycb(void *clientp, /* passed with CURLOPT_SSH_HOSTKEYDATA */
  39. int keytype, /* CURLKHTYPE */
  40. const char *key, /* host key to check */
  41. size_t keylen) /* length of the key */
  42. {
  43. /* 'clientp' points to the callback_data struct */
  44. /* investigate the situation and return the correct value */
  45. return CURLKHMATCH_OK;
  46. }
  47. int main(void)
  48. {
  49. struct mine callback_data;
  50. CURL *curl = curl_easy_init();
  51. if(curl) {
  52. curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/thisfile.txt");
  53. curl_easy_setopt(curl, CURLOPT_SSH_HOSTKEYFUNCTION, hostkeycb);
  54. curl_easy_setopt(curl, CURLOPT_SSH_HOSTKEYDATA, &callback_data);
  55. curl_easy_perform(curl);
  56. }
  57. }
  58. .fi
  59. .SH NOTES
  60. Work only with the libssh2 backend.
  61. .SH AVAILABILITY
  62. Added in curl 7.84.0
  63. .SH RETURN VALUE
  64. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  65. .SH SEE ALSO
  66. .BR CURLOPT_SSH_HOSTKEYDATA (3),
  67. .BR CURLOPT_SSH_KNOWNHOSTS (3)