public static void dh(NetworkStream s, StreamReader r, StreamWriter w) { try { // Diffie hellman key exchange on GF(P) // genererate byte[] rand = positive(Convert.FromBase64String(getSalt(128))); BigInteger a = new BigInteger(rand); // send g**secret to the server BigInteger g_a = BigInteger.ModPow(G, a, P); byte[] g_a_byte = g_a.ToByteArray().Reverse().ToArray(); w.WriteLine(base64_encode(g_a_byte)); w.Flush(); BigInteger g_b = new BigInteger(positive(Convert.FromBase64String(r.ReadLine()).Reverse().ToArray())); // read g_b and compute g_b_a // compute g_b_a byte[] secret = BigInteger.ModPow(g_b, a, P).ToByteArray().Reverse().ToArray(); if (secret.Length != 128) { byte[] temp = new byte[128]; Array.Copy(secret, 1, temp, 0, 128); Array.Copy(temp, secret, 128); } SHA256Managed sha = new SHA256Managed(); dh_secret = sha.ComputeHash(secret, 0, 128); } catch (Exception) { // DH error OtherThread.disconnect(); } // DONE DIFFIE HELLMAN }
// Saves the data in user object and close it public void LogOut() { OtherThread.stop(); if (this.user == null) { return; } this.SaveUserProfile(); this.user = null; this.MonthData = null; this.Contactes = null; MainWindow.settingsField = null; MainWindow.ContactesField = null; userPasswrd = ""; }
// Authenticates a user and sets its profile data to user object // Returns : null if the username doesn't exist, false if the password is not correct or true if the authenticathion succeeds public bool?LogIn(String username, String password) { if (this.user != null) { this.LogOut(); } bool?authenRes = this.usersLst.AuthenticateUser(username, password); if (authenRes != true) { return(authenRes); } userPasswrd = password; this.currentUserDataPath = Environment.CurrentDirectory + @"\Data\" + username; this.LoadUserProfile(username); this.LoadMonthData(DateTime.Now.Year, DateTime.Now.Month); this.LoadContactes(); MainWindow.mw.LoadActivities(); OtherThread.start(); return(true); }
public void AddEvenement(Evenement e) { if (this.user == null) { throw new Exception("User account is not loaded"); } if (e.DateDebut.Month == this.MonthData.Month.Month && e.DateDebut.Year == this.MonthData.Month.Year) { this.MonthData.AddEvenement(new DateTime(e.DateDebut.Year, e.DateDebut.Month, e.DateDebut.Day), e); MainWindow.CalendarField.UpdateCalendar(); MainWindow.TachesEventsField.Update(); } else { CalendarInfo ci = new CalendarInfo(this.currentUserDataPath + $"\\MonthData{e.DateDebut.Month}-{e.DateDebut.Year}.json", new DateTime(e.DateDebut.Year, e.DateDebut.Month, 1)); ci.AddEvenement(new DateTime(e.DateDebut.Year, e.DateDebut.Month, e.DateDebut.Day), e); ci.StoreData(); } foreach (Notif n in e.Alarms) { OtherThread.sendData(ConvertToNotification(n, "evenment", e.DateDebut, e.Title)); } }
public void AddTache(Tache t) { if (this.user == null) { throw new Exception("User account is not loaded"); } if (t.dateDebut.Month == this.MonthData.Month.Month && t.dateDebut.Year == this.MonthData.Month.Year) { this.MonthData.AddTache(new DateTime(t.dateDebut.Year, t.dateDebut.Month, t.dateDebut.Day), t); MainWindow.CalendarField.UpdateCalendar(); MainWindow.TachesEventsField.Update(); } else { CalendarInfo ci = new CalendarInfo(this.currentUserDataPath + $"\\MonthData{t.dateDebut.Month}-{t.dateDebut.Year}.json", new DateTime(t.dateDebut.Year, t.dateDebut.Month, 1)); ci.AddTache(new DateTime(t.dateDebut.Year, t.dateDebut.Month, t.dateDebut.Day), t); ci.StoreData(); } foreach (Notif n in t.Alarms) { OtherThread.sendData(ConvertToNotification(n, "tache", t.dateDebut, t.title)); } }
public void exit(object o, ExitEventArgs e) { OtherThread.stop(); }