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

setPayload flag and customized header properties #21

Merged
merged 5 commits into from
Apr 25, 2015

Conversation

brianjmiller
Copy link
Contributor

Trying this one again. It provides but fixes the same that was in #20 (which addresses #19).

It also now adds the ability to set custom properties in the header and have the verification on the other end still work. This was achieved by adding to the constructor for the JWS object a way to pass the header as an array rather than just the two individual options. The constructor change was the least change to the JWS::load method. Alternatively we could do the getHeader/setHeader dance.

Hopefully my tests have it covered this time. Note that I didn't alter the doc strings for the JWS constructor as I didn't know the best way to do so, nor whether it was worth publicizing. It might be left as an exercise for the reader who wants custom header properties.

Please have a look and let me know if any changes are needed. Thanks.

@brianjmiller
Copy link
Contributor Author

@Spomky interested in giving a look too?

}
}

parent::__construct(array(), $header);
Copy link
Contributor

Choose a reason for hiding this comment

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

TBH I think this will be confusing, as the algorith can either be the algorithm itself or a dictionary or headers. I think we should change the constructor rather than have this as it leads to misunderstanding and legacy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'm okay with that, I was just trying to maintain backwards compatibility to prevent the big version bump.

@odino
Copy link
Contributor

odino commented Jan 18, 2015

thanks man! I just have a couple things I want to clarify before being able to merge this. If we change the public API - as we probably should - then we also need to modify the README and I will bump the version to 3.0.0

cheers!

@brianjmiller
Copy link
Contributor Author

Yep, see my comments. Do you want to tackle the 3.0 bump changes?

@odino
Copy link
Contributor

odino commented Jan 19, 2015

yeah super open to keep the code as simple as possible even if it require
version bumps! :)

On Mon, Jan 19, 2015 at 8:36 PM, Brian J. Miller notifications@github.com
wrote:

Yep, see my comments. Do you want to tackle the 3.0 bump changes?


Reply to this email directly or view it on GitHub
#21 (comment).

Nadalin Alessandro
http://www.linkedin.com/in/alessandronadalin
www.odino.org
www.twitter.com/_odino_

@odino
Copy link
Contributor

odino commented Jan 21, 2015

btw are you using this branch anywhere in production? :)

@brianjmiller
Copy link
Contributor Author

No, ultimately (within the next couple weeks?) it will be a dependency in the OSS lib here:

https://github.com/RusticiSoftware/TinCanPHP

@odino
Copy link
Contributor

odino commented Jan 21, 2015

ok :) @Spomky any comment?

@brianjmiller
Copy link
Contributor Author

@odino finally got to this one. Changes include switching JWS to accept an array of options that becomes the header in the object with still auto setting the 'typ' property. Also edited the README to reflect the new construction interface and include the major version bump to 3. Tests updated. phpDoc doesn't seem to have a way to document associative array parameter values in depth so I followed an SO answer that suggested using the WordPress guidelines and so did that. (See https://make.wordpress.org/core/handbook/inline-documentation-standards/php-documentation-standards/#1-1-parameters-that-are-arrays)

@odino
Copy link
Contributor

odino commented Feb 4, 2015

i think im generally ok with this! @Spomky do you want to provide some feedback?

@Spomky
Copy link
Contributor

Spomky commented Feb 4, 2015

Hi,

I think it is useless to go deep into the explanation.
The problem is that if you are too restrictive (e.g. only accepts string=>string or string=>integer) you will create issues/warning for projects that want to allow custom headers with JSON Serializable objects.

IMO the following description is enough:

* @param array $header An associative array of headers. The value can be any type accepted by json_encode or a JSON serializable object
* @see http://php.net/manual/en/function.json-encode.php
* @see http://php.net/manual/en/jsonserializable.jsonserialize.php

@odino
Copy link
Contributor

odino commented Feb 5, 2015

BTW I think a nice way to handle with this problem is to:

  • switch to 3.X so that people wouldnt automatically upgrade
  • leave the automatic claims from the JWS class
  • have a new class that extends it, call it whatever, that adds the autoclaims on top of the JWS, if you dont pass them

