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

Fix x5t #304

Merged
merged 11 commits into from
Apr 30, 2020
Merged

Fix x5t #304

merged 11 commits into from
Apr 30, 2020

Conversation

mangas
Copy link
Contributor

@mangas mangas commented Apr 29, 2020

Fixes #299

@CLAassistant
Copy link

CLAassistant commented Apr 29, 2020

CLA assistant check
All committers have signed the CLA.

@@ -3,6 +3,7 @@ module github.com/square/go-jose/v3
go 1.12

require (
github.com/google/go-cmp v0.4.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is more for output readability on the test but happy to drop it if you'd rather not add the dependency

Copy link
Contributor

Choose a reason for hiding this comment

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

seems fine to me

Copy link
Contributor

Choose a reason for hiding this comment

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

especially that Go modules knows when an import is used in tests, and even though this dep is present in go.mod, it will not bloat the actual code.

@@ -129,13 +130,13 @@ func (k JSONWebKey) MarshalJSON() ([]byte, error) {
if x5tSHA1Len != sha1.Size {
return nil, fmt.Errorf("square/go-jose: invalid SHA-1 thumbprint (must be %d bytes, not %d)", sha1.Size, x5tSHA1Len)
}
raw.X5tSHA1 = newFixedSizeBuffer(k.CertificateThumbprintSHA1, sha1.Size)
raw.X5tSHA1 = base64.RawURLEncoding.EncodeToString(k.CertificateThumbprintSHA1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could be newFixedSizeBuffer(k.CertificateThumbprintSHA1, sha1.Size).base64() which I believe has additional error-checking and verifies the size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That causes some problems with !bytes.Equal on line 296 that's why I kept this one instead

}
if x5tSHA256Len > 0 {
if x5tSHA256Len != sha256.Size {
return nil, fmt.Errorf("square/go-jose: invalid SHA-256 thumbprint (must be %d bytes, not %d)", sha256.Size, x5tSHA256Len)
}
raw.X5tSHA256 = newFixedSizeBuffer(k.CertificateThumbprintSHA256, sha256.Size)
raw.X5tSHA256 = base64.RawURLEncoding.EncodeToString(k.CertificateThumbprintSHA256)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could be newFixedSizeBuffer(k.CertificateThumbprintSHA1, sha1.Size).base64() which I believe has additional error-checking and verifies the size.

}
}

func TestRoundtripX509Hex(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding tests!

@csstaub
Copy link
Collaborator

csstaub commented Apr 29, 2020

Looks like there's a build failure but otherwise this seems good.

@mangas
Copy link
Contributor Author

mangas commented Apr 29, 2020

Build failure was the linter rule but IMO reducing complexity will hurt readability in this particular function

@mangas mangas requested a review from csstaub April 29, 2020 21:24
@mangas
Copy link
Contributor Author

mangas commented Apr 29, 2020

Travis is happy now it seems :)

jwk.go Outdated Show resolved Hide resolved
@mangas mangas requested a review from mbyczkowski April 29, 2020 23:26
jwk.go Outdated
// checksum so we skip this. Otherwise if the checksum was hex encoded we expect a 40 byte sized array so we'll
// try to hex decode it. When Marshalling this value we'll always use a base64 encoded version of byte format checksum.
if len(x5tSHA1bytes) == 2*sha1.Size {
if hx, err := hex.DecodeString(string(x5tSHA1bytes)); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

if we can't decode hex, we should error here (especially that we know the length is not a correct SHA1 length) and same for SHA256 hex

Copy link
Contributor

Choose a reason for hiding this comment

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

oh I see, we compare the lengths below and then fail. Seems ok to do it this way. Maybe a small comment could help, though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with an explicit message here

jwk_test.go Outdated
},
},
{
name: "no x5t25",
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit: this should probably say no x5t?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

},
},
{
name: "no x5t",
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit: this should probably say no x5t#S256?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@mbyczkowski mbyczkowski left a comment

Choose a reason for hiding this comment

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

@mangas left some comments, but overall I think this is good. Appreciate your work on this! 🙌

@mangas mangas requested a review from mbyczkowski April 30, 2020 09:02
jwk.go Outdated Show resolved Hide resolved
jwk.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mbyczkowski mbyczkowski left a comment

Choose a reason for hiding this comment

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

:shipit:

@mbyczkowski mbyczkowski added the V2-Cherry-Pick should also be applied to v2 branch label Apr 30, 2020
@mbyczkowski mbyczkowski merged commit d84c719 into square:master Apr 30, 2020
@mangas mangas deleted the fix-x5t branch April 30, 2020 18:05
mbyczkowski added a commit that referenced this pull request Apr 30, 2020
When support for optional x5u, x5t, and x5t#S256 parameters in JWK was added in #242 (and subsequently released in 2.5.0) it actually broke parsing of JWKs which included those parameters.

See #299 for detailed analysis and discussion.

Cherry-picked from #304

Needed minor tweaks, since v2 doesn't use golangci linter nor Go
modules.

Co-authored-by: Mat Byczkowski <mbyczkowski@gmail.com>
@mbyczkowski mbyczkowski mentioned this pull request Apr 30, 2020
mbyczkowski added a commit that referenced this pull request Apr 30, 2020
When support for optional x5u, x5t, and x5t#S256 parameters in JWK was added in #242 (and subsequently released in 2.5.0) it actually broke parsing of JWKs which included those parameters.

See #299 for detailed analysis and discussion.

Cherry-picked from #304

Needed minor tweaks, since v2 doesn't use golangci linter nor Go
modules.

Co-authored-by: Mat Byczkowski <mbyczkowski@gmail.com>
@mbyczkowski mbyczkowski mentioned this pull request Apr 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
V2-Cherry-Pick should also be applied to v2 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Version 2.5.0: has breaking changes in terms of certificate verfication
4 participants