Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
import base64
|
|
|
|
import os
|
|
|
|
|
2019-11-25 14:37:55 +01:00
|
|
|
import gevent
|
|
|
|
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
from Plugin import PluginManager
|
2019-04-15 22:55:01 +02:00
|
|
|
from Crypt import CryptBitcoin, CryptHash
|
2019-11-25 14:37:55 +01:00
|
|
|
from Config import config
|
2020-03-05 17:54:46 +01:00
|
|
|
import sslcrypto
|
|
|
|
|
2019-03-15 21:06:59 +01:00
|
|
|
from . import CryptMessage
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
2020-03-05 17:54:46 +01:00
|
|
|
curve = sslcrypto.ecc.get_curve("secp256k1")
|
|
|
|
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
|
|
|
@PluginManager.registerTo("UiWebsocket")
|
|
|
|
class UiWebsocketPlugin(object):
|
|
|
|
# - Actions -
|
|
|
|
|
|
|
|
# Returns user's public key unique to site
|
|
|
|
# Return: Public key
|
|
|
|
def actionUserPublickey(self, to, index=0):
|
2020-03-05 17:54:46 +01:00
|
|
|
self.response(to, self.user.getEncryptPublickey(self.site.address, index))
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
|
|
|
# Encrypt a text using the publickey or user's sites unique publickey
|
|
|
|
# Return: Encrypted text using base64 encoding
|
|
|
|
def actionEciesEncrypt(self, to, text, publickey=0, return_aes_key=False):
|
|
|
|
if type(publickey) is int: # Encrypt using user's publickey
|
|
|
|
publickey = self.user.getEncryptPublickey(self.site.address, publickey)
|
2019-03-16 02:23:00 +01:00
|
|
|
aes_key, encrypted = CryptMessage.eciesEncrypt(text.encode("utf8"), publickey)
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
if return_aes_key:
|
2019-03-16 02:23:00 +01:00
|
|
|
self.response(to, [base64.b64encode(encrypted).decode("utf8"), base64.b64encode(aes_key).decode("utf8")])
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
else:
|
2019-03-16 02:23:00 +01:00
|
|
|
self.response(to, base64.b64encode(encrypted).decode("utf8"))
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
|
|
|
# Decrypt a text using privatekey or the user's site unique private key
|
|
|
|
# Return: Decrypted text or list of decrypted texts
|
|
|
|
def actionEciesDecrypt(self, to, param, privatekey=0):
|
|
|
|
if type(privatekey) is int: # Decrypt using user's privatekey
|
|
|
|
privatekey = self.user.getEncryptPrivatekey(self.site.address, privatekey)
|
|
|
|
|
|
|
|
if type(param) == list:
|
|
|
|
encrypted_texts = param
|
|
|
|
else:
|
|
|
|
encrypted_texts = [param]
|
|
|
|
|
2019-11-25 14:37:55 +01:00
|
|
|
texts = CryptMessage.eciesDecryptMulti(encrypted_texts, privatekey)
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
|
|
|
if type(param) == list:
|
|
|
|
self.response(to, texts)
|
|
|
|
else:
|
|
|
|
self.response(to, texts[0])
|
|
|
|
|
|
|
|
# Encrypt a text using AES
|
|
|
|
# Return: Iv, AES key, Encrypted text
|
2020-03-05 17:54:46 +01:00
|
|
|
def actionAesEncrypt(self, to, text, key=None):
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
if key:
|
2019-03-16 02:23:00 +01:00
|
|
|
key = base64.b64decode(key)
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
else:
|
2020-03-05 17:54:46 +01:00
|
|
|
key = sslcrypto.aes.new_key()
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
|
|
|
if text:
|
2020-03-05 17:54:46 +01:00
|
|
|
encrypted, iv = sslcrypto.aes.encrypt(text.encode("utf8"), key)
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
else:
|
2020-03-05 17:54:46 +01:00
|
|
|
encrypted, iv = b"", b""
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
2019-03-16 02:23:00 +01:00
|
|
|
res = [base64.b64encode(item).decode("utf8") for item in [key, iv, encrypted]]
|
|
|
|
self.response(to, res)
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
|
|
|
# Decrypt a text using AES
|
|
|
|
# Return: Decrypted text
|
|
|
|
def actionAesDecrypt(self, to, *args):
|
|
|
|
if len(args) == 3: # Single decrypt
|
|
|
|
encrypted_texts = [(args[0], args[1])]
|
|
|
|
keys = [args[2]]
|
|
|
|
else: # Batch decrypt
|
|
|
|
encrypted_texts, keys = args
|
|
|
|
|
|
|
|
texts = [] # Decoded texts
|
|
|
|
for iv, encrypted_text in encrypted_texts:
|
2019-03-16 02:23:00 +01:00
|
|
|
encrypted_text = base64.b64decode(encrypted_text)
|
|
|
|
iv = base64.b64decode(iv)
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
text = None
|
|
|
|
for key in keys:
|
|
|
|
try:
|
2020-03-05 17:54:46 +01:00
|
|
|
decrypted = sslcrypto.aes.decrypt(encrypted_text, iv, base64.b64decode(key))
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
if decrypted and decrypted.decode("utf8"): # Valid text decoded
|
2019-03-16 02:23:00 +01:00
|
|
|
text = decrypted.decode("utf8")
|
|
|
|
except Exception as err:
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
pass
|
|
|
|
texts.append(text)
|
|
|
|
|
|
|
|
if len(args) == 3:
|
|
|
|
self.response(to, texts[0])
|
|
|
|
else:
|
|
|
|
self.response(to, texts)
|
|
|
|
|
2019-04-15 22:55:01 +02:00
|
|
|
# Sign data using ECDSA
|
|
|
|
# Return: Signature
|
2019-04-19 19:34:07 +02:00
|
|
|
def actionEcdsaSign(self, to, data, privatekey=None):
|
|
|
|
if privatekey is None: # Sign using user's privatekey
|
|
|
|
privatekey = self.user.getAuthPrivatekey(self.site.address)
|
2019-04-15 22:55:01 +02:00
|
|
|
|
2019-04-20 09:48:56 +02:00
|
|
|
self.response(to, CryptBitcoin.sign(data, privatekey))
|
2019-04-15 22:55:01 +02:00
|
|
|
|
|
|
|
# Verify data using ECDSA (address is either a address or array of addresses)
|
|
|
|
# Return: bool
|
|
|
|
def actionEcdsaVerify(self, to, data, address, signature):
|
2019-04-20 09:48:56 +02:00
|
|
|
self.response(to, CryptBitcoin.verify(data, address, signature))
|
2019-04-15 22:55:01 +02:00
|
|
|
|
2019-05-01 06:42:56 +02:00
|
|
|
# Gets the publickey of a given privatekey
|
2019-05-19 14:52:36 +02:00
|
|
|
def actionEccPrivToPub(self, to, privatekey):
|
2020-03-05 17:54:46 +01:00
|
|
|
self.response(to, curve.private_to_public(curve.wif_to_private(privatekey)))
|
2019-05-01 06:42:56 +02:00
|
|
|
|
|
|
|
# Gets the address of a given publickey
|
2019-05-19 14:52:36 +02:00
|
|
|
def actionEccPubToAddr(self, to, publickey):
|
2020-03-05 17:54:46 +01:00
|
|
|
self.response(to, curve.public_to_address(bytes.fromhex(publickey)))
|
2019-05-01 06:42:56 +02:00
|
|
|
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
|
|
|
|
@PluginManager.registerTo("User")
|
|
|
|
class UserPlugin(object):
|
|
|
|
def getEncryptPrivatekey(self, address, param_index=0):
|
2019-07-03 18:35:55 +02:00
|
|
|
if param_index < 0 or param_index > 1000:
|
|
|
|
raise Exception("Param_index out of range")
|
|
|
|
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
site_data = self.getSiteData(address)
|
|
|
|
|
|
|
|
if site_data.get("cert"): # Different privatekey for different cert provider
|
|
|
|
index = param_index + self.getAddressAuthIndex(site_data["cert"])
|
|
|
|
else:
|
|
|
|
index = param_index
|
|
|
|
|
|
|
|
if "encrypt_privatekey_%s" % index not in site_data:
|
|
|
|
address_index = self.getAddressAuthIndex(address)
|
|
|
|
crypt_index = address_index + 1000 + index
|
|
|
|
site_data["encrypt_privatekey_%s" % index] = CryptBitcoin.hdPrivatekey(self.master_seed, crypt_index)
|
|
|
|
self.log.debug("New encrypt privatekey generated for %s:%s" % (address, index))
|
|
|
|
return site_data["encrypt_privatekey_%s" % index]
|
|
|
|
|
|
|
|
def getEncryptPublickey(self, address, param_index=0):
|
2019-07-03 18:35:55 +02:00
|
|
|
if param_index < 0 or param_index > 1000:
|
|
|
|
raise Exception("Param_index out of range")
|
|
|
|
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
site_data = self.getSiteData(address)
|
|
|
|
|
|
|
|
if site_data.get("cert"): # Different privatekey for different cert provider
|
|
|
|
index = param_index + self.getAddressAuthIndex(site_data["cert"])
|
|
|
|
else:
|
|
|
|
index = param_index
|
|
|
|
|
|
|
|
if "encrypt_publickey_%s" % index not in site_data:
|
|
|
|
privatekey = self.getEncryptPrivatekey(address, param_index)
|
2020-03-05 17:54:46 +01:00
|
|
|
publickey = curve.private_to_public(curve.wif_to_private(privatekey))
|
2019-03-16 02:23:00 +01:00
|
|
|
site_data["encrypt_publickey_%s" % index] = base64.b64encode(publickey).decode("utf8")
|
Version 0.3.4, Rev656, CryptMessage plugin for AES and ECIES encryption, Added pyelliptic lib for OpenSSSL based encryption methods, Test CryptMessage plugin, Force reload content.json before signing and after write, Escaped Sql IN queries support, Test Sql parameter escaping, ui_websocket Test fixture, Plugin testing support, Always return websocket errors as dict, Wait for file on weboscket fileGet command if its already in bad_files queue, PushState and ReplaceState url manipulation support in wrapper API, Per auth-address localstorage, Longer timeout for udp tracker query
2015-12-10 21:36:20 +01:00
|
|
|
return site_data["encrypt_publickey_%s" % index]
|
2019-11-19 02:05:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
@PluginManager.registerTo("Actions")
|
|
|
|
class ActionsPlugin:
|
|
|
|
publickey = "A3HatibU4S6eZfIQhVs2u7GLN5G9wXa9WwlkyYIfwYaj"
|
|
|
|
privatekey = "5JBiKFYBm94EUdbxtnuLi6cvNcPzcKymCUHBDf2B6aq19vvG3rL"
|
|
|
|
utf8_text = '\xc1rv\xedzt\xfbr\xf5t\xfck\xf6rf\xfar\xf3g\xe9p'
|
|
|
|
|
|
|
|
def getBenchmarkTests(self, online=False):
|
|
|
|
if hasattr(super(), "getBenchmarkTests"):
|
|
|
|
tests = super().getBenchmarkTests(online)
|
|
|
|
else:
|
|
|
|
tests = []
|
|
|
|
|
|
|
|
aes_key, encrypted = CryptMessage.eciesEncrypt(self.utf8_text.encode("utf8"), self.publickey) # Warm-up
|
|
|
|
tests.extend([
|
|
|
|
{"func": self.testCryptEciesEncrypt, "kwargs": {}, "num": 100, "time_standard": 1.2},
|
|
|
|
{"func": self.testCryptEciesDecrypt, "kwargs": {}, "num": 500, "time_standard": 1.3},
|
2019-11-25 14:37:55 +01:00
|
|
|
{"func": self.testCryptEciesDecryptMulti, "kwargs": {}, "num": 5, "time_standard": 0.68},
|
2019-11-19 02:05:02 +01:00
|
|
|
{"func": self.testCryptAesEncrypt, "kwargs": {}, "num": 10000, "time_standard": 0.27},
|
|
|
|
{"func": self.testCryptAesDecrypt, "kwargs": {}, "num": 10000, "time_standard": 0.25}
|
|
|
|
])
|
|
|
|
return tests
|
|
|
|
|
|
|
|
def testCryptEciesEncrypt(self, num_run=1):
|
|
|
|
for i in range(num_run):
|
|
|
|
aes_key, encrypted = CryptMessage.eciesEncrypt(self.utf8_text.encode("utf8"), self.publickey)
|
|
|
|
assert len(aes_key) == 32
|
|
|
|
yield "."
|
|
|
|
|
|
|
|
def testCryptEciesDecrypt(self, num_run=1):
|
|
|
|
aes_key, encrypted = CryptMessage.eciesEncrypt(self.utf8_text.encode("utf8"), self.publickey)
|
|
|
|
for i in range(num_run):
|
|
|
|
assert len(aes_key) == 32
|
2020-03-05 17:54:46 +01:00
|
|
|
decrypted = CryptMessage.eciesDecrypt(base64.b64encode(encrypted), self.privatekey)
|
|
|
|
assert decrypted == self.utf8_text.encode("utf8"), "%s != %s" % (decrypted, self.utf8_text.encode("utf8"))
|
2019-11-19 02:05:02 +01:00
|
|
|
yield "."
|
|
|
|
|
2019-11-25 14:37:55 +01:00
|
|
|
def testCryptEciesDecryptMulti(self, num_run=1):
|
|
|
|
yield "x 100 (%s threads) " % config.threads_crypt
|
|
|
|
aes_key, encrypted = CryptMessage.eciesEncrypt(self.utf8_text.encode("utf8"), self.publickey)
|
|
|
|
|
|
|
|
threads = []
|
|
|
|
for i in range(num_run):
|
|
|
|
assert len(aes_key) == 32
|
|
|
|
threads.append(gevent.spawn(
|
|
|
|
CryptMessage.eciesDecryptMulti, [base64.b64encode(encrypted)] * 100, self.privatekey
|
|
|
|
))
|
|
|
|
|
|
|
|
for thread in threads:
|
|
|
|
res = thread.get()
|
|
|
|
assert res[0] == self.utf8_text, "%s != %s" % (res[0], self.utf8_text)
|
|
|
|
assert res[0] == res[-1], "%s != %s" % (res[0], res[-1])
|
|
|
|
yield "."
|
|
|
|
gevent.joinall(threads)
|
|
|
|
|
2019-11-19 02:05:02 +01:00
|
|
|
def testCryptAesEncrypt(self, num_run=1):
|
|
|
|
for i in range(num_run):
|
|
|
|
key = os.urandom(32)
|
2020-03-05 17:54:46 +01:00
|
|
|
encrypted = sslcrypto.aes.encrypt(self.utf8_text.encode("utf8"), key)
|
2019-11-19 02:05:02 +01:00
|
|
|
yield "."
|
|
|
|
|
|
|
|
def testCryptAesDecrypt(self, num_run=1):
|
|
|
|
key = os.urandom(32)
|
2020-03-05 17:54:46 +01:00
|
|
|
encrypted_text, iv = sslcrypto.aes.encrypt(self.utf8_text.encode("utf8"), key)
|
2019-11-19 02:05:02 +01:00
|
|
|
|
|
|
|
for i in range(num_run):
|
2020-03-05 17:54:46 +01:00
|
|
|
decrypted = sslcrypto.aes.decrypt(encrypted_text, iv, key).decode("utf8")
|
2019-11-19 02:05:02 +01:00
|
|
|
assert decrypted == self.utf8_text
|
|
|
|
yield "."
|