That way its easier for people to pick which one to use and we keep the JWS class as simple as possible. Thoughts?

@brianjmiller
Copy link
Contributor Author

@Spomky that seems reasonable on the doc string, I might link directly to the JWS rfc as well as a suggestion of what "should" be there. I called out those two properties in particular to show that 'typ' has a default and because 'alg' is the bear minimum which used to be constructed for you. Seems like we're moving away from that which is fine.

@odino what would the new class be called? Would the constructor of the new class still take the header as its argument or would you revert it to what the original constructor in 2.x accepted?

@brianjmiller
Copy link
Contributor Author

I went ahead with some of these changes. I created a new class called EasyJWS that inherits from JWS. I moved the automatic handling of 'exp' and 'iat' into that class so that the base JWS class is barebones. Restoring the original constructor functionality was problematic because of the static load method still needing to construct with an array for the header. We could basically duplicate the load method from JWS in EasyJWS and make it work but I didn't like the non-DRYness of it.

I also updated the doc strings per @Spomky and updated the README to call out the JWT -> JWS -> EasyJWS structure.

@odino please have a look. thanks.

@odino
Copy link
Contributor

odino commented Feb 14, 2015

looks good! any suggestion for the class name instead of EasyJWS? it feels weird :)

@brianjmiller
Copy link
Contributor Author

Yeah, +1 if someone has a better suggestion, that was the best I could come up with.

@odino
Copy link
Contributor

odino commented Feb 25, 2015

hey brian could you please rebase your changes?

@brianjmiller
Copy link
Contributor Author

@odino rebased. Probably someone should review in light of the encoder changes, etc. that landed. I skimmed them but didn't look at them closely. Tests are passing as much as they were. Would be nice to get the 3 failures eliminated.

@odino
Copy link
Contributor

odino commented Mar 1, 2015

WDYM by the 3 failure aliminated? :)

@brianjmiller
Copy link
Contributor Author

I've been getting 3 failures consistently from the test suite since first started using the library. I think it may be environment specific, I thought I'd seen Travis blow up with the same but I can't seem to find that now. Here is the output from my environment:

repos/jose$ phpunit -c phpunit.xml.dist
PHPUnit 4.5.0 by Sebastian Bergmann and contributors.

Configuration read from /Users/brian/repos/jose/phpunit.xml.dist

...................F.F.F..............

Time: 154 ms, Memory: 6.75Mb

There were 3 failures:

1) Namshi\JOSE\Test\Signer\ES256Test::testSigningWorksProperly
Failed asserting that null is of type "string".

/Users/brian/repos/jose/tests/Namshi/JOSE/Test/Signer/ES256Test.php:41
/usr/local/pear/share/pear/PHPUnit/TextUI/Command.php:176
/usr/local/pear/share/pear/PHPUnit/TextUI/Command.php:129

2) Namshi\JOSE\Test\Signer\ES384Test::testSigningWorksProperly
Failed asserting that null is of type "string".

/Users/brian/repos/jose/tests/Namshi/JOSE/Test/Signer/ES384Test.php:31
/usr/local/pear/share/pear/PHPUnit/TextUI/Command.php:176
/usr/local/pear/share/pear/PHPUnit/TextUI/Command.php:129

3) Namshi\JOSE\Test\Signer\ES512Test::testSigningWorksProperly
Failed asserting that null is of type "string".

/Users/brian/repos/jose/tests/Namshi/JOSE/Test/Signer/ES512Test.php:31
/usr/local/pear/share/pear/PHPUnit/TextUI/Command.php:176
/usr/local/pear/share/pear/PHPUnit/TextUI/Command.php:129

FAILURES!
Tests: 38, Assertions: 62, Failures: 3.

@brianjmiller
Copy link
Contributor Author

@odino anything else needed here?

@odino
Copy link
Contributor

odino commented Mar 23, 2015

