summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/SkypeWeb/SkypeWeb.vcxproj3
-rw-r--r--protocols/SkypeWeb/SkypeWeb.vcxproj.filters9
-rw-r--r--protocols/SkypeWeb/src/requests/oauth.h68
-rw-r--r--protocols/SkypeWeb/src/skype_login.cpp5
-rw-r--r--protocols/SkypeWeb/src/skype_oauth.cpp120
-rw-r--r--protocols/SkypeWeb/src/skype_proto.h5
-rw-r--r--protocols/SkypeWeb/src/stdafx.h1
7 files changed, 205 insertions, 6 deletions
diff --git a/protocols/SkypeWeb/SkypeWeb.vcxproj b/protocols/SkypeWeb/SkypeWeb.vcxproj
index 8809650855..3bebbcf70a 100644
--- a/protocols/SkypeWeb/SkypeWeb.vcxproj
+++ b/protocols/SkypeWeb/SkypeWeb.vcxproj
@@ -47,6 +47,7 @@
<ClInclude Include="src\requests\subscriptions.h" />
<ClInclude Include="src\requests\trouter.h" />
<ClInclude Include="src\requests\mslogin.h" />
+ <ClInclude Include="src\requests\oauth.h" />
<ClInclude Include="src\requests\asm\files.h" />
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/protocols/SkypeWeb/SkypeWeb.vcxproj.filters b/protocols/SkypeWeb/SkypeWeb.vcxproj.filters
index ff284864b2..0f27a7e6bb 100644
--- a/protocols/SkypeWeb/SkypeWeb.vcxproj.filters
+++ b/protocols/SkypeWeb/SkypeWeb.vcxproj.filters
@@ -56,11 +56,14 @@
<ClInclude Include="src\requests\trouter.h">
<Filter>Header Files\requests</Filter>
</ClInclude>
- <ClInclude Include="src\requests\mslogin.h">
+ <ClInclude Include="src\requests\mslogin.h">
<Filter>Header Files\requests</Filter>
</ClInclude>
- <ClInclude Include="src\requests\asm\files.h">
+ <ClInclude Include="src\requests\oauth.h">
+ <Filter>Header Files\requests</Filter>
+ </ClInclude>
+ <ClInclude Include="src\requests\asm\files.h">
<Filter>Header Files\requests\ASM</Filter>
</ClInclude>
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/protocols/SkypeWeb/src/requests/oauth.h b/protocols/SkypeWeb/src/requests/oauth.h
new file mode 100644
index 0000000000..8d011aa797
--- /dev/null
+++ b/protocols/SkypeWeb/src/requests/oauth.h
@@ -0,0 +1,68 @@
+/*
+Copyright (c) 2015-17 Miranda NG project (http://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _SKYPE_REQUEST_OAUTH_H_
+#define _SKYPE_REQUEST_OAUTH_H_
+
+class OAuthRequest : public HttpRequest
+{
+public:
+ OAuthRequest() :
+ HttpRequest(REQUEST_GET, "login.live.com/login.srf")
+ {
+ flags |= NLHRF_REDIRECT;
+
+ Url
+ << CHAR_VALUE("wa", "wsignin1.0")
+ << CHAR_VALUE("wp", "MBI_SSL")
+ << CHAR_VALUE("wreply", "https%3A%2F%2Flw.skype.com%2Flogin%2Foauth%2Fproxy%3Fsite_name%3Dlw.skype.com")
+ << CHAR_VALUE("cobrandid", "90010");
+ }
+
+ OAuthRequest(const char *login, const char *password, const char *cookies, const char *ppft) :
+ HttpRequest(REQUEST_POST, "login.live.com/ppsecure/post.srf")
+ {
+ Url
+ << CHAR_VALUE("wa", "wsignin1.0")
+ << CHAR_VALUE("wp", "MBI_SSL")
+ << CHAR_VALUE("wreply", "https%3A%2F%2Flw.skype.com%2Flogin%2Foauth%2Fproxy%3Fsite_name%3Dlw.skype.com")
+ << CHAR_VALUE("cobrandid", "90010");
+
+ Headers
+ << CHAR_VALUE("Content-Type", "application/x-www-form-urlencoded")
+ << CHAR_VALUE("Cookie", cookies);
+
+ Body
+ << CHAR_VALUE("login", ptrA(mir_urlEncode(login)))
+ << CHAR_VALUE("passwd", ptrA(mir_urlEncode(password)))
+ << CHAR_VALUE("PPFT", ppft);
+ }
+
+ OAuthRequest(const char *t) :
+ HttpRequest(REQUEST_POST, "login.skype.com/login/microsoft")
+ {
+ Headers
+ << CHAR_VALUE ("Content-Type", "application/x-www-form-urlencoded");
+
+ Body
+ << CHAR_VALUE ("t", ptrA(mir_urlEncode(t)))
+ << CHAR_VALUE("site_name", "lw.skype.com")
+ << INT_VALUE ("oauthPartner", 999);
+ }
+};
+
+#endif //_SKYPE_REQUEST_OAUTH_H_
diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp
index fe9a67b680..f33ee5170e 100644
--- a/protocols/SkypeWeb/src/skype_login.cpp
+++ b/protocols/SkypeWeb/src/skype_login.cpp
@@ -37,13 +37,14 @@ void CSkypeProto::Login()
m_bHistorySynced = m_bThreadsTerminated = false;
if ((tokenExpires - 1800) > time(NULL))
OnLoginSuccess();
- else
+ /*else
{
if (strchr(li.szSkypename, '@'))
SendRequest(new LoginMSRequest(), &CSkypeProto::OnMSLoginFirst);
else
SendRequest(new LoginOAuthRequest((char*)li.szSkypename, szPassword), &CSkypeProto::OnLoginOAuth);
- }
+ }*/
+ PushRequest(new OAuthRequest(), &CSkypeProto::OnOAuthStart);
}
void CSkypeProto::OnLoginOAuth(const NETLIBHTTPREQUEST *response)
diff --git a/protocols/SkypeWeb/src/skype_oauth.cpp b/protocols/SkypeWeb/src/skype_oauth.cpp
new file mode 100644
index 0000000000..9926402232
--- /dev/null
+++ b/protocols/SkypeWeb/src/skype_oauth.cpp
@@ -0,0 +1,120 @@
+/*
+Copyright (c) 2015-17 Miranda NG project (http://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+void CSkypeProto::OnOAuthStart(const NETLIBHTTPREQUEST *response)
+{
+ if (response == NULL || response->pData == NULL)
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ std::regex regex;
+ std::smatch match;
+ std::map<std::string, std::string> scookies;
+ std::string content = response->pData;
+
+ regex = "<input type=\"hidden\" name=\"PPFT\" id=\"i0327\" value=\"(.+?)\"/>";
+
+ if (!std::regex_search(content, match, regex))
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+ std::string PPTF = match[1];
+
+ for (int i = 0; i < response->headersCount; i++)
+ {
+ if (mir_strcmpi(response->headers[i].szName, "Set-Cookie"))
+ continue;
+
+ regex = "^(.+?)=(.+?);";
+ content = response->headers[i].szValue;
+ if (std::regex_search(content, match, regex))
+ scookies[match[1]] = match[2];
+ }
+
+ ptrA login(getStringA(SKYPE_SETTINGS_ID));
+ ptrA password(getStringA(SKYPE_SETTINGS_PASSWORD));
+ CMStringA mscookies(FORMAT, "MSPRequ=%s;MSPOK=%s;CkTst=G%lld;", scookies["MSPRequ"].c_str(), scookies["MSPOK"].c_str(), time(NULL));
+
+ PushRequest(new OAuthRequest(login, password, mscookies.c_str(), PPTF.c_str()), &CSkypeProto::OnOAuthAuthorize);
+}
+
+void CSkypeProto::OnOAuthAuthorize(const NETLIBHTTPREQUEST *response)
+{
+ if (response == NULL || response->pData == NULL)
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ std::regex regex;
+ std::smatch match;
+ std::string content = response->pData;
+ ptrA szContent(response->pData);
+
+ regex = "<input type=\"hidden\" name=\"t\" id=\"t\" value=\"(.+?)\">";
+ if (!std::regex_search(content, match, regex))
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+ std::string t = match[1];
+
+ PushRequest(new OAuthRequest(t.c_str()), &CSkypeProto::OnOAuthEnd);
+}
+
+void CSkypeProto::OnOAuthEnd(const NETLIBHTTPREQUEST *response)
+{
+ if (response == NULL || response->pData == NULL)
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ std::regex regex;
+ std::smatch match;
+ std::string content = response->pData;
+
+ regex = "<input type=\"hidden\" name=\"skypetoken\" value=\"(.+?)\"/>";
+ if (!std::regex_search(content, match, regex))
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+ std::string token = match[1];
+ setString("TokenSecret", token.c_str());
+ regex = "<input type=\"hidden\" name=\"expires_in\" value=\"(.+?)\"/>";
+
+ if (std::regex_search(content, match, regex))
+ {
+ std::string expiresIn = match[1];
+ int seconds = atoi(expiresIn.c_str());
+ setDword("TokenExpiresIn", time(NULL) + seconds);
+ }
+
+ OnLoginSuccess();
+} \ No newline at end of file
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h
index fa1feb2635..504ee7b4b0 100644
--- a/protocols/SkypeWeb/src/skype_proto.h
+++ b/protocols/SkypeWeb/src/skype_proto.h
@@ -224,6 +224,11 @@ private:
// options
int __cdecl OnOptionsInit(WPARAM wParam, LPARAM lParam);
+ // oauth
+ void OnOAuthStart(const NETLIBHTTPREQUEST *response);
+ void OnOAuthAuthorize(const NETLIBHTTPREQUEST *response);
+ void OnOAuthEnd(const NETLIBHTTPREQUEST *response);
+
// login
void Login();
void OnMSLoginFirst(const NETLIBHTTPREQUEST *response);
diff --git a/protocols/SkypeWeb/src/stdafx.h b/protocols/SkypeWeb/src/stdafx.h
index ad04ab61e1..5e53f526da 100644
--- a/protocols/SkypeWeb/src/stdafx.h
+++ b/protocols/SkypeWeb/src/stdafx.h
@@ -130,6 +130,7 @@ struct MessageId
#include "requests/chatrooms.h"
#include "requests/trouter.h"
#include "requests/mslogin.h"
+#include "requests/oauth.h"
#include "requests/asm/files.h"
#include "request_queue.h"
#include "skype_proto.h"