def test_SigningSomeTextWithKey1AndVerifyingWithPubkey1_RaisesInvalidSignature( self): plain_text = "some text" key_1, pubkey_1 = rsa.generate_keys() key_2, pubkey_2 = rsa.generate_keys() with raises(rsa.InvalidSignature): valid_signature = rsa.sign(key_1, plain_text) rsa.verify(pubkey_2, valid_signature, plain_text)
def test_SigningSomeTextWithKey1AndVerifyingWithPubkey1_DoesNotRaiseInvalidSignature( self): plain_text = "some text" key, pubkey = rsa.generate_keys() valid_signature = rsa.sign(key, plain_text) rsa.verify(pubkey, valid_signature, plain_text)
def test_DumpingAPublicKeyAndLoadingTheRespectiveReturnsTheSameKey( self, tmpfile): key, pubkey = rsa.generate_keys() rsa.dump_pubkey(pubkey, tmpfile) loaded_pubkey = rsa.load_pubkey(tmpfile) assert pubkey == loaded_pubkey
def test_DumpingAPrivateKeyWithPasswordAndLoadingTheRespectiveReturnsTheSameKey( self, tmpfile): key, pubkey = rsa.generate_keys() rsa.dump_key(key, tmpfile, password="******") loaded_key, loaded_pubkey = rsa.load_keys(tmpfile, password="******") assert key == loaded_key assert pubkey == loaded_pubkey
def __init__(self, group_server_url: str, group_server_pubkey: str, main_server_pubkey: str, proxy_server_url: str, email: str, key_path=None, keys=None): self.group_server_url = group_server_url self.group_server_pubkey = group_server_pubkey self.main_server_pubkey = main_server_pubkey self.proxy_server_url = proxy_server_url self.email = email if key_path: self.key, self.pubkey = rsa.load_keys(key_path) elif keys: self.key, self.pubkey = keys else: self.key, self.pubkey = rsa.generate_keys()
def setUp(self): self.message_class = msg.MainServerJoin self.private_key, self.key = generate_keys() self.group = Group.objects.create(name='test', key=example_keys.G1_pub)
from utils.crypto.rsa import generate_keys G1_priv, G1_pub = generate_keys() G2_priv, G2_pub = generate_keys() C1_priv, C1_pub = generate_keys() C2_priv, C2_pub = generate_keys() C3_priv, C3_pub = generate_keys() C4_priv, C4_pub = generate_keys()
import json from http.client import HTTPResponse from unittest.mock import Mock, MagicMock from pytest import fixture from utils.crypto.rsa import generate_keys, InvalidSignature example_key, example_pub_key = generate_keys() def fake_body(parameters: dict) -> str: """ Creates a fake request body from a dict with parameters """ # there is no problem to use JSON directly to convert the parameters since # here it is not our goal to test the JSON format but input parameters return json.dumps(parameters) def fake_http_response(status=200, body=bytes()) -> HTTPResponse: """ Creates a fake HTTP response. :param status: status code of the response. :param body: body of the response in bytes :return: fake http response (mock object) """ http_response = Mock() http_response.status = status http_response.read = MagicMock(return_value=body) # noinspection PyTypeChecker
def test_SigningSomeNonStringValues(self): values = ["hey", 10, 56.4, 'ho'] key, pubkey = rsa.generate_keys() rsa.sign(key, *values)
def test_VerifyingACompletelyBrokenSignature_RaisesInvalidSignature(self): key, pubkey = rsa.generate_keys() with raises(rsa.InvalidSignature): rsa.verify(pubkey, "completelyBogûsÇigna_!ture", "not a chance!")