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

Add PKCS1v15 as a RSA signature and verification option on the Transit secret engine #4018

Merged
merged 7 commits into from
Mar 15, 2018
Merged

Add PKCS1v15 as a RSA signature and verification option on the Transit secret engine #4018

merged 7 commits into from
Mar 15, 2018

Conversation

broamski
Copy link
Contributor

No description provided.

@jefferai
Copy link
Member

What's the reason for this?

@broamski
Copy link
Contributor Author

My use case is I have a number of existing processes using PKCS1v15 signatures that are not using Vault and I would really like for them to start using Vault!

@joelthompson
Copy link
Contributor

Just throwing my $0.02 out here....

First, I think the option of signature type in the documentation should be clear that people should use PSS instead of PCKS1v15 unless they know what they're doing (or just omit it and leave it to be the default). Most people will be confused by the difference, and one thing Vault does well is it isolates people from needing to know the lower-level crypto details like the difference between PSS and PKCS1v15.

Second, it seems a bit kludgy to ask users to specify the signature type upon verify. Would it be possible to embed the signature type into the signed text returned by Vault so verify can just read it automatically?

@broamski
Copy link
Contributor Author

PSS was and is still the default. This provides the option for those who need it. Both signature types are clearly supported in crypto/rsa, so this shouldn't be alarming.

@jefferai
Copy link
Member

@broamski I'm not against adding it, although I think you're generally better off switching to PSS. I'm trying to think through the right place for this kind of option. It's definitely not that field, it's too single-purpose -- there's always the possibility that such a choice might become available for some other key type.

One possibility is simply a signature_algorithm field (and maybe renaming algorithm to hash_algorithm). Another might be to make it a configurable key property that you'd set with the keys/<key>/config endpoint. The benefit to doing that is that you take the onus off of the user to specify the parameter with every single sign/verify; the downside is you can't use the same key for both operations.

We could potentially do what Joel suggested and add it somehow to the output, although that would be a kind of a "spec change" for the output format.

@broamski
Copy link
Contributor Author

In my experience, both signing and verification don't always happen on Vault; usually, privileged actors sign with vault and the other end verifies using any number of different libraries - sometimes later, while offline. I have received a few grumbles from implementers of the offline verification process about having to remove the vault:<version>: prefix. I feel avoiding any further "spec change" is the right approach.

As far as proper placement of the parameter, I vote for signature_algorithm and algorithm -> hash_algorithm.

@joelthompson
Copy link
Contributor

PSS was and is still the default. This provides the option for those who need it. Both signature types are clearly supported in crypto/rsa, so this shouldn't be alarming.

Sure, but I can just see a lot of people asking the mailing list, "What is this signature_algorithm field? Which one should I use?" It'd be better to head off some of that by adding a little bit of information in the documentation, even if it's just something like, "If you don't have a need to explicitly set field, then leave it blank and accept the default."

@jefferai
Copy link
Member

Any chance you want to implement the algorithm->hash_algorithm? :-)

It's easy -- mark the first as deprecated, but in the code, read the second, and if it's not set, read the first.

@broamski
Copy link
Contributor Author

Of course! I'll try to get to it by later tonight/tomorrow morning.

@jefferai jefferai added this to the 0.9.5 milestone Feb 22, 2018
@broamski
Copy link
Contributor Author

Updated to reflect our latest consensus.

algorithm := d.Get("urlalgorithm").(string)
if algorithm == "" {
algorithm = d.Get("algorithm").(string)
hashalgorithm := d.Get("urlalgorithm").(string)
Copy link
Member

Choose a reason for hiding this comment

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

Can we use casing for this var? hashalgorithm -> hashAlgorithm

}
prehashed := d.Get("prehashed").(bool)
sigalgorithm := d.Get("signature_algorithm").(string)
Copy link
Member

Choose a reason for hiding this comment

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

s/sigalgorithm/sigAlgorithm

@@ -836,7 +836,7 @@ func (p *Policy) HMACKey(version int) ([]byte, error) {
return p.Keys[strconv.Itoa(version)].HMACKey, nil
}

func (p *Policy) Sign(ver int, context, input []byte, algorithm string) (*SigningResult, error) {
func (p *Policy) Sign(ver int, context, input []byte, hashalgorithm string, sigalgorithm string) (*SigningResult, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Specifying the type for hashAlgorithm can be skipped and hashAlgorithm, sigAlgorithm string should be sufficient.

@@ -805,6 +805,12 @@ supports signing.
hashed. If the key type is `rsa-2048` or `rsa-4096`, then the algorithm used
to hash the input should be indicated by the `algorithm` parameter.

- `rsa_sig_type` `(string: "pss")` – When using a RSA key, specifies the RSA
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be updated.

@broamski
Copy link
Contributor Author

Updated to address latest review.

@jefferai jefferai modified the milestones: 0.9.5, 0.9.6 Feb 28, 2018
"algorithm": &framework.FieldSchema{
Type: framework.TypeString,
Default: "sha2-256",
Description: `Deprecated: use "hash_algorithm" instead. Hash algorithm to use (POST body parameter). Valid values are:
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need to duplicate the help text here; should be sufficient to just mark it deprecated and to use hash_algorithm instead, since they can see the help text there, and the behavior for both parameters is exactly the same.

@@ -63,6 +78,12 @@ to the min_encryption_version configured on the key.`,
Type: framework.TypeBool,
Description: `Set to 'true' when the input is already hashed. If the key type is 'rsa-2048' or 'rsa-4096', then the algorithm used to hash the input should be indicated by the 'algorithm' parameter.`,
},
"signature_algorithm": &framework.FieldSchema{
Type: framework.TypeString,
Default: "pss",
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should have a default, it ties this strongly to RSA. Instead I'd suggest the default behavior is just dependent on the type of key and this stays a blank string.

algorithm = d.Get("algorithm").(string)
hashAlgorithm := d.Get("urlalgorithm").(string)
if hashAlgorithm == "" {
hashAlgorithm = d.Get("algorithm").(string)
Copy link
Member

Choose a reason for hiding this comment

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

Flip the order of these; prefer the non-deprecated one first.

@jefferai
Copy link
Member

Thanks!

@jefferai jefferai merged commit ecb3fe2 into hashicorp:master Mar 15, 2018
@jefferai jefferai added the ui label Apr 4, 2018
@meirish meirish mentioned this pull request Apr 6, 2018
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants