Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from typing import Dict
import unittest
from cryptography import x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric.dsa import DSAPublicKey
from devtools_testutils import AzureTestCase, ResourceGroupPreparer, PowerShellPreparer
Expand Down Expand Up @@ -116,21 +117,21 @@ def callback(token, signer):
# Helper functions to create keys and certificates wrapping those keys.
@staticmethod
def _create_ecds_key(): #type() -> EllipticCurvePrivateKey
return ec.generate_private_key(ec.SECP256R1()).private_bytes(
return ec.generate_private_key(ec.SECP256R1(), backend=default_backend()).private_bytes(
serialization.Encoding.DER,
serialization.PrivateFormat.PKCS8,
serialization.NoEncryption())

@staticmethod
def _create_rsa_key(): #type() -> EllipticCurvePrivateKey
return rsa.generate_private_key(65537, 2048).private_bytes(
return rsa.generate_private_key(65537, 2048, backend=default_backend()).private_bytes(
serialization.Encoding.DER,
serialization.PrivateFormat.PKCS8,
serialization.NoEncryption())

@staticmethod
def _create_x509_certificate(key_der, subject_name): #type(Union[EllipticCurvePrivateKey,RSAPrivateKey], str) -> Certificate
signing_key = serialization.load_der_private_key(key_der, password=None)
signing_key = serialization.load_der_private_key(key_der, password=None, backend=default_backend())
builder = CertificateBuilder()
builder = builder.subject_name(x509.Name([
x509.NameAttribute(NameOID.COMMON_NAME, subject_name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import functools
import cryptography
import cryptography.x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
import base64
import pytest
Expand Down Expand Up @@ -83,7 +84,7 @@ def test_aad_set_policy_sgx_unsecured(self, attestation_aad_url):
assert policy_get_response.value == attestation_policy

expected_policy = AttestationToken(body=StoredAttestationPolicy(attestation_policy=str(attestation_policy).encode('utf-8')))
hasher = hashes.Hash(hashes.SHA256())
hasher = hashes.Hash(hashes.SHA256(), backend=default_backend())
hasher.update(expected_policy.serialize().encode('utf-8'))
expected_hash = hasher.finalize()

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

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

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

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

Expand Down