Skip to content

curl tries to read known_hosts from wrong location #8033

Closed

Description

@jeffrson

I did this

curl -u user:pass -T file.dat sftp://host.domain.tld/folder

I expected the following

upload "file.dat" to host.domain.tld/folder

what happened

although host.domain.tld is contained in known_hosts there's an error message:
curl: (60) SSL peer certificate or SSH remote key was not OK

AFAICT, curl tries to load known_hosts from %APPDATA%\.ssh (user\AppData\Roaming\.ssh), while it should look at %USERPROFILE%\.ssh (user\.ssh), which is user's actual home folder and is used by OpenSSH integrated in Windows as well.

BTW, would be great to have an example of how to get the hash for --hostpubmd5 and --hostpubsha256 in the documentation (ie, what data to hash exactly).

curl/libcurl version

[curl -V output]

curl 7.80.0 (x86_64-pc-win32) libcurl/7.80.0 OpenSSL/3.0.0 (Schannel) zlib/1.2.11 brotli/1.0.9 zstd/1.5.0 libidn2/2.3.2 libssh2/1.10.0 nghttp2/1.46.0 libgsasl/1.10.0
Release-Date: 2021-11-10
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli gsasl HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz MultiSSL NTLM SPNEGO SSL SSPI TLS-SRP UnixSockets zstd

operating system

Windows 10 21H1

Activity

  1. changed the title [-]curl tries to read known_hosts from wrong location (Windows)[/-] [+]curl tries to read known_hosts from wrong location[/+] on Nov 19, 2021
  2. bagder commented on Nov 19, 2021

    @bagder
    Member

    it should look at %USERPROFILE%.ssh

    Is this practice/order documented or mandated somewhere official? curl has preferred APPDATA to USERPROFILE for finding the user's "home dir" since 8be602c, 18 years ago...

  3. jeffrson commented on Nov 19, 2021

    @jeffrson
    Author

    Well, that's interesting.

    I'm just using curl with SFTP for the first time and I stumbled across the certificate warning. So I was going to research.

    So what does it mean "official"?
    Some tools want to follow XDG base directories, other tools try to mimic Linux behaviour by using %USERPROFILE% as $HOME (that's what sounds reasonable to me). Yet another tools rely on explizit %HOME%.

    Also, there hasn't been "official" SSH until a few years ago in some Windows 10 update. Now, this ssh is using %USERPROFILE%\.ssh and I think it's practical to use the same data in curl as well, isn't it? It's not really useful to have two different known_hosts.

    BTW, IMO it's not too well documented that curl is using %APPDATA%. I actually had used Procmon to check whether it reads my known_hosts file.

    Do you know of other apps search .ssh at %APPDATA%?

    Maybe you could read %USERPROFILE%\.ssh, if the other does not exist? Or if it doesn't contain known_hosts?

  4. bagder commented on Nov 19, 2021

    @bagder
    Member

    curl also never actually use %USERPROFILE% now, it always uses %USERPROFILE%\Application Data - if APPDATA isn't set.

  5. self-assigned this
    on Nov 19, 2021
  6. bagder commented on Nov 19, 2021

    @bagder
    Member

    @jeffrson, Would you be able to try out #8035 ?

  7. jeffrson commented on Nov 21, 2021

    @jeffrson
    Author

    Great work, thank you very much!

    Unfortunately I don't have any local builds for curl :-( and I'm afraid I can't set it up in the short term either.

    Also I could not find a nightly or autobuild version - can you recommend one?

  8. added 2 commits that reference this issue on Nov 22, 2021
    4404435
    2be1aa6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions