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

Allow configuring the possible salt lengths for RSA PSS signatures #16549

Conversation

trishankatdatadog
Copy link
Contributor

The Golang crypto/rsa package allows for using at least two possible salt lengths (auto and hash for want better terminology) when creating/verifying RSA PSS signatures. However, these options are currently not exposed via the Vault Transit Secrets Engine. These options would allow for cross-platform signature verification without modifying downstream clients (e.g., the securesystemslib package, used by the python-tuf and python-in-toto supply chain security frameworks, which currently assumes a different salt length by default than Vault does).

This fixes issue #7531.

Copy link
Contributor

@stevendpclark stevendpclark 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 contribution @trishankatdatadog!

We've discussed it a bit internally and would like to move forward to get this improvement into Vault but would like a few modifications first.

I've made a few comments on the PR itself but the main change we would like is the ability for an end-user to specify a number of bytes on top of allowing the string values "auto" or "hash" within the new field. The new field would need some customized validation, substituting auto, hash for the PSS constants defined in go, or if the string is not blank, attempt to parse as a number and if successful, validate that it is >0 as well as replicate the same upper bounds validation as done in pss.go.

Some tests, documentation updates and a changelog entry would also be appreciated.

Please let me know if anything is unclear and once again thanks for taking the time to submit this improvement!

builtin/logical/transit/path_sign_verify.go Outdated Show resolved Hide resolved
builtin/logical/transit/path_sign_verify.go Outdated Show resolved Hide resolved
sdk/helper/keysutil/policy.go Outdated Show resolved Hide resolved
@trishankatdatadog
Copy link
Contributor Author

Thanks @stevendpclark! Happy to address these comments.

However, I see another PR #16227 along the same lines which I haven't taken a deep look at yet from @monomosc. How should we go about this?

@stevendpclark
Copy link
Contributor

stevendpclark commented Aug 8, 2022

Thanks @stevendpclark! Happy to address these comments.

Great, please let me know if anything is unclear.

However, I see another PR #16227 along the same lines which I haven't taken a deep look at yet from @monomosc. How should we go about this?

That is unfortunate. At the time that I had started looking at your PR, they had yet to sign the CLA so their PR couldn't be used. I'll leave it up to you if you wish to work with them on this PR together or finish this one up yourself, but in my mind at this time, you have first dibs on the PR.

@trishankatdatadog
Copy link
Contributor Author

That is unfortunate. At the time that I had started looking at your PR, they had yet to sign the CLA so their PR couldn't be used. I'll leave it up to you if you wish to work with them on this PR together or finish this one up yourself, but in my mind at this time, you have first dibs on the PR.

Sounds good. Let me see whether I can use some of their work here. Of course, if I do end up using it, I will credit them accordingly.

@trishankatdatadog
Copy link
Contributor Author

@stevendpclark is b1e3beb0671597c81a07d9e73130d5d8f151e159 better?

@stevendpclark
Copy link
Contributor

stevendpclark commented Aug 9, 2022

@stevendpclark is b1e3beb better?

@trishankatdatadog Yes thanks!

I'm not sure if you are working up to this but remember that one of the big things we would like to see in this PR is for an end-user to specify a number of bytes on top of allowing the string values "auto" or "hash" within the new field. So with that said I wouldn't define a custom map/type for SaltLength at least within the SDK. I'd keep it as an int within your new SigningOptions struct to allow passing in converted "auto", "hash" values from the pss.go constants (PSSSaltLengthAuto, PSSSaltLengthEqualsHash) or the user specified bytes value.

@trishankatdatadog
Copy link
Contributor Author

I'm not sure if you are working up to this but remember that one of the big things we would like to see in this PR is for an end-user to specify a number of bytes on top of allowing the string values "auto" or "hash" within the new field. So with that said I wouldn't define a custom map/type for SaltLength at least within the SDK. I'd keep it as an int within your new SigningOptions struct to allow passing in converted "auto", "hash" values from the pss.go constants (PSSSaltLengthAuto, PSSSaltLengthEqualsHash) or the user specified bytes value.

My bad, I did recall reading it somewhere, but somehow missed finding the original comment. Let me look into this tonight.

@monomosc
Copy link

monomosc commented Aug 10, 2022

I'm not sure if you are working up to this but remember that one of the big things we would like to see in this PR is for an end-user to specify a number of bytes on top of allowing the string values "auto" or "hash" within the new field. So with that said I wouldn't define a custom map/type for SaltLength at least within the SDK. I'd keep it as an int within your new SigningOptions struct to allow passing in converted "auto", "hash" values from the pss.go constants (PSSSaltLengthAuto, PSSSaltLengthEqualsHash) or the user specified bytes value.

My bad, I did recall reading it somewhere, but somehow missed finding the original comment. Let me look into this tonight.

Hi, you are of course free to use code from my (older) PR for this subject if you want. #16549

