コード例 #1
0
 def test_to_json(self):
     s = PasswordSetting("unit.test")
     s.set_modification_date("2005-01-01T01:14:12")
     s.set_creation_date("2001-01-01T02:14:12")
     s.set_salt("something".encode('utf-8'))
     s.set_iterations(213)
     s.set_template("xxxxxxxxxxoxxx")
     s.set_extra_character_set("XVLCWKHGFQUIAEOSNRTDYÜÖÄPZBMJ")
     s.set_notes("Some note.")
     self.assertIn("domain", s.to_dict())
     self.assertEqual("unit.test", s.to_dict()["domain"])
     self.assertIn("cDate", s.to_dict())
     self.assertEqual("2001-01-01T02:14:12", s.to_dict()["cDate"])
     self.assertIn("mDate", s.to_dict())
     self.assertEqual("2005-01-01T01:14:12", s.to_dict()["mDate"])
     self.assertIn("salt", s.to_dict())
     self.assertEqual(str(b64encode("something".encode('utf-8')), encoding='utf-8'), s.to_dict()["salt"])
     self.assertIn("iterations", s.to_dict())
     self.assertEqual(213, s.to_dict()["iterations"])
     self.assertIn("passwordTemplate", s.to_dict())
     self.assertEqual("xxxxxxxxxxoxxx", s.to_dict()["passwordTemplate"])
     self.assertIn("extras", s.to_dict())
     self.assertEqual("XVLCWKHGFQUIAEOSNRTDYÜÖÄPZBMJ", s.to_dict()["extras"])
     self.assertIn("notes", s.to_dict())
     self.assertEqual("Some note.", s.to_dict()["notes"])
コード例 #2
0
 def test_get_template(self):
     s = PasswordSetting("unit.test")
     s.set_template("xxxaxxxxxxx")
     self.assertEqual("xxxaxxxxxxx", s.get_template())
     s.set_template("6;xxxxxxoxxxnAxxxa")
     self.assertEqual("xxxxxxoxxxnAxxxa", s.get_template())
     self.assertEqual(16, len(s.get_template()))
コード例 #3
0
 def test_to_json(self):
     s = PasswordSetting("unit.test")
     s.set_modification_date("2005-01-01T01:14:12")
     s.set_creation_date("2001-01-01T02:14:12")
     s.set_salt("something".encode('utf-8'))
     s.set_iterations(213)
     s.set_template("xxxxxxxxxxoxxx")
     s.set_extra_character_set("XVLCWKHGFQUIAEOSNRTDYÜÖÄPZBMJ")
     s.set_notes("Some note.")
     self.assertIn("domain", s.to_dict())
     self.assertEqual("unit.test", s.to_dict()["domain"])
     self.assertIn("cDate", s.to_dict())
     self.assertEqual("2001-01-01T02:14:12.000", s.to_dict()["cDate"])
     self.assertIn("mDate", s.to_dict())
     self.assertEqual("2005-01-01T01:14:12.000", s.to_dict()["mDate"])
     self.assertIn("salt", s.to_dict())
     self.assertEqual(str(b64encode("something".encode('utf-8')), encoding='utf-8'), s.to_dict()["salt"])
     self.assertIn("iterations", s.to_dict())
     self.assertEqual(213, s.to_dict()["iterations"])
     self.assertIn("passwordTemplate", s.to_dict())
     self.assertEqual("xxxxxxxxxxoxxx", s.to_dict()["passwordTemplate"])
     self.assertIn("extras", s.to_dict())
     self.assertEqual("XVLCWKHGFQUIAEOSNRTDYÜÖÄPZBMJ", s.to_dict()["extras"])
     self.assertIn("notes", s.to_dict())
     self.assertEqual("Some note.", s.to_dict()["notes"])
コード例 #4
0
 def test_get_template(self):
     s = PasswordSetting("unit.test")
     s.set_template("xxxaxxxxxxx")
     self.assertEqual("xxxaxxxxxxx", s.get_template())
     s.set_template("6;xxxxxxoxxxnAxxxa")
     self.assertEqual("xxxxxxoxxxnAxxxa", s.get_template())
     self.assertEqual(16, len(s.get_template()))
