Compare commits
No commits in common. "11c9c463554d0423417f130e917cda76c6811394" and "61051d5711c4c3d02b150b49c05f09a5cf4ff910" have entirely different histories.
11c9c46355
...
61051d5711
@ -27,3 +27,10 @@ done
|
|||||||
echo "ran $ran integration tests."
|
echo "ran $ran integration tests."
|
||||||
echo "total test time $SECONDS"
|
echo "total test time $SECONDS"
|
||||||
ran=0;
|
ran=0;
|
||||||
|
|
||||||
|
#for f in tests/browser-tests/*.py; do
|
||||||
|
# python3 "$f" || close # if needed
|
||||||
|
# let "ran++"
|
||||||
|
#done
|
||||||
|
#echo "ran $ran browser tests."
|
||||||
|
#echo "total test time $SECONDS"
|
||||||
|
@ -1 +0,0 @@
|
|||||||
from wot.crypto import encryption
|
|
@ -1,55 +0,0 @@
|
|||||||
from typing import TYPE_CHECKING, Union
|
|
||||||
|
|
||||||
from ..identity import Identity
|
|
||||||
|
|
||||||
import nacl.public
|
|
||||||
import nacl.utils
|
|
||||||
|
|
||||||
|
|
||||||
def encrypt_to_identity_anonymously(
|
|
||||||
identity: 'Identity',
|
|
||||||
message: Union[bytes, str]) -> nacl.utils.EncryptedMessage:
|
|
||||||
their_public_key = identity.key.to_curve25519_public_key()
|
|
||||||
box = nacl.public.SealedBox(their_public_key)
|
|
||||||
|
|
||||||
try:
|
|
||||||
message = message.encode('utf-8')
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return box.encrypt(message)
|
|
||||||
|
|
||||||
|
|
||||||
def decrypt_from_identity_anonymously(
|
|
||||||
our_identity: 'Identity', message: bytes) -> bytes:
|
|
||||||
our_private_key = our_identity.private_key.to_curve25519_private_key()
|
|
||||||
box = nacl.public.SealedBox(our_private_key)
|
|
||||||
|
|
||||||
return box.decrypt(message)
|
|
||||||
|
|
||||||
|
|
||||||
def encrypt_to_identity(
|
|
||||||
our_identity: 'Identity',
|
|
||||||
identity: 'Identity',
|
|
||||||
message: Union[bytes, str]) -> nacl.utils.EncryptedMessage:
|
|
||||||
our_private_key = our_identity.private_key.to_curve25519_private_key()
|
|
||||||
their_public_key = identity.key.to_curve25519_public_key()
|
|
||||||
box = nacl.public.Box(our_private_key, their_public_key)
|
|
||||||
|
|
||||||
try:
|
|
||||||
message = message.encode('utf-8')
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return box.encrypt(message)
|
|
||||||
|
|
||||||
|
|
||||||
def decrypt_from_identity(
|
|
||||||
our_identity: 'Identity',
|
|
||||||
identity: 'Identity',
|
|
||||||
message: bytes) -> bytes:
|
|
||||||
our_private_key = our_identity.private_key.to_curve25519_private_key()
|
|
||||||
their_public_key = identity.key.to_curve25519_public_key()
|
|
||||||
box = nacl.public.Box(our_private_key, their_public_key)
|
|
||||||
|
|
||||||
return box.decrypt(message)
|
|
@ -1,84 +0,0 @@
|
|||||||
import dbm
|
|
||||||
import os, uuid
|
|
||||||
|
|
||||||
import time
|
|
||||||
|
|
||||||
TEST_DIR = 'testdata/%s-%s' % (str(uuid.uuid4())[:6], os.path.basename(__file__)) + '/'
|
|
||||||
print("Test directory:", TEST_DIR)
|
|
||||||
os.environ["ONIONR_HOME"] = TEST_DIR
|
|
||||||
os.makedirs(TEST_DIR)
|
|
||||||
|
|
||||||
from nacl import signing
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
import sys
|
|
||||||
sys.path.append('static-data/official-plugins/wot/')
|
|
||||||
sys.path.append("src/")
|
|
||||||
import onionrblocks
|
|
||||||
from blockdb import block_db_path
|
|
||||||
import nacl.public
|
|
||||||
import nacl.exceptions
|
|
||||||
import nacl.signing
|
|
||||||
|
|
||||||
import wot
|
|
||||||
from wot.identity import Identity
|
|
||||||
|
|
||||||
from wot import crypto
|
|
||||||
|
|
||||||
import blockdb
|
|
||||||
|
|
||||||
|
|
||||||
class TestEncryptToIdentity(unittest.TestCase):
|
|
||||||
|
|
||||||
def test_encrypt_to_identity_bytes(self):
|
|
||||||
iden_priv_key = signing.SigningKey.generate()
|
|
||||||
iden_public = iden_priv_key.verify_key
|
|
||||||
identity = Identity(iden_priv_key, "us")
|
|
||||||
|
|
||||||
their_priv_key = signing.SigningKey.generate()
|
|
||||||
their_public = their_priv_key.verify_key
|
|
||||||
their_identity = Identity(their_priv_key, "them")
|
|
||||||
|
|
||||||
test_message = b"test message"
|
|
||||||
|
|
||||||
encrypted = crypto.encryption.encrypt_to_identity(identity, their_identity, test_message)
|
|
||||||
decrypted = nacl.public.Box(their_priv_key.to_curve25519_private_key(), iden_public.to_curve25519_public_key()).decrypt(encrypted)
|
|
||||||
self.assertEqual(decrypted, test_message)
|
|
||||||
|
|
||||||
def test_encrypt_to_identity_str(self):
|
|
||||||
iden_priv_key = signing.SigningKey.generate()
|
|
||||||
iden_public = iden_priv_key.verify_key
|
|
||||||
identity = Identity(iden_priv_key, "us")
|
|
||||||
|
|
||||||
their_priv_key = signing.SigningKey.generate()
|
|
||||||
their_public = their_priv_key.verify_key
|
|
||||||
their_identity = Identity(their_priv_key, "them")
|
|
||||||
|
|
||||||
test_message = "test message"
|
|
||||||
|
|
||||||
encrypted = crypto.encryption.encrypt_to_identity(identity, their_identity, test_message)
|
|
||||||
decrypted = nacl.public.Box(their_priv_key.to_curve25519_private_key(), iden_public.to_curve25519_public_key()).decrypt(encrypted)
|
|
||||||
self.assertEqual(decrypted, test_message.encode('utf-8'))
|
|
||||||
|
|
||||||
def test_encrypt_to_identity_bytes_invalid(self):
|
|
||||||
iden_priv_key = signing.SigningKey.generate()
|
|
||||||
iden_public = iden_priv_key.verify_key
|
|
||||||
identity = Identity(iden_priv_key, "us")
|
|
||||||
|
|
||||||
their_priv_key = signing.SigningKey.generate()
|
|
||||||
their_public = their_priv_key.verify_key
|
|
||||||
their_identity = Identity(their_priv_key, "them")
|
|
||||||
|
|
||||||
test_message = b"test message"
|
|
||||||
|
|
||||||
encrypted = crypto.encryption.encrypt_to_identity(identity, their_identity, test_message)
|
|
||||||
encrypted = encrypted[:-1] + b'\x00'
|
|
||||||
try:
|
|
||||||
decrypted = nacl.public.Box(their_priv_key.to_curve25519_private_key(), iden_public.to_curve25519_public_key()).decrypt(encrypted)
|
|
||||||
except nacl.exceptions.CryptoError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.fail("Decrypted invalid message")
|
|
||||||
|
|
||||||
|
|
||||||
unittest.main()
|
|
@ -11,10 +11,9 @@ os.environ["ONIONR_HOME"] = TEST_DIR
|
|||||||
import unittest
|
import unittest
|
||||||
import sys
|
import sys
|
||||||
sys.path.append(".")
|
sys.path.append(".")
|
||||||
sys.path.append('static-data/official-plugins/wot/')
|
sys.path.append('static-data/official-plugins/wot/wot/')
|
||||||
sys.path.append("src/")
|
sys.path.append("src/")
|
||||||
import wot
|
from identity import Identity
|
||||||
from wot.identity import Identity
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
1
tests/runtime-result.txt
Normal file
1
tests/runtime-result.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
1611429331
|
Loading…
Reference in New Issue
Block a user