libktorrent  2.1.1
encryptedserverauthenticate.h
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef MSEENCRYPTEDSERVERAUTHENTICATE_H
21 #define MSEENCRYPTEDSERVERAUTHENTICATE_H
22 
23 #include <util/sha1hash.h>
24 #include <peer/serverauthenticate.h>
25 #include "bigint.h"
26 
27 namespace mse
28 {
29  class RC4Encryptor;
30 
31 
32  const Uint32 MAX_SEA_BUF_SIZE = 608 + 20 + 20 + 8 + 4 + 2 + 512 + 2 + 68;
36  class EncryptedServerAuthenticate : public bt::ServerAuthenticate
37  {
38  Q_OBJECT
39  public:
40  EncryptedServerAuthenticate(mse::EncryptedPacketSocket::Ptr sock);
41  ~EncryptedServerAuthenticate() override;
42 
43  private Q_SLOTS:
44  void onReadyRead() override;
45 
46  private:
47  void handleYA();
48  void sendYB();
49  void findReq1();
50  void calculateSKey();
51  void processVC();
52  void handlePadC();
53  void handleIA();
54 
55  private:
56  enum State
57  {
58  WAITING_FOR_YA,
59  WAITING_FOR_REQ1,
60  FOUND_REQ1,
61  FOUND_INFO_HASH,
62  WAIT_FOR_PAD_C,
63  WAIT_FOR_IA,
64  NON_ENCRYPTED_HANDSHAKE
65  };
66  BigInt xb,yb,s,ya;
67  bt::SHA1Hash skey,info_hash;
68  State state;
69  Uint8 buf[MAX_SEA_BUF_SIZE];
70  Uint32 buf_size;
71  Uint32 req1_off;
72  Uint32 crypto_provide,crypto_select;
73  Uint16 pad_C_len;
74  Uint16 ia_len;
75  RC4Encryptor* our_rc4;
76  };
77 
78 }
79 
80 #endif
mse::BigInt
Definition: bigint.h:43
bt::SHA1Hash
Stores a SHA1 hash.
Definition: sha1hash.h:41
mse::RC4Encryptor
Definition: rc4encryptor.h:42
bt::ServerAuthenticate
Definition: serverauthenticate.h:54