libktorrent  2.2.0
encryptedauthenticate.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 MSEENCRYPTEDAUTHENTICATE_H
21 #define MSEENCRYPTEDAUTHENTICATE_H
22 
23 #include <util/constants.h>
24 #include <util/sha1hash.h>
25 #include <peer/authenticate.h>
26 #include "bigint.h"
27 
28 
29 namespace mse
30 {
31  class RC4Encryptor;
32 
33  const Uint32 MAX_EA_BUF_SIZE = 622 + 512;
34 
41  {
42  Q_OBJECT
43  public:
44  EncryptedAuthenticate(const net::Address & addr,
45  bt::TransportProtocol proto,
46  const bt::SHA1Hash& info_hash,
47  const bt::PeerID& peer_id,
48  bt::PeerConnector::WPtr pcon);
49  ~EncryptedAuthenticate() override;
50 
51  private Q_SLOTS:
52  void connected() override;
53  void onReadyRead() override;
54 
55  private:
56  void handleYB();
57  void handleCryptoSelect();
58  void findVC();
59  void handlePadD();
60 
61  private:
62  enum State
63  {
64  NOT_CONNECTED,
65  SENT_YA,
66  GOT_YB,
67  FOUND_VC,
68  WAIT_FOR_PAD_D,
69  NORMAL_HANDSHAKE
70  };
71 
72  BigInt xa,ya,s,skey,yb;
73  State state;
74  RC4Encryptor* our_rc4;
75  Uint8 buf[MAX_EA_BUF_SIZE];
76  Uint32 buf_size;
77  Uint32 vc_off;
78  Uint32 dec_bytes;
79  bt::SHA1Hash enc,dec;
80  Uint32 crypto_select;
81  Uint16 pad_D_len;
82  Uint32 end_of_crypto_handshake;
83  };
84 
85 }
86 
87 #endif
mse::BigInt
Definition: bigint.h:43
net::Address
Definition: address.h:41
bt::SHA1Hash
Stores a SHA1 hash.
Definition: sha1hash.h:41
mse::EncryptedAuthenticate
Definition: encryptedauthenticate.h:41
bt::PeerID
Definition: peerid.h:33
bt::Authenticate
Authenicate a peer.
Definition: authenticate.h:47
mse::RC4Encryptor
Definition: rc4encryptor.h:42