1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 09:58:01 +00:00

Kimmo Parviainen points out that SSH software version strings have

restrictions on the use of hyphens and spaces.

[originally from svn r4939]
This commit is contained in:
Simon Tatham 2004-12-01 13:37:31 +00:00
parent a10edf435b
commit 22c46786be

81
ssh.c
View File

@ -2067,6 +2067,29 @@ static void ssh_detect_bugs(Ssh ssh, char *vstring)
} }
} }
/*
* The `software version' part of an SSH version string is required
* to contain no spaces or minus signs.
*/
static void ssh_fix_verstring(char *str)
{
/* Eat "SSH-<protoversion>-". */
assert(*str == 'S'); str++;
assert(*str == 'S'); str++;
assert(*str == 'H'); str++;
assert(*str == '-'); str++;
while (*str && *str != '-') str++;
assert(*str == '-'); str++;
/* Convert minus signs and spaces in the remaining string into
* underscores. */
while (*str) {
if (*str == '-' || *str == ' ')
*str = '_';
str++;
}
}
static int do_ssh_init(Ssh ssh, unsigned char c) static int do_ssh_init(Ssh ssh, unsigned char c)
{ {
struct do_ssh_init_state { struct do_ssh_init_state {
@ -2154,46 +2177,58 @@ static int do_ssh_init(Ssh ssh, unsigned char c)
crStop(0); crStop(0);
} }
{
char *verstring;
if (s->proto2 && (ssh->cfg.sshprot >= 2 || !s->proto1)) { if (s->proto2 && (ssh->cfg.sshprot >= 2 || !s->proto1)) {
/* /*
* Use v2 protocol. * Construct a v2 version string.
*/ */
char verstring[80], vlog[100]; verstring = dupprintf("SSH-2.0-%s\n", sshver);
sprintf(verstring, "SSH-2.0-%s", sshver); ssh->version = 2;
SHA_Init(&ssh->exhashbase); } else {
/*
* Construct a v1 version string.
*/
verstring = dupprintf("SSH-%s-%s\n",
(ssh_versioncmp(s->version, "1.5") <= 0 ?
s->version : "1.5"),
sshver);
ssh->version = 1;
}
ssh_fix_verstring(verstring);
if (ssh->version == 2) {
/* /*
* Hash our version string and their version string. * Hash our version string and their version string.
*/ */
sha_string(&ssh->exhashbase, verstring, strlen(verstring)); SHA_Init(&ssh->exhashbase);
sha_string(&ssh->exhashbase, verstring, strlen(verstring)-1);
sha_string(&ssh->exhashbase, s->vstring, strcspn(s->vstring, "\r\n")); sha_string(&ssh->exhashbase, s->vstring, strcspn(s->vstring, "\r\n"));
sprintf(vlog, "We claim version: %s", verstring);
logevent(vlog); /*
strcat(verstring, "\012"); * Initialise SSHv2 protocol.
logevent("Using SSH protocol version 2"); */
sk_write(ssh->s, verstring, strlen(verstring));
ssh->protocol = ssh2_protocol; ssh->protocol = ssh2_protocol;
ssh2_protocol_setup(ssh); ssh2_protocol_setup(ssh);
ssh->version = 2;
ssh->s_rdpkt = ssh2_rdpkt; ssh->s_rdpkt = ssh2_rdpkt;
} else { } else {
/* /*
* Use v1 protocol. * Initialise SSHv1 protocol.
*/ */
char verstring[80], vlog[100];
sprintf(verstring, "SSH-%s-%s",
(ssh_versioncmp(s->version, "1.5") <= 0 ? s->version : "1.5"),
sshver);
sprintf(vlog, "We claim version: %s", verstring);
logevent(vlog);
strcat(verstring, "\012");
logevent("Using SSH protocol version 1");
sk_write(ssh->s, verstring, strlen(verstring));
ssh->protocol = ssh1_protocol; ssh->protocol = ssh1_protocol;
ssh1_protocol_setup(ssh); ssh1_protocol_setup(ssh);
ssh->version = 1;
ssh->s_rdpkt = ssh1_rdpkt; ssh->s_rdpkt = ssh1_rdpkt;
} }
logeventf(ssh, "We claim version: %.*s",
strlen(verstring)-1, verstring);
sk_write(ssh->s, verstring, strlen(verstring));
sfree(verstring);
}
logeventf(ssh, "Using SSH protocol version %d", ssh->version);
update_specials_menu(ssh->frontend); update_specials_menu(ssh->frontend);
ssh->state = SSH_STATE_BEFORE_SIZE; ssh->state = SSH_STATE_BEFORE_SIZE;
ssh->pinger = pinger_new(&ssh->cfg, &ssh_backend, ssh); ssh->pinger = pinger_new(&ssh->cfg, &ssh_backend, ssh);