SSH: SshSession - Transport method prefrerences handling is fixed.

git-svn-id: svn://ultimatepp.org/upp/trunk@13637 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
oblivion 2019-10-12 22:54:29 +00:00
parent 6c660f4564
commit c59a668832
2 changed files with 23 additions and 13 deletions

View file

@ -175,14 +175,19 @@ bool SshSession::Connect(const String& host, int port, const String& user, const
return true;
})) goto Bailout;
if(!Run([=] () mutable {
if(session->iomethods.IsEmpty())
return true;
int rc = libssh2_session_method_pref(ssh->session, session->iomethods.GetKey(0), ~GetMethodNames(0));
while(!session->iomethods.IsEmpty()) {
if(!Run([=] () mutable {
int method = session->iomethods.GetKey(0);
String mnames = GetMethodNames(method);
int rc = libssh2_session_method_pref(ssh->session, method, ~mnames);
if(!WouldBlock(rc) && rc < 0) SetError(rc);
if(!rc) LLOG("Transport methods are successfully set.");
if(!rc && !session->iomethods.IsEmpty()) {
LLOG("Transport method: #" << method << " is set to [" << mnames << "]");
session->iomethods.Remove(0);
}
return !rc;
})) goto Bailout;
})) goto Bailout;
}
if(!Run([=] () mutable {
int rc = libssh2_session_handshake(ssh->session, session->socket.GetSOCKET());
@ -196,8 +201,10 @@ bool SshSession::Connect(const String& host, int port, const String& user, const
if(!Run([=] () mutable {
session->fingerprint = libssh2_hostkey_hash(ssh->session, session->hashtype);
if(session->fingerprint.IsEmpty()) LLOG("Warning: Fingerprint is not available!.");
LDUMPHEX(session->fingerprint);
if(session->fingerprint.IsEmpty())
LLOG("Warning: Fingerprint is not available!.");
else
LLOG("Fingerprint: " << HexString(session->fingerprint, 1, ':'));
if(WhenVerify && !WhenVerify(host, port))
SetError(-1);
return true;
@ -206,7 +213,7 @@ bool SshSession::Connect(const String& host, int port, const String& user, const
if(!Run([=] () mutable {
session->authmethods = libssh2_userauth_list(ssh->session, user, user.GetLength());
if(session->authmethods.IsEmpty()) { if(!WouldBlock()) SetError(-1); return false; }
LLOG("Authentication methods successfully retrieved.");
LLOG("Authentication methods list successfully retrieved: [" << session->authmethods << "]");
WhenAuth();
return true;
})) goto Bailout;
@ -341,9 +348,12 @@ ValueMap SshSession::GetMethods()
String SshSession::GetMethodNames(int type)
{
String names;
const auto& v = session->iomethods[type];
for(int i = 0; i < v.GetCount(); i++)
names << v[i].To<String>() << (i < v.GetCount() - 1 ? "," : "");
const Value& v = session->iomethods[type];
if(IsValueArray(v)) {
for(int i = 0; i < v.GetCount(); i++)
names << v[i].To<String>() << (i < v.GetCount() - 1 ? "," : "");
}
else names << v;
return pick(names);
}

View file

@ -29,7 +29,7 @@ public:
SshSession& HashType(Hash h) { session->hashtype = h == HASH_SHA1 ? LIBSSH2_HOSTKEY_HASH_SHA1 : LIBSSH2_HOSTKEY_HASH_MD5; return *this; }
SshSession& Keys(const String& prikey, const String& pubkey, const String& phrase, bool fromfile = true);
SshSession& Method(int type, Value method) { session->iomethods(type) = pick(method); return *this; }
SshSession& Method(int type, Value method) { session->iomethods(type) << pick(method); return *this; }
SshSession& Methods(ValueMap methods) { session->iomethods = pick(methods); return *this; }
SshSession& PasswordAuth() { session->authmethod = PASSWORD; return *this; }