Changeset 3203


Ignore:
Timestamp:
Sep 27, 2007, 2:43:33 PM (14 years ago)
Author:
charles
Message:

better support of the MSE protocol w.r.t. PadC and PadD

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/handshake.c

    r3184 r3203  
    1717#include <string.h>
    1818#include <stdio.h>
    19 #include <arpa/inet.h>
    2019
    2120#include <sys/types.h> /* event.h needs this */
     
    447446    }
    448447     
    449     /* ENCRYPT(VC, crypto_provide, len(PadC), PadC */
     448    /* ENCRYPT(VC, crypto_provide, len(PadC), PadC
     449     * PadC is reserved for future extensions to the handshake...
     450     * standard practice at this time is for it to be zero-length */
    450451    {
    451452        uint8_t vc[VC_LENGTH] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    452         uint8_t pad[512];
    453         uint16_t i, len;
    454         uint32_t crypto_provide;
    455453
    456454        tr_cryptoEncryptInit( handshake->crypto );
    457        
    458         /* vc */
    459         tr_cryptoEncrypt( handshake->crypto, VC_LENGTH, vc, vc );
    460         evbuffer_add( outbuf, vc, VC_LENGTH );
    461 
    462         /* crypto_provide */
    463         crypto_provide = htonl( getCryptoProvide( handshake ) );
    464         tr_cryptoEncrypt( handshake->crypto, sizeof(crypto_provide), &crypto_provide, &crypto_provide );
    465         evbuffer_add( outbuf, &crypto_provide, sizeof(crypto_provide) );
    466 
    467         /* len(padc) */
    468         i = len = tr_rand( 512 );
    469         i = htons( i );
    470         tr_cryptoEncrypt( handshake->crypto, sizeof(i), &i, &i );
    471         evbuffer_add( outbuf, &i, sizeof(i) );
    472 
    473         /* padc */
    474         for( i=0; i<len; ++i ) pad[i] = tr_rand( UCHAR_MAX );
    475         tr_cryptoEncrypt( handshake->crypto, len, pad, pad );
    476         evbuffer_add( outbuf, pad, len );
     455        tr_peerIoSetEncryption( handshake->io, PEER_ENCRYPTION_RC4 );
     456     
     457        tr_peerIoWriteBytes( handshake->io, outbuf, vc, VC_LENGTH );
     458        tr_peerIoWriteUint32( handshake->io, outbuf, getCryptoProvide( handshake ) );
     459        tr_peerIoWriteUint16( handshake->io, outbuf, 0 );
    477460    }
    478461
    479462    /* ENCRYPT len(IA)), ENCRYPT(IA) */
    480463    {
    481         uint16_t i;
    482         int msgSize;
    483         uint8_t * msg = buildHandshakeMessage( handshake, HANDSHAKE_EXTPREF_LTEP_PREFER, &msgSize );
    484 
    485         i = htons( msgSize );
    486         tr_cryptoEncrypt( handshake->crypto, sizeof(uint16_t), &i, &i );
    487         evbuffer_add( outbuf, &i, sizeof(uint16_t) );
    488 
    489         tr_cryptoEncrypt( handshake->crypto, msgSize, msg, msg );
    490         evbuffer_add( outbuf, msg, HANDSHAKE_SIZE );
     464        int msglen;
     465        uint8_t * msg = buildHandshakeMessage( handshake, HANDSHAKE_EXTPREF_LTEP_PREFER, &msglen );
     466
     467        tr_peerIoWriteUint16( handshake->io, outbuf, msglen );
     468        tr_peerIoWriteBytes( handshake->io, outbuf, msg, msglen );
     469
    491470        handshake->haveSentBitTorrentHandshake = 1;
    492 
    493471        tr_free( msg );
    494472    }
     
    941919
    942920dbgmsg( handshake, "sending pad d" );
    943     /* send pad d */
    944     {
    945         uint8_t pad[PadD_MAXLEN];
    946         const int len = tr_rand( PadD_MAXLEN );
    947         for( i=0; i<len; ++i )
    948             pad[i] = tr_rand( UCHAR_MAX );
     921    /* ENCRYPT(VC, crypto_provide, len(PadC), PadC
     922     * PadD is reserved for future extensions to the handshake...
     923     * standard practice at this time is for it to be zero-length */
     924    {
     925        const int len = 0;
    949926        tr_peerIoWriteUint16( handshake->io, outbuf, len );
    950         tr_peerIoWriteBytes( handshake->io, outbuf, pad, len );
    951927    }
    952928
Note: See TracChangeset for help on using the changeset viewer.