1 /* 2 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 3 4 SPDX-License-Identifier: GPL-2.0-or-later 5 */ 6 #ifndef MSEENCRYPTEDAUTHENTICATE_H 7 #define MSEENCRYPTEDAUTHENTICATE_H 8 9 #include "bigint.h" 10 #include <peer/authenticate.h> 11 #include <util/constants.h> 12 #include <util/sha1hash.h> 13 14 namespace mse 15 { 16 class RC4Encryptor; 17 18 const Uint32 MAX_EA_BUF_SIZE = 622 + 512; 19 20 /** 21 * @author Joris Guisson <joris.guisson@gmail.com> 22 * 23 * Encrypted version of the Authenticate class 24 */ 25 class EncryptedAuthenticate : public bt::Authenticate 26 { 27 Q_OBJECT 28 public: 29 EncryptedAuthenticate(const net::Address &addr, 30 bt::TransportProtocol proto, 31 const bt::SHA1Hash &info_hash, 32 const bt::PeerID &peer_id, 33 bt::PeerConnector::WPtr pcon); 34 ~EncryptedAuthenticate() override; 35 36 private Q_SLOTS: 37 void connected() override; 38 void onReadyRead() override; 39 40 private: 41 void handleYB(); 42 void handleCryptoSelect(); 43 void findVC(); 44 void handlePadD(); 45 46 private: 47 enum State { 48 NOT_CONNECTED, 49 SENT_YA, 50 GOT_YB, 51 FOUND_VC, 52 WAIT_FOR_PAD_D, 53 NORMAL_HANDSHAKE, 54 }; 55 56 BigInt xa, ya, s, skey, yb; 57 State state; 58 RC4Encryptor *our_rc4; 59 Uint8 buf[MAX_EA_BUF_SIZE]; 60 Uint32 buf_size; 61 Uint32 vc_off; 62 Uint32 dec_bytes; 63 bt::SHA1Hash enc, dec; 64 Uint32 crypto_select; 65 Uint16 pad_D_len; 66 Uint32 end_of_crypto_handshake; 67 }; 68 69 } 70 71 #endif 72