public async Task <DeviceFingerPrint> GenerateDeviceFingerPrint(RandomDeviceInfo randomDeviceInfo)
        {
            string deviceFingerPrintRaw = _GenerateDeviceFingerPrintRaw(randomDeviceInfo);

            return(new DeviceFingerPrint(deviceFingerPrintRaw,
                                         await _GetFingerPrintSignature(deviceFingerPrintRaw, randomDeviceInfo),
                                         LoginUtils.GetMD5(deviceFingerPrintRaw)));
        }
Example #2
0
        private async Task <InitialCsrfToken> _GetCsrfToken(DeviceFingerPrint deviceFingerPrint, RandomDeviceInfo randomDeviceInfo)
        {
            // Declare HttpClient
            var httpHandler = new HttpClientHandler()
            {
                CookieContainer = _cookieContainer
            };

            var httpClient = new HttpClient(httpHandler)
            {
                BaseAddress = new Uri("https://login.xunlei.com")
            };

            // Prepare the header
            httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(randomDeviceInfo.userAgent);
            httpClient.DefaultRequestHeaders.Add("Referer", randomDeviceInfo.referrer);

            // Prepare the signature and submit
            string stringContent = string.Format("xl_fp_raw={0}&xl_fp={1}&xl_fp_sign={2}&cachetime={3}",
                                                 deviceFingerPrint.DeviceFingerPrintRaw, deviceFingerPrint.DeviceFingerPrintChecksum,
                                                 deviceFingerPrint.DeviceFingerPrintSingature, DateTimeOffset.Now.ToUnixTimeMilliseconds());

            // Merge into a POST content
            var postContent = new StringContent(stringContent, Encoding.UTF8, "text/plain");

            // Fire the hole!
            var httpResponse = await httpClient.PostAsync(string.Format("/risk?cmd=report",
                                                                        DateTimeOffset.Now.ToUnixTimeMilliseconds().ToString()), postContent);

            // If not successful, return an empty string (to shut up the compiler!)
            if (!httpResponse.IsSuccessStatusCode)
            {
                httpClient.Dispose();

                return(new InitialCsrfToken()
                {
                    ErrorMessage = string.Format("HTTP {0} - {1}", ((int)httpResponse.StatusCode).ToString(),
                                                 httpResponse.ReasonPhrase),

                    IsSuccessful = false
                });
            }

            // Get device ID from cookie container
            // The device ID will be granted by Thunder's server (https://login.xunlei.com/risk?cmd=report)
            // The format of a device ID is something like this:
            //         wdi10.abcabcabcabcabbabcabccabcabceeabcabcaabcabcabcaabcabcaaabcabcabc
            string deviceId = LoginUtils.FindCookieValue(_cookieContainer, "deviceid", "http://xunlei.com");

            // Then we need to get its MD5 hash, substring from it with length 32 (i.e. get the first 32 chars)
            string csrfToken = LoginUtils.GetMD5(deviceId.Substring(0, 32));

            // Dispose the http client and return
            httpClient.Dispose();

            return(new InitialCsrfToken()
            {
                IsSuccessful = true,
                CsrfToken = csrfToken,
                ErrorMessage = string.Empty
            });
        }