- Notifications
You must be signed in to change notification settings - Fork 267
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import hashlib | ||
| class ALGORITHMS(object): | ||
| NONE = 'none' | ||
| HS256 = 'HS256' | ||
| 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 | ||
| 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 |
Uh oh!
There was an error while loading. Please reload this page.
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