public Database_mock_up(long remote_pub_key, long remote_shared_key)
 {
     Session_Holder temp_session = new Session_Holder(this, remote_pub_key, remote_shared_key);
     sessionID = temp_session.session_id;
     calculatedKey = db_calculatedKey.convert_list_of_calculatedKey_to_Hashtable(temp_session.calulated_key);
     loginData = temp_session.data;
     _sessions.Add(temp_session);
 }
        public void check_for_unique_pub_keyTest_should_return_false_when_the_same_REMOTE_key_exists()
        {
            DataEntities db = new DataEntities();
            EF_Login_Data_Repository target = new EF_Login_Data_Repository(db);
            target.reset_db();
            Session_Holder session = new Session_Holder(target, _sample_remote_pub_key, _sample_remote_shared_key);
            target.store_session(session);

            Assert.IsFalse(target.check_for_unique_pub_and_shared_key(_sample_remote_pub_key, _sample_remote_shared_key));
        }
        public void check_for_unique_data_stringTest_should_return_false_when_string_is_found_in_db()
        {
            DataEntities db = new DataEntities();
            EF_Login_Data_Repository target = new EF_Login_Data_Repository(db);
            target.reset_db();
            Session_Holder session = new Session_Holder(target, _sample_remote_pub_key, _sample_shared_key);
            target.store_session(session);

            Assert.IsFalse(target.check_for_unique_data_string(session.data));
        }
        public void validateloginTest_should_return_false_when_login_attempt_is_empty()
        {
            Session_Holder target = new Session_Holder();
            target.calulated_key = new List<db_calculatedKey>();
            target.calulated_key.Add(new db_calculatedKey("test", "test_value"));

            Hashtable login_attempt = new Hashtable();

            bool expected = false;
            bool actual;
            actual = target.validate_login(login_attempt);
            Assert.AreEqual(expected, actual);
        }
        public void validateloginTest_should_return_false_when_SessionHolder_contains_no_values()
        {
            Session_Holder target = new Session_Holder();
            target.calulated_key = new List<db_calculatedKey>();

            Hashtable login_attempt = new Hashtable();
            login_attempt.Add("a random thing", "anything");
            login_attempt.Add("sdf", "sdf");

            bool expected = false;
            bool actual;
            actual = target.validate_login(login_attempt);
            Assert.AreEqual(expected, actual);
        }
 private string decrypt_message(Session_Holder session, string message)
 {
     return encryption_wrapper.decrypt_message(_sample_remote_priv_key, _sample_remote_shared_key, message);
 }
 public void store_session(Session_Holder session)
 {
     _db.Session.Add(session);
     _db.SaveChanges();
 }
        public void validateloginTest_should_return_true_when_SessionHolder_contains_alls_same_element_dispite_extra_passed_in_elements()
        {
            Session_Holder target = new Session_Holder();
            target.calulated_key = new List<db_calculatedKey>();
            target.calulated_key.Add(new db_calculatedKey("test", "test_value"));
            target.calulated_key.Add(new db_calculatedKey("a random thing", "anything"));

            Hashtable login_attempt = new Hashtable();
            login_attempt.Add("a random thing", "anything");
            login_attempt.Add("test", "test_value");
            login_attempt.Add("sdf", "sdf");

            bool expected = true;
            bool actual;
            actual = target.validate_login(login_attempt);
            Assert.AreEqual(expected, actual);
        }
        public void validateloginTest_should_return_true_when_login_attempt_from_different_hash_objects()
        {
            Session_Holder target = new Session_Holder();
            string data = "pa2ge_19_text=secretPassword;page_1_button_3=true;";
            target.calulated_key = (new Raw_Data_Builder(data)).Get_Login_Data;

            List<db_calculatedKey> login_attempt = (new Raw_Data_Builder(data)).Get_Login_Data;

            bool expected = true;
            bool actual;
            actual = target.validate_login(db_calculatedKey.convert_list_of_calculatedKey_to_Hashtable(login_attempt));
            Assert.AreEqual(expected, actual);
        }
        public void expire_sessionTest()
        {
            DataEntities db = new DataEntities();
            EF_Login_Data_Repository target = new EF_Login_Data_Repository(db);
            target.reset_db();
            Session_Holder session = new Session_Holder(target, _sample_remote_pub_key, _sample_shared_key);
            target.store_session(session);

            int id = session.session_id;
            Assert.IsFalse(target.get_session(session.session_id).expired);
            target.expire_session(id);
            Assert.IsTrue(target.get_session(session.session_id).expired);
        }
 public void store_session(Session_Holder session)
 {
     _sessions.Add(session);
 }
        public void check_for_unique_pub_keyTest_should_return_false_when_the_same_SERVER_key_exists()
        {
            DataEntities db = new DataEntities();
            EF_Login_Data_Repository target = new EF_Login_Data_Repository(db);
            target.reset_db();
            //Server_keys server_key = new Server_keys(_sample_pub_key, _sample_priv_key, _sample_shared_key);
            //db.server_keys.Add(server_key);
            Session_Holder session = new Session_Holder();
            session.remote_pub_key = _sample_pub_key;
            session.remote_shared_key = _sample_shared_key;
            db.Session.Add(session);
            db.SaveChanges();

            Assert.IsFalse(target.check_for_unique_pub_and_shared_key(_sample_pub_key, _sample_shared_key));
        }
        public void store_sessionTest_should_allow_multiple_sessions_to_be_stored()
        {
            DataEntities db = new DataEntities();
            EF_Login_Data_Repository target = new EF_Login_Data_Repository(db);
            target.reset_db();

            Session_Holder session = new Session_Holder(target, _sample_remote_pub_key, _sample_shared_key);
            target.store_session(session);
            Assert.IsNotNull(target.get_session(session.session_id));

            session = new Session_Holder(target, _sample_remote_pub_key+1, _sample_shared_key+1);
            target.store_session(session);
            Assert.IsNotNull(target.get_session(session.session_id));

            session = new Session_Holder(target, _sample_remote_pub_key + 2, _sample_shared_key + 2);
            target.store_session(session);
            Assert.IsNotNull(target.get_session(session.session_id));
        }
        public void get_sessionTest()
        {
            DataEntities db = new DataEntities();
            EF_Login_Data_Repository target = new EF_Login_Data_Repository(db);
            target.reset_db();
            Session_Holder session = new Session_Holder(target, _sample_remote_pub_key, _sample_shared_key);
            target.store_session(session);

            int id = session.session_id;
            Session_Holder expected = session;
            Session_Holder actual;
            actual = target.get_session(id);
            Assert.AreEqual(expected, actual);
        }
 private string encrypt_message(Session_Holder session, string message)
 {
     return encryption_wrapper.encrypt_message(session.server_key.public_key, session.server_key.shared_key, message);
 }
        //
        // GET: /Authentication/
        //public ActionResult Index()
        //{
        //    return View();
        //}
        //
        // GET: /authentication/initialize?remote_public_key=43235359345345345&shared_key=4325465423452345&
        public ActionResult initialize(long remote_public_key, string shared_key)
        {
            string strHostName = System.Net.Dns.GetHostName();
            string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();

            if (_service_manager.is_ip_locked(clientIPAddress))
            {
                ViewBag.message = "Server has been locked!";
                _service_manager.record_failed_attempt(clientIPAddress);
                save_Service_Manager();
                return View();
            }

            long long_remote_shared_key;
            if (validate_key.validate(shared_key) &&
                Int64.TryParse(validate_key.clean_key(shared_key), out long_remote_shared_key)&&
                _db.check_for_unique_pub_and_shared_key(remote_public_key, long_remote_shared_key) &&
                _db.check_that_initialize_is_not_locked()&&
                long_remote_shared_key > remote_public_key)
            {
                // incoming data seems to be good
            }
            else//somone tried passing in a bad key
            {
                _db.store_failed_initialize_attempt(Convert.ToString(remote_public_key), shared_key);
                _service_manager.record_failed_attempt(clientIPAddress);
                ViewBag.message = "lasdflj2fjlwjefljawlj3";
                save_Service_Manager();
                return View();
            }

            Session_Holder session = new Session_Holder(_db, remote_public_key, long_remote_shared_key);
            _db.store_session(session);
            ViewBag.message = session.encrypted_message;

            save_Service_Manager();
            return View();
        }
        public void check_for_unique_session_idTest_should_return_false_when_id_is_found_in_db()
        {
            DataEntities db = new DataEntities();
            EF_Login_Data_Repository target = new EF_Login_Data_Repository(db);
            target.reset_db();
            Session_Holder session = new Session_Holder(target, _sample_remote_pub_key, _sample_shared_key);
            target.store_session(session);

            int id = session.session_id;
            bool actual;
            actual = target.check_for_unique_session_id(id);
            Assert.IsFalse(actual);
        }