1CURLOPT_SSH_KEYFUNCTION(3) curl_easy_setopt options CURLOPT_SSH_KEYFUNCTION(3)
2
3
4

NAME

6       CURLOPT_SSH_KEYFUNCTION - callback for known host matching logic
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       enum curl_khstat {
12         CURLKHSTAT_FINE_ADD_TO_FILE,
13         CURLKHSTAT_FINE,
14         CURLKHSTAT_REJECT, /* reject the connection, return an error */
15         CURLKHSTAT_DEFER,  /* do not accept it, but we can't answer right
16                               now so this causes a CURLE_DEFER error but
17                               otherwise the connection will be left intact
18                               etc */
19       };
20
21       enum curl_khmatch {
22         CURLKHMATCH_OK,       /* match */
23         CURLKHMATCH_MISMATCH, /* host found, key mismatch! */
24         CURLKHMATCH_MISSING,  /* no matching host/key found */
25       };
26
27       struct curl_khkey {
28         const char *key; /* points to a zero-terminated string encoded with
29                             base64 if len is zero, otherwise to the "raw"
30                             data */
31         size_t len;
32         enum curl_khtype keytype;
33       };
34
35       int ssh_keycallback(CURL *easy,
36                           const struct curl_khkey *knownkey,
37                           const struct curl_khkey *foundkey,
38                           enum curl_khmatch,
39                           void *clientp);
40
41       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SSH_KEYFUNCTION,
42                                 ssh_keycallback);
43

DESCRIPTION

45       Pass a pointer to your callback function, which should match the proto‐
46       type shown above.
47
48       It gets called when the known_host matching has been done, to allow the
49       application  to act and decide for libcurl how to proceed. The callback
50       will only be called if CURLOPT_SSH_KNOWNHOSTS(3) is also set.
51
52       This callback function gets passed the CURL handle, the  key  from  the
53       known_hosts  file knownkey, the key from the remote site foundkey, info
54       from libcurl on the matching status and a custom pointer (set with CUR‐
55       LOPT_SSH_KEYDATA(3)).  It MUST return one of the following return codes
56       to tell libcurl how to act:
57
58
59       CURLKHSTAT_FINE_ADD_TO_FILE
60              The host+key is accepted and  libcurl  will  append  it  to  the
61              known_hosts  file  before  continuing  with the connection. This
62              will also add the host+key combo to the known_host pool kept  in
63              memory if it wasn't already present there. The adding of data to
64              the file is done by completely replacing the  file  with  a  new
65              copy, so the permissions of the file must allow this.
66
67       CURLKHSTAT_FINE
68              The  host+key is accepted libcurl will continue with the connec‐
69              tion. This will also add the host+key combo  to  the  known_host
70              pool kept in memory if it wasn't already present there.
71
72       CURLKHSTAT_REJECT
73              The  host+key  is  rejected. libcurl will deny the connection to
74              continue and it will be closed.
75
76       CURLKHSTAT_DEFER
77              The host+key is rejected, but the SSH connection is asked to  be
78              kept  alive.   This  feature could be used when the app wants to
79              somehow return back and act on the host+key situation  and  then
80              retry without needing the overhead of setting it up from scratch
81              again.
82

DEFAULT

84       NULL
85

PROTOCOLS

87       SFTP and SCP
88

EXAMPLE

90       static int keycb(CURL *easy,
91                        const struct curl_khkey *knownkey,
92                        const struct curl_khkey *foundkey,
93                        enum curl_khmatch,
94                        void *clientp)
95       {
96         /* 'clientp' points to the callback_data struct */
97         /* investigate the situation and return the correct value */
98         return CURLKHSTAT_FINE_ADD_TO_FILE;
99       }
100       {
101         curl_easy_setopt(curl, CURLOPT_URL, "sftp://example.com/thisfile.txt");
102         curl_easy_setopt(curl, CURLOPT_SSH_KEYFUNCTION, keycb);
103         curl_easy_setopt(curl, CURLOPT_SSH_KEYDATA, &callback_data);
104         curl_easy_setopt(curl, CURLOPT_SSH_KNOWNHOSTS, "/home/user/known_hosts");
105
106         curl_easy_perform(curl);
107       }
108

AVAILABILITY

110       Added in 7.19.6
111

RETURN VALUE

113       Returns CURLE_OK if the option is supported,  and  CURLE_UNKNOWN_OPTION
114       if not.
115

SEE ALSO

117       CURLOPT_SSH_KEYDATA(3), CURLOPT_SSH_KNOWNHOSTS(3),
118
119
120
121libcurl 7.61.1                   May 31, 2017       CURLOPT_SSH_KEYFUNCTION(3)
Impressum