Skip to content

Commit 4af5950

Browse files
Added more default backends (Azure#18614)
1 parent 24eb609 commit 4af5950

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

sdk/attestation/azure-security-attestation/tests/test_attestation_token.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import Dict
1212
import unittest
1313
from cryptography import x509
14+
from cryptography.hazmat.backends import default_backend
1415
from cryptography.hazmat.primitives import hashes, serialization
1516
from cryptography.hazmat.primitives.asymmetric.dsa import DSAPublicKey
1617
from devtools_testutils import AzureTestCase, ResourceGroupPreparer, PowerShellPreparer
@@ -116,21 +117,21 @@ def callback(token, signer):
116117
# Helper functions to create keys and certificates wrapping those keys.
117118
@staticmethod
118119
def _create_ecds_key(): #type() -> EllipticCurvePrivateKey
119-
return ec.generate_private_key(ec.SECP256R1()).private_bytes(
120+
return ec.generate_private_key(ec.SECP256R1(), backend=default_backend()).private_bytes(
120121
serialization.Encoding.DER,
121122
serialization.PrivateFormat.PKCS8,
122123
serialization.NoEncryption())
123124

124125
@staticmethod
125126
def _create_rsa_key(): #type() -> EllipticCurvePrivateKey
126-
return rsa.generate_private_key(65537, 2048).private_bytes(
127+
return rsa.generate_private_key(65537, 2048, backend=default_backend()).private_bytes(
127128
serialization.Encoding.DER,
128129
serialization.PrivateFormat.PKCS8,
129130
serialization.NoEncryption())
130131

131132
@staticmethod
132133
def _create_x509_certificate(key_der, subject_name): #type(Union[EllipticCurvePrivateKey,RSAPrivateKey], str) -> Certificate
133-
signing_key = serialization.load_der_private_key(key_der, password=None)
134+
signing_key = serialization.load_der_private_key(key_der, password=None, backend=default_backend())
134135
builder = CertificateBuilder()
135136
builder = builder.subject_name(x509.Name([
136137
x509.NameAttribute(NameOID.COMMON_NAME, subject_name),

sdk/attestation/azure-security-attestation/tests/test_policy_getset.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import functools
2525
import cryptography
2626
import cryptography.x509
27+
from cryptography.hazmat.backends import default_backend
2728
from cryptography.hazmat.primitives import serialization
2829
import base64
2930
import pytest
@@ -83,7 +84,7 @@ def test_aad_set_policy_sgx_unsecured(self, attestation_aad_url):
8384
assert policy_get_response.value == attestation_policy
8485

8586
expected_policy = AttestationToken(body=StoredAttestationPolicy(attestation_policy=str(attestation_policy).encode('utf-8')))
86-
hasher = hashes.Hash(hashes.SHA256())
87+
hasher = hashes.Hash(hashes.SHA256(), backend=default_backend())
8788
hasher.update(expected_policy.serialize().encode('utf-8'))
8889
expected_hash = hasher.finalize()
8990

@@ -106,7 +107,7 @@ def test_aad_set_policy_sgx_secured(self, attestation_aad_url, attestation_polic
106107
assert policy_get_response.value == attestation_policy
107108

108109
expected_policy = AttestationToken(body=StoredAttestationPolicy(attestation_policy=str(attestation_policy).encode('ascii')), signer=AttestationSigningKey(key, signing_certificate))
109-
hasher = hashes.Hash(hashes.SHA256())
110+
hasher = hashes.Hash(hashes.SHA256(), backend=default_backend())
110111
hasher.update(expected_policy.serialize().encode('utf-8'))
111112
expected_hash = hasher.finalize()
112113

@@ -129,7 +130,7 @@ def test_isolated_set_policy_sgx_secured(self, attestation_isolated_url, attesta
129130
assert policy_get_response.value == attestation_policy
130131

131132
expected_policy = AttestationToken(body=StoredAttestationPolicy(attestation_policy=str(attestation_policy).encode('ascii')), signer=AttestationSigningKey(key, decoded_cert))
132-
hasher = hashes.Hash(hashes.SHA256())
133+
hasher = hashes.Hash(hashes.SHA256(), backend=default_backend())
133134
hasher.update(expected_policy.serialize().encode('utf-8'))
134135
expected_hash = hasher.finalize()
135136

0 commit comments

Comments
 (0)