コード例 #5
0
 def test_store_local_settings(self):
     abc_setting = self.manager.get_setting('abc.de')
     abc_setting.set_template('xAxonaxxxx')
     self.manager.set_setting(abc_setting)
     new_setting = PasswordSetting('hugo.com')
     new_setting.set_template('xonxAxxaxxxx')
     self.manager.set_setting(new_setting)
     kgk_manager = KgkManager()
     kgk_manager.set_preference_manager(self.preference_manager)
     kgk_manager.create_new_kgk()
     salt = os.urandom(32)
     kgk_manager.create_and_save_new_kgk_block(
         Crypter(Crypter.createIvKey(b'xyz', salt, iterations=3)))
     self.manager.store_local_settings(kgk_manager)
     with open(os.path.expanduser('~/.ctSESAM_test.pws'), 'br') as f:
         data = f.read()
     settings_crypter = PasswordSettingsManager.get_settings_crypter(
         kgk_manager)
     decrypted_settings = settings_crypter.decrypt(data[144:])
     sync_settings_len = struct.unpack('!I', decrypted_settings[:4])[0]
     data = json.loads(
         Packer.decompress(
             decrypted_settings[4 + sync_settings_len:]).decode('utf8'))
     self.assertEqual('abc.de', data['settings']['abc.de']['domain'])
     self.assertEqual('xAxonaxxxx',
                      data['settings']['abc.de']['passwordTemplate'])
     self.assertEqual('hugo.com', data['settings']['hugo.com']['domain'])
     self.assertEqual('xonxAxxaxxxx',
                      data['settings']['hugo.com']['passwordTemplate'])
 def test_custom_salt(self):
     setting = PasswordSetting('some.domain')
     setting.set_salt(b'qanisaoerna56745678eornsiarteonstiaroenstiaeroh')
     setting.set_template("oxAxxaxxnx")
     manager = CtSesam(domain=setting.get_domain(),
                       username=setting.get_username(),
                       kgk='foo'.encode('utf-8'))
     self.assertEqual(")hN8ol<;6<", manager.generate(setting))
 def test_default(self):
     setting = PasswordSetting('some.domain')
     setting.set_salt('pepper'.encode('utf-8'))
     setting.set_template("xaxnxxAoxx")
     manager = CtSesam(domain=setting.get_domain(),
                       username=setting.get_username(),
                       kgk='foo'.encode('utf-8'))
     self.assertEqual("]ew26XW.X<", manager.generate(setting))
コード例 #8
0
 def test_get_character_set(self):
     s = PasswordSetting("unit.test")
     self.assertEqual("c", s.get_character_set()[12])
     s.set_extra_character_set("axFLp0")
     s.set_template("xox")
     self.assertEqual(6, len(s.get_character_set()))
     self.assertEqual("F", s.get_character_set()[2])
     self.assertEqual("0", s.get_character_set()[5])
コード例 #9
0
 def test_custom_character_set(self):
     setting = PasswordSetting('some.domain')
     setting.set_salt('pepper'.encode('utf-8'))
     setting.set_extra_character_set(
         'abcdefghijklmnopqrstuvwxyzABCDUFGHJKLMNPQRTEVWXYZ0123456789#!"§$%&/()[]{}=-_+*<>;:.')
     setting.set_template("oxxxxxxxxx")
     manager = CtSesam(domain=setting.get_domain(), username=setting.get_username(), kgk='foo'.encode('utf-8'))
     self.assertEqual("5#%KiEvUU7", manager.generate(setting))
コード例 #10
0
 def test_get_character_set(self):
     s = PasswordSetting("unit.test")
     self.assertEqual("c", s.get_character_set()[12])
     s.set_extra_character_set("axFLp0")
     s.set_template("xox")
     self.assertEqual(6, len(s.get_character_set()))
     self.assertEqual("F", s.get_character_set()[2])
     self.assertEqual("0", s.get_character_set()[5])
コード例 #11
0
 def test_long(self):
     setting = PasswordSetting('some.domain')
     setting.set_salt('pepper'.encode('utf-8'))
     setting.set_template("Aanoxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
     manager = CtSesam(domain=setting.get_domain(),
                       username=setting.get_username(),
                       kgk='foo'.encode('utf-8'))
     self.assertEqual("Ba0=}#K.X<$/eS0AuGjRm>(\"dnDnvZCx",
                      manager.generate(setting))
コード例 #12
0
 def test_custom_character_set(self):
     setting = PasswordSetting("some.domain")
     setting.set_salt("pepper".encode("utf-8"))
     setting.set_extra_character_set(
         'abcdefghijklmnopqrstuvwxyzABCDUFGHJKLMNPQRTEVWXYZ0123456789#!"§$%&/()[]{}=-_+*<>;:.'
     )
     setting.set_template("oxxxxxxxxx")
     manager = CtSesam(domain=setting.get_domain(), username=setting.get_username(), kgk="foo".encode("utf-8"))
     self.assertEqual("5#%KiEvUU7", manager.generate(setting))
コード例 #13
0
 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))
