def test_load_from_json(self):
     json_str = "{\"domain\": \"unit.test\", \"username\": \"testilinius\", " +\
                "\"notes\": \"interesting note\", \"legacyPassword\": \"rtSr?bS,mi\", " +\
                "\"usedCharacters\": \"AEIOUaeiou\", \"iterations\": 5341, " +\
                "\"length\": 16, \"salt\": \"ZmFzY2luYXRpbmc=\", " +\
                "\"cDate\": \"2001-01-01T02:14:12\", \"mDate\": \"2005-01-01T01:14:12\"}"
     s = PasswordSetting(json.loads(json_str)["domain"])
     s.load_from_dict(json.loads(json_str))
     self.assertEquals("unit.test", s.get_domain())
     self.assertEquals("testilinius", s.get_username())
     self.assertEquals("interesting note", s.get_notes())
     self.assertEquals("rtSr?bS,mi", s.get_legacy_password())
     self.assertFalse(s.use_lower_case())
     self.assertFalse(s.use_upper_case())
     self.assertFalse(s.use_digits())
     self.assertFalse(s.use_extra())
     self.assertTrue(s.use_custom_character_set())
     self.assertEquals("AEIOUaeiou", s.get_character_set())
     self.assertEquals(5341, s.get_iterations())
     self.assertEquals(16, s.get_length())
     expected_salt = "fascinating".encode('utf-8')
     self.assertEqual(len(expected_salt), len(s.get_salt()))
     for i in range(len(expected_salt)):
         self.assertEqual(expected_salt[i], s.get_salt()[i])
     self.assertEquals("2001-01-01T02:14:12", s.get_creation_date())
     self.assertEquals("2005-01-01T01:14:12", s.get_modification_date())
 def test_salt(self):
     s = PasswordSetting("unit.test")
     self.assertEqual(32, len(s.get_salt()))
     s.set_salt("somethingelse".encode('utf-8'))
     expected = "somethingelse".encode('utf-8')
     self.assertEqual(len(expected), len(s.get_salt()))
     for i in range(len(expected)):
         self.assertEqual(expected[i], s.get_salt()[i])
 def test_salt(self):
     s = PasswordSetting("unit.test")
     self.assertEqual(32, len(s.get_salt()))
     s.set_salt("somethingelse".encode('utf-8'))
     expected = "somethingelse".encode('utf-8')
     self.assertEqual(len(expected), len(s.get_salt()))
     for i in range(len(expected)):
         self.assertEqual(expected[i], s.get_salt()[i])
 def test_load_from_json(self):
     json_str = "{\"domain\": \"unit.test\", \"username\": \"testilinius\", " +\
                "\"notes\": \"interesting note\", \"legacyPassword\": \"rtSr?bS,mi\", " +\
                "\"extras\": \"AEIOUaeiou\", \"iterations\": 5341, " +\
                "\"passwordTemplate\": \"7;xxxxoxxxxxxxxxxx\", \"salt\": \"ZmFzY2luYXRpbmc=\", " +\
                "\"cDate\": \"2001-01-01T02:14:12.000\", \"mDate\": \"2005-01-01T01:14:12.000\"}"
     s = PasswordSetting(json.loads(json_str)["domain"])
     s.load_from_dict(json.loads(json_str))
     self.assertEqual("unit.test", s.get_domain())
     self.assertEqual("testilinius", s.get_username())
     self.assertEqual("interesting note", s.get_notes())
     self.assertEqual("rtSr?bS,mi", s.get_legacy_password())
     self.assertEqual("AEIOUaeiou", s.get_character_set())
     self.assertEqual(5341, s.get_iterations())
     self.assertEqual("xxxxoxxxxxxxxxxx", s.get_template())
     expected_salt = "fascinating".encode('utf-8')
     self.assertEqual(len(expected_salt), len(s.get_salt()))
     for i in range(len(expected_salt)):
         self.assertEqual(expected_salt[i], s.get_salt()[i])
     self.assertEqual("2001-01-01T02:14:12.000", s.get_creation_date())
     self.assertEqual("2005-01-01T01:14:12.000", s.get_modification_date())
 def test_simple_password_3_tpl(self):
     setting = PasswordSetting('FooBar')
     setting.set_iterations(8192)
     setting.set_template("xxAxxx")
     setting.set_salt('blahfasel'.encode('utf-8'))
     kgk = 'test'.encode('utf-8')
     manager = CtSesam(domain=setting.get_domain(),
                       username=setting.get_username(),
                       kgk=kgk,
                       salt=setting.get_salt(),
                       iterations=setting.get_iterations())
     self.assertEqual(
         unhexlify(
             "309d504d68dc921dcece9d10c14b406673715f15782032d64229b4b42336c8ec860cd9b9451048"
             + "24ce43720b3a088828843df4029fdb8b2314f8b5129c815949"),
         manager.hash_value)
     self.assertEqual("BAELOH", manager.generate(setting))
 def test_pin(self):
     setting = PasswordSetting('Bank')
     setting.set_iterations(1)
     setting.set_extra_character_set("0123456789")
     setting.set_template("oxxx")
     setting.set_salt('pepper'.encode('utf-8'))
     kgk = 'reallysafe'.encode('utf-8')
     manager = CtSesam(domain=setting.get_domain(),
                       username=setting.get_username(),
                       kgk=kgk,
                       salt=setting.get_salt(),
                       iterations=setting.get_iterations())
     self.assertEqual(
         unhexlify(
             "55b5f5cdd9bf2845e339650b4f6e1398cf7fe9ceed087eb5f5bc059882723579fc8ec27443417"
             + "cf33c9763bafac6277fbe991bf27dd0206e78f7d9dfd574167f"),
         manager.hash_value)
     self.assertEqual("7809", manager.generate(setting))
 def test_simple_password_1_tpl(self):
     setting = PasswordSetting('FooBar')
     setting.set_extra_character_set("#!\"$%&/()[]{}=-_+*<>;:.")
     setting.set_iterations(4096)
     setting.set_template("xxoxAxxxxxxxxxaxx")
     setting.set_salt('blahfasel'.encode('utf-8'))
     kgk = 'test'.encode('utf-8')
     manager = CtSesam(domain=setting.get_domain(),
                       username=setting.get_username(),
                       kgk=kgk,
                       salt=setting.get_salt(),
                       iterations=setting.get_iterations())
     self.assertEqual(
         unhexlify(
             "4e9e2503556bda7ad06cf45cab4490213becd3473845a868900fb61fa17d1c448496d11987c4"
             + "446d8007562029cce7f176eda4157604012a44e42add594a524e"),
         manager.hash_value)
     self.assertEqual("pU)VUfgJ-Ws*wgzzE", manager.generate(setting))
 def test_simple_password_4_tpl(self):
     setting = PasswordSetting('FooBar')
     setting.set_iterations(8192)
     setting.set_extra_character_set("0123456789abcdef")
     setting.set_template("xxxxxxxxxxxxxxxxxxxxxxxoxxxx")
     setting.set_salt('SALT'.encode('utf-8'))
     kgk = 'MY_T0P_5ecr57_PA55W0RD ;-)'.encode('utf-8')
     manager = CtSesam(domain=setting.get_domain(),
                       username=setting.get_username(),
                       kgk=kgk,
                       salt=setting.get_salt(),
                       iterations=setting.get_iterations())
     self.assertEqual(
         unhexlify(
             "4993fd21600977c6f56b833eed223dda9b1bd34294afd1db4925553099cce402abda7000a22d2c"
             + "fda152afcf8a3a142e55ce57a9597434a39d05ccd93a853626"),
         manager.hash_value)
     self.assertEqual("626358a39dcc50d93a4347959a75",
                      manager.generate(setting))
 def test_simple_password_2(self):
     setting = PasswordSetting('MyFavoriteDomain')
     setting.set_extra_character_set(
         "abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRTUVWXYZ")
     setting.set_iterations(8192)
     setting.set_template("oxxxxxxxxxxxxxxx")
     setting.set_salt('pepper'.encode('utf-8'))
     kgk = 'foobar'.encode('utf-8')
     manager = CtSesam(domain=setting.get_domain(),
                       username=setting.get_username(),
                       kgk=kgk,
                       salt=setting.get_salt(),
                       iterations=setting.get_iterations())
     self.assertEqual(
         unhexlify(
             "cb0ae7b2b7fc969770a9bfc1eef3a9afd02d2b28d6d8e9cb324f41a31392a0f800ea7e2e43"
             + "e847537ceb863a16a869d5e4dd6822cf3be0206440eff97dc2001c"),
         manager.hash_value)
     self.assertEqual("wLUwoQvKzBaYXbme", manager.generate(setting))
 def test_simple_password_1(self):
     setting = PasswordSetting('ct.de')
     setting.set_extra_character_set(
         "abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNPQRTUVWXYZ0123456789" +
         "#!\"§$%&/()[]{}=-_+*<>;:.")
     setting.set_iterations(4096)
     setting.set_template("oxxxxxxxxx")
     setting.set_salt('pepper'.encode('utf-8'))
     kgk = 'test'.encode('utf-8')
     manager = CtSesam(domain=setting.get_domain(),
                       username=setting.get_username(),
                       kgk=kgk,
                       salt=setting.get_salt(),
                       iterations=setting.get_iterations())
     self.assertEqual(
         unhexlify(
             "f4d54b303b21ee3d8bff9c1eae6f66d90db58c0a5cc770eee322cc59d4dec65793bf8f5dec"
             + "717fd1404bbfacf59befa68c4ad9168bfeaa6a9e28b326a76a82bb"),
         manager.hash_value)
     self.assertEqual("YBVUH=sN/3", manager.generate(setting))