/* * 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 #include "../OpenSSL/rc4.h" #include "../OpenSSL/hmac.h" class WAConnection; class BinTreeNodeReader; class BinTreeNodeWriter; class KeyStream { private: RC4_KEY rc4; HMAC_CTX hmac; unsigned char* key; int keyLength; void hmacsha1(unsigned char* text, int textLength, unsigned char *out); public: KeyStream(unsigned char* key, size_t keyLegnth); virtual ~KeyStream(); static void keyFromPasswordAndNonce(const std::string& pass, const std::vector& 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: static const std::string NONCE_KEY; KeyStream* outputKey; WAConnection* connection; BinTreeNodeReader* inn; BinTreeNodeWriter* out; std::vector* getAuthBlob(const std::vector& nonce); void sendResponse(const std::vector& challengeData); void sendFeatures(); void sendAuth(const std::vector& nonce); std::vector* readFeaturesUntilChallengeOrSuccess(); void parseSuccessNode(ProtocolTreeNode* node); std::vector readSuccess(); std::string getResponse(const std::string& challenge); public: std::string user; std::string domain; std::string password; std::string resource; std::string push_name; bool supports_receipt_acks; time_t expire_date; int account_kind; WALogin(WAConnection* connection, BinTreeNodeReader *reader, BinTreeNodeWriter *writer, const std::string& domain, const std::string& user, const std::string& resource, const std::string& password, const std::string& push_name); std::vector* login(const std::vector& blobLength); BinTreeNodeReader *getTreeNodeReader(); BinTreeNodeWriter *getTreeNodeWriter(); virtual ~WALogin(); }; #endif /* WALOGIN_H_ */