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

JWE Support #220

Closed
wants to merge 8 commits into from
Closed

JWE Support #220

wants to merge 8 commits into from

Conversation

ortyomka
Copy link

Issue #67

Add support of JWE with one key (Compact)

Add AES GCM cipher to encrypt content
Add RSA-OAEP to encrypt key

Add test from RFC7516 Section 3.3

cc @mfridman

Signed-off-by: ortyomka <iurin.art@gmail.com>
Signed-off-by: ortyomka <iurin.art@gmail.com>
Signed-off-by: ortyomka <iurin.art@gmail.com>
Signed-off-by: ortyomka <iurin.art@gmail.com>
Add tests

Signed-off-by: ortyomka <iurin.art@gmail.com>
Signed-off-by: ortyomka <iurin.art@gmail.com>
@mfridman
Copy link
Member

I think this was an oversight on our part. This likely doesn't belong in this package.

https://github.com/golang-jwt/jwt#signing-vs-encryption

Not sure if our stance on this has changed cc @oxisto

@ortyomka
Copy link
Author

As I understand it, this section was written before this issue was created. And in the issue, the author of the section writes that he doesn't mind supporting JWE.

dgrijalva commented on Jul 30, 2019
I've looked into it. JWE is a sibling standard to JWT. I'm open to supporting it

Moreover, some people are waiting for this support.

ptman commented on Mar 22
JWE support seems to still be missing. What other libraries have people had good success with?

I purposely put JWE in a separate module so as not to affect the main part of the project. Developers need to intentionally include the JWE module if they want to use it.

@oxisto
Copy link
Collaborator

oxisto commented Jun 25, 2022

I think this was an oversight on our part. This likely doesn't belong in this package.

https://github.com/golang-jwt/jwt#signing-vs-encryption

Not sure if our stance on this has changed cc @oxisto

Personally, I wouldn’t mind JWE support. We probably need to come up with a good naming / packaging scheme. I hopefully can allocate some time next week to give this a first review round.

Signed-off-by: ortyomka <iurin.art@gmail.com>
@ortyomka
Copy link
Author

ortyomka commented Jul 1, 2022

Reminder about PR

@oxisto @mfridman

@oxisto
Copy link
Collaborator

oxisto commented Jul 2, 2022

Before we go any further with this, I wonder whether it would be more appropriate to move this into a separate repository, @mfridman? Since JWT and JWE are more sibling references, and JWE support within the JWT repository might be confusing. So we would have github.com/golang-jwt/jwt and github.com/golang-jwt/jwe.

Copy link
Collaborator

@oxisto oxisto left a comment

Choose a reason for hiding this comment

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

First round of reviews

jwe/aesgcm.go Outdated Show resolved Hide resolved
"strings"
)

func NewJWE(alg KeyAlgorithm, key interface{}, method EncryptionType, plaintext []byte) (*jwe, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Documentation for exported function

Copy link
Author

Choose a reason for hiding this comment

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

Added documentation

jwe/jwe.go Outdated
}

type jwe struct {
protected map[string]string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to make this header a struct with specific values?

Copy link
Author

Choose a reason for hiding this comment

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

Changed to struct

@@ -0,0 +1,56 @@
package jwe_test
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice if we could re-use example data from https://datatracker.ietf.org/doc/html/rfc7516#appendix-A

Copy link
Author

Choose a reason for hiding this comment

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

Reused, This required setting a random, so I made a global random reader similar to the crypto.rand package.
Here

"strings"
)

func NewJWE(alg KeyAlgorithm, key interface{}, method EncryptionType, plaintext []byte) (*jwe, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Plaintext is the JWT in compact form, correct?

Copy link
Author

Choose a reason for hiding this comment

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

Any sensitive info. It can be JWT in compact form.

jwe/keycrypter.go Outdated Show resolved Hide resolved

var RSA_OAEP = KeyAlgorithm("RSA-OAEP")

func rsaEncrypt(key *rsa.PublicKey, cek []byte, alg KeyAlgorithm) ([]byte, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

any particular reason why you are using functions here instead of a struct with methods? Just wondering. The latter might be better if we want to make an interface out of it.

Copy link
Author

Choose a reason for hiding this comment

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

Changed to struct with Encrypt and Decrypt. For the future

Change map to struct with json tags
Rename enum values
Add documentation

Signed-off-by: ortyomka <iurin.art@gmail.com>
@ortyomka ortyomka requested a review from oxisto July 4, 2022 11:28
@ortyomka
Copy link
Author

ortyomka commented Jul 4, 2022

@oxisto thank you for the review. I fixed all comments, ask for re-review.

@mfridman
Copy link
Member

mfridman commented Jul 6, 2022

Before we go any further with this, I wonder whether it would be more appropriate to move this into a separate repository, @mfridman? Since JWT and JWE are more sibling references, and JWE support within the JWT repository might be confusing. So we would have github.com/golang-jwt/jwt and github.com/golang-jwt/jwe.

Yes, I think this should be moved to its own repository. github.com/golang-jwt/jwe sounds fine to me.

@ortyomka
Copy link
Author

ortyomka commented Jul 6, 2022

Before we go any further with this, I wonder whether it would be more appropriate to move this into a separate repository, @mfridman? Since JWT and JWE are more sibling references, and JWE support within the JWT repository might be confusing. So we would have github.com/golang-jwt/jwt and github.com/golang-jwt/jwe.

Yes, I think this should be moved to its own repository. github.com/golang-jwt/jwe sounds fine to me.

@mfridman, who can create new repo? I will forward this PR to there

@oxisto
Copy link
Collaborator

oxisto commented Jul 6, 2022

Before we go any further with this, I wonder whether it would be more appropriate to move this into a separate repository, @mfridman? Since JWT and JWE are more sibling references, and JWE support within the JWT repository might be confusing. So we would have github.com/golang-jwt/jwt and github.com/golang-jwt/jwe.

Yes, I think this should be moved to its own repository. github.com/golang-jwt/jwe sounds fine to me.

@mfridman, who can create new repo? I will forward this PR to there

https://github.com/golang-jwt/jwe

@ortyomka
Copy link
Author

ortyomka commented Jul 6, 2022

Before we go any further with this, I wonder whether it would be more appropriate to move this into a separate repository, @mfridman? Since JWT and JWE are more sibling references, and JWE support within the JWT repository might be confusing. So we would have github.com/golang-jwt/jwt and github.com/golang-jwt/jwe.

Yes, I think this should be moved to its own repository. github.com/golang-jwt/jwe sounds fine to me.

@mfridman, who can create new repo? I will forward this PR to there

https://github.com/golang-jwt/jwe

@oxisto need some init commit, I cannot fork or open PR

@ortyomka
Copy link
Author

ortyomka commented Jul 6, 2022

Moved to golang-jwt/jwe#1

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.

None yet

3 participants