Skip to content

Commit

Permalink
Bug 1833: Cannot connect to SSH-1 servers
Browse files Browse the repository at this point in the history
https://winscp.net/tracker/1833

Source commit: ba032585e748ac2590bce428c1c74b0c76c9aeb9
  • Loading branch information
martinprikryl committed Mar 5, 2020
1 parent 717d401 commit 5a54aaf
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 6 deletions.
8 changes: 7 additions & 1 deletion source/core/PuttyIntf.cpp
Expand Up @@ -946,14 +946,20 @@ UnicodeString __fastcall ParseOpenSshPubLine(const UnicodeString & Line, const s
return Result;
}
//---------------------------------------------------------------------------
UnicodeString __fastcall GetSsh1KeyType()
{
return UnicodeString(ssh_rsa.cache_id);
}
//---------------------------------------------------------------------------
UnicodeString __fastcall GetKeyTypeHuman(const UnicodeString & KeyType)
{
UnicodeString Result;
if (KeyType == ssh_dss.cache_id)
{
Result = L"DSA";
}
else if (KeyType == ssh_rsa.cache_id)
else if ((KeyType == ssh_rsa.cache_id) ||
(KeyType == L"rsa")) // SSH1
{
Result = L"RSA";
}
Expand Down
1 change: 1 addition & 0 deletions source/core/PuttyTools.h
Expand Up @@ -37,6 +37,7 @@ void __fastcall DllHijackingProtection();
UnicodeString __fastcall ParseOpenSshPubLine(const UnicodeString & Line, const struct ssh_keyalg *& Algorithm);
//---------------------------------------------------------------------------
UnicodeString __fastcall GetKeyTypeHuman(const UnicodeString & KeyType);
UnicodeString __fastcall GetSsh1KeyType();
//---------------------------------------------------------------------------
bool IsOpenSSH(const UnicodeString & SshImplementation);
//---------------------------------------------------------------------------
Expand Down
24 changes: 20 additions & 4 deletions source/core/SecureShell.cpp
Expand Up @@ -2297,12 +2297,28 @@ void __fastcall TSecureShell::VerifyHostKey(
GetRealHost(Host, Port);

UnicodeString Buf = Fingerprint;
UnicodeString SignKeyAlg = CutToChar(Buf, L' ', false);
UnicodeString SignKeySize = CutToChar(Buf, L' ', false);
UnicodeString SignKeyAlg, SignKeySize, MD5, SHA256;
if (get_ssh_version(FBackendHandle) == 1)
{
SignKeyAlg = GetSsh1KeyType();
}
else
{
SignKeyAlg = CutToChar(Buf, L' ', false);
}
SignKeySize = CutToChar(Buf, L' ', false);
MD5 = CutToChar(Buf, L' ', false);
if (get_ssh_version(FBackendHandle) == 1)
{
SHA256 = L"-";
DebugAssert(Buf.IsEmpty());
}
else
{
SHA256 = Buf;
}
UnicodeString SignKeyType = SignKeyAlg + L' ' + SignKeySize;
UnicodeString MD5 = CutToChar(Buf, L' ', false);
UnicodeString FingerprintMD5 = SignKeyType + L' ' + MD5;
UnicodeString SHA256 = Buf;
UnicodeString FingerprintSHA256 = SignKeyType + L' ' + SHA256;

FSessionInfo.HostKeyFingerprintSHA256 = FingerprintSHA256;
Expand Down
30 changes: 29 additions & 1 deletion source/putty/ssh1connection.c
Expand Up @@ -37,6 +37,7 @@ static void ssh1_connection_special_cmd(PacketProtocolLayer *ppl,
static bool ssh1_connection_want_user_input(PacketProtocolLayer *ppl);
static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl);
static void ssh1_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
static unsigned int ssh1_connection_winscp_query(PacketProtocolLayer *ppl, int query);

static const struct PacketProtocolLayerVtable ssh1_connection_vtable = {
ssh1_connection_free,
Expand All @@ -47,6 +48,7 @@ static const struct PacketProtocolLayerVtable ssh1_connection_vtable = {
ssh1_connection_got_user_input,
ssh1_connection_reconfigure,
NULL /* no layer names in SSH-1 */,
ssh1_connection_winscp_query,
};

static void ssh1_rportfwd_remove(
Expand Down Expand Up @@ -217,7 +219,7 @@ static void ssh1_connection_free(PacketProtocolLayer *ppl)
if (s->antispoof_prompt)
free_prompts(s->antispoof_prompt);

delete_callbacks_for_context(ppl->seat, s);
delete_callbacks_for_context(get_seat_callback_set(ppl->seat), s);

sfree(s);
}
Expand Down Expand Up @@ -843,3 +845,29 @@ static void ssh1_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf)
if (s->portfwdmgr_configured)
portfwdmgr_config(s->portfwdmgr, s->conf);
}

#include <puttyexp.h>

static unsigned int ssh1_connection_winscp_query(PacketProtocolLayer *ppl, int query)
{
struct ssh1_connection_state *s =
container_of(ppl, struct ssh1_connection_state, ppl);

if (query == WINSCP_QUERY_TIMER)
{
return 0; // dummy
}
else if (query == WINSCP_QUERY_REMMAXPKT)
{
return 0; // dummy
}
else if (query == WINSCP_QUERY_MAIN_CHANNEL)
{
return s->finished_setup;
}
else
{
assert(0);
return 0;
}
}
22 changes: 22 additions & 0 deletions source/putty/ssh1login.c
Expand Up @@ -71,6 +71,7 @@ static void ssh1_login_special_cmd(PacketProtocolLayer *ppl,
static bool ssh1_login_want_user_input(PacketProtocolLayer *ppl);
static void ssh1_login_got_user_input(PacketProtocolLayer *ppl);
static void ssh1_login_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
static unsigned int ssh1_login_winscp_query(PacketProtocolLayer *ppl, int query);

static const struct PacketProtocolLayerVtable ssh1_login_vtable = {
ssh1_login_free,
Expand All @@ -81,6 +82,7 @@ static const struct PacketProtocolLayerVtable ssh1_login_vtable = {
ssh1_login_got_user_input,
ssh1_login_reconfigure,
NULL /* no layer names in SSH-1 */,
ssh1_login_winscp_query,
};

static void ssh1_login_agent_query(struct ssh1_login_state *s, strbuf *req);
Expand Down Expand Up @@ -1187,3 +1189,23 @@ static void ssh1_login_reconfigure(PacketProtocolLayer *ppl, Conf *conf)
container_of(ppl, struct ssh1_login_state, ppl);
ssh_ppl_reconfigure(s->successor_layer, conf);
}

#include <puttyexp.h>

static unsigned int ssh1_login_winscp_query(PacketProtocolLayer *ppl, int query)
{
struct ssh1_login_state *s =
container_of(ppl, struct ssh1_login_state, ppl);
if (query == WINSCP_QUERY_TIMER)
{
return 0;
}
else if (s->successor_layer->vt->winscp_query != NULL)
{
return ssh_ppl_winscp_query(s->successor_layer, query);
}
else
{
return 0;
}
}

0 comments on commit 5a54aaf

Please sign in to comment.