sorry man :( had very little time lately and we also had to rework on this library due to this

Ill try to give it a shot this weekend though I cant promise anything :-S

@brianjmiller
Copy link
Contributor Author

Catching up now on https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/. Presumably this PR needs to be rebased again and potentially examined based on how it handles the header.

@odino
Copy link
Contributor

odino commented Apr 1, 2015

oh yeah, definitely :( I think it actually needs to be rebased cause we pushed some fixes a few weeks ago to exactly target those vulnerabilities

@brianjmiller
Copy link
Contributor Author

@odino rebased again, would love to get this landed so that we can push forward with our other library's additions, dependencies are hard :-).

@cirpo
Copy link
Contributor

cirpo commented Apr 21, 2015

@brianjmiller could you please rebase it again? We just created version 3.0.0 which includes phpSeclib
thanks

@brianjmiller
Copy link
Contributor Author

Merging this change would then bump to 4.0.0 because it is non-backwards compatible. This will be the third rebase, will it actually be merged in timely manner? I can't continue to spend time rebasing and sitting on projects waiting on the dependency. Alternatively I could revert to the original implementation which didn't cause the backwards incompatible breakage, but was not prefer from a "complexity" of code standpoint. Either way appreciate the efforts, just need to make progress, thanks @cirpo.

@cirpo
Copy link
Contributor

cirpo commented Apr 21, 2015

@brianjmiller yes, we will bump up to 4.0.0 and yes I will merge it in less than 24h!

sorry and thanks a lot for your patience

@cirpo
Copy link
Contributor

cirpo commented Apr 21, 2015

@brianjmiller it would be great if you can also modify the README pointing out the incompatibility between 4.0.0 and 3.0.0

* Switch JWS constructor to accept header as array
* Includes bump to major version 4 in README
* Move auto claim handling into new EasyJWS class
@brianjmiller
Copy link
Contributor Author

@cirpo squashed + rebased. The number of commits was getting pretty ugly from the rebases (the conflict fixes) so I figured I'd clean up the history a bit.

@cirpo
Copy link
Contributor

cirpo commented Apr 22, 2015

@brianjmiller thanks, I'm gonna look into that today, thanks

@@ -100,16 +97,6 @@ public function testVerificationRS256()
$this->assertEquals('b', $payload['a']);
}

public function testValidationOfAValidJWS()
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any reason why these tests are deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests are specifically hitting the valid method which is moved into the EasyJWS class, so the corresponding tests got moved into EasyJWSTest. The other tests in this file hit verify which is the important method for the base JWS class after these changes.

@cirpo
Copy link
Contributor

cirpo commented Apr 22, 2015

@brianjmiller I made some comments, could you also please mention the differences between version 2, 3 and 4 in the README? Otherwise I will merge the PR, commit with an updated README/CHANGELOG and tag it 4.0.
Thanks, I promise we will get to the release in no time :)

@brianjmiller
Copy link
Contributor Author

@cirpo should be addressed. I wasn't clear on the bump from 1 to 2 or whether there were prior releases, you'd have to round that out if you want it.

@brianjmiller
Copy link
Contributor Author

@cirpo updated with indication in README.

@cirpo
Copy link
Contributor

cirpo commented Apr 24, 2015

@brianjmiller thank you! I was thinking about the EasyJws name, what about SimpleJWS?
We can even merge and tag now, I feel you're going to kill us :P

@brianjmiller
Copy link
Contributor Author

I think I went "Easy" because it implies the public interface is easy to use, as opposed to "Simple" because that might imply under featured. It honestly doesn't matter much to me, I don't love either :-).

@brianjmiller
Copy link
Contributor Author

@cirpo new commit EasyJWS -> SimpleJWS.

@cirpo
Copy link
Contributor

cirpo commented Apr 25, 2015

@brianjmiller thanks, merging!

cirpo added a commit that referenced this pull request Apr 25, 2015
setPayload flag and customized header properties
@cirpo cirpo merged commit a418f6c into namshi:master Apr 25, 2015
@cirpo
Copy link
Contributor

cirpo commented Apr 25, 2015

done and tagged!

@brianjmiller
Copy link
Contributor Author

phew, thanks!

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

4 participants