1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*
* WALogin.h
*
* Created on: 26/06/2012
* Author: Antonio
*/
#ifndef WALOGIN_H_
#define WALOGIN_H_
#include "BinTreeNodeReader.h"
#include "BinTreeNodeWriter.h"
#include "WAConnection.h"
#include <string>
#include "../OpenSSL/rc4.h"
#include "../OpenSSL/hmac.h"
class WAConnection;
class BinTreeNodeReader;
class BinTreeNodeWriter;
class KeyStream {
private:
RC4_KEY rc4;
unsigned char key[20], keyMac[20];
int seq;
HMAC_CTX hmac;
void hmacsha1(unsigned char* text, int textLength, unsigned char *out);
public:
KeyStream();
~KeyStream();
void init(unsigned char *_key, unsigned char *_keyMac);
static void keyFromPasswordAndNonce(const std::string &pass, const std::vector<unsigned char>& nonce, unsigned char *out);
void decodeMessage(unsigned char* buffer, int macOffset, int offset, const int length);
void encodeMessage(unsigned char* buffer, int macOffset, int offset, const int length);
};
class WALogin {
private:
WAConnection *m_pConnection;
std::vector<unsigned char>* getAuthBlob(const std::vector<unsigned char>& nonce);
void sendResponse(const std::vector<unsigned char>& challengeData);
void sendFeatures();
void sendAuth(const std::vector<unsigned char>& nonce);
std::vector<unsigned char> readFeaturesUntilChallengeOrSuccess();
void parseSuccessNode(ProtocolTreeNode *node);
std::vector<unsigned char> readSuccess();
public:
time_t m_tExpireDate;
int m_iAccountKind;
std::string m_szPassword;
WALogin(WAConnection* connection, const std::string &password);
~WALogin();
std::vector<unsigned char> login(const std::vector<unsigned char> &blob);
};
#endif /* WALOGIN_H_ */
|