Test CryptMessage ui_websocket result more reliable way
This commit is contained in:
parent
545acebbaf
commit
6f0531c663
1 changed files with 21 additions and 28 deletions
|
@ -46,60 +46,54 @@ class TestCrypt:
|
||||||
pub2 = ui_websocket.testAction("UserPublickey", 0)
|
pub2 = ui_websocket.testAction("UserPublickey", 0)
|
||||||
assert pub1 != pub2
|
assert pub1 != pub2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def testEcies(self, ui_websocket):
|
def testEcies(self, ui_websocket):
|
||||||
ui_websocket.actionUserPublickey(0, 0)
|
ui_websocket.actionUserPublickey(0, 0)
|
||||||
pub = ui_websocket.ws.result
|
pub = ui_websocket.ws.getResult()
|
||||||
|
|
||||||
ui_websocket.actionEciesEncrypt(0, "hello", pub)
|
ui_websocket.actionEciesEncrypt(0, "hello", pub)
|
||||||
encrypted = ui_websocket.ws.result
|
encrypted = ui_websocket.ws.getResult()
|
||||||
assert len(encrypted) == 180
|
assert len(encrypted) == 180
|
||||||
|
|
||||||
# Don't allow decrypt using other privatekey index
|
# Don't allow decrypt using other privatekey index
|
||||||
ui_websocket.actionEciesDecrypt(0, encrypted, 123)
|
ui_websocket.actionEciesDecrypt(0, encrypted, 123)
|
||||||
decrypted = ui_websocket.ws.result
|
decrypted = ui_websocket.ws.getResult()
|
||||||
assert decrypted != "hello"
|
assert decrypted != "hello"
|
||||||
|
|
||||||
# Decrypt using correct privatekey
|
# Decrypt using correct privatekey
|
||||||
ui_websocket.actionEciesDecrypt(0, encrypted)
|
ui_websocket.actionEciesDecrypt(0, encrypted)
|
||||||
decrypted = ui_websocket.ws.result
|
decrypted = ui_websocket.ws.getResult()
|
||||||
assert decrypted == "hello"
|
assert decrypted == "hello"
|
||||||
|
|
||||||
# Decrypt batch
|
# Decrypt batch
|
||||||
ui_websocket.actionEciesDecrypt(0, [encrypted, "baad", encrypted])
|
ui_websocket.actionEciesDecrypt(0, [encrypted, "baad", encrypted])
|
||||||
decrypted = ui_websocket.ws.result
|
decrypted = ui_websocket.ws.getResult()
|
||||||
assert decrypted == ["hello", None, "hello"]
|
assert decrypted == ["hello", None, "hello"]
|
||||||
|
|
||||||
|
|
||||||
def testEciesUtf8(self, ui_websocket):
|
def testEciesUtf8(self, ui_websocket):
|
||||||
# Utf8 test
|
# Utf8 test
|
||||||
utf8_text = u'\xc1rv\xedzt\xfbr\xf5t\xfck\xf6rf\xfar\xf3g\xe9p'
|
ui_websocket.actionEciesEncrypt(0, self.utf8_text)
|
||||||
ui_websocket.actionEciesEncrypt(0, utf8_text)
|
encrypted = ui_websocket.ws.getResult()
|
||||||
encrypted = ui_websocket.ws.result
|
|
||||||
|
|
||||||
ui_websocket.actionEciesDecrypt(0, encrypted)
|
ui_websocket.actionEciesDecrypt(0, encrypted)
|
||||||
assert ui_websocket.ws.result == utf8_text
|
assert ui_websocket.ws.getResult() == self.utf8_text
|
||||||
|
|
||||||
|
|
||||||
def testEciesAes(self, ui_websocket):
|
def testEciesAes(self, ui_websocket):
|
||||||
ui_websocket.actionEciesEncrypt(0, "hello", return_aes_key=True)
|
ui_websocket.actionEciesEncrypt(0, "hello", return_aes_key=True)
|
||||||
ecies_encrypted, aes_key = ui_websocket.ws.result
|
ecies_encrypted, aes_key = ui_websocket.ws.getResult()
|
||||||
|
|
||||||
# Decrypt using Ecies
|
# Decrypt using Ecies
|
||||||
ui_websocket.actionEciesDecrypt(0, ecies_encrypted)
|
ui_websocket.actionEciesDecrypt(0, ecies_encrypted)
|
||||||
assert ui_websocket.ws.result == "hello"
|
assert ui_websocket.ws.getResult() == "hello"
|
||||||
|
|
||||||
# Decrypt using AES
|
# Decrypt using AES
|
||||||
aes_iv, aes_encrypted = CryptMessage.split(ecies_encrypted.decode("base64"))
|
aes_iv, aes_encrypted = CryptMessage.split(base64.b64decode(ecies_encrypted))
|
||||||
|
|
||||||
ui_websocket.actionAesDecrypt(0, aes_iv.encode("base64"), aes_encrypted.encode("base64"), aes_key)
|
|
||||||
assert ui_websocket.ws.result == "hello"
|
|
||||||
|
|
||||||
|
ui_websocket.actionAesDecrypt(0, base64.b64encode(aes_iv), base64.b64encode(aes_encrypted), aes_key)
|
||||||
|
assert ui_websocket.ws.getResult() == "hello"
|
||||||
|
|
||||||
def testAes(self, ui_websocket):
|
def testAes(self, ui_websocket):
|
||||||
ui_websocket.actionAesEncrypt(0, "hello")
|
ui_websocket.actionAesEncrypt(0, "hello")
|
||||||
key, iv, encrypted = ui_websocket.ws.result
|
key, iv, encrypted = ui_websocket.ws.getResult()
|
||||||
|
|
||||||
assert len(key) == 44
|
assert len(key) == 44
|
||||||
assert len(iv) == 24
|
assert len(iv) == 24
|
||||||
|
@ -107,26 +101,25 @@ class TestCrypt:
|
||||||
|
|
||||||
# Single decrypt
|
# Single decrypt
|
||||||
ui_websocket.actionAesDecrypt(0, iv, encrypted, key)
|
ui_websocket.actionAesDecrypt(0, iv, encrypted, key)
|
||||||
assert ui_websocket.ws.result == "hello"
|
assert ui_websocket.ws.getResult() == "hello"
|
||||||
|
|
||||||
# Batch decrypt
|
# Batch decrypt
|
||||||
ui_websocket.actionAesEncrypt(0, "hello")
|
ui_websocket.actionAesEncrypt(0, "hello")
|
||||||
key2, iv2, encrypted2 = ui_websocket.ws.result
|
key2, iv2, encrypted2 = ui_websocket.ws.getResult()
|
||||||
|
|
||||||
assert [key, iv, encrypted] != [key2, iv2, encrypted2]
|
assert [key, iv, encrypted] != [key2, iv2, encrypted2]
|
||||||
|
|
||||||
# 2 correct key
|
# 2 correct key
|
||||||
ui_websocket.actionAesDecrypt(0, [[iv, encrypted], [iv, encrypted], [iv, "baad"], [iv2, encrypted2]], [key])
|
ui_websocket.actionAesDecrypt(0, [[iv, encrypted], [iv, encrypted], [iv, "baad"], [iv2, encrypted2]], [key])
|
||||||
assert ui_websocket.ws.result == ["hello", "hello", None, None]
|
assert ui_websocket.ws.getResult() == ["hello", "hello", None, None]
|
||||||
|
|
||||||
# 3 key
|
# 3 key
|
||||||
ui_websocket.actionAesDecrypt(0, [[iv, encrypted], [iv, encrypted], [iv, "baad"], [iv2, encrypted2]], [key, key2])
|
ui_websocket.actionAesDecrypt(0, [[iv, encrypted], [iv, encrypted], [iv, "baad"], [iv2, encrypted2]], [key, key2])
|
||||||
assert ui_websocket.ws.result == ["hello", "hello", None, "hello"]
|
assert ui_websocket.ws.getResult() == ["hello", "hello", None, "hello"]
|
||||||
|
|
||||||
def testAesUtf8(self, ui_websocket):
|
def testAesUtf8(self, ui_websocket):
|
||||||
utf8_text = u'\xc1rv\xedzt\xfbr\xf5t\xfck\xf6rf\xfar\xf3g\xe9'
|
ui_websocket.actionAesEncrypt(0, self.utf8_text)
|
||||||
ui_websocket.actionAesEncrypt(0, utf8_text)
|
key, iv, encrypted = ui_websocket.ws.getResult()
|
||||||
key, iv, encrypted = ui_websocket.ws.result
|
|
||||||
|
|
||||||
ui_websocket.actionAesDecrypt(0, iv, encrypted, key)
|
ui_websocket.actionAesDecrypt(0, iv, encrypted, key)
|
||||||
assert ui_websocket.ws.result == utf8_text
|
assert ui_websocket.ws.getResult() == self.utf8_text
|
||||||
|
|
Loading…
Reference in a new issue