Skip to content

Commit

Permalink
feat(crypto): include admin db table name in 'aad' [#411]
Browse files Browse the repository at this point in the history
  • Loading branch information
rmlibre committed Jul 27, 2024
1 parent 080ae11 commit 7799379
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions hushline/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ def value(self) -> bytearray:
vault = current_app.config.get("VAULT", None)
if self.name == self._APP_ADMIN_SECRET_SALT_NAME:
return bytearray(self._value)
return bytearray(vault.decrypt(self._value, domain=self.name.encode()))
aad = deque([self.__tablename__.encode()])
return bytearray(vault.decrypt(self._value, domain=self.name.encode(), aad=aad))

@value.setter
def value(self, secret: bytes | bytearray) -> None:
vault = current_app.config.get("VAULT", None)
if self.name == self._APP_ADMIN_SECRET_SALT_NAME:
self._value = bytes(secret)
else:
self._value = vault.encrypt(bytes(secret), domain=self.name.encode())
aad = deque([self.__tablename__.encode()])
self._value = vault.encrypt(bytes(secret), domain=self.name.encode(), aad=aad)


class User(Model):
Expand Down
4 changes: 3 additions & 1 deletion tests/test_secrets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def test_admin_db_secrets_are_static_once_created(static_app: Flask, name: str)
assert db_value != secret
assert isinstance(db_value, bytes)
assert len(db_value) > 32
assert vault.decrypt(db_value, domain=name.encode()) == secret

aad = deque([InfrastructureAdmin.__tablename__.encode()])
assert vault.decrypt(db_value, domain=name.encode(), aad=aad) == secret


@pytest.mark.parametrize("size", list(range(33)))
Expand Down

0 comments on commit 7799379

Please sign in to comment.