Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactors AWSSigner; scheme no longer required. #724

Merged
merged 11 commits into from
Apr 11, 2024
Merged

refactors AWSSigner; scheme no longer required. #724

merged 11 commits into from
Apr 11, 2024

Conversation

ianhundere
Copy link
Contributor

@ianhundere ianhundere commented Jan 30, 2024

resolves #668

Description of the changes being introduced by the pull request:

This refactors AWSSigner to no longer require local_scheme, and instead, gets scheme from AWS' response (e.g. request["SigningAlgorithms"]).

ecdsa:

"SigningAlgorithms": [
    "ECDSA_SHA_256"
]

The caveat is that RSA keys have multiple SigningAlgorithms, so if local_scheme is not provided and the keytype is rsa then rsassa-pss-sha256 is chosen by default as is the case throughout securesystemslib.

rsa:

"SigningAlgorithms": [
    "RSASSA_PKCS1_V1_5_SHA_256",
    "RSASSA_PKCS1_V1_5_SHA_384",
    "RSASSA_PKCS1_V1_5_SHA_512",
    "RSASSA_PSS_SHA_256",
    "RSASSA_PSS_SHA_384",
    "RSASSA_PSS_SHA_512"
]

Also includes updated docs and error handling.

Please verify and check that the pull request fulfills the following requirements:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

cc @jku @lukpueh

@ianhundere ianhundere closed this Jan 30, 2024
@ianhundere ianhundere reopened this Jan 30, 2024
@ianhundere ianhundere changed the title refactors AWSSigner and updates check_aws_signer. refactors AWSSigner; scheme no longer required. Jan 31, 2024
@ianhundere ianhundere requested a review from jku February 5, 2024 21:10
Copy link
Collaborator

@jku jku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I think this is good to merge: it improves import_() in that it can be used without the other argument.

I'll leave some notes below but I am not requesting changes: I have no access to AWS signer so I can't really tell what is smart and what is not.

So just as a comment: the lookup (from-AWS-response-to-securesystemslib-key-type-and-scheme) still looks more complicated than it probably is

  • RSA users can now choose the hash length but ECDSA users for some reason cannot?
  • the real import_() argument probably should have been hash_size: Optional[int] = None if that's the only real variable. This would be an API change for AWSSigner so maybe the scheme string still makes sense though
  • then the single lookup function would be def _get_keytype_and_scheme(aws_response, hash_size) -> Tuple[str, str] (or def _get_keytype_and_scheme(aws_response, scheme_from_user) -> Tuple[str, str] if the import_() argument is the scheme string)

securesystemslib/signer/_aws_signer.py Show resolved Hide resolved
Copy link
Member

@lukpueh lukpueh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for commenting late. I am not a big fan of the new key-type specific argument. It breaks the API and feels inconsistent.

I suggest to keep the local_scheme, make it optional, and use it like so:

get key from aws by keyid

if scheme is passed:
  if scheme is not allowed for key
    raise

else:
  assign default scheme for key

I don't know exactly what schemes are supported for what key, but I expect that for any rsa key in the kms you should be able to use any of the securesystemslib schemes, whereas for ecdsa there is only one scheme per key.

A very brief look at the docs seems to support my assumption.

@ianhundere
Copy link
Contributor Author

@jku @lukpueh thanks for y'all's input, i've gone ahead and renamed rsa-scheme back to local_scheme.

securesystemslib/signer/_aws_signer.py Outdated Show resolved Hide resolved
securesystemslib/signer/_aws_signer.py Show resolved Hide resolved
securesystemslib/signer/_aws_signer.py Outdated Show resolved Hide resolved
@lukpueh
Copy link
Member

lukpueh commented Feb 6, 2024

fyi @ianhundere, I've tested AWSSigner with Localstack for the first time today and it works like a charm! 🚀 ❤️
repository-service-tuf/repository-service-tuf-worker#452

Thanks for your efforts!

@ianhundere ianhundere requested a review from lukpueh March 4, 2024 14:18
Copy link
Member

@lukpueh lukpueh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! There is one small bug in import_ which needs to be fixed before we can merge this. The rest is polishing.

securesystemslib/signer/_aws_signer.py Outdated Show resolved Hide resolved
securesystemslib/signer/_aws_signer.py Show resolved Hide resolved
securesystemslib/signer/_aws_signer.py Outdated Show resolved Hide resolved
securesystemslib/signer/_aws_signer.py Outdated Show resolved Hide resolved
@ianhundere ianhundere requested review from lukpueh and jku March 14, 2024 18:53
Copy link
Member

@lukpueh lukpueh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your persistence! It looks like you are still not consistently checking, if the key supports the chosen scheme according to SigningAlgorithms in the response.

As I said, I'm okay, if we improve that in a follow-up PR.

Please address my inline comment and we can merge this (or let me know, if I should address it).

securesystemslib/signer/_aws_signer.py Outdated Show resolved Hide resolved
@ianhundere ianhundere requested a review from lukpueh March 18, 2024 13:47
@ianhundere
Copy link
Contributor Author

Thanks for the updates! There is one small bug in import_ which needs to be fixed before we can merge this. The rest is polishing.

okay, i think that about does it; thanks for all your feedback. 🙇

securesystemslib/signer/_aws_signer.py Outdated Show resolved Hide resolved
securesystemslib/signer/_aws_signer.py Outdated Show resolved Hide resolved
@ianhundere ianhundere requested a review from lukpueh March 25, 2024 13:22
@lukpueh
Copy link
Member

lukpueh commented Apr 11, 2024

Thanks for your continued efforts, @ianhundere!

@lukpueh lukpueh merged commit fdaa97b into secure-systems-lab:main Apr 11, 2024
17 checks passed
@ianhundere ianhundere deleted the refactors_aws_kms_signer branch April 11, 2024 13:51
lukpueh added a commit to lukpueh/securesystemslib that referenced this pull request Apr 11, 2024
**Simplify**
- remove redundant keytype/scheme switches
- remove try/except, which catches an exception only to re-raise it

**Strengthen**
- choose default scheme based on schemes supported by the key

Roughly implements the algorithm suggested in:
secure-systems-lab#724 (review)

**Unrelated changes**
- fix secure-systems-lab#765 fix typo AND disable scheme until SSlibKey adds support
- fail in __init__ if public_key.scheme is not in aws_algos

TODO:
* add tests

Many thanks to @ianhundere for the solid ground work!

Signed-off-by: Lukas Puehringer <[email protected]>
lukpueh added a commit to lukpueh/securesystemslib that referenced this pull request Apr 12, 2024
**Simplify**
- remove redundant keytype/scheme switches
- remove try/except, which catches an exception only to re-raise it

**Strengthen**
- choose default scheme based on schemes supported by the key

Roughly implements the algorithm suggested in:
secure-systems-lab#724 (review)

**Unrelated changes**
- fix secure-systems-lab#765 fix typo AND disable scheme until SSlibKey adds support
- fail in __init__ if public_key.scheme is not in aws_algos

**TODO**
* add tests

Many thanks to @ianhundere for the solid ground work!

Signed-off-by: Lukas Puehringer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Does AWSSigner.import_() really require scheme string?
3 participants