-
Notifications
You must be signed in to change notification settings - Fork 255
BLOCKED: Switch to pyelliptic for faster EC2 handling #39
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import hashlib | ||
|
|
||
|
|
||
| class ALGORITHMS(object): | ||
| NONE = 'none' | ||
| HS256 = 'HS256' | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,11 +40,9 @@ def sign(payload, key, headers=None, algorithm=ALGORITHMS.HS256): | |
|
|
||
| if algorithm not in ALGORITHMS.SUPPORTED: | ||
| raise JWSError('Algorithm %s not supported.' % algorithm) | ||
|
|
||
| encoded_header = _encode_header(algorithm, additional_headers=headers) | ||
| encoded_payload = _encode_payload(payload) | ||
| signed_output = _sign_header_and_claims(encoded_header, encoded_payload, algorithm, key) | ||
|
|
||
| return signed_output | ||
|
|
||
|
|
||
|
|
@@ -161,7 +159,11 @@ def _sign_header_and_claims(encoded_header, encoded_claims, algorithm, key_data) | |
| signing_input = b'.'.join([encoded_header, encoded_claims]) | ||
| try: | ||
| key = jwk.construct(key_data, algorithm) | ||
| signature = key.sign(signing_input) | ||
| # signing_input is a binary stream, which we need to re-encode to | ||
| # a base string. Decoding produces a ustring, encoding produces a | ||
| # base string. This resolves compatibility for 2.7+ and 3.x | ||
| dat = signing_input.decode('utf8').encode('utf8') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This could use a comment explaining why it's being round-tripped through the decoder/encoder |
||
| signature = key.sign(dat) | ||
| except Exception as e: | ||
| raise JWSError(e) | ||
|
|
||
|
|
@@ -211,7 +213,7 @@ def _sig_matches_keys(keys, signing_input, signature, alg): | |
| try: | ||
| if key.verify(signing_input, signature): | ||
| return True | ||
| except: | ||
| except Exception: | ||
| pass | ||
| return False | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| pycrypto | ||
| six | ||
| future | ||
| pyasn1==0.1.9 | ||
| pyelliptic==1.6.0 | ||
| # Until 1.6.0 lands, the corrected pyelliptic library is available at: | ||
| # -e git+https://github.com/jrconlin/pyelliptic.git#egg=pyelliptic |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an elif instead of if would be a bit clearer here