sftp: add the option CURLKHSTAT_FINE_REPLACE

Replace the old fingerprint of the host with a new.

Closes #5685
This commit is contained in:
Michael Musset 2020-07-15 16:39:40 +02:00 committed by Daniel Stenberg
parent ddf47bbc0a
commit ebc6c54c74
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 20 additions and 4 deletions

View file

@ -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 =