Beispiel #1
0
 def test_multiple_cycles(self):
     """
     Ciphers can only be used once - CryptImpl is supposed to
     have a workaround that refreshes the cipher after each use
     :return:
     """
     crypt = create_crypt(self.pw)
     for tt in plain_texts:
         ct = crypt.encrypt(tt)
         pt = crypt.decrypt(ct)
         assert pt == tt
     for crypt_id in list_crypts():
         crypt = create_crypt(self.pw, crypt_id)
         crypt_id = crypt.crypt_id
         pw_hash = crypt.pw_hash
         salt = crypt.salt
         for tt in plain_texts:
             ct = crypt.encrypt(tt)
             pt = crypt.decrypt(ct)
             assert pt == tt
         crypt = get_crypt(crypt_id, self.pw, pw_hash, salt)
         for tt in plain_texts:
             ct = crypt.encrypt(tt)
             pt = crypt.decrypt(ct)
             assert pt == tt
Beispiel #2
0
 def create(
         cls, password: str, crypt_id: str, locker_name: str = None
 ) -> Locker:
     """
     Create a Locker object
     :param password: Password for the new locker
     :param crypt_id: ID of the crypt_impl to create
     :param locker_name: The optional name of the locker.
                  Must be unique in storage
     """
     crypt_inst = create_crypt(password=password, crypt_id=crypt_id)
     LockerModel(
         pw_hash=crypt_inst.pw_hash,
         salt=crypt_inst.salt,
         locker_id=Locker.get_locker_id(locker_name=locker_name),
         crypt_id=crypt_inst.crypt_id
     )
     # Verify it is accessible
     try:
         instance = cls.get(password=password, locker_name=locker_name)
     except Exception as err:
         raise PhibesUnknownError(f' unknown {err=}')
     if not instance:
         raise PhibesNotFoundError(locker_name)
     return instance
Beispiel #3
0
 def test_what(self):
     pw = "this right here"
     crypt = create_crypt(pw)
     file_pw_hash = crypt.pw_hash
     crypt_id = crypt.crypt_id
     file_salt = crypt.salt
     crypt = get_crypt(crypt_id, pw, file_pw_hash, file_salt)
     assert crypt
Beispiel #4
0
 def test_create_encrypt_decrypt(self, plaintext):
     for crypt_id in list_crypts():
         crypt = create_crypt(self.pw, crypt_id)
         step1 = crypt.encrypt(plaintext)
         step2 = crypt.decrypt(step1)
         assert step2 == plaintext, (f"{crypt=}\n"
                                     f"{plaintext=}\n"
                                     f"{step1=}\n"
                                     f"{step2=}\n")
Beispiel #5
0
 def test_create_encrypt_decrypt(self, plaintext):
     try:
         crypt_id = register_crypt(BadCrypt,
                                   fallback_id=default_id,
                                   key_rounds=100100)
     except ValueError:
         crypt_id = "BadCryptkey_rounds100100"
     crypt = create_crypt(self.pw, crypt_id)
     assert crypt.decrypt(crypt.encrypt(plaintext)) == plaintext
Beispiel #6
0
 def setup_method(self):
     self.pw = "s00p3rsekrit"
     self.crypts = {}
     for cid in list_crypts():
         crypt_impl = create_crypt(self.pw, crypt_id=cid)
         self.crypts[cid] = {
             'password': self.pw,
             'pw_hash': crypt_impl.pw_hash,
             'salt': crypt_impl.salt,
             'crypt_impl': crypt_impl
         }
     return