From 11822f442f96b074e5e39bd4cc14d277205a9307 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 2 Jun 2013 18:35:56 +0000 Subject: first version of Wassup that compiles git-svn-id: http://svn.miranda-ng.org/main/trunk@4863 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- .../WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp | 8 ++--- .../WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp | 2 +- protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp | 7 +++-- protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp | 3 +- .../WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp | 3 +- protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp | 4 +-- protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp | 25 ++++------------ protocols/WhatsApp/src/WhatsAPI++/WALogin.h | 5 ++-- protocols/WhatsApp/src/WhatsAPI++/base64.cpp | 2 +- protocols/WhatsApp/src/WhatsAPI++/stdafx.cpp | 8 ----- protocols/WhatsApp/src/WhatsAPI++/stdafx.h | 14 --------- protocols/WhatsApp/src/WhatsAPI++/utilities.cpp | 35 ++++++++-------------- protocols/WhatsApp/src/WhatsAPI++/utilities.h | 3 -- 13 files changed, 37 insertions(+), 82 deletions(-) delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/stdafx.cpp delete mode 100644 protocols/WhatsApp/src/WhatsAPI++/stdafx.h (limited to 'protocols/WhatsApp/src/WhatsAPI++') diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp index 7155334c7f..f7909fa625 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeReader.cpp @@ -4,15 +4,13 @@ * Created on: 26/06/2012 * Author: Antonio */ -#include "stdafx.h" +#include "../common.h" #include "BinTreeNodeReader.h" #include "WAException.h" #include "ProtocolTreeNode.h" #include "utilities.h" #include - - BinTreeNodeReader::BinTreeNodeReader(WAConnection* conn, ISocketConnection* connection, const char** dictionary, const int dictionarysize) { this->conn = conn; this->rawIn = connection; @@ -263,7 +261,7 @@ std::string BinTreeNodeReader::getToken(int token) { return ret; } - + void BinTreeNodeReader::getTopLevelStream() { int stanzaSize; int flags; @@ -276,7 +274,7 @@ void BinTreeNodeReader::getTopLevelStream() { stanzaSize = (size0 << 16) + (size1 << 8) + size2; if (this->buf->size() < (size_t) stanzaSize) { - int newsize = std::max((int) (this->buf->size() * 3 / 2), stanzaSize); + int newsize = max((int) (this->buf->size() * 3 / 2), stanzaSize); delete this->buf; this->buf = new std::vector(newsize); } diff --git a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp index dd35f6a8e7..96ef32f415 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/BinTreeNodeWriter.cpp @@ -4,7 +4,7 @@ * Created on: 26/06/2012 * Author: Antonio */ -#include "stdafx.h" +#include "../common.h" #include "BinTreeNodeWriter.h" #include #include "utilities.h" diff --git a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp b/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp index 44354a4e3d..785c5c2323 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/ByteArray.cpp @@ -4,7 +4,8 @@ * Created on: 26/06/2012 * Author: Antonio */ -#include "stdafx.h" + +#include "../common.h" #include "ByteArray.h" #include "WAException.h" #include @@ -79,7 +80,7 @@ ByteArrayOutputStream::~ByteArrayOutputStream() { ByteArrayInputStream::ByteArrayInputStream(std::vector* buf, size_t off, size_t length ) { this->buf = buf; this->pos = off; - this->count = std::min(off + length, buf->size()); + this->count = min(off + length, buf->size()); } ByteArrayInputStream::ByteArrayInputStream(std::vector* buf) { @@ -114,7 +115,7 @@ int ByteArrayInputStream::read(std::vector& b, size_t off, size_ } b[off + i] = (unsigned char) c; } - } catch (std::exception& ee) { + } catch (std::exception& ) { } return i; } diff --git a/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp b/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp index e50d409ea9..03015e8e11 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/FMessage.cpp @@ -4,7 +4,8 @@ * Created on: 02/07/2012 * Author: Antonio */ -#include "stdafx.h" + +#include "../common.h" #include #include #include diff --git a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp index 0ed60edbb8..c3c75cbd3e 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/ProtocolTreeNode.cpp @@ -4,7 +4,8 @@ * Created on: 26/06/2012 * Author: Antonio */ -#include "stdafx.h" + +#include "../common.h" #include "WAException.h" #include "ProtocolTreeNode.h" diff --git a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp index da5837f682..af1f65d6ae 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WAConnection.cpp @@ -4,13 +4,13 @@ * Created on: 26/06/2012 * Author: Antonio */ -#include "stdafx.h" + +#include "../common.h" #include "WAConnection.h" #include "ProtocolTreeNode.h" #include #include #include "utilities.h" -#include "base64.h" const char* WAConnection::dictionary[] = { "", diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp index 3836a94a3c..578e88c67d 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/WALogin.cpp @@ -5,20 +5,16 @@ * Author: Antonio */ -#include "stdafx.h" +#include "../common.h" #include "WALogin.h" #include "ByteArray.h" //#include "ApplicationData.h" #include "ProtocolTreeNode.h" #include "WAException.h" -#include "base64.h" #include #include #include #include -#include -#include - using namespace Utilities; @@ -68,7 +64,7 @@ BinTreeNodeWriter* WALogin::getTreeNodeWriter() { } std::string WALogin::getResponse(const std::string& challenge) { - unsigned char md5_buffer[/*MD5_DIGEST_SIZE*/ MD5_DIGEST_LENGTH /*#WORKAROUND*/]; + unsigned char md5_buffer[16]; size_t i = challenge.find(WALogin::NONCE_KEY); i += WALogin::NONCE_KEY.length(); @@ -84,8 +80,7 @@ std::string WALogin::getResponse(const std::string& challenge) { _LOGDATA("cinfo = %s", cinfo.c_str()); ByteArrayOutputStream bos; - _LOGDATA((char*) md5digest((unsigned char*) cinfo.data(), cinfo.length(), md5_buffer), MD5_DIGEST_SIZE); - bos.write(md5digest((unsigned char*) cinfo.data(), cinfo.length(), md5_buffer), MD5_DIGEST_SIZE); + bos.write(utils::md5string(cinfo, md5_buffer), SIZEOF(md5_buffer)); bos.write(58); bos.write(nonce); bos.write(58); @@ -95,12 +90,12 @@ std::string WALogin::getResponse(const std::string& challenge) { std::string digest_uri = "xmpp/" + this->domain; std::vector* A1 = bos.toByteArray(); std::string A2 = "AUTHENTICATE:" + digest_uri; - std::string KD((char*) bytesToHex(md5digest(&A1->front(), A1->size(), md5_buffer), MD5_DIGEST_SIZE), MD5_DIGEST_SIZE * 2); - KD += + ":" + nonce + ":" + nc + ":" + cnonce + ":auth:" + std::string((char*) bytesToHex(md5digest((unsigned char*) A2.data(), A2.size(), md5_buffer), MD5_DIGEST_SIZE), MD5_DIGEST_SIZE*2); + std::string KD((char*) bytesToHex(utils::md5string(&A1->front(), (int)A1->size(), md5_buffer), SIZEOF(md5_buffer)), SIZEOF(md5_buffer) * 2); + KD += + ":" + nonce + ":" + nc + ":" + cnonce + ":auth:" + std::string((char*) bytesToHex(utils::md5string(A2, md5_buffer), SIZEOF(md5_buffer)), SIZEOF(md5_buffer)*2); _LOGDATA("KD = %s", KD.c_str()); - std::string response((char*) bytesToHex(md5digest((unsigned char*) KD.data(), KD.size(), md5_buffer), MD5_DIGEST_SIZE), MD5_DIGEST_SIZE*2); + std::string response((char*) bytesToHex(utils::md5string(KD, md5_buffer), SIZEOF(md5_buffer)), SIZEOF(md5_buffer)*2); _LOGDATA("response = %s", response.c_str()); @@ -329,14 +324,6 @@ void KeyStream::encodeMessage(unsigned char* buffer, int macOffset, int offset, } void KeyStream::hmacsha1(unsigned char* text, int textLength, unsigned char *out) { - // CHMAC_SHA1 hmac; - - // hmac.HMAC_SHA1(text, textLength, this->key, this->keyLength, out); - unsigned int mdLength; HMAC(EVP_sha1(), this->key, this->keyLength, text, textLength, out, &mdLength); } - - - - diff --git a/protocols/WhatsApp/src/WhatsAPI++/WALogin.h b/protocols/WhatsApp/src/WhatsAPI++/WALogin.h index 92054abf54..600dc83112 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/WALogin.h +++ b/protocols/WhatsApp/src/WhatsAPI++/WALogin.h @@ -11,10 +11,11 @@ #include "BinTreeNodeReader.h" #include "BinTreeNodeWriter.h" #include "WAConnection.h" -#include -#include #include +#include "../OpenSSL/rc4.h" +#include "../OpenSSL/hmac.h" + class WAConnection; class BinTreeNodeReader; class BinTreeNodeWriter; diff --git a/protocols/WhatsApp/src/WhatsAPI++/base64.cpp b/protocols/WhatsApp/src/WhatsAPI++/base64.cpp index 842ca4aed3..b3ff4fb2e0 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/base64.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/base64.cpp @@ -4,7 +4,7 @@ * Created on: 26/06/2012 * Author: Antonio */ -#include "stdafx.h" +#include "../common.h" #include "base64.h" #include diff --git a/protocols/WhatsApp/src/WhatsAPI++/stdafx.cpp b/protocols/WhatsApp/src/WhatsAPI++/stdafx.cpp deleted file mode 100644 index 8d5b5b5857..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/stdafx.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// stdafx.cpp : Quelldatei, die nur die Standard-Includes einbindet. -// WhatsAPI++.pch ist der vorkompilierte Header. -// stdafx.obj enthält die vorkompilierten Typinformationen. - -#include "stdafx.h" - -// TODO: Auf zusätzliche Header verweisen, die in STDAFX.H -// und nicht in dieser Datei erforderlich sind. diff --git a/protocols/WhatsApp/src/WhatsAPI++/stdafx.h b/protocols/WhatsApp/src/WhatsAPI++/stdafx.h deleted file mode 100644 index 9649140359..0000000000 --- a/protocols/WhatsApp/src/WhatsAPI++/stdafx.h +++ /dev/null @@ -1,14 +0,0 @@ -// stdafx.h : Includedatei für Standardsystem-Includedateien -// oder häufig verwendete projektspezifische Includedateien, -// die nur in unregelmäßigen Abständen geändert werden. -// - -#pragma once - -#include "targetver.h" - -#define WIN32_LEAN_AND_MEAN // Selten verwendete Teile der Windows-Header nicht einbinden. - - - -// TODO: Hier auf zusätzliche Header, die das Programm erfordert, verweisen. diff --git a/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp b/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp index 97b437452b..489d222a66 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp @@ -1,9 +1,8 @@ -#include "stdafx.h" +#include "../common.h" #include "utilities.h" //#include "ApplicationData.h" #include #include -#include #include #include #include @@ -15,8 +14,6 @@ namespace Utilities{ -const int MD5_DIGEST_SIZE = MD5_DIGEST_LENGTH; - const static char digits[] = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , @@ -81,24 +78,18 @@ std::string itoa(int value, unsigned int base) { } -unsigned char* md5digest(unsigned char *bytes, int length, unsigned char* buffer) { - MD5(bytes, length, buffer); - return buffer; -} - - std::string processIdentity(const std::string& id){ std::string buffer_str = reverseString(id); - unsigned char buffer[MD5_DIGEST_LENGTH]; - MD5((unsigned char*) buffer_str.data(), buffer_str.length(), buffer); + BYTE digest[16]; + utils::md5string(buffer_str, digest); buffer_str.clear(); - for(int i =0; i< MD5_DIGEST_LENGTH; i++){ - int tmp = buffer[i]+128; + for(int i =0; i < SIZEOF(digest); i++){ + int tmp = digest[i]+128; int f = tmp & 0xff; - buffer_str=buffer_str.append(itoa(f,16)); + buffer_str = buffer_str.append(itoa(f,16)); } return buffer_str; @@ -226,10 +217,10 @@ unsigned char forDigit(int b) { } string md5String(const string& data) { - unsigned char md5_buffer[Utilities::MD5_DIGEST_SIZE + 1]; - md5_buffer[Utilities::MD5_DIGEST_SIZE] = '\0'; - md5digest((unsigned char*) data.c_str(), data.length(), md5_buffer); - std::string result((char*) Utilities::bytesToHex(md5_buffer, Utilities::MD5_DIGEST_SIZE), Utilities::MD5_DIGEST_SIZE*2); + unsigned char md5_buffer[16+1]; + md5_buffer[16] = '\0'; + utils::md5string(data, md5_buffer); + std::string result((char*) Utilities::bytesToHex(md5_buffer, 16), 16*2); return result; } @@ -284,14 +275,14 @@ vector* loadFileToBytes(const string& path) { bool fileExists(const std::string& path) { std::ifstream in(path.c_str()); - return in; + return in != NULL; } string removeWaDomainFromJid(const string& jid) { string result = jid; - int index = jid.find("@s.whatsapp.net"); + size_t index = jid.find("@s.whatsapp.net"); if (index != string::npos) { result.replace(index, 15, ""); return result; @@ -307,7 +298,7 @@ string removeWaDomainFromJid(const string& jid) { } string getNameFromPath(const std::string& path) { - int i = path.rfind('/'); + size_t i = path.rfind('/'); if (i == string::npos) i = 0; else diff --git a/protocols/WhatsApp/src/WhatsAPI++/utilities.h b/protocols/WhatsApp/src/WhatsAPI++/utilities.h index 48db82b145..1c071471bd 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/utilities.h +++ b/protocols/WhatsApp/src/WhatsAPI++/utilities.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include @@ -47,12 +46,10 @@ using namespace std; namespace Utilities{ extern void configureLogging(const char* ident); extern void closeLog(); - extern const int MD5_DIGEST_SIZE; extern string getCountryCode(); extern string getMcc(); extern string getMnc(); extern string reverseString(const string& str); - extern unsigned char* md5digest(unsigned char *bytes, int length, unsigned char* buffer); extern string processIdentity(const std::string& password); extern int64_t randLong(); extern int64_t absLong(int64_t num); -- cgit v1.2.3