-
Notifications
You must be signed in to change notification settings - Fork 78
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
symmetric encryption fixed #1542
Conversation
security issue
Thanks for taking a look at this code. With these changes, are the unit tests passing? Why do you say "fixed"? It worked before; the unit tests passed. It looks more like a refactor, specifically a code cleanup. (Not a "fix".) Thanks, |
Like I said, I think a new test is needed : "I wanted to test symmetric encryption and test the result with wrong key. And all keys works !" So to be shorter, the code always encrypts with a key0 (a fixed absolute key) and always decrypt with it, and even with any key as input ! No message can be protected ! A new test is to check if the decrypt function is not working with a wrong key. Possible test :
I have updated the crypto test |
add test wrong sym key
Thank you for the thorough response. We will review the code in detail, aiming for the next 24 hours. Best, |
ocean_lib/ocean/crypto.py
Outdated
@@ -18,7 +18,7 @@ | |||
def calc_symkey(base_str: str) -> str: | |||
"""Compute a symmetric private key that's a function of the base_str""" | |||
base_b = base_str.encode("utf-8") # bytes | |||
hash_b = sha256(base_b) | |||
hash_b = sha256(base_b).hexdigest() | |||
symkey_b = b64encode(str(hash_b).encode("ascii"))[:43] + b"=" # bytes |
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.
I think in line 22, we no longer need the str cast, since hash_b is already a string
OK go ahead and merge it. Thanks! |
security issue
Fixes # .
Changes proposed in this PR:
I was trying to test some function in the repo :
https://github.com/oceanprotocol/ocean.py/blob/main/ocean_lib/ocean/crypto.py
I wanted to test symmetric encryption and test the result with wrong key...
And all keys works !
if you look at the code of calc_symkey at line 21 and 22 :
hash_b = sha256(base_b)
symkey_b = b64encode(str(hash_b).encode("ascii"))[:43] + b"=" # bytes
Actually the result of "str(hash_b)" is not a hash but the string representation of the hash object.
e.g. :
<sha256 _hashlib.HASH object @ 0x11d3aaa30>
To have a hash, you need to just replace line 21 by :
hash_b = sha256(base_b).hexdigest()
e.g. :
eadd5118ccd09b09649ff613c3cb457c10f686187d7c26103dadb64772f8b03b
With the current code, I think that all symmetric key with
calc_symkey
give the same encryption !I have tried, and I can decrypt with any symmetric key issued with
calc_symkey
something encrypted.