Diff

Differences From Artifact [2c3857dac9]:

To Artifact [8332414fab]:


2092
2093
2094
2095
2096
2097
2098
2099

2100
2101
2102
2103
2104
2105
2106

2107
2108
2109
2110
2111
2112
2113
2092
2093
2094
2095
2096
2097
2098

2099
2100
2101
2102
2103
2104
2105

2106
2107
2108
2109
2110
2111
2112
2113







-
+






-
+







        haylen--, haystack++;          /* skip over comma itself */
    }
}

/*
 * SSH2 key creation method.
 */
static void ssh2_mkkey(Bignum K, char *H, char chr, char *keyspace) {
static void ssh2_mkkey(Bignum K, char *H, char *sessid, char chr, char *keyspace) {
    SHA_State s;
    /* First 20 bytes. */
    SHA_Init(&s);
    sha_mpint(&s, K);
    SHA_Bytes(&s, H, 20);
    SHA_Bytes(&s, &chr, 1);
    SHA_Bytes(&s, H, 20);
    SHA_Bytes(&s, sessid, 20);
    SHA_Final(&s, keyspace);
    /* Next 20 bytes. */
    SHA_Init(&s);
    sha_mpint(&s, K);
    SHA_Bytes(&s, H, 20);
    SHA_Bytes(&s, keyspace, 20);
    SHA_Final(&s, keyspace+20);
2129
2130
2131
2132
2133
2134
2135

2136
2137
2138
2139
2140
2141
2142
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143







+







    static const struct ssh_mac *scmac_tobe = NULL;
    static const struct ssh_compress *cscomp_tobe = NULL;
    static const struct ssh_compress *sccomp_tobe = NULL;
    static char *hostkeydata, *sigdata, *keystr, *fingerprint;
    static int hostkeylen, siglen;
    static void *hkey;		       /* actual host key */
    static unsigned char exchange_hash[20];
    static unsigned char first_exchange_hash[20];
    static unsigned char keyspace[40];
    static const struct ssh_cipher *preferred_cipher;
    static const struct ssh_compress *preferred_comp;
    static int first_kex;

    crBegin;
    random_init();
2385
2386
2387
2388
2389
2390
2391

2392
2393



2394
2395
2396
2397
2398
2399
2400
2386
2387
2388
2389
2390
2391
2392
2393


2394
2395
2396
2397
2398
2399
2400
2401
2402
2403







+
-
-
+
+
+







     * Authenticate remote host: verify host key. (We've already
     * checked the signature of the exchange hash.)
     */
    keystr = hostkey->fmtkey(hkey);
    fingerprint = hostkey->fingerprint(hkey);
    verify_ssh_host_key(savedhost, savedport, hostkey->keytype,
                        keystr, fingerprint);
    if (first_kex) {		       /* don't bother logging this in rekeys */
    logevent("Host key fingerprint is:");
    logevent(fingerprint);
	logevent("Host key fingerprint is:");
	logevent(fingerprint);
    }
    sfree(fingerprint);
    sfree(keystr);
    hostkey->freekey(hkey);

    /*
     * Send SSH2_MSG_NEWKEYS.
     */
2409
2410
2411
2412
2413
2414
2415
2416


2417



2418
2419
2420
2421
2422
2423











2424
2425
2426
2427
2428
2429
2430
2412
2413
2414
2415
2416
2417
2418

2419
2420
2421
2422
2423
2424






2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442







-
+
+

+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+







    csmac = csmac_tobe;
    scmac = scmac_tobe;
    cscomp = cscomp_tobe;
    sccomp = sccomp_tobe;
    cscomp->compress_init();
    sccomp->decompress_init();
    /*
     * Set IVs after keys.
     * Set IVs after keys. Here we use the exchange hash from the
     * _first_ key exchange.
     */
    if (first_kex)
	memcpy(first_exchange_hash, exchange_hash, sizeof(exchange_hash));
    ssh2_mkkey(K, exchange_hash, first_exchange_hash, 'C', keyspace);
    ssh2_mkkey(K, exchange_hash, 'C', keyspace); cscipher->setcskey(keyspace);
    ssh2_mkkey(K, exchange_hash, 'D', keyspace); sccipher->setsckey(keyspace);
    ssh2_mkkey(K, exchange_hash, 'A', keyspace); cscipher->setcsiv(keyspace);
    ssh2_mkkey(K, exchange_hash, 'B', keyspace); sccipher->setsciv(keyspace);
    ssh2_mkkey(K, exchange_hash, 'E', keyspace); csmac->setcskey(keyspace);
    ssh2_mkkey(K, exchange_hash, 'F', keyspace); scmac->setsckey(keyspace);
    cscipher->setcskey(keyspace);
    ssh2_mkkey(K, exchange_hash, first_exchange_hash, 'D', keyspace);
    sccipher->setsckey(keyspace);
    ssh2_mkkey(K, exchange_hash, first_exchange_hash, 'A', keyspace);
    cscipher->setcsiv(keyspace);
    ssh2_mkkey(K, exchange_hash, first_exchange_hash, 'B', keyspace);
    sccipher->setsciv(keyspace);
    ssh2_mkkey(K, exchange_hash, first_exchange_hash, 'E', keyspace);
    csmac->setcskey(keyspace);
    ssh2_mkkey(K, exchange_hash, first_exchange_hash, 'F', keyspace);
    scmac->setsckey(keyspace);

    /*
     * 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
     * itself before it sees an actual packet. In subsequent key
     * exchange phases, we don't pass SSH2_MSG_NEWKEYS on, because
2440
2441
2442
2443
2444
2445
2446

2447
2448
2449
2450
2451
2452
2453
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466







+







     * function so that other things can run on top of the
     * transport. If we ever see a KEXINIT, we must go back to the
     * start.
     */
    do {
        crReturn(1);
    } while (!(ispkt && pktin.type == SSH2_MSG_KEXINIT));
    logevent("Server initiated key re-exchange");
    goto begin_key_exchange;

    crFinish(1);
}

/*
 * Add data to an SSH2 channel output buffer.