From: Stricted Date: Sat, 20 May 2017 11:00:32 +0000 (+0200) Subject: add login support for v050124.03.05.017 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f896de0c3e5401ee90dc6de0541ed95b28bd03b1;p=GitHub%2FStricted%2FSpeedportHybridControl.git add login support for v050124.03.05.017 --- diff --git a/SpeedportHybridControl/Data/SpeedportHybridAPI.cs b/SpeedportHybridControl/Data/SpeedportHybridAPI.cs index eea95ea..59c9a7c 100644 --- a/SpeedportHybridControl/Data/SpeedportHybridAPI.cs +++ b/SpeedportHybridControl/Data/SpeedportHybridAPI.cs @@ -36,9 +36,10 @@ namespace SpeedportHybridControl.Data * * @return string */ - public string getChallenge() + public string getChallenge_old() { - string response = sendRequest("data/Login.json", "csrf_token=nulltoken&showpw=0&challengev=null"); + /* var challenge = "3FFBFE45EF0B7f76b6BCADD3fccBC5ab07b1aa36EC97Ab690C23F90Fd374c016"; */ + string response = sendRequest("data/Login.json", "csrf_token=nulltoken&showpw=0&challengev=null"); if (response.IsNullOrEmpty()) return string.Empty; @@ -59,14 +60,33 @@ namespace SpeedportHybridControl.Data return challenge; } + public string getChallenge() + { + string response = sendRequest("html/content/overview/index.html"); + if (response.IsNullOrEmpty()) + return string.Empty; - /** + string a = "challenge = \""; + if (response.IndexOf(a) == -1) + { + response = null; + return getChallenge_old(); + } + + string token = response.Substring((response.IndexOf(a) + a.Length), 64); + + response = null; + + return token; + } + + /** * calculate the derivedk * * @param string $password * @return string */ - public string getDerviedk() + public string getDerviedk() { return _password.sha256().pbkdf2(_challenge.Substring(0, 16)); } @@ -90,12 +110,19 @@ namespace SpeedportHybridControl.Data _challenge = getChallenge(); _hash = string.Concat(_challenge, ":", password).sha256(); - string response = sendRequest("data/Login.json", string.Concat("csrf_token=nulltoken&showpw=0&password=", _hash)); + string response = sendRequest("data/Login.json", string.Concat("csrf_token=nulltoken", "&challengev=", _challenge, "&showpw=0&password=", _hash)); if (response.IsNullOrEmpty()) return false; - _cookie.Add(new Cookie("challengev", _challenge) { Domain = "speedport.ip" }); + if (response.IndexOf("challenge") != -1) + { + response = sendRequest("data/Login.json", string.Concat("csrf_token=nulltoken&showpw=0&password=", _hash)); + if (response.IsNullOrEmpty()) + return false; + _cookie.Add(new Cookie("challengev", _challenge) { Domain = _ip }); + } + bool login = false; try {