Changeset 6987
- Timestamp:
- Oct 29, 2008, 8:18:56 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/handshake.c
r6986 r6987 123 123 AWAITING_PAD_C, 124 124 AWAITING_IA, 125 AWAITING_PAYLOAD_STREAM, 125 126 126 127 /* outgoing */ … … 928 929 { 929 930 int i; 930 const size_t needlen = handshake->ia_len + HANDSHAKE_SIZE;931 const size_t needlen = handshake->ia_len; 931 932 struct evbuffer * outbuf; 932 933 uint32_t crypto_select; … … 938 939 return READ_LATER; 939 940 940 dbgmsg( handshake, "reading IA..." ); 941 /** 942 *** B->A: ENCRYPT(VC, crypto_select, len(padD), padD), ENCRYPT2(Payload 943 ***Stream) 944 **/ 945 946 tr_cryptoEncryptInit( handshake->crypto ); 947 outbuf = evbuffer_new( ); 948 949 dbgmsg( handshake, "sending vc" ); 950 /* send VC */ 951 { 952 uint8_t vc[VC_LENGTH]; 953 memset( vc, 0, VC_LENGTH ); 954 tr_peerIoWriteBytes( handshake->io, outbuf, vc, VC_LENGTH ); 955 } 956 957 /* send crypto_select */ 958 crypto_select = getCryptoSelect( handshake, handshake->crypto_provide ); 959 if( crypto_select ) 960 { 961 dbgmsg( handshake, "selecting crypto mode '%d'", (int)crypto_select ); 962 tr_peerIoWriteUint32( handshake->io, outbuf, crypto_select ); 963 } 964 else 965 { 966 dbgmsg( handshake, "peer didn't offer an encryption mode we like." ); 967 evbuffer_free( outbuf ); 968 return tr_handshakeDone( handshake, FALSE ); 969 } 970 971 dbgmsg( handshake, "sending pad d" ); 972 /* ENCRYPT(VC, crypto_provide, len(PadC), PadC 973 * PadD is reserved for future extensions to the handshake... 974 * standard practice at this time is for it to be zero-length */ 975 { 976 const int len = 0; 977 tr_peerIoWriteUint16( handshake->io, outbuf, len ); 978 } 979 980 /* maybe de-encrypt our connection */ 981 if( crypto_select == CRYPTO_PROVIDE_PLAINTEXT ) 982 tr_peerIoSetEncryption( handshake->io, PEER_ENCRYPTION_NONE ); 983 984 dbgmsg( handshake, "sending handshake" ); 985 /* send our handshake */ 986 { 987 int msgSize; 988 uint8_t * msg = buildHandshakeMessage( handshake, &msgSize ); 989 tr_peerIoWriteBytes( handshake->io, outbuf, msg, msgSize ); 990 handshake->haveSentBitTorrentHandshake = 1; 991 tr_free( msg ); 992 } 993 994 /* send it out */ 995 tr_peerIoWriteBuf( handshake->io, outbuf ); 996 evbuffer_free( outbuf ); 997 998 /* now await the handshake */ 999 setState( handshake, AWAITING_PAYLOAD_STREAM ); 1000 return READ_NOW; 1001 } 1002 1003 static int 1004 readPayloadStream( tr_handshake * handshake, 1005 struct evbuffer * inbuf ) 1006 { 1007 int i; 1008 const size_t needlen = HANDSHAKE_SIZE; 1009 struct evbuffer * outbuf; 1010 1011 dbgmsg( handshake, "reading payload stream... have %d, need %d", 1012 (int)EVBUFFER_LENGTH( inbuf ), (int)needlen ); 1013 if( EVBUFFER_LENGTH( inbuf ) < needlen ) 1014 return READ_LATER; 1015 941 1016 /* parse the handshake ... */ 942 1017 i = parseHandshake( handshake, inbuf ); … … 945 1020 return tr_handshakeDone( handshake, FALSE ); 946 1021 947 /**948 *** B->A: ENCRYPT(VC, crypto_select, len(padD), padD), ENCRYPT2(Payload949 ***Stream)950 **/951 952 tr_cryptoEncryptInit( handshake->crypto );953 outbuf = evbuffer_new( );954 955 dbgmsg( handshake, "sending vc" );956 /* send VC */957 {958 uint8_t vc[VC_LENGTH];959 memset( vc, 0, VC_LENGTH );960 tr_peerIoWriteBytes( handshake->io, outbuf, vc, VC_LENGTH );961 }962 963 /* send crypto_select */964 crypto_select = getCryptoSelect( handshake, handshake->crypto_provide );965 if( crypto_select )966 {967 dbgmsg( handshake, "selecting crypto mode '%d'", (int)crypto_select );968 tr_peerIoWriteUint32( handshake->io, outbuf, crypto_select );969 }970 else971 {972 dbgmsg( handshake, "peer didn't offer an encryption mode we like." );973 evbuffer_free( outbuf );974 return tr_handshakeDone( handshake, FALSE );975 }976 977 dbgmsg( handshake, "sending pad d" );978 /* ENCRYPT(VC, crypto_provide, len(PadC), PadC979 * PadD is reserved for future extensions to the handshake...980 * standard practice at this time is for it to be zero-length */981 {982 const int len = 0;983 tr_peerIoWriteUint16( handshake->io, outbuf, len );984 }985 986 /* maybe de-encrypt our connection */987 if( crypto_select == CRYPTO_PROVIDE_PLAINTEXT )988 tr_peerIoSetEncryption( handshake->io, PEER_ENCRYPTION_NONE );989 990 dbgmsg( handshake, "sending handshake" );991 /* send our handshake */992 {993 int msgSize;994 uint8_t * msg = buildHandshakeMessage( handshake, &msgSize );995 tr_peerIoWriteBytes( handshake->io, outbuf, msg, msgSize );996 handshake->haveSentBitTorrentHandshake = 1;997 tr_free( msg );998 }999 1000 /* send it out */1001 tr_peerIoWriteBuf( handshake->io, outbuf );1002 evbuffer_free( outbuf );1003 1004 1022 /* we've completed the BT handshake... pass the work on to peer-msgs */ 1005 1023 return tr_handshakeDone( handshake, TRUE ); … … 1048 1066 case AWAITING_IA: 1049 1067 ret = readIA ( handshake, inbuf ); break; 1068 1069 case AWAITING_PAYLOAD_STREAM: 1070 ret = readPayloadStream( handshake, inbuf ); break; 1050 1071 1051 1072 case AWAITING_YB:
Note: See TracChangeset
for help on using the changeset viewer.