| ︙ | | | ︙ | |
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
const static struct ssh_mac *macs[] = {
&ssh_sha1, &ssh_md5, &ssh_mac_none
};
const static struct ssh_mac *buggymacs[] = {
&ssh_sha1_buggy, &ssh_md5, &ssh_mac_none
};
static void ssh_comp_none_init(void)
{
}
static int ssh_comp_none_block(unsigned char *block, int len,
unsigned char **outblock, int *outlen)
{
return 0;
}
static int ssh_comp_none_disable(void)
{
return 0;
}
const static struct ssh_compress ssh_comp_none = {
"none",
ssh_comp_none_init, ssh_comp_none_block,
ssh_comp_none_init, ssh_comp_none_block,
ssh_comp_none_disable
};
extern const struct ssh_compress ssh_zlib;
const static struct ssh_compress *compressions[] = {
&ssh_zlib, &ssh_comp_none
};
enum { /* channel types */
|
>
>
>
>
|
|
|
|
|
|
|
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
const static struct ssh_mac *macs[] = {
&ssh_sha1, &ssh_md5, &ssh_mac_none
};
const static struct ssh_mac *buggymacs[] = {
&ssh_sha1_buggy, &ssh_md5, &ssh_mac_none
};
static void *ssh_comp_none_init(void)
{
return NULL;
}
static void ssh_comp_none_cleanup(void *handle)
{
}
static int ssh_comp_none_block(void *handle, unsigned char *block, int len,
unsigned char **outblock, int *outlen)
{
return 0;
}
static int ssh_comp_none_disable(void *handle)
{
return 0;
}
const static struct ssh_compress ssh_comp_none = {
"none",
ssh_comp_none_init, ssh_comp_none_cleanup, ssh_comp_none_block,
ssh_comp_none_init, ssh_comp_none_cleanup, ssh_comp_none_block,
ssh_comp_none_disable, NULL
};
extern const struct ssh_compress ssh_zlib;
const static struct ssh_compress *compressions[] = {
&ssh_zlib, &ssh_comp_none
};
enum { /* channel types */
|
| ︙ | | | ︙ | |
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
void *v1_cipher_ctx;
void *crcda_ctx;
const struct ssh2_cipher *cscipher, *sccipher;
void *cs_cipher_ctx, *sc_cipher_ctx;
const struct ssh_mac *csmac, *scmac;
void *cs_mac_ctx, *sc_mac_ctx;
const struct ssh_compress *cscomp, *sccomp;
const struct ssh_kex *kex;
const struct ssh_signkey *hostkey;
unsigned char v2_session_id[20];
void *kex_ctx;
char *savedhost;
int savedport;
|
>
|
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
|
void *v1_cipher_ctx;
void *crcda_ctx;
const struct ssh2_cipher *cscipher, *sccipher;
void *cs_cipher_ctx, *sc_cipher_ctx;
const struct ssh_mac *csmac, *scmac;
void *cs_mac_ctx, *sc_mac_ctx;
const struct ssh_compress *cscomp, *sccomp;
void *cs_comp_ctx, *sc_comp_ctx;
const struct ssh_kex *kex;
const struct ssh_signkey *hostkey;
unsigned char v2_session_id[20];
void *kex_ctx;
char *savedhost;
int savedport;
|
| ︙ | | | ︙ | |
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
|
}
ssh->pktin.body = ssh->pktin.data + st->pad + 1;
if (ssh->v1_compressing) {
unsigned char *decompblk;
int decomplen;
zlib_decompress_block(ssh->pktin.body - 1, ssh->pktin.length + 1,
&decompblk, &decomplen);
if (ssh->pktin.maxlen < st->pad + decomplen) {
ssh->pktin.maxlen = st->pad + decomplen;
ssh->pktin.data = srealloc(ssh->pktin.data,
ssh->pktin.maxlen + APIEXTRA);
ssh->pktin.body = ssh->pktin.data + st->pad + 1;
|
>
|
|
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
|
}
ssh->pktin.body = ssh->pktin.data + st->pad + 1;
if (ssh->v1_compressing) {
unsigned char *decompblk;
int decomplen;
zlib_decompress_block(ssh->sc_comp_ctx,
ssh->pktin.body - 1, ssh->pktin.length + 1,
&decompblk, &decomplen);
if (ssh->pktin.maxlen < st->pad + decomplen) {
ssh->pktin.maxlen = st->pad + decomplen;
ssh->pktin.data = srealloc(ssh->pktin.data,
ssh->pktin.maxlen + APIEXTRA);
ssh->pktin.body = ssh->pktin.data + st->pad + 1;
|
| ︙ | | | ︙ | |
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
|
/*
* Decompress packet payload.
*/
{
unsigned char *newpayload;
int newlen;
if (ssh->sccomp &&
ssh->sccomp->decompress(ssh->pktin.data + 5, ssh->pktin.length - 5,
&newpayload, &newlen)) {
if (ssh->pktin.maxlen < newlen + 5) {
ssh->pktin.maxlen = newlen + 5;
ssh->pktin.data = srealloc(ssh->pktin.data,
ssh->pktin.maxlen + APIEXTRA);
}
ssh->pktin.length = 5 + newlen;
|
|
>
|
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
|
/*
* Decompress packet payload.
*/
{
unsigned char *newpayload;
int newlen;
if (ssh->sccomp &&
ssh->sccomp->decompress(ssh->sc_comp_ctx,
ssh->pktin.data + 5, ssh->pktin.length - 5,
&newpayload, &newlen)) {
if (ssh->pktin.maxlen < newlen + 5) {
ssh->pktin.maxlen = newlen + 5;
ssh->pktin.data = srealloc(ssh->pktin.data,
ssh->pktin.maxlen + APIEXTRA);
}
ssh->pktin.length = 5 + newlen;
|
| ︙ | | | ︙ | |
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
|
log_packet(PKT_OUTGOING, ssh->pktout.type, ssh1_pkt_type(ssh->pktout.type),
ssh->pktout.body, ssh->pktout.length);
if (ssh->v1_compressing) {
unsigned char *compblk;
int complen;
zlib_compress_block(ssh->pktout.body - 1, ssh->pktout.length + 1,
&compblk, &complen);
ssh1_pktout_size(ssh, complen - 1);
memcpy(ssh->pktout.body - 1, compblk, complen);
sfree(compblk);
}
len = ssh->pktout.length + 5; /* type and CRC */
|
>
|
|
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
|
log_packet(PKT_OUTGOING, ssh->pktout.type, ssh1_pkt_type(ssh->pktout.type),
ssh->pktout.body, ssh->pktout.length);
if (ssh->v1_compressing) {
unsigned char *compblk;
int complen;
zlib_compress_block(ssh->cs_comp_ctx,
ssh->pktout.body - 1, ssh->pktout.length + 1,
&compblk, &complen);
ssh1_pktout_size(ssh, complen - 1);
memcpy(ssh->pktout.body - 1, compblk, complen);
sfree(compblk);
}
len = ssh->pktout.length + 5; /* type and CRC */
|
| ︙ | | | ︙ | |
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
|
/*
* Compress packet payload.
*/
{
unsigned char *newpayload;
int newlen;
if (ssh->cscomp &&
ssh->cscomp->compress(ssh->pktout.data + 5, ssh->pktout.length - 5,
&newpayload, &newlen)) {
ssh->pktout.length = 5;
ssh2_pkt_adddata(ssh, newpayload, newlen);
sfree(newpayload);
}
}
|
>
|
|
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
|
/*
* Compress packet payload.
*/
{
unsigned char *newpayload;
int newlen;
if (ssh->cscomp &&
ssh->cscomp->compress(ssh->cs_comp_ctx, ssh->pktout.data + 5,
ssh->pktout.length - 5,
&newpayload, &newlen)) {
ssh->pktout.length = 5;
ssh2_pkt_adddata(ssh, newpayload, newlen);
sfree(newpayload);
}
}
|
| ︙ | | | ︙ | |
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
|
bombout(("Protocol confusion"));
crReturnV;
} else if (ssh->pktin.type == SSH1_SMSG_FAILURE) {
c_write_str(ssh, "Server refused to compress\r\n");
}
logevent("Started compression");
ssh->v1_compressing = TRUE;
zlib_compress_init();
zlib_decompress_init();
}
/*
* Start the shell or command.
*
* Special case: if the first-choice command is an SSH2
* subsystem (hence not usable here) and the second choice
|
|
>
|
>
|
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
|
bombout(("Protocol confusion"));
crReturnV;
} else if (ssh->pktin.type == SSH1_SMSG_FAILURE) {
c_write_str(ssh, "Server refused to compress\r\n");
}
logevent("Started compression");
ssh->v1_compressing = TRUE;
ssh->cs_comp_ctx = zlib_compress_init();
logevent("Initialised zlib (RFC1950) compression");
ssh->sc_comp_ctx = zlib_decompress_init();
logevent("Initialised zlib (RFC1950) decompression");
}
/*
* Start the shell or command.
*
* Special case: if the first-choice command is an SSH2
* subsystem (hence not usable here) and the second choice
|
| ︙ | | | ︙ | |
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
|
ssh->cs_mac_ctx = ssh->csmac->make_context();
if (ssh->sc_mac_ctx)
ssh->scmac->free_context(ssh->sc_mac_ctx);
ssh->scmac = s->scmac_tobe;
ssh->sc_mac_ctx = ssh->scmac->make_context();
ssh->cscomp = s->cscomp_tobe;
ssh->sccomp = s->sccomp_tobe;
ssh->cscomp->compress_init();
ssh->sccomp->decompress_init();
/*
* Set IVs after keys. Here we use the exchange hash from the
* _first_ key exchange.
*/
{
unsigned char keyspace[40];
if (s->first_kex)
|
>
>
>
>
>
>
|
|
|
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
|
ssh->cs_mac_ctx = ssh->csmac->make_context();
if (ssh->sc_mac_ctx)
ssh->scmac->free_context(ssh->sc_mac_ctx);
ssh->scmac = s->scmac_tobe;
ssh->sc_mac_ctx = ssh->scmac->make_context();
if (ssh->cs_comp_ctx)
ssh->cscomp->compress_cleanup(ssh->cs_comp_ctx);
ssh->cscomp = s->cscomp_tobe;
ssh->cs_comp_ctx = ssh->cscomp->compress_init();
if (ssh->sc_comp_ctx)
ssh->sccomp->decompress_cleanup(ssh->sc_comp_ctx);
ssh->sccomp = s->sccomp_tobe;
ssh->sc_comp_ctx = ssh->sccomp->decompress_init();
/*
* Set IVs after keys. Here we use the exchange hash from the
* _first_ key exchange.
*/
{
unsigned char keyspace[40];
if (s->first_kex)
|
| ︙ | | | ︙ | |
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
|
char buf[256];
sprintf(buf, "Initialised %.200s client->server encryption",
ssh->cscipher->text_name);
logevent(buf);
sprintf(buf, "Initialised %.200s server->client encryption",
ssh->sccipher->text_name);
logevent(buf);
}
/*
* If this is the first key exchange phase, we must pass the
* SSH2_MSG_NEWKEYS packet to the next layer, not because it
* wants to see it but because it will need time to initialise
|
>
>
>
>
>
>
>
>
>
>
|
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
|
char buf[256];
sprintf(buf, "Initialised %.200s client->server encryption",
ssh->cscipher->text_name);
logevent(buf);
sprintf(buf, "Initialised %.200s server->client encryption",
ssh->sccipher->text_name);
logevent(buf);
if (ssh->cscomp->text_name) {
sprintf(buf, "Initialised %.200s compression",
ssh->cscomp->text_name);
logevent(buf);
}
if (ssh->sccomp->text_name) {
sprintf(buf, "Initialised %.200s decompression",
ssh->sccomp->text_name);
logevent(buf);
}
}
/*
* If this is the first key exchange phase, we must pass the
* SSH2_MSG_NEWKEYS packet to the next layer, not because it
* wants to see it but because it will need time to initialise
|
| ︙ | | | ︙ | |
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
|
* so we can guarantee to get this string
* exactly the length we want it. The
* compression-disabling routine should
* return an integer indicating how many
* bytes we should adjust our string length
* by.
*/
stringlen -= ssh->cscomp->disable_compression();
}
ssh2_pkt_init(ssh, SSH2_MSG_IGNORE);
ssh2_pkt_addstring_start(ssh);
for (i = 0; i < stringlen; i++) {
char c = (char) random_byte();
ssh2_pkt_addstring_data(ssh, &c, 1);
}
|
>
|
|
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
|
* so we can guarantee to get this string
* exactly the length we want it. The
* compression-disabling routine should
* return an integer indicating how many
* bytes we should adjust our string length
* by.
*/
stringlen -=
ssh->cscomp->disable_compression(ssh->cs_comp_ctx);
}
ssh2_pkt_init(ssh, SSH2_MSG_IGNORE);
ssh2_pkt_addstring_start(ssh);
for (i = 0; i < stringlen; i++) {
char c = (char) random_byte();
ssh2_pkt_addstring_data(ssh, &c, 1);
}
|
| ︙ | | | ︙ | |
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
|
ssh->sccipher = NULL;
ssh->sc_cipher_ctx = NULL;
ssh->csmac = NULL;
ssh->sc_mac_ctx = NULL;
ssh->scmac = NULL;
ssh->sc_mac_ctx = NULL;
ssh->cscomp = NULL;
ssh->sccomp = NULL;
ssh->kex = NULL;
ssh->hostkey = NULL;
ssh->exitcode = -1;
ssh->state = SSH_STATE_PREPACKET;
ssh->size_needed = FALSE;
ssh->eof_needed = FALSE;
{
|
>
>
|
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
|
ssh->sccipher = NULL;
ssh->sc_cipher_ctx = NULL;
ssh->csmac = NULL;
ssh->sc_mac_ctx = NULL;
ssh->scmac = NULL;
ssh->sc_mac_ctx = NULL;
ssh->cscomp = NULL;
ssh->cs_comp_ctx = NULL;
ssh->sccomp = NULL;
ssh->sc_comp_ctx = NULL;
ssh->kex = NULL;
ssh->hostkey = NULL;
ssh->exitcode = -1;
ssh->state = SSH_STATE_PREPACKET;
ssh->size_needed = FALSE;
ssh->eof_needed = FALSE;
{
|
| ︙ | | | ︙ | |