protectedTaskGetUserToken(){// Get the index page of the ubooquity server (not with /opds-comics/)varresponse=awaitClient.GetAsync("comic.server.url");if(response.StatusCode==HttpStatusCode.OK){// Load the html into a DOM class to make parsing the website easier (I'm using library)vardata=awaitresponse.Content.ReadAsStringAsync();vardoc=newHtmlDocument();doc?.LoadHtml(data);// Navigating to the html body of the page. varhtml=doc?.DocumentNode?.ChildNodes.FirstOrDefault(n=>n.Name.Equals("html"));varbody=html?.ChildNodes?.FirstOrDefault(n=>n.Name.Equals("body"));// The login form contains the serversalt and servertime values.varserversalt=body?.ChildNodes?.FirstOrDefault(n=>n.Id.Equals("serversalt"))?.Attributes?.FirstOrDefault(a=>a.Name.Equals("value"))?.Value;varservertime=body?.ChildNodes?.FirstOrDefault(n=>n.Id.Equals("servertime"))?.Attributes?.FirstOrDefault(a=>a.Name.Equals("value"))?.Value;// Hash the password with the server salt and then hash the result with the servertime.varhashed_password=Hash(Hash(Credentials.Password,serversalt),servertime);// Create a HttpRequestvarrequest=newHttpRequestMessage(HttpMethod.Post,"/");// Include the "entered" values for the form in the request.varformData=newList<KeyValuePair<string,string>>{newKeyValuePair<string,string>("servertime",servertime),newKeyValuePair<string,string>("login",Credentials.UserName),newKeyValuePair<string,string>("hash",hashed_password)};request.Content=newFormUrlEncodedContent(formData);// Send the request, the response automatically adds the cookie to Client object and any future// requests through Client.response=awaitClient.SendAsync(request);// var content = await response.Content.ReadAsStringAsync();}}protectedstringHash(stringKey,stringMsg){// Transform strings into binary arrays.varbKey=Key.ToBinaryByteArray();varbMsg=Msg.ToBinaryByteArray();// Create a hasher(?) using the binary key.varhmac=newHMACSHA256(bKey);// Use the hasher to hash the binary message.varhash=hmac.ComputeHash(bMsg);// Encode the hash as a hex string.varbuff=CryptographicBuffer.CreateFromByteArray(hash);varres=CryptographicBuffer.EncodeToHexString(buff);returnres;}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.