Imported Upstream version 7.48.0
[platform/upstream/curl.git] / docs / libcurl / opts / CURLOPT_SSH_KEYFUNCTION.3
1 .\" **************************************************************************
2 .\" *                                  _   _ ____  _
3 .\" *  Project                     ___| | | |  _ \| |
4 .\" *                             / __| | | | |_) | |
5 .\" *                            | (__| |_| |  _ <| |___
6 .\" *                             \___|\___/|_| \_\_____|
7 .\" *
8 .\" * Copyright (C) 1998 - 2014, 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.haxx.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
30 enum curl_khstat {
31   CURLKHSTAT_FINE_ADD_TO_FILE,
32   CURLKHSTAT_FINE,
33   CURLKHSTAT_REJECT, /* reject the connection, return an error */
34   CURLKHSTAT_DEFER,  /* do not accept it, but we can't answer right
35                         now so this causes a CURLE_DEFER error but
36                         otherwise the connection will be left intact
37                         etc */
38 };
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
46 struct curl_khkey {
47   const char *key; /* points to a zero-terminated string encoded with
48                       base64 if len is zero, otherwise to the "raw"
49                       data */
50   size_t len;
51   enum curl_khtype keytype;
52 };
53
54 int ssh_keycallback(CURL *easy,
55                     const struct curl_khkey *knownkey,
56                     const struct curl_khkey *foundkey,
57                     enum curl_khmatch,
58                     void *clientp);
59
60 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSH_KEYFUNCTION,
61                           ssh_keycallback);
62 .SH DESCRIPTION
63 Pass a pointer to your callback function, which should match the prototype
64 shown above.
65
66 It gets called when the known_host matching has been done, to allow the
67 application to act and decide for libcurl how to proceed. The callback will
68 only be called if \fICURLOPT_SSH_KNOWNHOSTS(3)\fP is also set.
69
70 This callback function gets passed the CURL handle, the key from the
71 known_hosts file \fIknownkey\fP, the key from the remote site \fIfoundkey\fP,
72 info from libcurl on the matching status and a custom pointer (set with
73 \fICURLOPT_SSH_KEYDATA(3)\fP). It MUST return one of the following return
74 codes to tell libcurl how to act:
75
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 wasn't 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 wasn't
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 TODO
100 .SH AVAILABILITY
101 Added in 7.19.6
102 .SH RETURN VALUE
103 Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
104 .SH "SEE ALSO"
105 .BR CURLOPT_SSH_KEYDATA "(3), " CURLOPT_SSH_KNOWNHOSTS "(3), "