Skip to content

Conversation

hslatman
Copy link
Member

No description provided.

@hslatman hslatman changed the title Add support for RSA-OAEP (key) encryption Add support for RSA-OAEP (key) encryption (WIP) May 18, 2023
@hslatman hslatman requested a review from maraino May 18, 2023 20:45
@hslatman hslatman changed the title Add support for RSA-OAEP (key) encryption (WIP) Add support for RSA-OAEP (key) encryption May 18, 2023
Copy link

@maraino maraino left a comment

Choose a reason for hiding this comment

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

It looks good, but I've added a few comments that we might want to consider.

@@ -77,7 +75,11 @@ var (
OIDEncryptionAlgorithmECDSAP384 = asn1.ObjectIdentifier{1, 3, 132, 0, 34}
OIDEncryptionAlgorithmECDSAP521 = asn1.ObjectIdentifier{1, 3, 132, 0, 35}

// Encryption Algorithms
// Asymmetric Encryption Algorithms
Copy link

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added some references now. Not to all of them; will revisit sometime.

// KeyEncryptionAlgorithm determines the algorithm used to encrypt a
// content key. Change the value of this variable to change which
// algorithm is used in the Encrypt() function.
var KeyEncryptionAlgorithm = OIDEncryptionAlgorithmRSA
Copy link

Choose a reason for hiding this comment

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

If possible, we should use RSA OAEP by default.

Copy link

Choose a reason for hiding this comment

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

Are we considering adding new encrypt methods so we don't have to change the value of this variable?

The same applies to ContentEncryptionAlgorithm. And should we default to EncryptionAlgorithmAES256GCM. I guess we cannot use XSalsa20+Poly1305 here.

Copy link
Member Author

@hslatman hslatman May 19, 2023

Choose a reason for hiding this comment

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

Right now it uses the current default, making this fork backwards compatible with the current Mozilla one (with some fixes and new features). But I agree that defaulting to RSA OAEP is better going forward. Same applies to EncryptionAlgorithmAES256GCM.

For XSalsa20+Poly1305 in CMS there exists a proposed standard: https://datatracker.ietf.org/doc/html/rfc8103. So I guess it can be added; it's just a bit less "standard" than the other algorithms, but still something that has been reviewed by IETF.

Yes, changing the API of this package is something I would like to do. If we add new functions, the changes could be backwards compatible: create new methods that take options, backed by private methods, and adapt the current methods. But it might also make sense to start a new major version, so that there's no need to be fully backwards compatible and can make breaking changes in terms of supported algorithms.

Copy link

@maraino maraino left a comment

Choose a reason for hiding this comment

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

lgtm

@hslatman hslatman merged commit 4b0ad5e into patches May 19, 2023
@hslatman hslatman deleted the encrypt-key-encryption-algorithm branch May 19, 2023 18:01
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.

2 participants