CURLOPT_SSH_KEYFUNCTION.3 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2022, 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_KEYFUNCTION 3 "19 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
  26. .SH NAME
  27. CURLOPT_SSH_KEYFUNCTION \- callback for known host matching logic
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. enum curl_khstat {
  32. CURLKHSTAT_FINE_ADD_TO_FILE,
  33. CURLKHSTAT_FINE,
  34. CURLKHSTAT_REJECT, /* reject the connection, return an error */
  35. CURLKHSTAT_DEFER, /* do not accept it, but we cannot answer right
  36. now. Causes a CURLE_PEER_FAILED_VERIFICATION error but
  37. the connection will be left intact */
  38. CURLKHSTAT_FINE_REPLACE
  39. };
  40. enum curl_khmatch {
  41. CURLKHMATCH_OK, /* match */
  42. CURLKHMATCH_MISMATCH, /* host found, key mismatch! */
  43. CURLKHMATCH_MISSING, /* no matching host/key found */
  44. };
  45. struct curl_khkey {
  46. const char *key; /* points to a null-terminated string encoded with
  47. base64 if len is zero, otherwise to the "raw"
  48. data */
  49. size_t len;
  50. enum curl_khtype keytype;
  51. };
  52. int ssh_keycallback(CURL *easy,
  53. const struct curl_khkey *knownkey,
  54. const struct curl_khkey *foundkey,
  55. enum curl_khmatch,
  56. void *clientp);
  57. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSH_KEYFUNCTION,
  58. ssh_keycallback);
  59. .SH DESCRIPTION
  60. Pass a pointer to your callback function, which should match the prototype
  61. shown above.
  62. It gets called when the known_host matching has been done, to allow the
  63. application to act and decide for libcurl how to proceed. The callback will
  64. only be called if \fICURLOPT_SSH_KNOWNHOSTS(3)\fP is also set.
  65. This callback function gets passed the CURL handle, the key from the
  66. known_hosts file \fIknownkey\fP, the key from the remote site \fIfoundkey\fP,
  67. info from libcurl on the matching status and a custom pointer (set with
  68. \fICURLOPT_SSH_KEYDATA(3)\fP). It MUST return one of the following return
  69. codes to tell libcurl how to act:
  70. .IP CURLKHSTAT_FINE_REPLACE
  71. The new host+key is accepted and libcurl will replace the old host+key into
  72. the known_hosts file before continuing with the connection. This will also
  73. add the new host+key combo to the known_host pool kept in memory if it was not
  74. already present there. The adding of data to the file is done by completely
  75. replacing the file with a new copy, so the permissions of the file must allow
  76. this. (Added in 7.73.0)
  77. .IP CURLKHSTAT_FINE_ADD_TO_FILE
  78. The host+key is accepted and libcurl will append it to the known_hosts file
  79. before continuing with the connection. This will also add the host+key combo
  80. to the known_host pool kept in memory if it was not already present there. The
  81. adding of data to the file is done by completely replacing the file with a new
  82. copy, so the permissions of the file must allow this.
  83. .IP CURLKHSTAT_FINE
  84. The host+key is accepted libcurl will continue with the connection. This will
  85. also add the host+key combo to the known_host pool kept in memory if it was not
  86. already present there.
  87. .IP CURLKHSTAT_REJECT
  88. The host+key is rejected. libcurl will deny the connection to continue and it
  89. will be closed.
  90. .IP CURLKHSTAT_DEFER
  91. The host+key is rejected, but the SSH connection is asked to be kept alive.
  92. This feature could be used when the app wants to somehow return back and act
  93. on the host+key situation and then retry without needing the overhead of
  94. setting it up from scratch again.
  95. .SH DEFAULT
  96. NULL
  97. .SH PROTOCOLS
  98. SFTP and SCP
  99. .SH EXAMPLE
  100. .nf
  101. static int keycb(CURL *easy,
  102. const struct curl_khkey *knownkey,
  103. const struct curl_khkey *foundkey,
  104. enum curl_khmatch,
  105. void *clientp)
  106. {
  107. /* 'clientp' points to the callback_data struct */
  108. /* investigate the situation and return the correct value */
  109. return CURLKHSTAT_FINE_ADD_TO_FILE;
  110. }
  111. {
  112. curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/thisfile.txt");
  113. curl_easy_setopt(curl, CURLOPT_SSH_KEYFUNCTION, keycb);
  114. curl_easy_setopt(curl, CURLOPT_SSH_KEYDATA, &callback_data);
  115. curl_easy_setopt(curl, CURLOPT_SSH_KNOWNHOSTS, "/home/user/known_hosts");
  116. curl_easy_perform(curl);
  117. }
  118. .fi
  119. .SH AVAILABILITY
  120. Added in 7.19.6
  121. .SH RETURN VALUE
  122. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  123. .SH "SEE ALSO"
  124. .BR CURLOPT_SSH_KEYDATA "(3), " CURLOPT_SSH_KNOWNHOSTS "(3), "