Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Add support for PBES2 Key algorithms #190

Merged
merged 3 commits into from Aug 1, 2018
Merged

Add support for PBES2 Key algorithms #190

merged 3 commits into from Aug 1, 2018

Conversation

maraino
Copy link
Contributor

@maraino maraino commented Jul 9, 2018

Add functionality to support for password-based cryptography with the optional key algorithms:

  • PBES2-HS256+A128KW
  • PBES2-HS384+A192KW
  • PBES2-HS512+A256KW

PBES2 algorithms require two new parameters in the header p2c (pbkdf2 number of iterations) and p2s (salt). I added those parameters in the recipient and they are optional. Safe defaults are used if they are left empty, 100,000 for the count and a 128 bits salt. NIST recommendation is at least 10,000, but some applications like 1Password are already using 100k.

I'm open to suggestions, do a PR for the master branch, change the defaults, or use EncrypterOptions to add the extra parameters instead of the recipient.

Adds functionality to support the optional key algorithms:
 * PBES2-HS256+A128KW
 * PBES2-HS384+A192KW
 * PBES2-HS512+A256KW
@CLAassistant
Copy link

CLAassistant commented Jul 9, 2018

CLA assistant check
All committers have signed the CLA.

@csstaub
Copy link
Collaborator

csstaub commented Jul 25, 2018

Hi @maraino! Thanks for your pull request! I finally have time to review this, will take a look now.

crypter.go Outdated
@@ -108,6 +108,8 @@ type Recipient struct {
Algorithm KeyAlgorithm
Key interface{}
KeyID string
P2C int
P2S []byte
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we change the names of these fields to make it clear what they do? Or, alternatively, add doc comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternative names could be PBES2Count and PBES2Salt, or just Count and Salt. But I rather add docs and have the field names match better the data written in the header.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like PBES2Count and PBES2Salt. Since this struct doesn't directly represent a header I think it's ok to to have names not match the header fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll change it

func (parsed rawHeader) getP2C() (int, error) {
v := parsed[headerP2C]
if v == nil {
return 0, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should probably return an error here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was following the behavior of similar methods on the rawHeader type, getString(), getByteBuffer(), getJWK(), ...

@csstaub
Copy link
Collaborator

csstaub commented Jul 25, 2018

This looks pretty good! It looks like they key is still passed in as []byte, but since this is for password-based encryption maybe we have the type for the key be string for PBES2 algorithms? What do you think?

@maraino
Copy link
Contributor Author

maraino commented Jul 26, 2018

This looks pretty good! It looks like the key is still passed in as []byte, but since this is for password-based encryption maybe we have the type for the key be string for PBES2 algorithms? What do you think?

@csstaub: that makes sense. I can accept both string and []byte

@maraino
Copy link
Contributor Author

maraino commented Jul 26, 2018

@csstaub: just pushed the changes requested. For consistency with other methods, I haven't change the getP2C() behavior.

@maraino
Copy link
Contributor Author

maraino commented Jul 31, 2018

@csstaub: any update on this?

@csstaub csstaub merged commit 8254d6c into square:v2 Aug 1, 2018
@csstaub
Copy link
Collaborator

csstaub commented Aug 1, 2018

@maraino LGTM, thanks for your contribution! If you would like for me to tag/release a new version with this included let me know.

@maraino
Copy link
Contributor Author

maraino commented Aug 1, 2018

If you would like for me to tag/release a new version with this included let me know.

@csstaub: I leave this up to you, I have no preferences.

@maraino
Copy link
Contributor Author

maraino commented Aug 1, 2018

@csstaub: go ahead and add a new tag, it will be cleaner and easier to manage.

@csstaub
Copy link
Collaborator

csstaub commented Aug 8, 2018

Tagged as v2.1.8: https://github.com/square/go-jose/releases/tag/v2.1.8

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

Successfully merging this pull request may close these issues.

None yet

3 participants