def test_rsassa_2k_sha384(): LOGGER.info('Sign data with newly generated RSA2k key and SHA384') setup_keys_2k() s = rsassa.sign(pytest.twok, pytest.tbs_str, hash_algorithm='sha384') assert isinstance(s.signature, bytes) assert len(s.signature) > 0 assert s.hash_alg == 'sha384' assert s.keyid in KeyId assert s.algorithm == 'sha384_rsa'
def test_rsassa_1k_sha256(): LOGGER.info('Sign data with newly generated RSA1k key and SHA256') setup_keys_1k() s = rsassa.sign(pytest.onek, pytest.tbs_str) assert isinstance(s.signature, bytes) assert len(s.signature) > 0 assert s.hash_alg == 'sha256' assert s.keyid in KeyId assert s.algorithm == 'sha256_rsa'
def test_1k_signverify(): LOGGER.info('Sign data with newly generated RSA1k key and verify result') setup_keys_1k() ha = 'sha256' s = rsassa.sign(pytest.onek, pytest.tbs_str) print('[{}]'.format(', '.join(hex(x) for x in list(s.signature)))) pubkey_info = keys.PublicKeyInfo.load(pytest.onek.pkey) # Load a public key into the oscrypto engine to using it in the verify function public = load_public_key(pubkey_info) rsa_pkcs1v15_verify(public, s.signature, pytest.tbs_str, ha) # Assert wrong text with pytest.raises(SignatureError): rsa_pkcs1v15_verify(public, s.signature, pytest.tbs_str_fail, ha) # Assert wrong key with pytest.raises(SignatureError): pubkey_info = keys.PublicKeyInfo.load(pytest.onek_fail.pkey) public = load_public_key(pubkey_info) rsa_pkcs1v15_verify(public, s.signature, pytest.tbs_str, ha)
def test_rsassa_checkcopy(): LOGGER.info('Sign data with newly generated RSA1k key and check return value') setup_keys_1k() s = rsassa.sign(pytest.onek, pytest.tbs_str) assert s.keyid is pytest.onek.keyid
def test_rsassa_nonkey_2(): LOGGER.info('Sign faulty data with a correct key') setup_keys_1k() with pytest.raises(TypeError): rsassa.sign(pytest.onek, int(19273917398739829))
def test_rsassa_nonkey(): LOGGER.info('Sign data with empty key') with pytest.raises(TypeError): rsassa.sign(bytearray(35), pytest.tbs_str)