コード例 #14
0
 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))
コード例 #15
0
 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))
コード例 #16
0
 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))
コード例 #17
0
 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))
コード例 #18
0
 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))
コード例 #19
0
 def test_character_set(self):
     s = PasswordSetting("unit.test")
     self.assertEqual("0123456789" +
                      "abcdefghijklmnopqrstuvwxyz" +
                      "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
                      "#!\"§$%&/()[]{}=-_+*<>;:.", s.get_character_set())
     s.set_extra_character_set("&=Oo0wWsS$#uUvVzZ")
     s.set_template("oxxxxxxxxx")
     self.assertEqual("&=Oo0wWsS$#uUvVzZ", s.get_character_set())
     s.set_extra_character_set(
         "abcdefghijklmnopqrstuvwxyz" +
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
         "0123456789" +
         "#!\"§$%&/()[]{}=-_+*<>;:.")
     self.assertEqual("abcdefghijklmnopqrstuvwxyz" +
                      "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
                      "0123456789" +
                      "#!\"§$%&/()[]{}=-_+*<>;:.", s.get_character_set())
     s.set_template("noxxxxxxxx")
     s.set_extra_character_set("#!\"§$%&/()[]{}=-_+*<>;:.")
     self.assertEqual("0123456789#!\"§$%&/()[]{}=-_+*<>;:.", s.get_character_set())
     s.set_template("xaxxxAxxx")
     self.assertEqual("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", s.get_character_set())
コード例 #20
0
 def test_character_set(self):
     s = PasswordSetting("unit.test")
     self.assertEqual("0123456789" +
                      "abcdefghijklmnopqrstuvwxyz" +
                      "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
                      "#!\"§$%&/()[]{}=-_+*<>;:.", s.get_character_set())
     s.set_extra_character_set("&=Oo0wWsS$#uUvVzZ")
     s.set_template("oxxxxxxxxx")
     self.assertEqual("&=Oo0wWsS$#uUvVzZ", s.get_character_set())
     s.set_extra_character_set(
         "abcdefghijklmnopqrstuvwxyz" +
         "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
         "0123456789" +
         "#!\"§$%&/()[]{}=-_+*<>;:.")
     self.assertEqual("abcdefghijklmnopqrstuvwxyz" +
                      "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
                      "0123456789" +
                      "#!\"§$%&/()[]{}=-_+*<>;:.", s.get_character_set())
     s.set_template("noxxxxxxxx")
     s.set_extra_character_set("#!\"§$%&/()[]{}=-_+*<>;:.")
     self.assertEqual("0123456789#!\"§$%&/()[]{}=-_+*<>;:.", s.get_character_set())
     s.set_template("xaxxxAxxx")
     self.assertEqual("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", s.get_character_set())
コード例 #21
0
 def test_long(self):
     setting = PasswordSetting("some.domain")
     setting.set_salt("pepper".encode("utf-8"))
     setting.set_template("Aanoxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
     manager = CtSesam(domain=setting.get_domain(), username=setting.get_username(), kgk="foo".encode("utf-8"))
     self.assertEqual('Ba0=}#K.X<$/eS0AuGjRm>("dnDnvZCx', manager.generate(setting))
コード例 #22
0
 def test_custom_salt(self):
     setting = PasswordSetting("some.domain")
     setting.set_salt(b"qanisaoerna56745678eornsiarteonstiaroenstiaeroh")
     setting.set_template("oxAxxaxxnx")
     manager = CtSesam(domain=setting.get_domain(), username=setting.get_username(), kgk="foo".encode("utf-8"))
     self.assertEqual(")hN8ol<;6<", manager.generate(setting))
コード例 #23
0
 def test_default(self):
     setting = PasswordSetting("some.domain")
     setting.set_salt("pepper".encode("utf-8"))
     setting.set_template("xaxnxxAoxx")
     manager = CtSesam(domain=setting.get_domain(), username=setting.get_username(), kgk="foo".encode("utf-8"))
     self.assertEqual("]ew26XW.X<", manager.generate(setting))