2
0

CURLOPT_SSH_KEYFUNCTION.3 5.3 KB

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