static gboolean poll_file_send_progress(gpointer user_data) { SkypeWebFileTransfer *swft = user_data; SkypeWebAccount *sa = swft->sa; PurpleHttpURL *httpurl; const gchar *host, *path; gchar *headers; httpurl = purple_http_url_parse(swft->url); host = purple_http_url_get_host(httpurl); path = purple_http_url_get_path(httpurl); headers = g_strdup_printf("GET /%s HTTP/1.0\r\n" "Connection: close\r\n" "Cookie: skypetoken_asm=%s\r\n" "Host: %s\r\n" "\r\n\r\n", path, sa->skype_token, host); skypeweb_fetch_url_request(sa, swft->url, TRUE, NULL, FALSE, headers, FALSE, -1, got_file_send_progress, swft); g_free(headers); purple_http_url_free(httpurl); return FALSE; }
static void skypeweb_init_file_download(PurpleXfer *xfer) { SkypeWebFileTransfer *swft; const gchar *view_location; gint64 content_full_length; PurpleHttpURL *httpurl; gchar *headers; swft = purple_xfer_get_protocol_data(xfer); view_location = json_object_get_string_member(swft->info, "view_location"); content_full_length = json_object_get_int_member(swft->info, "content_full_length"); purple_xfer_start(xfer, -1, NULL, 0); httpurl = purple_http_url_parse(view_location); headers = g_strdup_printf("GET /%s HTTP/1.0\r\n" "Connection: close\r\n" "Cookie: skypetoken_asm=%s\r\n" "Host: %s\r\n" "\r\n\r\n", purple_http_url_get_path(httpurl), swft->sa->skype_token, purple_http_url_get_host(httpurl)); skypeweb_fetch_url_request(swft->sa, view_location, TRUE, NULL, FALSE, headers, FALSE, content_full_length, skypeweb_got_file, swft); g_free(headers); purple_http_url_free(httpurl); }
void skypeweb_download_uri_to_conv(SkypeWebAccount *sa, const gchar *uri, PurpleConversation *conv) { gchar *headers; PurpleUtilFetchUrlData *requestdata; PurpleHttpURL *httpurl; httpurl = purple_http_url_parse(uri); headers = g_strdup_printf("GET /%s HTTP/1.0\r\n" "Connection: close\r\n" "Accept: image/*\r\n" "Cookie: skypetoken_asm=%s\r\n" "Host: %s\r\n" "\r\n\r\n", purple_http_url_get_path(httpurl), sa->skype_token, purple_http_url_get_host(httpurl)); requestdata = skypeweb_fetch_url_request(sa, uri, TRUE, NULL, FALSE, headers, FALSE, -1, skypeweb_got_imagemessage, conv); if (requestdata != NULL) requestdata->num_times_redirected = 10; /* Prevent following redirects */ g_free(headers); purple_http_url_free(httpurl); }
void skypeweb_begin_oauth_login(SkypeWebAccount *sa) { const gchar *login_url = "https://" SKYPEWEB_LOGIN_HOST "/login/oauth/microsoft?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com"; skypeweb_fetch_url_request(sa, login_url, TRUE, NULL, FALSE, NULL, TRUE, 524288, skypeweb_login_got_ppft, sa); purple_connection_set_state(sa->pc, PURPLE_CONNECTION_CONNECTING); purple_connection_update_progress(sa->pc, _("Connecting"), 1, 4); }
static void skypeweb_xfer_send_init(PurpleXfer *xfer) { PurpleConnection *pc = purple_account_get_connection(purple_xfer_get_account(xfer)); SkypeWebAccount *sa = purple_connection_get_protocol_data(pc); gchar *basename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); gchar *id, *post, *headers; SkypeWebFileTransfer *swft = purple_xfer_get_protocol_data(xfer); JsonObject *obj = json_object_new(); JsonObject *permissions = json_object_new(); JsonArray *userpermissions = json_array_new(); purple_xfer_set_filename(xfer, basename); purple_xfer_ref(xfer); json_object_set_string_member(obj, "type", "sharing/file"); json_object_set_string_member(obj, "filename", basename); if (SKYPEWEB_BUDDY_IS_MSN(swft->from)) { id = g_strconcat("1:", swft->from, NULL); } else { id = g_strconcat("8:", swft->from, NULL); } json_array_add_string_element(userpermissions, "read"); json_object_set_array_member(permissions, id, userpermissions); json_object_set_object_member(obj, "permissions", permissions); post = skypeweb_jsonobj_to_string(obj); //POST to api.asm.skype.com /v1/objects //{"type":"sharing/file","permissions":{"8:eionrobb":["read"]},"filename":"GiantLobsterMoose.txt"} headers = g_strdup_printf("POST /v1/objects HTTP/1.0\r\n" "Connection: close\r\n" "Authorization: skype_token %s\r\n" //slightly different to normal! "Host: " SKYPEWEB_XFER_HOST "\r\n" "Content-Length: %d\r\n" "Content-Type: application/json\r\n" "\r\n\r\n%s", sa->skype_token, strlen(post), post); skypeweb_fetch_url_request(sa, "https://" SKYPEWEB_XFER_HOST, TRUE, NULL, FALSE, headers, FALSE, -1, skypeweb_got_object_for_file, swft); g_free(post); json_object_unref(obj); g_free(id); g_free(basename); }
static void skypeweb_init_vm_download(PurpleXfer *xfer) { SkypeWebAccount *sa; JsonObject *file = xfer->data; gint64 fileSize; const gchar *url; fileSize = json_object_get_int_member(file, "fileSize"); url = json_object_get_string_member(file, "url"); purple_xfer_set_completed(xfer, FALSE); sa = purple_connection_get_protocol_data(purple_account_get_connection(xfer->account)); skypeweb_fetch_url_request(sa, url, TRUE, NULL, FALSE, NULL, FALSE, fileSize, skypeweb_got_vm_file, xfer); json_object_unref(file); }
static void skypeweb_login_got_t(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message) { SkypeWebAccount *sa = user_data; const gchar *login_url = "https://" SKYPEWEB_LOGIN_HOST;// "/login/oauth?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com"; gchar *request; GString *postdata; gchar *magic_t_value; // T is for tasty sa->url_datas = g_slist_remove(sa->url_datas, url_data); // <input type="hidden" name="t" id="t" value="..."> magic_t_value = skypeweb_string_get_chunk(url_text, len, "=\"t\" value=\"", "\""); if (!magic_t_value) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting Magic T value")); return; } // postdata: t=...&oauthPartner=999&client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com postdata = g_string_new(""); g_string_append_printf(postdata, "t=%s&", purple_url_encode(magic_t_value)); g_string_append(postdata, "oauthPartner=999&"); g_string_append(postdata, "client_id=578134&"); g_string_append(postdata, "redirect_uri=https%3A%2F%2Fweb.skype.com"); // post the t to https://login.skype.com/login/oauth?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com request = g_strdup_printf("POST /login/microsoft?client_id=578134&redirect_uri=https%%3A%%2F%%2Fweb.skype.com HTTP/1.0\r\n" "Connection: close\r\n" "Accept: */*\r\n" "BehaviorOverride: redirectAs404\r\n" "Host: " SKYPEWEB_LOGIN_HOST "\r\n" "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s", strlen(postdata->str), postdata->str); skypeweb_fetch_url_request(sa, login_url, TRUE, NULL, FALSE, request, TRUE, 524288, skypeweb_login_did_auth, sa); g_string_free(postdata, TRUE); g_free(request); g_free(magic_t_value); purple_connection_update_progress(sa->pc, _("Verifying"), 3, 4); }
static void skypeweb_get_icon_now(PurpleBuddy *buddy) { SkypeWebBuddy *sbuddy; gchar *url; purple_debug_info("skypeweb", "getting new buddy icon for %s\n", purple_buddy_get_name(buddy)); sbuddy = purple_buddy_get_protocol_data(buddy); if (sbuddy != NULL && sbuddy->avatar_url && sbuddy->avatar_url[0]) { url = g_strdup(sbuddy->avatar_url); } else { url = g_strdup_printf("https://api.skype.com/users/%s/profile/avatar", purple_url_encode(purple_buddy_get_name(buddy))); } skypeweb_fetch_url_request(sbuddy->sa, url, TRUE, NULL, FALSE, NULL, FALSE, 524288, skypeweb_get_icon_cb, buddy); g_free(url); active_icon_downloads++; }
void skypeweb_present_uri_as_filetransfer(SkypeWebAccount *sa, const gchar *uri, const gchar *from) { PurpleHttpURL *httpurl; const gchar *host; gchar *path; SkypeWebFileTransfer *swft; gchar *headers; httpurl = purple_http_url_parse(uri); host = purple_http_url_get_host(httpurl); if (g_str_has_suffix(uri, "/views/original/status")) { path = g_strconcat(purple_http_url_get_path(httpurl), NULL); } else { path = g_strconcat(purple_http_url_get_path(httpurl), "/views/original/status", NULL); } headers = g_strdup_printf("GET /%s HTTP/1.0\r\n" "Connection: close\r\n" "Cookie: skypetoken_asm=%s\r\n" "Host: %s\r\n" "\r\n\r\n", path, sa->skype_token, host); swft = g_new0(SkypeWebFileTransfer, 1); swft->sa = sa; swft->url = g_strdup(uri); swft->from = g_strdup(from); skypeweb_fetch_url_request(sa, uri, TRUE, NULL, FALSE, headers, FALSE, -1, skypeweb_got_file_info, swft); g_free(path); g_free(headers); purple_http_url_free(httpurl); }
static void skypeweb_login_got_pie(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message) { SkypeWebAccount *sa = user_data; PurpleAccount *account = sa->account; gchar *pie; gchar *etm; const gchar *login_url = "https://" SKYPEWEB_LOGIN_HOST;// "/login?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com"; GString *postdata; gchar *request; struct timeval tv; struct timezone tz; gint tzhours, tzminutes; sa->url_datas = g_slist_remove(sa->url_datas, url_data); if (error_message && *error_message) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, error_message); return; } gettimeofday(&tv, &tz); (void) tv; tzminutes = tz.tz_minuteswest; if (tzminutes < 0) tzminutes = -tzminutes; tzhours = tzminutes / 60; tzminutes -= tzhours * 60; pie = skypeweb_string_get_chunk(url_text, len, "=\"pie\" value=\"", "\""); if (!pie) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting PIE value")); return; } etm = skypeweb_string_get_chunk(url_text, len, "=\"etm\" value=\"", "\""); if (!etm) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting ETM value")); return; } postdata = g_string_new(""); g_string_append_printf(postdata, "username=%s&", purple_url_encode(purple_account_get_username(account))); g_string_append_printf(postdata, "password=%s&", purple_url_encode(purple_account_get_password(account))); g_string_append_printf(postdata, "timezone_field=%c|%d|%d&", (tz.tz_minuteswest < 0 ? '+' : '-'), tzhours, tzminutes); g_string_append_printf(postdata, "pie=%s&", purple_url_encode(pie)); g_string_append_printf(postdata, "etm=%s&", purple_url_encode(etm)); g_string_append_printf(postdata, "js_time=%" G_GINT64_FORMAT "&", skypeweb_get_js_time()); g_string_append(postdata, "client_id=578134&"); g_string_append(postdata, "redirect_uri=https://web.skype.com/"); request = g_strdup_printf("POST /login?client_id=578134&redirect_uri=https%%3A%%2F%%2Fweb.skype.com HTTP/1.0\r\n" "Connection: close\r\n" "Accept: */*\r\n" "BehaviorOverride: redirectAs404\r\n" "Host: " SKYPEWEB_LOGIN_HOST "\r\n" "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s", strlen(postdata->str), postdata->str); skypeweb_fetch_url_request(sa, login_url, TRUE, NULL, FALSE, request, TRUE, 524288, skypeweb_login_did_auth, sa); g_string_free(postdata, TRUE); g_free(request); g_free(pie); g_free(etm); purple_connection_update_progress(sa->pc, _("Authenticating"), 2, 4); }
static void skypeweb_login_got_ppft(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message) { SkypeWebAccount *sa = user_data; const gchar *live_login_url = "https://login.live.com";// "/ppsecure/post.srf?wa=wsignin1.0&wreply=https%3A%2F%2Fsecure.skype.com%2Flogin%2Foauth%2Fproxy%3Fclient_id%3D578134%26redirect_uri%3Dhttps%253A%252F%252Fweb.skype.com"; gchar *msprequ_cookie; gchar *mspok_cookie; gchar *cktst_cookie; gchar *ppft; GString *postdata; gchar *request; sa->url_datas = g_slist_remove(sa->url_datas, url_data); // grab PPFT and cookies (MSPRequ, MSPOK) msprequ_cookie = skypeweb_string_get_chunk(url_text, len, "Set-Cookie: MSPRequ=", ";"); if (!msprequ_cookie) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting MSPRequ cookie")); return; } mspok_cookie = skypeweb_string_get_chunk(url_text, len, "Set-Cookie: MSPOK=", ";"); if (!mspok_cookie) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting MSPOK cookie")); return; } // <input type="hidden" name="PPFT" id="i0327" value="..."/> ppft = skypeweb_string_get_chunk(url_text, len, "name=\"PPFT\" id=\"i0327\" value=\"", "\""); if (!ppft) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting PPFT value")); return; } // CkTst=G + timestamp e.g. G1422309314913 cktst_cookie = g_strdup_printf("G%" G_GINT64_FORMAT, skypeweb_get_js_time()); // postdata: login={username}&passwd={password}&PPFT={ppft value} postdata = g_string_new(""); g_string_append_printf(postdata, "login=%s&", purple_url_encode(purple_account_get_username(sa->account))); g_string_append_printf(postdata, "passwd=%s&", purple_url_encode(purple_account_get_password(sa->account))); g_string_append_printf(postdata, "PPFT=%s&", purple_url_encode(ppft)); // POST to https://login.live.com/ppsecure/post.srf?wa=wsignin1.0&wreply=https%3A%2F%2Fsecure.skype.com%2Flogin%2Foauth%2Fproxy%3Fclient_id%3D578134%26redirect_uri%3Dhttps%253A%252F%252Fweb.skype.com request = g_strdup_printf("POST /ppsecure/post.srf?wa=wsignin1.0&wp=MBI_SSL&wreply=https%%3A%%2F%%2Fsecure.skype.com%%2Flogin%%2Foauth%%2Fproxy%%3Fclient_id%%3D578134%%26redirect_uri%%3Dhttps%%253A%%252F%%252Fweb.skype.com HTTP/1.0\r\n" "Connection: close\r\n" "Accept: */*\r\n" "Host: login.live.com\r\n" "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" "Cookie: MSPRequ=%s;MSPOK=%s;CkTst=%s;\r\n" "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s", msprequ_cookie, mspok_cookie, cktst_cookie, strlen(postdata->str), postdata->str); skypeweb_fetch_url_request(sa, live_login_url, TRUE, NULL, FALSE, request, FALSE, 524288, skypeweb_login_got_t, sa); g_string_free(postdata, TRUE); g_free(request); g_free(msprequ_cookie); g_free(mspok_cookie); g_free(cktst_cookie); g_free(ppft); purple_connection_update_progress(sa->pc, _("Authenticating"), 2, 4); }
static void skypeweb_login_got_t(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message) { SkypeWebAccount *sa = user_data; const gchar *login_url = "https://" SKYPEWEB_LOGIN_HOST;// "/login/oauth?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com"; gchar *request; GString *postdata; gchar *magic_t_value; // T is for tasty sa->url_datas = g_slist_remove(sa->url_datas, url_data); // <input type="hidden" name="t" id="t" value="..."> magic_t_value = skypeweb_string_get_chunk(url_text, len, "=\"t\" value=\"", "\""); if (!magic_t_value) { //No Magic T???? Maybe it be the mighty 2fa-beast if (FALSE) /*if (g_strnstr(url_text, len, "Set-Cookie: LOpt=0;"))*/ { //XX - Would this be better retrieved with JSON decoding the "var ServerData = {...}" code? // <script type="text/javascript">var ServerData = {...};</script> gchar *session_state = skypeweb_string_get_chunk(url_text, len, ":'https://login.live.com/GetSessionState.srf?", "',"); if (session_state) { //These two appear to have different object keys each request :( gchar *PPFT = skypeweb_string_get_chunk(url_text, len, ",sFT:'", "',"); gchar *SLK = skypeweb_string_get_chunk(url_text, len, ",aB:'", "',"); gchar *ppauth_cookie = skypeweb_string_get_chunk(url_text, len, "Set-Cookie: PPAuth=", ";"); gchar *mspok_cookie = skypeweb_string_get_chunk(url_text, len, "Set-Cookie: MSPOK=", "; domain="); //Poll https://login.live.com/GetSessionState.srv?{session_state} to retrieve GIF(!!) of 2fa status //1x1 size GIF means pending, 2x2 rejected, 1x2 approved //Then re-request the MagicT, if approved with a slightly different GET parameters //purpose=eOTT_OneTimePassword&PPFT={ppft}&login={email}&SLK={slk} return; } } purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting Magic T value")); return; } // postdata: t=...&oauthPartner=999&client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com postdata = g_string_new(""); g_string_append_printf(postdata, "t=%s&", purple_url_encode(magic_t_value)); g_string_append(postdata, "site_name=lw.skype.com&"); g_string_append(postdata, "oauthPartner=999&"); g_string_append(postdata, "client_id=578134&"); g_string_append(postdata, "redirect_uri=https%3A%2F%2Fweb.skype.com"); // post the t to https://login.skype.com/login/oauth?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com request = g_strdup_printf("POST /login/microsoft?client_id=578134&redirect_uri=https%%3A%%2F%%2Fweb.skype.com HTTP/1.0\r\n" "Connection: close\r\n" "Accept: */*\r\n" "BehaviorOverride: redirectAs404\r\n" "Host: " SKYPEWEB_LOGIN_HOST "\r\n" "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s", strlen(postdata->str), postdata->str); skypeweb_fetch_url_request(sa, login_url, TRUE, NULL, FALSE, request, TRUE, 524288, skypeweb_login_did_auth, sa); g_string_free(postdata, TRUE); g_free(request); g_free(magic_t_value); purple_connection_update_progress(sa->pc, _("Verifying"), 3, 4); }