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

fix(hmac) handle invalid Base64-encoded signatures #2283

Merged
merged 1 commit into from
Mar 31, 2017

Conversation

p0pr0ck5
Copy link
Contributor

We don't need to try to compare against an empty string.

Additionally, remove the needless length comparison. This was bugged
to begin with, but the length comparison is needless, and doing so
removes the constant time factor from this function.

@Tieske
Copy link
Member

Tieske commented Mar 29, 2017

see also #2189

@p0pr0ck5
Copy link
Contributor Author

Yep, thanks @Tieske. This PR would obviate that one.

@p0pr0ck5 p0pr0ck5 force-pushed the fix/hmac-digest-equals branch 2 times, most recently from 3327946 to fd1627b Compare March 29, 2017 18:16
@@ -108,6 +108,21 @@ describe("Plugin: hmac-auth (access)", function()
assert.equal(SIGNATURE_NOT_VALID, body.message)
end)

it("show not be authorized when the HMAC signature is properly base64 encoded", function()
Copy link
Member

Choose a reason for hiding this comment

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

"is not properly base64 encoded" ?

@p0pr0ck5 p0pr0ck5 force-pushed the fix/hmac-digest-equals branch from fd1627b to 5e278e4 Compare March 29, 2017 18:28
local body = assert.res_status(403, res)
body = cjson.decode(body)
assert.equal(SIGNATURE_NOT_VALID, body.message)
end)
Copy link
Member

@thibaultcha thibaultcha Mar 29, 2017

Choose a reason for hiding this comment

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

As @Tieske pointed out in the other PR, this test does indeed pass without the fix. Hmmm 🤔

Copy link
Contributor Author

@p0pr0ck5 p0pr0ck5 Mar 29, 2017

Choose a reason for hiding this comment

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

Incorrectly written test. The value to be tested is the signature portion of the (proxy) authorization header, not the whole authorization header.

And also remember this new test would still not fail with the existing codebase, because digest_2 is never examined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

noting here for posterity because github doesnt track patchset versions in PR with amended commits:

@thibaultcha's comment refers to the face that previously the authorization header was not a properly encoded base64 value. the purpose of the test is to determine the behavior of the module when the signature portion of the header is not properly encoded, not that the whole header value is an invalid encoding.

Copy link
Member

Choose a reason for hiding this comment

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

And also remember this new test would still not fail with the existing codebase, because digest_2 is never examined.

Yes, noticed that as well. Quite the surprise.

Copy link
Contributor

Choose a reason for hiding this comment

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

it would have still failed if digests were different. Just the initial length check was wrong.

@p0pr0ck5 p0pr0ck5 force-pushed the fix/hmac-digest-equals branch from 5e278e4 to 1f6b7e4 Compare March 29, 2017 21:01
it("should not be authorized when the HMAC signature is not properly base64 encoded", function()
local date = os.date("!%a, %d %b %Y %H:%M:%S GMT")
local hmacAuth = [["hmac username="bob",algorithm="hmac-sha1",]]
..[[headers="date",signature="not really a base64 encoded value!!!"]]
Copy link
Member

Choose a reason for hiding this comment

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

Looks much better, I just ran a few debug statements and realized what the test was doing 😅

@p0pr0ck5 p0pr0ck5 force-pushed the fix/hmac-digest-equals branch from 1f6b7e4 to 148ed47 Compare March 29, 2017 21:24
@Tieske
Copy link
Member

Tieske commented Mar 30, 2017

shouldn't this be against master instead of next?

@p0pr0ck5
Copy link
Contributor Author

@Tieske why? This doesn't feel like a super critical hotfix.

@p0pr0ck5 p0pr0ck5 changed the base branch from next to master March 30, 2017 21:17
@p0pr0ck5 p0pr0ck5 force-pushed the fix/hmac-digest-equals branch from 148ed47 to c70d6a8 Compare March 30, 2017 21:20
We don't need to try to compare against an empty string.

Additionally, remove the needless length comparison. This was bugged
to begin with, but the length comparison is needless, and doing so
removes the constant time factor from this function.
@p0pr0ck5 p0pr0ck5 force-pushed the fix/hmac-digest-equals branch from c70d6a8 to 19e2e79 Compare March 30, 2017 21:23
@p0pr0ck5
Copy link
Contributor Author

re-targeted and rebased to merge into master

@Tieske Tieske merged commit 7345134 into master Mar 31, 2017
@Tieske Tieske deleted the fix/hmac-digest-equals branch March 31, 2017 09:14
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.

4 participants