python: Turn the signature buffer into a bytearray.

This is a workaround for a bug where signature verification would
overwrite the variable holding the signature.

This only happens on python2.

Signed-off-by: Damir Jelić <poljar@termina.org.uk>
This commit is contained in:
Damir Jelić 2019-01-23 17:49:42 +01:00 committed by Hubert Chathi
parent 94f664e725
commit 45091c158d
2 changed files with 19 additions and 2 deletions

View file

@ -81,14 +81,15 @@ class _Utility(object):
byte_key = to_bytes(key) byte_key = to_bytes(key)
byte_message = to_bytearray(message) byte_message = to_bytearray(message)
byte_signature = to_bytes(signature) byte_signature = to_bytearray(signature)
try: try:
cls._check_error( cls._check_error(
lib.olm_ed25519_verify(cls._utility, byte_key, len(byte_key), lib.olm_ed25519_verify(cls._utility, byte_key, len(byte_key),
ffi.from_buffer(byte_message), ffi.from_buffer(byte_message),
len(byte_message), len(byte_message),
byte_signature, len(byte_signature))) ffi.from_buffer(byte_signature),
len(byte_signature)))
finally: finally:
# clear out copies of the message, which may be a plaintext # clear out copies of the message, which may be a plaintext
if byte_message is not message: if byte_message is not message:

View file

@ -98,3 +98,19 @@ class TestClass(object):
with pytest.raises(OlmVerifyError): with pytest.raises(OlmVerifyError):
ed25519_verify(signing_key, message, signature) ed25519_verify(signing_key, message, signature)
@given(text())
def test_signature_verification_twice(self, message):
alice = Account()
signature = alice.sign(message)
signing_key = alice.identity_keys["ed25519"]
assert signature
assert signing_key
ed25519_verify(signing_key, message, signature)
assert signature == alice.sign(message)
ed25519_verify(signing_key, message, signature)
assert signature == alice.sign(message)