Esempio n. 1
0
void CSkypeProto::Login()
{
	// login
	m_iStatus = ID_STATUS_CONNECTING;
	requestQueue->Start();
	int tokenExpires(getDword("TokenExpiresIn", 0));

	li.szSkypename = getStringA(SKYPE_SETTINGS_ID);

	pass_ptrA szPassword(getStringA(SKYPE_SETTINGS_PASSWORD));
	if (li.szSkypename == NULL || szPassword == NULL)
	{
		ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
		return;
	}	
	m_bHistorySynced = m_bThreadsTerminated = false;
	if ((tokenExpires - 1800) > time(NULL))
		OnLoginSuccess();
	else
	{
		if (strchr(li.szSkypename, '@'))
			SendRequest(new LoginMSRequest(), &CSkypeProto::OnMSLoginFirst);
		else
			SendRequest(new LoginOAuthRequest(li.szSkypename, szPassword), &CSkypeProto::OnLoginOAuth);
	}
}
Esempio n. 2
0
void CSteamProto::OnGotRsaKey(const HttpResponse *response)
{
	if (!CheckResponse(response))
		return;

	// load rsa key parts
	JSONNode root = JSONNode::parse(response->pData);
	if (!root)
		return;

	if (!root["success"].as_bool())
		return;

	std::string modulus = root["publickey_mod"].as_string();
	// exponent "010001" is used as constant in CSteamProto::RsaEncrypt
	//std::string exponent = root["publickey_exp"].as_string();

	std::string timestamp = root["timestamp"].as_string();

	// encrcrypt password
	ptrA base64RsaEncryptedPassword;
	ptrA szPassword(getStringA("Password"));

	DWORD error = 0;
	DWORD encryptedSize = 0;
	if ((error = RsaEncrypt(modulus.c_str(), szPassword, NULL, encryptedSize)) != 0)
	{
		debugLogA("CSteamProto::OnGotRsaKey: encryption error (%lu)", error);
		return;
	}

	BYTE *encryptedPassword = (BYTE*)mir_calloc(encryptedSize);
	if ((error = RsaEncrypt(modulus.c_str(), szPassword, encryptedPassword, encryptedSize)) != 0)
	{
		debugLogA("CSteamProto::OnGotRsaKey: encryption error (%lu)", error);
		return;
	}

	base64RsaEncryptedPassword = mir_base64_encode(encryptedPassword, encryptedSize);
	mir_free(encryptedPassword);

	// run authorization request
	T2Utf username(getTStringA("Username"));

	ptrA guardId(getStringA("GuardId"));
	if (!guardId) guardId = mir_strdup("");
	ptrA guardCode(getStringA("GuardCode"));
	if (!guardCode) guardCode = mir_strdup("");

	ptrA captchaId(getStringA("CaptchaId"));
	if (!captchaId) captchaId = mir_strdup("-1");
	ptrA captchaText(getStringA("CaptchaText"));
	if (!captchaText) captchaText = mir_strdup("");

	PushRequest(
		new AuthorizationRequest(username, base64RsaEncryptedPassword, timestamp.c_str(), "", guardCode, guardId, captchaId, captchaText),
		&CSteamProto::OnAuthorization);
}
Esempio n. 3
0
void WhatsAppProto::stayConnectedLoop(void*)
{
	ptrA cc(getStringA(WHATSAPP_KEY_CC));
	if (mir_strlen(cc) == 0) {
		NotifyEvent(m_tszUserName, TranslateT("Please enter a country code."), NULL, WHATSAPP_EVENT_CLIENT);
		return;
	}

	ptrA in(getStringA(WHATSAPP_KEY_LOGIN));
	if (mir_strlen(in) == 0) {
		NotifyEvent(m_tszUserName, TranslateT("Please enter a phone number without country code."), NULL, WHATSAPP_EVENT_CLIENT);
		return;
	}

	m_szPhoneNumber = std::string(cc) + std::string(in);
	m_szJid = m_szPhoneNumber + "@s.whatsapp.net";

	ptrA szNick(getStringA(WHATSAPP_KEY_NICK));
	if (mir_strlen(szNick) == 0) {
		NotifyEvent(m_tszUserName, TranslateT("Please enter a nickname."), NULL, WHATSAPP_EVENT_CLIENT);
		return;
	}
	m_szNick = szNick;

	ptrA szPassword(getStringA(WHATSAPP_KEY_PASS));
	if (mir_strlen(szPassword) == 0) {
		NotifyEvent(m_tszUserName, TranslateT("Please enter a password."), NULL, WHATSAPP_EVENT_CLIENT);
		return;
	}

	// -----------------------------
	Mutex writerMutex;
	bool error = false;

	m_pSocket = NULL;

	while (true) {
		if (m_pConnection != NULL) {
			delete m_pConnection;
			m_pConnection = NULL;
		}
		if (m_pSocket != NULL) {
			delete m_pSocket;
			m_pSocket = NULL;
		}

		if (m_iDesiredStatus == ID_STATUS_OFFLINE || error) {
			debugLogA("Set status to offline");
			SetAllContactStatuses(ID_STATUS_OFFLINE, true);
			ToggleStatusMenuItems(false);
			int prevStatus = m_iStatus;
			m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
			ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)prevStatus, m_iStatus);
			break;
		}

		debugLogA("Connecting...");

		try {
			unsigned passLen;
			ptrA passBin((char*)mir_base64_decode(szPassword, &passLen));
			std::string password(passBin, passLen), resource = ACCOUNT_RESOURCE;
			int portNumber;
			if (getByte(WHATSAPP_KEY_SSL, 0))
				portNumber = 443, resource += "-443";
			else
				portNumber = 5222, resource += "-5222";

			m_pSocket = new WASocketConnection("c.whatsapp.net", portNumber);
			m_pConnection = new WAConnection(m_szPhoneNumber, resource, &connMutex, &writerMutex, m_pSocket, this, this);
			{
				WALogin login(m_pConnection, password);

				m_Challenge = login.login(m_Challenge);
				m_pConnection->setLogin(&login);
			}
			m_pConnection->nick = m_szNick;
			if (m_iDesiredStatus != ID_STATUS_INVISIBLE)
				m_pConnection->sendAvailableForChat();

			debugLogA("Set status to online");
			m_iStatus = m_iDesiredStatus;
			ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus);
			ToggleStatusMenuItems(true);

			ForkThread(&WhatsAppProto::ProcessBuddyList, NULL);

			// #TODO Move out of try block. Exception is expected on disconnect
			while (true) {
				m_tLastWriteTime = time(NULL);
				if (!m_pConnection->read())
					break;
			}
			debugLogA("Exit from read-loop");
		}
		catch (WAException &e) {
			debugLogA("Exception: %s", e.what());
			error = true;
		}
		catch (exception &e) {
			debugLogA("Exception: %s", e.what());
			error = true;
		}
		catch (...) {
			debugLogA("Unknown exception");
			error = true;
		}
	}
	debugLogA("Break out from loop");
}