mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +00:00
Further restructuring
[originally from svn r657]
This commit is contained in:
parent
bfec52c1c9
commit
a4a9ccc70b
77
ssh.c
77
ssh.c
@ -263,6 +263,13 @@ static struct rdpkt1_state_tag {
|
|||||||
int chunk;
|
int chunk;
|
||||||
} rdpkt1_state;
|
} rdpkt1_state;
|
||||||
|
|
||||||
|
static struct rdpkt2_state_tag {
|
||||||
|
long len, pad, payload, packetlen, maclen;
|
||||||
|
int i;
|
||||||
|
int cipherblk;
|
||||||
|
unsigned long incoming_sequence;
|
||||||
|
} rdpkt2_state;
|
||||||
|
|
||||||
static int ssh_channelcmp(void *av, void *bv) {
|
static int ssh_channelcmp(void *av, void *bv) {
|
||||||
struct ssh_channel *a = (struct ssh_channel *)av;
|
struct ssh_channel *a = (struct ssh_channel *)av;
|
||||||
struct ssh_channel *b = (struct ssh_channel *)bv;
|
struct ssh_channel *b = (struct ssh_channel *)bv;
|
||||||
@ -425,29 +432,24 @@ next_packet:
|
|||||||
|
|
||||||
static int ssh2_rdpkt(unsigned char **data, int *datalen)
|
static int ssh2_rdpkt(unsigned char **data, int *datalen)
|
||||||
{
|
{
|
||||||
static long len, pad, payload, packetlen, maclen;
|
struct rdpkt2_state_tag *st = &rdpkt2_state;
|
||||||
static int i;
|
|
||||||
static int cipherblk;
|
|
||||||
static unsigned long incoming_sequence = 0;
|
|
||||||
|
|
||||||
crBegin;
|
crBegin;
|
||||||
|
|
||||||
next_packet:
|
next_packet:
|
||||||
|
|
||||||
pktin.type = 0;
|
pktin.type = 0;
|
||||||
pktin.length = 0;
|
pktin.length = 0;
|
||||||
|
if (sccipher)
|
||||||
if (cipher)
|
st->cipherblk = sccipher->blksize;
|
||||||
cipherblk = cipher->blksize;
|
|
||||||
else
|
else
|
||||||
cipherblk = 8;
|
st->cipherblk = 8;
|
||||||
if (cipherblk < 8)
|
if (st->cipherblk < 8)
|
||||||
cipherblk = 8;
|
st->cipherblk = 8;
|
||||||
|
|
||||||
if (pktin.maxlen < cipherblk) {
|
if (pktin.maxlen < st->cipherblk) {
|
||||||
pktin.maxlen = cipherblk;
|
pktin.maxlen = st->cipherblk;
|
||||||
pktin.data = (pktin.data == NULL ? malloc(cipherblk+APIEXTRA) :
|
pktin.data = (pktin.data == NULL ? malloc(st->cipherblk+APIEXTRA) :
|
||||||
realloc(pktin.data, cipherblk+APIEXTRA));
|
realloc(pktin.data, st->cipherblk+APIEXTRA));
|
||||||
if (!pktin.data)
|
if (!pktin.data)
|
||||||
fatalbox("Out of memory");
|
fatalbox("Out of memory");
|
||||||
}
|
}
|
||||||
@ -456,10 +458,10 @@ next_packet:
|
|||||||
* Acquire and decrypt the first block of the packet. This will
|
* Acquire and decrypt the first block of the packet. This will
|
||||||
* contain the length and padding details.
|
* contain the length and padding details.
|
||||||
*/
|
*/
|
||||||
for (i = len = 0; i < cipherblk; i++) {
|
for (st->i = st->len = 0; st->i < st->cipherblk; st->i++) {
|
||||||
while ((*datalen) == 0)
|
while ((*datalen) == 0)
|
||||||
crReturn(cipherblk-i);
|
crReturn(st->cipherblk-st->i);
|
||||||
pktin.data[i] = *(*data)++;
|
pktin.data[st->i] = *(*data)++;
|
||||||
(*datalen)--;
|
(*datalen)--;
|
||||||
}
|
}
|
||||||
#ifdef FWHACK
|
#ifdef FWHACK
|
||||||
@ -468,32 +470,32 @@ next_packet:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (sccipher)
|
if (sccipher)
|
||||||
sccipher->decrypt(pktin.data, cipherblk);
|
sccipher->decrypt(pktin.data, st->cipherblk);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now get the length and padding figures.
|
* Now get the length and padding figures.
|
||||||
*/
|
*/
|
||||||
len = GET_32BIT(pktin.data);
|
st->len = GET_32BIT(pktin.data);
|
||||||
pad = pktin.data[4];
|
st->pad = pktin.data[4];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This enables us to deduce the payload length.
|
* This enables us to deduce the payload length.
|
||||||
*/
|
*/
|
||||||
payload = len - pad - 1;
|
st->payload = st->len - st->pad - 1;
|
||||||
|
|
||||||
pktin.length = payload + 5;
|
pktin.length = st->payload + 5;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* So now we can work out the total packet length.
|
* So now we can work out the total packet length.
|
||||||
*/
|
*/
|
||||||
packetlen = len + 4;
|
st->packetlen = st->len + 4;
|
||||||
maclen = scmac ? scmac->len : 0;
|
st->maclen = scmac ? scmac->len : 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adjust memory allocation if packet is too big.
|
* Adjust memory allocation if packet is too big.
|
||||||
*/
|
*/
|
||||||
if (pktin.maxlen < packetlen+maclen) {
|
if (pktin.maxlen < st->packetlen+st->maclen) {
|
||||||
pktin.maxlen = packetlen+maclen;
|
pktin.maxlen = st->packetlen+st->maclen;
|
||||||
pktin.data = (pktin.data == NULL ? malloc(pktin.maxlen+APIEXTRA) :
|
pktin.data = (pktin.data == NULL ? malloc(pktin.maxlen+APIEXTRA) :
|
||||||
realloc(pktin.data, pktin.maxlen+APIEXTRA));
|
realloc(pktin.data, pktin.maxlen+APIEXTRA));
|
||||||
if (!pktin.data)
|
if (!pktin.data)
|
||||||
@ -503,31 +505,32 @@ next_packet:
|
|||||||
/*
|
/*
|
||||||
* Read and decrypt the remainder of the packet.
|
* Read and decrypt the remainder of the packet.
|
||||||
*/
|
*/
|
||||||
for (i = cipherblk; i < packetlen + maclen; i++) {
|
for (st->i = st->cipherblk; st->i < st->packetlen + st->maclen; st->i++) {
|
||||||
while ((*datalen) == 0)
|
while ((*datalen) == 0)
|
||||||
crReturn(packetlen + maclen - i);
|
crReturn(st->packetlen + st->maclen - st->i);
|
||||||
pktin.data[i] = *(*data)++;
|
pktin.data[st->i] = *(*data)++;
|
||||||
(*datalen)--;
|
(*datalen)--;
|
||||||
}
|
}
|
||||||
/* Decrypt everything _except_ the MAC. */
|
/* Decrypt everything _except_ the MAC. */
|
||||||
if (sccipher)
|
if (sccipher)
|
||||||
sccipher->decrypt(pktin.data + cipherblk, packetlen - cipherblk);
|
sccipher->decrypt(pktin.data + st->cipherblk,
|
||||||
|
st->packetlen - st->cipherblk);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
debug(("Got packet len=%d pad=%d\r\n", len, pad));
|
debug(("Got packet len=%d pad=%d\r\n", st->len, st->pad));
|
||||||
for (i = 0; i < packetlen; i++)
|
for (st->i = 0; st->i < st->packetlen; st->i++)
|
||||||
debug((" %02x", (unsigned char)pktin.data[i]));
|
debug((" %02x", (unsigned char)pktin.data[st->i]));
|
||||||
debug(("\r\n"));
|
debug(("\r\n"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check the MAC.
|
* Check the MAC.
|
||||||
*/
|
*/
|
||||||
if (scmac && !scmac->verify(pktin.data, len+4, incoming_sequence)) {
|
if (scmac && !scmac->verify(pktin.data, st->len+4, st->incoming_sequence)) {
|
||||||
bombout(("Incorrect MAC received on packet"));
|
bombout(("Incorrect MAC received on packet"));
|
||||||
crReturn(0);
|
crReturn(0);
|
||||||
}
|
}
|
||||||
incoming_sequence++; /* whether or not we MACed */
|
st->incoming_sequence++; /* whether or not we MACed */
|
||||||
|
|
||||||
pktin.savedpos = 6;
|
pktin.savedpos = 6;
|
||||||
pktin.type = pktin.data[5];
|
pktin.type = pktin.data[5];
|
||||||
@ -1028,6 +1031,8 @@ static int do_ssh_init(void) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rdpkt2_state.incoming_sequence = 0;
|
||||||
|
|
||||||
*vsp = 0;
|
*vsp = 0;
|
||||||
sprintf(vlog, "Server version: %s", vstring);
|
sprintf(vlog, "Server version: %s", vstring);
|
||||||
vlog[strcspn(vlog, "\r\n")] = '\0';
|
vlog[strcspn(vlog, "\r\n")] = '\0';
|
||||||
|
Loading…
Reference in New Issue
Block a user