diff --git a/sdk/keyvault/azure-keyvault-keys/tests/keys.py b/sdk/keyvault/azure-keyvault-keys/tests/keys.py new file mode 100644 index 000000000000..80db438ae5f2 --- /dev/null +++ b/sdk/keyvault/azure-keyvault-keys/tests/keys.py @@ -0,0 +1,103 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +"""Keys for use in test cases""" + +from azure.keyvault.keys import KeyCurveName, KeyVaultKey + +EC_KEYS = { + KeyCurveName.p_256: KeyVaultKey( + key_id="https://localhost/keys/key-name/version", + jwk={ + "kty": "EC", + "key_ops": ["encrypt", "decrypt", "wrapKey", "unwrapKey", "sign", "verify"], + "d": b"^T\xf9F\r\xb5\xa8\x1a \n\xa6[\xfa\x12-0\n\xb7\x92\t\xee\xd1\x03\x9d\xd5\xca\x9c\n\xc4\x10\xefI", + "crv": "P-256", + "x": b"\xba\xb3Z\\\xea\x01\x10\xb4\xbe\x81\xb0\xc4h\xc2\xeb1\xa3\xbfb\x11A\xd939\xcc\x8aY\x05\xf3\x83\x12E", + "y": b"\x1fs\xbe\xfa\xc7\xef\xd3{H\xea\x1a\xcb:r\xc2\x8c\xf2\xde#z2B]\xc3\xa6>\xc0\xa6.pUN", + }, + ), + KeyCurveName.p_384: KeyVaultKey( + key_id="https://localhost/keys/key-name/version", + jwk={ + "kty": "EC", + "key_ops": ["encrypt", "decrypt", "wrapKey", "unwrapKey", "sign", "verify"], + "d": b"\xe1\x13g}\xdeV\xad(`\x85\xed\x8c\xc4}\x9f\x9eE\x14\x1c\x12\xff\xa4s\xa5L\x05j*W\xb3X\x88A\xe2?\x1f\x80\xd6\xf1\x0fR\x91\x0fh\xf3EH\xcf", + "crv": "P-384", + "x": b"\xa5\xd1\tFX\x12\xd5\xa8\xb5\x00\xe4p\xf8S\x8e\x8d\x80q\xdc.\xbe\x86\xef\xf1\x99\x15\xaa\xde0\xb1'(\xc0\xcb;43\xca\x14\x17,\xe1T\x10\xc2iK\x08", + "y": b"H6\x19\x8c\xe6\xcc\x0brhJ\x98\xd3\x9b\xf2\x08\xf5\xf0z&/S\xd2\xb3x \x18[\xcc\xb9E\xb6M\x87\xfb\x06z\xd9\x95\xcbj\x84\x8aPq$\xf3t\x9c", + }, + ), + KeyCurveName.p_256_k: KeyVaultKey( + key_id="https://localhost/keys/key-name/version", + jwk={ + "kty": "EC", + "key_ops": ["encrypt", "decrypt", "wrapKey", "unwrapKey", "sign", "verify"], + "d": b"\x84\x9f\xb9\x07\x91\x1c\xb9V#\x8d\xb8\xec+\x8e\xba\x17%\xc9[\xb1\xd0J\x94\xfd\xcb\x1c\x89\xd1[\x10\x86R", + "crv": "P-256K", + "x": b"~\xa5i\xa0\n\xe5wo\xf7\x08of\xb8\xf1\xee\xc8\x0b\x18\xde\x99t\x95\x06\x9c\xccb&L\xe4|;\xf6", + "y": b"t\xe9\x9d\x07^\x81\xb3\xdb(8\x90\x95\xdd \xa7\xf6\x0ep\xec$\x1cq\xc7\xcf\x08\xf8\xb5r\x9e04\xf3", + }, + ), + KeyCurveName.p_521: KeyVaultKey( + key_id="https://localhost/keys/key-name/version", + jwk={ + "kty": "EC", + "key_ops": ["encrypt", "decrypt", "wrapKey", "unwrapKey", "sign", "verify"], + "d": b"\xb55`\xbe\xd7\x0f'0D\xdf\xe0 \xd4\xed?\xf4\xee\xe0\xf0l\xd7\x08\x87l0\x04R\x01l1\x85\xb7\xf5\x14H\xde\x19\xeb\x13\xab_\xf0\t\xbe\x88\x18\x1b\xbd.\x89\xe9\xda3\xdc\x97\xc5\x18\x0f8\xa4\xbeb\x83z\xf0", + "crv": "P-521", + "x": b"\x83\x95Q\x1e\xa3\xf3\xad\xde\xc6\xb4\xdd\xe8\x1d^}\x15\x85\\\xcc\x95\xe4\xfc\xea\x89\x7f\x8d\xd2\xe5\x81/u\xbb^\xd0W\t\x93P\xdb3\xd6T\x8f\x9c\x90\xa1\x95\xffQ\xa0\x96\xd7\x11a.C\x03?\x81\x02D\xb2x\xf3\xaa", + "y": b'\x01\x8c\xda\xc9\x1ej\xe5B7\xcc\xaaFD\x0e\xb2\xe9\xaad\xf9\n\xc5\x93:\xcaBE\xbc\x04\x94\x03\xe0\xb8h\x00K3L"\xfa\r\x91\x8fJ\xbfJF2\x17\xd0\xfb\xbb@9\xbe\x87+\x05I\xab\x9cu\xafV\xaa\x1c\x99', + }, + ), +} + + +RSA_KEYS = { + 2048: KeyVaultKey( + key_id="https://localhost/keys/key-name/version", + jwk={ + "kty": "RSA", + "key_ops": ["encrypt", "decrypt", "wrapKey", "unwrapKey", "sign", "verify"], + "n": b"\xeb\xc8z\xdb\xa4\xa3U;\xb7Bn\xcfP\x9dA\x89\xdcq\xc7\x89\xe2I\x8dI9\xd5\x90b\xf0\xe5\t\xaf\x90\xf2\x8aC`5\xb1h\xbb\x19U\x86\xe1\xc2\x9f\xee_N\x93\xdec*\xc8J\x1bS3\xe4\xa0\xe5\x82\x0e\xd7P\xba\x1d\xbbb\xfbF\x85\x80\x9c\xb8)\xfb\xbb\xc0Y\xbasb\xc9-AZ\x85\xeajt\xcc\xf1\x96\x14\xaeD\x88,\xa3\x13\xcaE\xb3\xb2\xd7\x152P\xee\xf6lS\x1c\xdbp\xe4^\xd3\xf1\x18\xe6?\x94\xc9\x1dS\xdc\xc9\x08s\xd1bA\xa5\x1a?\x0cT\x7fAs\xb8\xfc\xdb\x0c\x82\xad+\x80\xb8=\xa2:\x85~\xe1\xef\xdc@w\x04\\j\x9c\x18h\x14j?*\xa8g\xd5\x91+\xe1\t!:\x0b\x10\xe0\x99\xc9\xe3g\x1e\xfao\xb5\x8fD\xd6r\x7f\x94\x7fX\x00\x9e#]\xcf@z\xae\x82\xa1\xa2)\x00\x8e\xb3\xdc\xc1\xdczNm\xb5', + "dp": b"\x91|\xbd\xa3\xf6\x01\x08\xb7\x92\x1c\x1a}\xe3\xc4\xb1#\x97\x0bxT\xb6\x13\xecx\x8f\xf6\xf3=B=\x80\xb2@\xf2\xce6rSDtB\x04u\x8d\x0c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\xae\r\xd6\x9e\x18\xa3\xdb\xc5\x81*\xd2\xa2r\xf0Q\x94\x97\x0eMd\x9c\xe0v\xb0"\x13\xac\x91\xcc\x8e\x15\xba\xf7\xc1\x82\xc2k\x83\x9c\n\xbd\x8f$^\xcaz4r3\xd6\xab\xc0p:\xe6\x95\t\x98\x89<\x17\xd7\x9a\x9e\t\xaa\xaf\xefW\xceR\x07v[\xa8\xa22\x99|\x9eM\xe4\x17{\xb3\x12\x86p\xc6\xdc\r\x0f', + "q": b"\xf2.Z\xe0pT\x8cE|\xbd\xaar\xa4}\xfaP\xe6\x86\x00,a\xd8@&\xed\xa3.Q\x89\xccbo\xd2\"\\\x97}\x0f\xa1;~{\x08\xb8\xc3\xb5'\x12aL}\xb2\xe9H\x13Z\xaf\x80\xaf\xa3Q\x84l\xee\xc8\xdd\x1c\xe3\xd5\x9a\x1c<\xd4'\x1c\xa3\x14\xa5\x85\xe8b\xe7\xb6\\\xe5\x8d\xbc\xf8u'\xa1\xfb\x03\xd0e!\xdc\xb8\xc6\xacA\x82\x7f\xecZ$\xf8w\xae\x1cO\xbb;)\xf5\x12;\xc6=9q\xe9\x1a\xe4PZ\xe7[", + }, + ), + 3072: KeyVaultKey( + key_id="https://localhost/keys/key-name/version", + jwk={ + "kty": "RSA", + "key_ops": ["encrypt", "decrypt", "wrapKey", "unwrapKey", "sign", "verify"], + "n": b"\xd4\x17\x03\t\xed\x10q\x96~\xaf\xf1\xa2\xd6Cb\xbf5\x9a\t\xda\xe0\xfe\x0c\xfa8C\x94\xad\x84\xdb\x90B\xb17\xf4\xb4\x16\x1b\x8d\xdc\xd2\t3\xae\x86\xffP\xfa\x07\x8cm\xb2?ZH\x0e\xb3\xdf\x18y`\x95\xf1\xe0\xf5\xa80O\xfdZ\x07\x00}\xd7g@\xd7\xce\x1a3|\xeb\x80(\xf5\xb9XR\x82`\xd9m\xd3\x9d\xf4\x02BPN\xdf\xfb\xcd\xad\r\xe7mM\xf9'\xdd\x1b9vK\x82!\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xb7\xd5\xd3\x92\x84\x81\xf4\xa7\xc0\xc3\xffz`\x91\x96M]\x180\xbfp#k)\x10\x19\xb5\x82\x1dg\xbak\x91\xff\xf8\niZ\xa4@\x03\xa1SB\xc6`e\xa7\xd1\xde\xec\x03\xf7\x94\x9b\x1bTr\x17\n\xee*\xd4s0\x0bc9\x91\x02W\x84\x96\xa7|f@\xdf\xa8Q&\xf4\xf9", + }, + ), + 4096: KeyVaultKey( + key_id="https://localhost/keys/key-name/version", + jwk={ + "kty": "RSA", + "key_ops": ["encrypt", "decrypt", "wrapKey", "unwrapKey", "sign", "verify"], + "n": b"\xea\x1e\x81=\n\x98\x81\xdf'T\x9e\xbaH\x19\n\x1d\x8b\x9a\xf1DJ\xe9\x7f6Q\x84o\x9f\x13}5p/\xce\xf7\xc5;\xef\x1a\x88\xb6\nvm\x94\xc1_N\xc4\xbd)\x80Z)\x12\x1e\xa5&\x8a]\xff\xbe\xfc1\x8e\xc8\xfa\x0b\x14\x0c\xeen\xa4S\xc5P\x08\x0e|\x1b\x01/\x98\xe1\xd8A\xa5\x88\x9b\xbd\xb9i\xe83A(p\x9f\xbf3Gp\xc7\xb7\xcc\xf7\x86\x08\xff\x10\x9f)=W\xe8\x8a\xa4H\xb6\x0c\xd44\xe3K\xa7L\x11.\xdd\x1d\xe5\xc9\xcf\xed.4mo\xe2\x03\x8e\xc9\xc2F\xc1\xf3\xdc\x18\\3\xe7\xe2Z\xf8\xccr\xea\xc4\x0c\x82I\x01E\x8e\x875\x87\x8f\xb4r\xd6\x1fZts\x1f\x05\xfa\xa9\xec\xe6z5\xd7\x19V*\xfeY\t$\xeegG\xfdz\x92\x10\xcb\xbb\x19$\xaa\xeb\x0c\t\xd1Nk6\x84c[`\x16\xd2!\x97\x19\xcc\x08\x9f\xc4\x1c\xed\x12k3{\xa1`\x97\x97\xa7\x05:L\x11t\xfa\xc4I\xab\xber\xd0M\xf4Fi\r\xaa-\x9b\xdb\xdaX?\x98w\xf1\xc4O\x01\xd2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xe0`!Y(\xf8K{\xbb\x8d\xdf\x05\xaac\xc7\xbaeo\x1d\xb4\x11\x01r\xc8`'\x02\x92f\xc1^\xc5\xf7H\r\xfd\xd2.A\xb8&\xd7*>\xe8[;\xd5\xa0Z*\x8b^{\xc7\x8bw\x8d\x1c\xbe6\xd4}\x12\xd5+", + "q": b'\xee\xd3\x7fo\xff\r\x91<}\x9f\xe0\x8f\xc6\x06\xad\x80\x1em\xbe\xa6_\xdd[%Z?\x8b\xe4\xb1\xcd\xea\xec\x9b\xd2\x19\'\x7f\xe8\x80\xf0\xc40A\xcc\xa8} N\xd3\xcbXI\xf6\xb1\xa7\xf7lp\xf3\xaaq\x8d\x80\x83\x10\xc8\xbb)\x06\xc8\x8f\xea\x11\\\xd2\x99C\x95\x7f\xd9\x92w)\xd4\x90\x1dNF\xbd\xf3\xed"\x84\xcej\x81\xfb\xf9\xd2qv\xc9\x152K\xb8\xf7\x10|\xc7\xeb\xdc\xf0\xb9s\x0f\xc0\x0c\xf7T\xb7B\xa4\x05\xbb\x124\xde\xc0\xec\x88\xb5"qI\x91=\x0cso\\R\xc8\x9a\xe3\xff\xc3\xc5\xdb\xb9\xf8\xbdL\xfc\x9c;\xf3\x90\xa1\xa2\xf3\x08\xb5\x07\x19\xceZ@\xea\xe2\x9acO\r\x1f\x1fL\x1c#?\x0b\x0e\x9d\xbd\x97/\xb5\xb0\x90\x84>s\xccs\xa9R\x988\x06\x18\xaf\r\xfa=\xa3\xcf\xa4\x90o\x95\x95\xbd\x1c\xee\xac*\xc2\xad\xeec4THb\xcb{\xc0\x08Nj>?\x16%\x9d\x0eC\x83\xf7\xc8\x80\x14\x91l\x19p\x17\xb8C\xf3\xf4\xb8\x07\xfe\xa6)', + }, + ), +} diff --git a/sdk/keyvault/azure-keyvault-keys/tests/test_local_crypto.py b/sdk/keyvault/azure-keyvault-keys/tests/test_local_crypto.py new file mode 100644 index 000000000000..4d39f3334f04 --- /dev/null +++ b/sdk/keyvault/azure-keyvault-keys/tests/test_local_crypto.py @@ -0,0 +1,89 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ +import hashlib +import os + +from azure.keyvault.keys import KeyCurveName, KeyVaultKey +from azure.keyvault.keys.crypto import EncryptionAlgorithm, KeyWrapAlgorithm, SignatureAlgorithm +from azure.keyvault.keys.crypto._providers import get_local_cryptography_provider +import pytest + +from keys import EC_KEYS, RSA_KEYS + + +@pytest.mark.parametrize( + "key,algorithm,hash_function", + ( + (EC_KEYS[KeyCurveName.p_256], SignatureAlgorithm.es256, hashlib.sha256), + (EC_KEYS[KeyCurveName.p_256_k], SignatureAlgorithm.es256_k, hashlib.sha256), + (EC_KEYS[KeyCurveName.p_384], SignatureAlgorithm.es384, hashlib.sha384), + (EC_KEYS[KeyCurveName.p_521], SignatureAlgorithm.es512, hashlib.sha512), + ), +) +def test_ec_sign_verify(key, algorithm, hash_function): + provider = get_local_cryptography_provider(key) + digest = hash_function(b"message").digest() + sign_result = provider.sign(algorithm, digest) + verify_result = provider.verify(sign_result.algorithm, digest, sign_result.signature) + assert verify_result.is_valid + + +@pytest.mark.parametrize("key", RSA_KEYS.values()) +@pytest.mark.parametrize("algorithm", (a for a in EncryptionAlgorithm if a.startswith("RSA"))) +def test_rsa_encrypt_decrypt(key, algorithm): + provider = get_local_cryptography_provider(key) + plaintext = b"plaintext" + encrypt_result = provider.encrypt(algorithm, plaintext) + decrypt_result = provider.decrypt(encrypt_result.algorithm, encrypt_result.ciphertext) + assert decrypt_result.plaintext == plaintext + + +@pytest.mark.parametrize("key", RSA_KEYS.values()) +@pytest.mark.parametrize( + "algorithm,hash_function", + ( + ( + (SignatureAlgorithm.ps256, hashlib.sha256), + (SignatureAlgorithm.ps384, hashlib.sha384), + (SignatureAlgorithm.ps512, hashlib.sha512), + (SignatureAlgorithm.rs256, hashlib.sha256), + (SignatureAlgorithm.rs384, hashlib.sha384), + (SignatureAlgorithm.rs512, hashlib.sha512), + ) + ), +) +def test_rsa_sign_verify(key, algorithm, hash_function): + message = b"message" + provider = get_local_cryptography_provider(key) + digest = hash_function(message).digest() + sign_result = provider.sign(algorithm, digest) + verify_result = provider.verify(sign_result.algorithm, digest, sign_result.signature) + assert verify_result.is_valid + + +@pytest.mark.parametrize("key", RSA_KEYS.values()) +@pytest.mark.parametrize("algorithm", (a for a in KeyWrapAlgorithm if a.startswith("RSA"))) +def test_rsa_wrap_unwrap(key, algorithm): + plaintext = b"arbitrary bytes" + provider = get_local_cryptography_provider(key) + + wrap_result = provider.wrap_key(algorithm, plaintext) + assert wrap_result.key_id == key.id + + unwrap_result = provider.unwrap_key(wrap_result.algorithm, wrap_result.encrypted_key) + assert unwrap_result.key == plaintext + + +def test_symmetric_wrap_unwrap(): + jwk = {"k": os.urandom(32), "kty": "oct", "key_ops": ("unwrapKey", "wrapKey")} + key = KeyVaultKey(key_id="http://localhost/keys/key/version", jwk=jwk) + provider = get_local_cryptography_provider(key) + key_bytes = os.urandom(32) + + wrap_result = provider.wrap_key(KeyWrapAlgorithm.aes_256, key_bytes) + assert wrap_result.key_id == key.id + + unwrap_result = provider.unwrap_key(wrap_result.algorithm, wrap_result.encrypted_key) + assert unwrap_result.key == key_bytes