From c26da096875d609b354ea5989f62af662f9c609e Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 16 May 2015 19:34:06 +0900 Subject: Add --ssh-host-key-md option Set checksum for SSH host public key. Use same syntax with --checksum option. TYPE is hash type. The supported hash type is sha-1 or md5. DIGEST is hex digest. For example: sha-1=b030503d4de4539dc7885e6f0f5e256704edf4c3. This option can be used to validate server's public key when SFTP is used. If this option is not set, which is default, no validation takes place. --- src/SocketCore.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/SocketCore.cc') diff --git a/src/SocketCore.cc b/src/SocketCore.cc index 320f04a6..701fc33e 100644 --- a/src/SocketCore.cc +++ b/src/SocketCore.cc @@ -989,7 +989,8 @@ bool SocketCore::tlsHandshake(TLSContext* tlsctx, const std::string& hostname) #ifdef HAVE_LIBSSH2 -bool SocketCore::sshHandshake() +bool SocketCore::sshHandshake(const std::string& hashType, + const std::string& digest) { wantRead_ = false; wantWrite_ = false; @@ -1009,6 +1010,19 @@ bool SocketCore::sshHandshake() throw DL_ABORT_EX(fmt("SSH handshake failure: %s", sshSession_->getLastErrorString().c_str())); } + if (!hashType.empty()) { + auto actualDigest = sshSession_->hostkeyMessageDigest(hashType); + if (actualDigest.empty()) { + throw DL_ABORT_EX(fmt("Empty host key fingerprint from SSH layer: " + "perhaps hash type %s is not supported?", + hashType.c_str())); + } + if (digest != actualDigest) { + throw DL_ABORT_EX(fmt("Unexpected SSH host key: expected %s, actual %s", + util::toHex(digest).c_str(), + util::toHex(actualDigest).c_str())); + } + } return true; } -- cgit