-
Notifications
You must be signed in to change notification settings - Fork 1k
hmac.compare_digest is not in earlier version python2.7.7 #13
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
hmac.compare_digest is not in earlier version python2.7.7 #13
Conversation
85fe814 to
276e67c
Compare
|
Hi, @charsyam OK. In the near future, I will fix this issue and release 1.0.2 version. |
|
maybe @charsyam can get hint here https://github.com/python/cpython/blob/2.7/Modules/operator.c#L289 |
f44920c to
305adf6
Compare
|
Hi, @be-hase could you review this? I implemented safe_compare_digest func to refer tscmp |
|
Oh... thanks for your patch. 👍 |
linebot/webhook.py
Outdated
| return hmac.compare_digest( | ||
| signature.encode('utf-8'), base64.b64encode(gen_signature) | ||
| ) | ||
| if hexversion >= 0x020707F0: |
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.
Would you like to use if hasattr(hmac, "compare_digest"): ?
I think that it is readable.
305adf6 to
f590147
Compare
linebot/webhook.py
Outdated
| return ret == 0 | ||
|
|
||
|
|
||
| compare_digest = safe_compare_digest |
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.
@be-hase how about this approach?
I applied hasattr and made function reference as compare_digest.
|
One more thing, we adopt Google style docstring but yours is reST format. Can you rewrite your function's docstring as Google one? Google python style guide This SO question will help you :) |
|
Why does not use |
|
@okdtsk Good Catch, I will apply your review to use len2 directlry |
f590147 to
9450c09
Compare
linebot/webhook.py
Outdated
| if len1 == len2: | ||
| left = str1 | ||
| ret = 0 | ||
|
|
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.
why not else ?
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.
In your hint. There is an answer. so I avoid to use else :)
/* don't use else here to keep the amount of CPU instructions constant,
* volatile forces re-evaluation */
|
I'm sorry reply late.
Yes, we use reST format. Sorry @okdtsk 😢 This feature is sensitive, so I want a test code. |
|
And... |
|
@be-hase Yes, I also worry about that. How we can test it well? |
|
@be-hase and We can't just return False when length is different. |
|
@charsyam LINE Signature is hashed by SHA-256 algorithm, so bytes length must be 32bytes. (Example) |
af51cb1 to
9827e6d
Compare
linebot/utils.py
Outdated
| def safe_compare_digest(val1, val2): | ||
| """safe_compare_digest method. | ||
| :param str or bytes val1: string or bytes for compare |
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.
OK, looks good to me.
Sorry..., How about this ?
:param val1: string or bytes for compare
:type val1: str | bytes
ref:
https://github.com/line/line-bot-sdk-python/blob/master/linebot/api.py#L79-L83
And Have you signed up ICLA?
( https://feedback.line.me/enquete/public/919-h9Yqmr1u )
If you have completed, I will merge and release 1.0.2
Thanks 😄
fix indent implement tscmp for preventing timing attack remove semicolon apply flake8 apply flake8 refactoring using hasattr refactoring using len2 directly add test and refactoring add test and refactoring change docstring
9827e6d to
29759f7
Compare
|
@be-hase I singed ICLA and update your review for changing docstring Thanks |
earlier version python2.7.7
hmac doesn't support compare_digest
so I implement workaround for this. :)