diff options
author | George Hazan <ghazan@miranda.im> | 2017-06-05 14:14:54 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-06-05 14:14:54 +0300 |
commit | 9a80a756aa3bee92b85e09466b234c4c26c744b4 (patch) | |
tree | 5e6de095198102dee23e6ea4ba1d96e00c385753 /protocols/MSN/src/msn_auth.cpp | |
parent | 0407b43e6cab29046775ecaf73b31f2a7ee3b95b (diff) |
MSN
- fix for rare crash;
- all pre-MSNP24 code removed
Diffstat (limited to 'protocols/MSN/src/msn_auth.cpp')
-rw-r--r-- | protocols/MSN/src/msn_auth.cpp | 200 |
1 files changed, 99 insertions, 101 deletions
diff --git a/protocols/MSN/src/msn_auth.cpp b/protocols/MSN/src/msn_auth.cpp index 1ef0c8c3bc..a805672f17 100644 --- a/protocols/MSN/src/msn_auth.cpp +++ b/protocols/MSN/src/msn_auth.cpp @@ -146,7 +146,7 @@ static const char authPacket[] = /////////////////////////////////////////////////////////////////////////////////////////
// Tokens, tokens, tokens.....
-GenericToken::GenericToken(const char *pszTokenName):
+GenericToken::GenericToken(const char *pszTokenName) :
m_pszTokenName(pszTokenName),
m_pszToken(NULL),
m_tExpires(0),
@@ -157,7 +157,6 @@ GenericToken::GenericToken(const char *pszTokenName): GenericToken::~GenericToken()
{
mir_free(m_pszToken);
-// mir_free(m_pszRefreshToken);
}
bool GenericToken::Load()
@@ -190,11 +189,11 @@ void GenericToken::Save() bool GenericToken::Expired(time_t t)
{
- return t+3600 >= m_tExpires;
+ return t + 3600 >= m_tExpires;
}
void GenericToken::SetToken(const char *pszToken, time_t tExpires)
-{
+{
replaceStr(m_pszToken, pszToken);
m_tExpires = tExpires;
Save();
@@ -219,7 +218,7 @@ void GenericToken::Clear() m_proto->delSetting(szTokenName);
}
-OAuthToken::OAuthToken(const char *pszTokenName, const char *pszService, bool bPrependT):
+OAuthToken::OAuthToken(const char *pszTokenName, const char *pszService, bool bPrependT) :
GenericToken(pszTokenName),
m_pszService(pszService),
m_bPreprendT(bPrependT)
@@ -244,7 +243,7 @@ bool OAuthToken::Refresh(bool bForce) return true;
}
-SkypeToken::SkypeToken(const char *pszTokenName):
+SkypeToken::SkypeToken(const char *pszTokenName) :
GenericToken(pszTokenName)
{
}
@@ -267,16 +266,17 @@ bool SkypeToken::Refresh(bool bForce) CMStringA szPOST;
if (m_proto->MyOptions.netId == NETID_SKYPE) {
BYTE digest[16];
- char szPassword[100]={0};
+ char szPassword[100] = { 0 };
- int cbPasswd=mir_snprintf(szPassword, sizeof(szPassword), "%s\nskyper\n", m_proto->MyOptions.szEmail);
+ int cbPasswd = mir_snprintf(szPassword, sizeof(szPassword), "%s\nskyper\n", m_proto->MyOptions.szEmail);
if (db_get_static(NULL, m_proto->m_szModuleName, "Password", szPassword + cbPasswd, sizeof(szPassword) - cbPasswd - 1))
return false;
mir_md5_hash((BYTE*)szPassword, mir_strlen(szPassword), digest);
mir_base64_encodebuf(digest, sizeof(digest), szPassword, sizeof(szPassword));
nlhr.szUrl = "https://api.skype.com/login/skypetoken";
szPOST.Format("scopes=client&clientVersion=%s&username=%s&passwordHash=%s", msnProductVer, m_proto->MyOptions.szEmail, szPassword);
- } else {
+ }
+ else {
// Get skype_token
nlhr.szUrl = "https://api.skype.com/rps/skypetoken";
szPOST.Format("scopes=client&clientVersion=%s&access_token=%s&partner=999", msnProductVer, m_proto->authSkypeComToken.Token());
@@ -290,7 +290,7 @@ bool SkypeToken::Refresh(bool bForce) m_proto->mHttpsTS = clock();
bool bRet = false;
- if (nlhrReply) {
+ if (nlhrReply) {
m_proto->hHttpsConnection = nlhrReply->nlc;
if (nlhrReply->resultCode == 200 && nlhrReply->pData) {
@@ -307,7 +307,8 @@ bool SkypeToken::Refresh(bool bForce) }
}
Netlib_FreeHttpRequest(nlhrReply);
- } else m_proto->hHttpsConnection = NULL;
+ }
+ else m_proto->hHttpsConnection = NULL;
return bRet;
}
@@ -316,7 +317,7 @@ const char* SkypeToken::XSkypetoken() Refresh();
if (m_pszToken) {
char *pszRet = strchr(m_pszToken, ' ');
- if (pszRet) return pszRet+1;
+ if (pszRet) return pszRet + 1;
}
return NULL;
}
@@ -401,7 +402,7 @@ int CMsnProto::MSN_GetPassportAuth(void) ezxml_t xml_expires = ezxml_get(tokr, "wst:Lifetime", 0, "wsu:Expires", -1);
time_t expires;
- expires = xml_expires?IsoToUnixTime(ezxml_txt(xml_expires)):time(NULL)+86400;
+ expires = xml_expires ? IsoToUnixTime(ezxml_txt(xml_expires)) : time(NULL) + 86400;
if (mir_strcmp(addr, "http://Passport.NET/tb") == 0) {
@@ -652,10 +653,10 @@ CMStringA CMsnProto::HotmailLogin(const char* url) }
/* 1 - Login successful
- 0 - Login failed
- -1 - Loading Skylogin library failed
- -2 - Functions cannot be loaded from Skylogin library
- -3 - Initializing Skylogin library failed
+ 0 - Login failed
+ -1 - Loading Skylogin library failed
+ -2 - Functions cannot be loaded from Skylogin library
+ -3 - Initializing Skylogin library failed
*/
int CMsnProto::MSN_SkypeAuth(const char *pszNonce, char *pszUIC)
{
@@ -670,8 +671,7 @@ int CMsnProto::MSN_SkypeAuth(const char *pszNonce, char *pszUIC) SkyLogin_SetLogFunction(hLogin, debugLogSkyLoginA, this);
if (!db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword))) {
if (SkyLogin_LoadCredentials(hLogin, MyOptions.szEmail) ||
- SkyLogin_PerformLogin(hLogin, MyOptions.szEmail, szPassword))
- {
+ SkyLogin_PerformLogin(hLogin, MyOptions.szEmail, szPassword)) {
if (SkyLogin_CreateUICString(hLogin, pszNonce, pszUIC))
iRet = 1;
}
@@ -684,7 +684,7 @@ int CMsnProto::MSN_SkypeAuth(const char *pszNonce, char *pszUIC) }
/* 1 - Login successful
- 0 - Login failed
+ 0 - Login failed
*/
int CMsnProto::LoginSkypeOAuth(const char *pRefreshToken)
@@ -697,22 +697,21 @@ int CMsnProto::LoginSkypeOAuth(const char *pRefreshToken) CMStringA szLoginToken;
SkyLogin_SetLogFunction(hLogin, debugLogSkyLoginA, this);
if (RefreshOAuth(pRefreshToken, "service::login.skype.com::MBI_SSL", &szLoginToken, nullptr, nullptr) &&
- SkyLogin_PerformLoginOAuth(hLogin, szLoginToken))
- {
+ SkyLogin_PerformLoginOAuth(hLogin, szLoginToken)) {
char szUIC[1024];
if (SkyLogin_GetCredentialsUIC(hLogin, szUIC)) {
char *pszPartner;
replaceStr(authUIC, szUIC);
iRet = 1;
- if (pszPartner = SkyLogin_GetUser(hLogin))
+ if (pszPartner = SkyLogin_GetUser(hLogin))
setString("SkypePartner", pszPartner);
}
}
else
iRet = 0;
SkyLogin_Exit(hLogin);
- }
+ }
return iRet;
}
@@ -729,10 +728,10 @@ static int CopyCookies(NETLIBHTTPREQUEST *nlhrReply, NETLIBHTTPHEADER *hdr) for (i = 0; i < nlhrReply->headersCount; i++) {
if (mir_strcmpi(nlhrReply->headers[i].szName, "Set-Cookie"))
continue;
- if (p=strchr(nlhrReply->headers[i].szValue, ';')) *p=0;
+ if (p = strchr(nlhrReply->headers[i].szValue, ';')) *p = 0;
if (hdr) {
- if (*hdr->szValue) mir_strcat (hdr->szValue, "; ");
- mir_strcat (hdr->szValue, nlhrReply->headers[i].szValue);
+ if (*hdr->szValue) mir_strcat(hdr->szValue, "; ");
+ mir_strcat(hdr->szValue, nlhrReply->headers[i].szValue);
}
else nSize += (int)mir_strlen(nlhrReply->headers[i].szValue) + 2;
}
@@ -740,7 +739,7 @@ static int CopyCookies(NETLIBHTTPREQUEST *nlhrReply, NETLIBHTTPHEADER *hdr) }
/*
- pszService:
+ pszService:
service::login.skype.com::MBI_SSL - For LoginSkypeOAuth
service::ssl.live.com::MBI_SSL - For ssl-compact-ticket
service::contacts.msn.com::MBI_SSL - Contact SOAP service -> authContactToken
@@ -772,7 +771,7 @@ bool CMsnProto::RefreshOAuth(const char *pszRefreshToken, const char *pszService nlhr.headers[2].szName = "Cookie";
nlhr.headers[2].szValue = authCookies;
post.Format("client_id=00000000480BC46C&scope=%s&grant_type=refresh_token&refresh_token=%s", ptrA(mir_urlEncode(pszService)), pszRefreshToken);
-
+
nlhr.pData = (char*)(const char*)post;
nlhr.dataLength = (int)mir_strlen(nlhr.pData);
nlhr.szUrl = "https://login.live.com/oauth20_token.srf";
@@ -781,7 +780,7 @@ bool CMsnProto::RefreshOAuth(const char *pszRefreshToken, const char *pszService mHttpsTS = clock();
NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(hNetlibUserHttps, &nlhr);
mHttpsTS = clock();
- if (nlhrReply) {
+ if (nlhrReply) {
hHttpsConnection = nlhrReply->nlc;
if (nlhrReply->resultCode == 200 && nlhrReply->pData) {
JSONROOT root(nlhrReply->pData);
@@ -793,7 +792,7 @@ bool CMsnProto::RefreshOAuth(const char *pszRefreshToken, const char *pszService if (pszAccessToken->IsEmpty())
bRet = false;
}
-
+
if (pszOutRefreshToken) {
*pszOutRefreshToken = (*root)["refresh_token"].as_mstring();
if (pszOutRefreshToken->IsEmpty())
@@ -861,7 +860,8 @@ void CMsnProto::SaveAuthTokensDB(void) setString("authRefreshToken", authRefreshToken);
}
-typedef struct {
+typedef struct
+{
/* Internal */
IEEmbed *pEmbed;
/* Input */
@@ -875,16 +875,15 @@ typedef struct { LRESULT CALLBACK AuthWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- switch (uMsg)
- {
- case WM_SIZE:
+ switch (uMsg) {
+ case WM_SIZE:
{
IEAUTH_PARAM *pAuth = (IEAUTH_PARAM*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
if (pAuth && pAuth->pEmbed) pAuth->pEmbed->ResizeBrowser();
return(0);
}
- case WM_CREATE:
+ case WM_CREATE:
{
IEAUTH_PARAM *pAuth = (IEAUTH_PARAM*)((LPCREATESTRUCT)lParam)->lpCreateParams;
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pAuth);
@@ -896,7 +895,7 @@ LRESULT CALLBACK AuthWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar return(0);
}
- case UM_DOCCOMPLETE:
+ case UM_DOCCOMPLETE:
{
if (!lParam) return 1;
IEAUTH_PARAM *pAuth = (IEAUTH_PARAM*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
@@ -929,7 +928,7 @@ LRESULT CALLBACK AuthWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar (pAuth->pszCookies = (char*)mir_alloc(cbCookie))) {
fpInternetGetCookieExA("https://login.live.com", NULL, pAuth->pszCookies, &cbCookie, INTERNET_COOKIE_HTTPONLY, NULL);
}
- else pAuth->pszCookies = mir_u2a(pAuth->pEmbed->getCookies());
+ else pAuth->pszCookies = mir_u2a(pAuth->pEmbed->getCookies());
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
else if (wcsstr((WCHAR*)lParam, L"res=cancel") || wcsstr((WCHAR*)lParam, L"access_denied")) {
@@ -938,12 +937,12 @@ LRESULT CALLBACK AuthWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPar return(0);
}
- case WM_CLOSE:
- DestroyWindow(hwnd);
- PostQuitMessage(0);
- break;
+ case WM_CLOSE:
+ DestroyWindow(hwnd);
+ PostQuitMessage(0);
+ break;
- case WM_DESTROY:
+ case WM_DESTROY:
{
IEAUTH_PARAM *pAuth = (IEAUTH_PARAM*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
if (pAuth && pAuth->pEmbed) delete pAuth->pEmbed;
@@ -960,28 +959,27 @@ void __cdecl CMsnProto::msn_IEAuthThread(void *pParam) {
HWND hWnd;
MSG msg;
- WNDCLASSEX wc={0};
- static const wchar_t *ClassName = L"SkypeLoginWindow";
-
- CoInitialize(NULL);
-
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.cbWndExtra = sizeof(void*);
- wc.hInstance = g_hInst;
- wc.lpfnWndProc = AuthWindowProc;
- wc.lpszClassName = ClassName;
- RegisterClassEx(&wc);
-
- if ((hWnd = CreateWindowEx(0, ClassName, L"MSN Login", WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
- HWND_DESKTOP, NULL, g_hInst, pParam))) {
- ShowWindow( hWnd, SW_SHOW );
- UpdateWindow( hWnd );
-
- while( GetMessage(&msg, NULL, 0, 0) )
- {
- TranslateMessage( &msg );
- DispatchMessage( &msg );
+ WNDCLASSEX wc = { 0 };
+ static const wchar_t *ClassName = L"SkypeLoginWindow";
+
+ CoInitialize(NULL);
+
+ wc.cbSize = sizeof(WNDCLASSEX);
+ wc.cbWndExtra = sizeof(void*);
+ wc.hInstance = g_hInst;
+ wc.lpfnWndProc = AuthWindowProc;
+ wc.lpszClassName = ClassName;
+ RegisterClassEx(&wc);
+
+ if ((hWnd = CreateWindowEx(0, ClassName, L"MSN Login", WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
+ HWND_DESKTOP, NULL, g_hInst, pParam))) {
+ ShowWindow(hWnd, SW_SHOW);
+ UpdateWindow(hWnd);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
}
}
@@ -994,22 +992,23 @@ bool CMsnProto::parseLoginPage(char *pszHTML, NETLIBHTTPREQUEST *nlhr, CMStringA char *pPPFT, *pEnd;
/* Get PPFT */
- if ((pPPFT = strstr(pszHTML, "name=\"PPFT\"")) && (pPPFT = strstr(pPPFT, "value=\"")) && (pEnd=strchr(pPPFT+7, '"'))) {
- *pEnd=0;
- pPPFT+=7;
+ if ((pPPFT = strstr(pszHTML, "name=\"PPFT\"")) && (pPPFT = strstr(pPPFT, "value=\"")) && (pEnd = strchr(pPPFT + 7, '"'))) {
+ *pEnd = 0;
+ pPPFT += 7;
/* Get POST URL if available */
- if ((nlhr->szUrl = strstr(pszHTML, "urlPost:'")) && (pEnd=strchr(nlhr->szUrl+9, '\''))) {
- *pEnd=0;
+ if ((nlhr->szUrl = strstr(pszHTML, "urlPost:'")) && (pEnd = strchr(nlhr->szUrl + 9, '\''))) {
+ *pEnd = 0;
nlhr->szUrl += 9;
- } else nlhr->szUrl = POST_URL;
+ }
+ else nlhr->szUrl = POST_URL;
/* Create POST data */
char szPassword[100];
if (db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword)))
return false;
szPassword[99] = 0;
- post->Format("PPFT=%s&login=%s&passwd=%s", ptrA(mir_urlEncode(pPPFT)),
+ post->Format("PPFT=%s&login=%s&passwd=%s", ptrA(mir_urlEncode(pPPFT)),
ptrA(mir_urlEncode(MyOptions.szEmail)), ptrA(mir_urlEncode(szPassword)));
/* Do the login and get the required tokens */
@@ -1026,54 +1025,54 @@ bool CMsnProto::parseLoginPage(char *pszHTML, NETLIBHTTPREQUEST *nlhr, CMStringA int CMsnProto::MSN_RefreshOAuthTokens(bool bJustCheck)
{
time_t t;
- int i=authMethod==2?0:1, iRet;
- OAuthToken *tokens[] = {&authStrToken, &authContactToken, &authStorageToken, &authSSLToken, &authSkypeComToken};
+ int i = authMethod == 2 ? 0 : 1, iRet;
+ OAuthToken *tokens[] = { &authStrToken, &authContactToken, &authStorageToken, &authSSLToken, &authSkypeComToken };
time(&t);
if (bJustCheck) {
- for (;i<sizeof(tokens)/sizeof(tokens[0]);i++)
+ for (; i < sizeof(tokens) / sizeof(tokens[0]); i++)
if (tokens[i]->Expired(t)) return 1;
return 0;
}
- for (iRet=0;i<sizeof(tokens)/sizeof(tokens[0]);i++) {
+ for (iRet = 0; i < sizeof(tokens) / sizeof(tokens[0]); i++) {
if (tokens[i]->Expired())
- iRet=tokens[i]->Refresh(true)?1:-1;
+ iRet = tokens[i]->Refresh(true) ? 1 : -1;
}
return iRet;
}
-void CMsnProto::MSN_SendATH(ThreadData* info)
+void CMsnProto::MSN_SendATH(ThreadData *info)
{
- if (MyOptions.netId!=NETID_SKYPE) {
+ if (MyOptions.netId != NETID_SKYPE) {
/* MSN account login */
- switch (authMethod)
- {
- case 1:
+ switch (authMethod) {
+ case 1:
info->sendPacketPayload("ATH", "CON\\USER",
"<user><ssl-compact-ticket>t=%s</ssl-compact-ticket>"
"<uic>%s</uic>"
- "<id>%s</id><alias>%s</alias></user>\r\n",
- (const char*)authSSLToken ? ptrA(HtmlEncode(authSSLToken)) : "",
- authUIC,
+ "<id>%s</id><alias>%s</alias></user>\r\n",
+ (const char*)authSSLToken ? ptrA(HtmlEncode(authSSLToken)) : "",
+ authUIC,
GetMyUsername(NETID_MSN), GetMyUsername(NETID_SKYPE));
break;
- case 2:
+ case 2:
info->sendPacketPayload("ATH", "CON\\USER",
"<user><ssl-compact-ticket>%s</ssl-compact-ticket>"
"<uic>%s</uic>"
"<ssl-site-name>chatservice.live.com</ssl-site-name>"
- "</user>\r\n",
+ "</user>\r\n",
(const char*)authStrToken ? ptrA(HtmlEncode(authStrToken)) : "",
authUIC);
break;
}
- } else {
+ }
+ else {
info->sendPacketPayload("ATH", "CON\\USER",
- "<user><uic>%s</uic><id>%s</id></user>\r\n",
+ "<user><uic>%s</uic><id>%s</id></user>\r\n",
authUIC, MyOptions.szEmail);
}
}
@@ -1112,7 +1111,7 @@ int CMsnProto::MSN_AuthOAuth(void) NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(hNetlibUserHttps, &nlhr);
mHttpsTS = clock();
- if (nlhrReply) {
+ if (nlhrReply) {
hHttpsConnection = nlhrReply->nlc;
if (nlhrReply->resultCode == 200 && nlhrReply->pData) {
@@ -1137,11 +1136,11 @@ int CMsnProto::MSN_AuthOAuth(void) NETLIBHTTPREQUEST *nlhrReply2 = Netlib_HttpTransaction(hNetlibUserHttps, &nlhr);
mHttpsTS = clock();
if (nlhrReply2) {
- char *pszURL=NULL, *pAccessToken, *pEnd;
+ char *pszURL = NULL, *pAccessToken, *pEnd;
hHttpsConnection = nlhrReply2->nlc;
bPassportAuth = true;
-
+
if (nlhrReply2->resultCode == 302) {
/* Extract access_token from Location can be found */
for (int i = 0; i < nlhrReply2->headersCount; i++) {
@@ -1156,7 +1155,7 @@ int CMsnProto::MSN_AuthOAuth(void) * window in order to let user login there. May also be used for 2-factor auth */
if (nlhrReply2->resultCode == 200 && nlhrReply2->pData) {
UINT uThreadId;
- IEAUTH_PARAM param = {NULL, this, &nlhr, nlhrReply2, NULL, NULL};
+ IEAUTH_PARAM param = { NULL, this, &nlhr, nlhrReply2, NULL, NULL };
bAskingForAuth = true;
WaitForSingleObject(ForkThreadEx(&CMsnProto::msn_IEAuthThread, ¶m, &uThreadId), INFINITE);
@@ -1273,11 +1272,12 @@ int CMsnProto::MSN_AuthOAuth(void) }
else hHttpsConnection = NULL;
- if (retVal<=0) authSkypeComToken.Clear(); else {
+ if (retVal <= 0) authSkypeComToken.Clear(); else {
if (bPassportAuth) {
// Fast authentication with just 1 SOAP call supported :)
MSN_GetPassportAuth();
- } else {
+ }
+ else {
// Slow authentication required by fetching multiple tokens, i.e. 2-factor auth :(
if (authMethod == 2) authStrToken.Refresh();
authContactToken.Refresh();
@@ -1288,19 +1288,17 @@ int CMsnProto::MSN_AuthOAuth(void) return retVal;
}
-int CMsnProto::GetMyNetID(void)
+int CMsnProto::GetMyNetID(void)
{
- return strchr(MyOptions.szEmail, '@')?NETID_MSN:NETID_SKYPE;
+ return strchr(MyOptions.szEmail, '@') ? NETID_MSN : NETID_SKYPE;
}
const char *CMsnProto::GetMyUsername(int netId)
{
static char szPartner[128];
- if (netId == NETID_SKYPE)
- {
- if (MyOptions.netId==NETID_MSN)
- {
+ if (netId == NETID_SKYPE) {
+ if (MyOptions.netId == NETID_MSN) {
if (db_get_static(NULL, m_szModuleName, "SkypePartner", szPartner, sizeof(szPartner)) == 0)
return szPartner;
}
|