# coding: utf-8

# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------

from typing import Any, Dict
import pytest

from devtools_testutils.azure_testcase import _is_autorest_v3
from devtools_testutils import AzureRecordedTestCase
from devtools_testutils.aio import recorded_by_proxy_async
from azure.security.attestation.aio import (
    AttestationClient,
    AttestationAdministrationClient,
)
from azure.security.attestation import AttestationType
import cryptography
import cryptography.x509
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from attestation_preparer import AttestationPreparer
from preparers_async import AllInstanceTypes
import json

from helpers import base64url_decode

''' cspell:disable '''
_open_enclave_report = (
    "AQAAAAIAAADkEQAAAAAAAAMAAg"
    + "AAAAAABQAKAJOacjP3nEyplAoNs5V_Bgc42MPzGo7hPWS_h-3tExJrAAAAABERAwX_g"
    + "AYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAA"
    + "BwAAAAAAAAC3eSAmGL7LY2do5dkC8o1SQiJzX6-1OeqboHw_wXGhwgAAAAAAAAAAAAA"
    + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAALBpElSroIHE1xsKbdbjAKTcu6UtnfhXCC9QjQP"
    + "ENQaoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
    + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB"
    + "AAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
    + "AAAAAAAAAAAAAAAAA7RGp65ffwXBToyppkucdBPfsmW5FUZq3EJNq-0j5BB0AAAAAAA"
    + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAQAAB4iv_XjOJsrFMrPvIYOBCeMR2q6"
    +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dBRUM2bkV3TURJWVpPai9pUFdzQ3phRUtpNwoxT2lPU0xSRmhX"
    + "R2pibkJWSmZWbmtZNHUzSWprRFlZTDBNeE80bXFzeVlqbEJhbFRWWXhGUDJzSkJLNXp"
    + "sS09CCnV6Q0J1REFmQmdOVkhTTUVHREFXZ0JRaVpReldXcDAwaWZPRHRKVlN2MUFiT1"
    + "NjR3JEQlNCZ05WSFI4RVN6QkoKTUVlZ1JhQkRoa0ZvZEhSd2N6b3ZMMk5sY25ScFptb"
    + "GpZWFJsY3k1MGNuVnpkR1ZrYzJWeWRtbGpaWE11YVc1MApaV3d1WTI5dEwwbHVkR1Zz"
    + "VTBkWVVtOXZkRU5CTG1OeWJEQWRCZ05WSFE0RUZnUVVJbVVNMWxxZE5JbnpnN1NWClV"
    + "yOVFHemtuQnF3d0RnWURWUjBQQVFIL0JBUURBZ0VHTUJJR0ExVWRFd0VCL3dRSU1BWU"
    + "JBZjhDQVFFd0NnWUkKS29aSXpqMEVBd0lEU0FBd1JRSWdRUXMvMDhyeWNkUGF1Q0ZrO"
    + "FVQUVhDTUFsc2xvQmU3TndhUUdUY2RwYTBFQwpJUUNVdDhTR3Z4S21qcGNNL3owV1A5"
    + "RHZvOGgyazVkdTFpV0RkQmtBbiswaWlBPT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0"
    + "tLQoA"
)

_runtime_data = (
    "CiAgICAgICAgewogI"
    + "CAgICAgICAgICAiandrIiA6IHsKICAgICAgICAgICAgICAgICJrdHkiOiJFQyIsCiAg"
    + "ICAgICAgICAgICAgICAidXNlIjoic2lnIiwKICAgICAgICAgICAgICAgICJjcnYiOiJ"
    + "QLTI1NiIsCiAgICAgICAgICAgICAgICAieCI6IjE4d0hMZUlnVzl3Vk42VkQxVHhncH"
    + "F5MkxzellrTWY2SjhualZBaWJ2aE0iLAogICAgICAgICAgICAgICAgInkiOiJjVjRkU"
    + "zRVYUxNZ1BfNGZZNGo4aXI3Y2wxVFhsRmRBZ2N4NTVvN1RrY1NBIgogICAgICAgICAg"
    + "ICB9CiAgICAgICAgfQogICAgICAgIA"
)

_attest_tpm_payload = "eyJwYXlsb2FkIjogeyJ0eXBlIjogImFpa2NlcnQifX0"
''' cspell:enable '''

