diff options
author | Michael Musset <mickamusset@gmail.com> | 2020-07-15 16:39:40 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2020-08-24 17:26:08 +0200 |
commit | ebc6c54c74fc65abf1385f7206caf766847f4302 (patch) | |
tree | 5842a399e406989da3b2284ee1fd0bc6d6ff1549 /lib/vssh | |
parent | ddf47bbc0a30f8b57af7d25f852e7906979d2e28 (diff) | |
download | curl-ebc6c54c74fc65abf1385f7206caf766847f4302.tar.gz |
sftp: add the option CURLKHSTAT_FINE_REPLACE
Replace the old fingerprint of the host with a new.
Closes #5685
Diffstat (limited to 'lib/vssh')
-rw-r--r-- | lib/vssh/libssh2.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c index dc4db6f2e..968bc1e20 100644 --- a/lib/vssh/libssh2.c +++ b/lib/vssh/libssh2.c @@ -442,6 +442,7 @@ static CURLcode ssh_knownhost(struct connectdata *conn) if(data->set.str[STRING_SSH_KNOWNHOSTS]) { /* we're asked to verify the host against a file */ struct ssh_conn *sshc = &conn->proto.sshc; + struct libssh2_knownhost *host = NULL; int rc; int keytype; size_t keylen; @@ -456,7 +457,6 @@ static CURLcode ssh_knownhost(struct connectdata *conn) * What host name does OpenSSH store in its file if an IDN name is * used? */ - struct libssh2_knownhost *host; enum curl_khmatch keymatch; curl_sshkeycallback func = data->set.ssh_keyfunc?data->set.ssh_keyfunc:sshkeycallback; @@ -568,7 +568,13 @@ static CURLcode ssh_knownhost(struct connectdata *conn) /* DEFER means bail out but keep the SSH_HOSTKEY state */ result = sshc->actualcode = CURLE_PEER_FAILED_VERIFICATION; break; + case CURLKHSTAT_FINE_REPLACE: + /* remove old host+key that doesn't match */ + if(host) + libssh2_knownhost_del(sshc->kh, host); + /*FALLTHROUGH*/ case CURLKHSTAT_FINE: + /*FALLTHROUGH*/ case CURLKHSTAT_FINE_ADD_TO_FILE: /* proceed */ if(keycheck != LIBSSH2_KNOWNHOST_CHECK_MATCH) { @@ -583,7 +589,8 @@ static CURLcode ssh_knownhost(struct connectdata *conn) if(addrc) infof(data, "Warning adding the known host %s failed!\n", conn->host.name); - else if(rc == CURLKHSTAT_FINE_ADD_TO_FILE) { + else if(rc == CURLKHSTAT_FINE_ADD_TO_FILE || + rc == CURLKHSTAT_FINE_REPLACE) { /* now we write the entire in-memory list of known hosts to the known_hosts file */ int wrc = |