High level, my PR added the pss_salt_length as an (optional) Integer. This automatically solves all problems, as the golang default value for an integer is 0, and thus will not change behavior. -1 would correlate to auto (see https://pkg.go.dev/crypto/rsa#pkg-constants) and any other number would declare the desired salt length directly.

I have also added some sanity unit-tests; I suggest copying them as well.

Lastly there is an open question as to how to handle invalid salt lengths. Every RSA-Key-Size corresponds to a maximum legal salt length; exceeding it willr esult in a fmt.Error with some internal error message by crypto/rsa.

@trishankatdatadog
Copy link
Contributor Author

Hi, you are of course free to use code from my (older) PR for this subject if you want. #16549

Thanks! I am writing something independently now, so let me finish it, and we'll compare and see 🙂 I think we are basically using the same approach.

@trishankatdatadog
Copy link
Contributor Author

trishankatdatadog commented Aug 11, 2022

@stevendpclark @monomosc Generalised the salt length to an int, and have fairly comprehensive unit tests. Pls let me know what you think, thx.

@monomosc
Copy link

monomosc commented Aug 11, 2022

Your tests now do fail though; I (as a customer) would be happy with the solution though.

Copy link
Contributor

@stevendpclark stevendpclark left a comment

Choose a reason for hiding this comment

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

@trishankatdatadog thanks for the unit tests and changes to the SDK. I've added a few more comments, sorry if I wasn't clear previously, my comments were directed to the SDK api only not the end-user facing api.

builtin/logical/transit/path_sign_verify.go Outdated Show resolved Hide resolved
sdk/helper/keysutil/policy.go Show resolved Hide resolved
sdk/helper/keysutil/policy.go Outdated Show resolved Hide resolved
builtin/logical/transit/path_sign_verify.go Outdated Show resolved Hide resolved
@trishankatdatadog
Copy link
Contributor Author

Your tests now do fail though; I (as a customer) would be happy with the solution though.

Glad you like it. Let me address @stevendpclark's comments, and then I think we'll all be happy (well, after I also look at the failing tests, could be a red herring).

stevendpclark added a commit that referenced this pull request Aug 11, 2022
 - Found by @trishankatdatadog in PR #16549, we were masking errors
   coming out of the rsa verification calls as verfication errors and
   not returning when they were usage errors.
hashibot-web pushed a commit that referenced this pull request Aug 13, 2022
…16695)

- Found by @trishankatdatadog in PR #16549, we were masking errors
   coming out of the rsa verification calls as verfication errors and
   not returning when they were usage errors.
@trishankatdatadog trishankatdatadog force-pushed the trishankatdatadog/rsassa-pss-salt-lengths branch 2 times, most recently from bef8669 to 4ff3817 Compare August 16, 2022 03:33
@trishankatdatadog
Copy link
Contributor Author

@stevendpclark ok, almost done: just want to add a unit test (if not already there) for being able to automatically verify RSA PSS signatures from previous versions of Vault (shouldn't be a problem, but still).

@trishankatdatadog
Copy link
Contributor Author

@stevendpclark OK, I have added about every unit test I can think of for both the SDK and HTTP API.

Of course, just like everyone else, I want to make sure we don't even accidentally break verification of signatures from previous versions of Vault, but I'm fairly certain that these unit tests already cover that case. Please advise. Thanks!

Copy link
Contributor

@stevendpclark stevendpclark left a comment

Choose a reason for hiding this comment

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

Hi @trishankatdatadog,

Sorry for a bit of delay, took some PTO time and been playing catch up. This looks absolutely great, wonderful work! I have one small nit about a test, see comment below.

Other then that all that is missing is a documentation update to the api docs (see https://github.com/hashicorp/vault/blob/main/website/content/api-docs/secret/transit.mdx) and a changelog entry (see https://github.com/hashicorp/vault/blob/main/CONTRIBUTING.md#changelog-entries)

sdk/helper/keysutil/policy_test.go Outdated Show resolved Hide resolved
@trishankatdatadog
Copy link
Contributor Author

@stevendpclark Done, PTAL, thanks!

@stevendpclark
Copy link
Contributor

stevendpclark commented Aug 31, 2022

Hi @trishankatdatadog, this looks great! I have no additional comments.

Would you be able to rebase this on top of the current main branch to pull in the fixes for the test-go-remote-docker and test-go-reace-remote-docker failures, that way I can merge it in. Sorry about all the back and forth...

@trishankatdatadog trishankatdatadog force-pushed the trishankatdatadog/rsassa-pss-salt-lengths branch from 2820548 to 0ec0679 Compare August 31, 2022 15:34
@trishankatdatadog
Copy link
Contributor Author

Would you be able to rebase this on top of the current main branch to pull in the fixes for the test-go-remote-docker and test-go-reace-remote-docker failures, that way I can merge it in. Sorry about all the back and forth...

No problem, and looks like it worked! Only Vercel left 🙂

@stevendpclark stevendpclark merged commit 754c119 into hashicorp:main Aug 31, 2022
@stevendpclark
Copy link
Contributor

Thanks for the contribution @trishankatdatadog and being so great with all the feedback, much appreciated!

@trishankatdatadog
Copy link
Contributor Author

Thanks for the contribution @trishankatdatadog and being so great with all the feedback, much appreciated!

Thank you for being so responsive and shepherding the process to help us fix the issue, much appreciated too 🙂

@trishankatdatadog
Copy link
Contributor Author

Oh, BTW: in which release could we expect this code?

@stevendpclark
Copy link
Contributor

Oh, BTW: in which release could we expect this code?

It will make it out into the next major release of Vault so 1.12...

@ofek
Copy link

ofek commented Sep 1, 2022

When is 1.12 expected to be released?

@stevendpclark
Copy link
Contributor

When is 1.12 expected to be released?

Hi @ofek, rc1 for Vault 1.12.0 is out now if you would like to test this, binaries available at: https://releases.hashicorp.com/vault/1.12.0-rc1/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants