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

Support the b64 header parameter #230

Merged
merged 4 commits into from
May 20, 2019
Merged

Support the b64 header parameter #230

merged 4 commits into from
May 20, 2019

Conversation

philtay
Copy link
Contributor

@philtay philtay commented May 13, 2019

Closes #225

@CLAassistant
Copy link

CLAassistant commented May 13, 2019

CLA assistant check
All committers have signed the CLA.

@philtay
Copy link
Contributor Author

philtay commented May 14, 2019

This PR is ready for review.

/cc @csstaub @mcpherrinm

jws.go Outdated
var serializedProtected string
var buf bytes.Buffer

pro := new(rawHeader)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a nit, but I'd prefer if we gave these variables more descriptive names. It's not clear at first glance what "pro", "enc" and "buf" mean or what they're used for.

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about calling these protectedHeader, needsBase64, and authData (or something along those lines)?

@@ -349,6 +350,21 @@ func (parsed rawHeader) getP2S() (*byteBuffer, error) {
return parsed.getByteBuffer(headerP2S)
}

// getB64 extracts parsed "b64" from the raw JSON, defaulting to true.
func (parsed rawHeader) getB64() (bool, error) {
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 ever be necessary here to distinguish between the header being present, and set, or the header being not present and the default return value being false?

signing.go Outdated
input.WriteString(base64.RawURLEncoding.EncodeToString(serializedProtected))
input.WriteByte('.')

enc := true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment as above, let's call this something other than "enc". Could be confused to mean "encrypt" for example.

ExtraHeaders: map[HeaderKey]interface{}{
"b64": false,
},
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems somewhat non-obvious, would it be better to have this be a first-class option in SignerOptions and have the signing code add the header if that's selected?

@csstaub
Copy link
Collaborator

csstaub commented May 14, 2019

Hi @philtay, thank you so much for your pull request! I left a couple of comments inline, but I think what's also missing is code to add the b64 header to the list of crit headers (see RFC 7797, Section 6). But otherwise this looks pretty good!

@philtay
Copy link
Contributor Author

philtay commented May 15, 2019

@csstaub thanks for the review. The last commit takes in account your comments and brings some improvements.

@philtay
Copy link
Contributor Author

philtay commented May 20, 2019

@csstaub can you review the updated PR? I'm eager to have this merged. Thanks!

@csstaub
Copy link
Collaborator

csstaub commented May 20, 2019

Hi @philtay, changes look good to me! Thank you very much for your contribution. I'll merge this and play around with it a bit and then will try to make a tagged release later this week.

@csstaub csstaub merged commit 35ecfcd into square:v2 May 20, 2019
@philtay
Copy link
Contributor Author

philtay commented May 21, 2019

@csstaub thanks! I've another PR to open before making a tagged release. A func (obj JSONWebSignature) DetachedCompactSerialize() (string, error) method as per RFC 7797 (compact serialization and detached payload). I'll open the PR later today or tomorrow. If you want, I'm also interested in closing #223 and cutting a v3.0.0. Just merge the v2 branch into master and I'll do the rest. Let me know.

@csstaub
Copy link
Collaborator

csstaub commented May 21, 2019

Sounds good, let's do it.

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.

3 participants