class TestAsyncAzureAttestation(AzureRecordedTestCase):
    @AttestationPreparer()
    @recorded_by_proxy_async
    async def test_shared_getopenidmetadataasync(self, attestation_location_short_name):
        attest_client = self.shared_client(attestation_location_short_name)
        open_id_metadata = await attest_client.get_open_id_metadata()
        print("{}".format(open_id_metadata))
        assert open_id_metadata["response_types_supported"] is not None
        if self.is_live:
            assert (
                open_id_metadata["jwks_uri"]
                == self.shared_base_uri(attestation_location_short_name) + "/certs"
            )
            assert open_id_metadata["issuer"] == self.shared_base_uri(
                attestation_location_short_name
            )

    @pytest.mark.live_test_only
    @AttestationPreparer()
    async def test_aad_getopenidmetadataasync(self, **kwargs):
        attestation_aad_url = kwargs.pop("attestation_aad_url")
        attest_client = self.create_client(attestation_aad_url)
        open_id_metadata = await attest_client.get_open_id_metadata()
        assert open_id_metadata["response_types_supported"] is not None
        assert open_id_metadata["jwks_uri"] == attestation_aad_url + "/certs"
        assert open_id_metadata["issuer"] == attestation_aad_url

    @pytest.mark.live_test_only
    @AttestationPreparer()
    async def test_isolated_getopenidmetadataasync(self, **kwargs):
        attestation_isolated_url = kwargs.pop("attestation_isolated_url")
        attest_client = self.create_client(attestation_isolated_url)
        open_id_metadata = await attest_client.get_open_id_metadata()
        assert open_id_metadata["response_types_supported"] is not None
        assert open_id_metadata["jwks_uri"] == attestation_isolated_url + "/certs"
        assert open_id_metadata["issuer"] == attestation_isolated_url

    @AttestationPreparer()
    @recorded_by_proxy_async
    async def test_shared_getsigningcertificatesasync(
        self, **kwargs
    ):
        attestation_location_short_name = kwargs.pop("attestation_location_short_name")
        attest_client = self.shared_client(attestation_location_short_name)
        signers = await attest_client.get_signing_certificates()
        for signer in signers:
            cryptography.x509.load_pem_x509_certificate(
                signer.certificates[0].encode("ascii"), backend=default_backend()
            )

    @AttestationPreparer()
    @recorded_by_proxy_async
    async def test_aad_getsigningcertificatesasync(self, attestation_aad_url):
        # type: (str) -> None
        attest_client = self.create_client(attestation_aad_url)
        signers = await attest_client.get_signing_certificates()
        for signer in signers:
            cryptography.x509.load_pem_x509_certificate(
                signer.certificates[0].encode("ascii"), backend=default_backend()
            )

    @AttestationPreparer()
    @recorded_by_proxy_async
    async def test_isolated_getsigningcertificatesasync(self, attestation_isolated_url):
        # type: (str) -> None
        attest_client = self.create_client(attestation_isolated_url)
        signers = await attest_client.get_signing_certificates()
        for signer in signers:
            cryptography.x509.load_pem_x509_certificate(
                signer.certificates[0].encode("ascii"), backend=default_backend()
            )

    async def _test_attest_open_enclave(self, client_uri):
        # type: (str) -> None
        attest_client = self.create_client(client_uri)
        oe_report = base64url_decode(_open_enclave_report)
        runtime_data = base64url_decode(_runtime_data)
        response, _ = await attest_client.attest_open_enclave(
            oe_report, runtime_data=runtime_data
        )
        assert response.enclave_held_data == runtime_data
        assert response.sgx_collateral is not None

        # Now do the validation again, this time specifying runtime data as JSON.
        response, token = await attest_client.attest_open_enclave(
            oe_report, runtime_json=runtime_data
        )
        # Because the runtime data is JSON, enclave_held_data will be empty.
        assert response.enclave_held_data == None
        assert response.runtime_claims.get("jwk") is not None
        assert response.runtime_claims["jwk"]["crv"] == "P-256"
        assert response.sgx_collateral is not None
        assert token._get_body().iss == response.issuer

    @AttestationPreparer()
    @AllInstanceTypes
    @recorded_by_proxy_async
    async def test_shared_attest_open_enclave(self, **kwargs):
        # type: (str, **Any) -> None
        await self._test_attest_open_enclave(kwargs.pop("instance_url"))

    async def _test_attest_sgx_enclave(self, base_uri):
        # type: (str) -> None
        attest_client = self.create_client(base_uri)
        oe_report = base64url_decode(_open_enclave_report)
        # Convert the OE report into an SGX quote by stripping off the first 16 bytes.
        quote = oe_report[16:]
        runtime_data = base64url_decode(_runtime_data)
        response, _ = await attest_client.attest_sgx_enclave(
            quote, runtime_data=runtime_data
        )
        assert response.enclave_held_data == runtime_data
        assert response.sgx_collateral is not None

        # Now do the validation again, this time specifying runtime data as JSON.
        response, _ = await attest_client.attest_sgx_enclave(
            quote, runtime_json=runtime_data
        )
        # Because the runtime data is JSON, enclave_held_data will be empty.
        assert response.enclave_held_data == None
        assert response.runtime_claims.get("jwk") is not None
        assert response.runtime_claims["jwk"]["crv"] == "P-256"
        assert response.sgx_collateral is not None

    @AttestationPreparer()
    @AllInstanceTypes
    @recorded_by_proxy_async
    async def test_attest_sgx_enclave(self, **kwargs):
        # type: (str, **Any) -> None
        await self._test_attest_sgx_enclave(kwargs.pop("instance_url"))

    """
        # Commented out call showing the modifications needed to convert this to a call
        # to an MAA instance running locally for diagnostic purposes.
        @AttestationPreparer()
        def test_local_attest_open_enclave(self):
            attest_client = self.create_client('http://localhost:8080')

            oe_report = Base64Url.decode(_open_enclave_report)
    #        # Convert the OE report into an SGX quote by stripping off the first 16 bytes.
    #        quote = oe_report[16:-1]
            runtime_data = Base64Url.decode(_runtime_data)
            response = attest_client.attest_open_enclave(
            oe_report,
            None, False,
            runtime_data, False, 
            enforce_https=False,
            headers={"tenantName": "tenant1"})
            print(response)
    """

    @AttestationPreparer()
    @recorded_by_proxy_async
    async def test_tpm_attestation(self, attestation_aad_url):
        # type: (str) -> None
        client = self.create_client(attestation_aad_url)
        admin_client = self.create_adminclient(attestation_aad_url)

        # TPM attestation requires that there be a policy present, so set one.
        basic_policy = "version=1.0; authorizationrules{=> permit();}; issuancerules{};"
        await admin_client.set_policy(AttestationType.TPM, basic_policy)

        payload = base64url_decode(_attest_tpm_payload)
        tpm_response = await client.attest_tpm(payload)

        decoded_response = json.loads(tpm_response.data)
        assert decoded_response["payload"] is not None
        payload = decoded_response["payload"]
        assert payload["challenge"] is not None
        assert payload["service_context"] is not None

    def create_client(self, base_uri, **kwargs):
        # type: (str, Dict[str, Any]) -> AttestationClient
        """
        docstring
        """
        credential = self.get_credential(AttestationClient, is_async=True)
        attest_client = self.create_client_from_credential(
            AttestationClient,
            credential=credential,
            endpoint=base_uri,
            validate_token=True,
            validate_signature=True,
            validate_issuer=self.is_live,
            issuer=base_uri,
            validate_expiration=self.is_live,
            **kwargs
        )
        return attest_client

    def create_adminclient(self, base_uri, **kwargs):
        # type: (str, Any) -> AttestationAdministrationClient
        """
        docstring
        """
        credential = self.get_credential(AttestationAdministrationClient, is_async=True)
        attest_client = self.create_client_from_credential(
            AttestationAdministrationClient,
            credential=credential,
            endpoint=base_uri,
            validate_token=True,
            validate_signature=True,
            validate_issuer=self.is_live,
            issuer=base_uri,
            validate_expiration=self.is_live,
            **kwargs
        )
        return attest_client

    def shared_client(self, location_name):
        """
        docstring
        """
        return self.create_client(self.shared_base_uri(location_name))

    def shared_base_uri(self, location_name: str):
        return (
            "https://shared" + location_name + "." + location_name + ".attest.azure.net"
        )
