Agent: Simplify credentials object in aggregating credentials store

This commit is contained in:
Ilija Lazoroski 2022-07-18 11:29:52 +02:00
parent f421f42604
commit 0f2fc0902f
2 changed files with 32 additions and 35 deletions

View File

@ -26,14 +26,12 @@ class AggregatingCredentialsStore(ICredentialsStore):
def add_credentials(self, credentials_to_add: Iterable[Credentials]):
for credentials in credentials_to_add:
usernames = {
identity.username
for identity in credentials.identities
if identity.credential_type is CredentialComponentType.USERNAME
}
self._stored_credentials.setdefault("exploit_user_list", set()).update(usernames)
self._stored_credentials.setdefault("exploit_user_list", set()).add(
credentials.identity.username
)
secret = credentials.secret
for secret in credentials.secrets:
if secret.credential_type is CredentialComponentType.PASSWORD:
self._stored_credentials.setdefault("exploit_password_list", set()).add(
secret.password

View File

@ -30,21 +30,20 @@ EMPTY_CHANNEL_CREDENTIALS = {
TEST_CREDENTIALS = [
Credentials(
[Username("user1"), Username("user3")],
[
Password("abcdefg"),
Password("root"),
SSHKeypair(public_key="some_public_key_1", private_key="some_private_key_1"),
],
)
identity=Username("user1"),
secret=Password("root"),
),
Credentials(identity=Username("user1"), secret=Password("abcdefg")),
Credentials(
identity=Username("user3"),
secret=SSHKeypair(public_key="some_public_key_1", private_key="some_private_key_1"),
),
]
SSH_KEYS_CREDENTIALS = [
Credentials(
[Username("root")],
[
Username("root"),
SSHKeypair(public_key="some_public_key", private_key="some_private_key"),
],
)
]