import pytest
import os
import sys

# Add root opal dir to use local src as package for tests (i.e, no need for python -m pytest)
root_dir = os.path.abspath(
    os.path.join(
        os.path.dirname(__file__),
        os.path.pardir,
        os.path.pardir,
        os.path.pardir,
    )
)
sys.path.append(root_dir)

# -----------------------------------------------------------------------------
import asyncio
from typing import List, Optional
from pathlib import Path
from uuid import uuid4
from datetime import timedelta

from opal_common.authentication.types import EncryptionKeyFormat, JWTAlgorithm, JWTClaims, PrivateKey, PublicKey
from opal_common.authentication.casting import cast_private_key, cast_public_key
from opal_common.authentication.signer import JWTSigner
from opal_common.authentication.verifier import JWTVerifier

KEY_FILENAME = "opal_test_crypto_key"
PASSPHRASE = "whiterabbit"

AUTH_JWT_AUDIENCE = "https://api.authorizon.com/v1/"
AUTH_JWT_ISSUER = "https://authorizon.com/"
CUSTOM_CLAIMS = {"color": "red"}


async def run_subprocess(command: str):
    process = await asyncio.create_subprocess_shell(
        command,
        stdout=asyncio.subprocess.PIPE,
        stderr=asyncio.subprocess.PIPE,
        start_new_session=True,
    )
    return_code = await process.wait()
    assert return_code == 0

async def run_commands(commands: List[str]):
    # the await inside the for-loop is intentional, these commands should not run in parallel
    for command in commands:
        await run_subprocess(command)

async def verify_crypto_keys(
    private_key_filename: Path,
    public_key_filename: Path,
    private_key_format: EncryptionKeyFormat,
    public_key_format: EncryptionKeyFormat,
    algorithm: JWTAlgorithm,
    passphrase: Optional[str] = None
    ):
    # assert keys created
    assert private_key_filename.exists()
    assert public_key_filename.exists()

    private_key: Optional[PrivateKey] = cast_private_key(private_key_filename, private_key_format, passphrase)
    assert private_key is not None

    public_key: Optional[PublicKey] = cast_public_key(public_key_filename, public_key_format)
    assert public_key is not None

    verifier = JWTVerifier(public_key, algorithm, AUTH_JWT_AUDIENCE, AUTH_JWT_ISSUER)
    assert verifier.enabled

    signer = JWTSigner(private_key, public_key, algorithm, AUTH_JWT_AUDIENCE, AUTH_JWT_ISSUER)
    assert signer.enabled

    token: str = signer.sign(uuid4(), timedelta(days=1), CUSTOM_CLAIMS)
    claims: JWTClaims = verifier.verify(token)

    for k in CUSTOM_CLAIMS:
        assert k in claims.keys()
        assert CUSTOM_CLAIMS[k] == claims[k]


@pytest.mark.asyncio
async def test_encryption_keys_RFC_4253_ssh_format_with_passphrase(tmp_path):
    """
    Test key encryption format: RFC_4253

    such keys can be generate by this command:
    ```
    ssh-keygen -t rsa -b 4096 -m pem
    ```
    the private key is in PEM format
    the public key in in ssh format
    """
    # creates the keys under temp paths that are auto-deleted after the test
    private_key_filename = Path(os.path.join(tmp_path, KEY_FILENAME))
    public_key_filename = Path(f"{private_key_filename}.pub")

    # commands to generate crypto keys
    await run_commands([
        f"ssh-keygen -t rsa -b 4096 -m pem -f {private_key_filename} -N {PASSPHRASE}",
    ])

    await verify_crypto_keys(
        private_key_filename = private_key_filename,
        public_key_filename = public_key_filename,
        private_key_format = EncryptionKeyFormat.pem,
        public_key_format = EncryptionKeyFormat.ssh,
        algorithm = getattr(JWTAlgorithm, "RS256"),
        passphrase= PASSPHRASE
    )

@pytest.mark.asyncio
async def test_encryption_keys_RFC_4253_ssh_format_no_passphrase(tmp_path):
    # creates the keys under temp paths that are auto-deleted after the test
    private_key_filename = Path(os.path.join(tmp_path, KEY_FILENAME))
    public_key_filename = Path(f"{private_key_filename}.pub")

    # commands to generate crypto keys
    await run_commands([
        f"ssh-keygen -t rsa -b 4096 -m pem -f {private_key_filename}",
    ])

    await verify_crypto_keys(
        private_key_filename = private_key_filename,
        public_key_filename = public_key_filename,
        private_key_format = EncryptionKeyFormat.pem,
        public_key_format = EncryptionKeyFormat.ssh,
        algorithm = getattr(JWTAlgorithm, "RS256"),
        passphrase = None
    )

@pytest.mark.asyncio
async def test_encryption_keys_PKCS1_format_with_passphrase(tmp_path):
    # creates the keys under temp paths that are auto-deleted after the test
    private_key_filename = Path(os.path.join(tmp_path, KEY_FILENAME))
    public_key_filename = Path(f"{private_key_filename}.pub")

    # commands to generate crypto keys
    await run_commands([
        f"ssh-keygen -t rsa -b 4096 -m pem -f {private_key_filename} -N {PASSPHRASE}",
        f"ssh-keygen -e -m pem -f {private_key_filename} -P {PASSPHRASE} > {public_key_filename}"
    ])

    await verify_crypto_keys(
        private_key_filename = private_key_filename,
        public_key_filename = public_key_filename,
        private_key_format = EncryptionKeyFormat.pem,
        public_key_format = EncryptionKeyFormat.pem,
        algorithm = getattr(JWTAlgorithm, "RS256"),
        passphrase = PASSPHRASE
    )

@pytest.mark.asyncio
async def test_encryption_keys_X509_SPKI_format_with_passphrase(tmp_path):
    # creates the keys under temp paths that are auto-deleted after the test
    private_key_filename = Path(os.path.join(tmp_path, KEY_FILENAME))
    public_key_filename = Path(f"{private_key_filename}.pub")

    # commands to generate crypto keys
    await run_commands([
        f"ssh-keygen -t rsa -b 4096 -m pem -f {private_key_filename} -N {PASSPHRASE}",
        f"ssh-keygen -e -m pkcs8 -f {private_key_filename} -P {PASSPHRASE} > {public_key_filename}"
    ])

    await verify_crypto_keys(
        private_key_filename = private_key_filename,
        public_key_filename = public_key_filename,
        private_key_format = EncryptionKeyFormat.pem,
        public_key_format = EncryptionKeyFormat.pem,
        algorithm = getattr(JWTAlgorithm, "RS256"),
        passphrase = PASSPHRASE
    )

@pytest.mark.asyncio
async def test_encryption_keys_PKCS1_format_with_passphrase_hardcoded_keys(tmp_path):
    """
    these hardcoded keys are for test purposes only - NEVER use them!!!!
    """
    # creates the keys under temp paths that are auto-deleted after the test
    private_key_filename = Path(os.path.join(tmp_path, KEY_FILENAME))
    public_key_filename = Path(f"{private_key_filename}.pub")

    open(private_key_filename, 'w').write("""
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,76065A0C88ABA1D6B5B812ED6BE346B5

9OS+Y6htk1GYnFFwz4Od7wPQ5ieRrMWsRkIl1wfB18VX8mqSrm3JR1wxnDGrE71+
/iF5hF8KycZt6Tzcm/M+ykBYTvhr9+ZkLG/qBTPZF7Pc49kx+KPuaHTVJ8E88Zxn
fOV0M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SzuvZSNi4VOnro8GIHdi+9t+J0cRBkuAy0kcOvyH99AY76PrYZgOmsxkQ
C9eHj0aGuYBf+avq407tqm70kRfcSkeIaQNbM7c3TSnb5eOwKSWYNoCV04dOK891
73f9j3ejbyL1jlrd0GRTLD25rTl43mv1WWkspW2N1t6Zg0bQAutPTGQwy1YzAp6m
c9ePf6B/EFkPTlf6PlSpeQ9giR9M+zE2kgDswqGAuRynCeKDcFctE7OBt9cu+B71
Bh2O+tV52QgLQWTxnPBpogrh4aqSv9vevjI+Gb8rAnw9uls3UVngsSJ25uyy/6oi
2VNTqSoErdzHpwtZyyhLjhEnHYt7LKd2vXPDnCUeNjdUDNyZ80Puu0/T/r7/24Bc
d/e/zqdN/7QtAVLFhkvUmRuNGRxY8DfGiBBb99j8wuwvMzwvhwKNM+poHKMniPzU
R++pB/9ljGKjboRI/y7E6G6WkYVkjKstiP94esyIHO2t6+z2Io/RoRMClqhLV2/i
rGu5SWa2R10YbK8YBY+633cZPdQkTpNZ6JpPAAEcfid6Gap6WQun5At0I43b8525
76GnjPiNoWExOVZb/MYNhlUE99OZugIU1ozzVZ4cPwz46hV6EOo9TWoSdE5E7s+E
p+vpqaafIUp9U0bbrgq0IBh3utqren36yrfLvSI74F4WIDJsRvxxyPj29U16zia6
OJ43JAiQTN3dy/yI0BmtciNtR/C0ZeJqfuN4QL57/GEKo5Pt1mR64/UySIGiyf64
vY9r3DyoT74c0NpmsqEuH5Og4bhGlKFbRBtAyntt4BsmATiJVhxjCqzL5dgz5rxw
czAmf7lN7G5Qii/Z3q9Msp+r+elmf5hOcBxrBKo+K0J7bWJHb+rT7T+ywQe2veu/
-----END RSA PRIVATE KEY-----"""
    )

    open(public_key_filename, 'w').write("""
-----BEGIN RSA PUBLIC KEY-----
MIICCgKCAgEAoTtleKwCPQ4kUGAAk4uDnjZStr/LbzFaYTPrfFWbRmEFzVoWREST
STesIuoTgdLLiDY0wksC6IZ/wlvVvxbuRG4PljUPiOvfHTDI2giC7JoH40b0HNI+
1YlDWU+pnvS1SeoPzzVwC2uVP97g0Z0d7BlXZY8ufsvQPfHQP4sTuvFXiMNC18dQ
OVLZS8EpeNhORf+iTe43OgNNnD4KCl9w1VScUlR58K+N+glQ6qONZjayII9Qn0vP
IZfw/RseR5qprJuA30s+hPMtOhqwfoWwIP8dGRL/rbPoVb0tvLTWnmbDySQGDyof
7aWlW0LN+7/5wPlxhq8coaRcTxlCU0Iro1xL/TpOvOQb4Q+++qUphIc+t1a8j2Ge
X4/+N5kSSNU83NJpEGLLknaoiR9cYvNBJksJhAGHvu0kLmb5/91nK/CHJMsma82W
GR9TQAtoSOlOh8P3cpeLCEHdMd3iXHdMUQ7rzIRGjZyPPMv+JxumQ1MJ76vNHB4j
JgN5LRWeo+H17t7bnO/Ot6qmmp7ZN3dc3QBlsy09cCdQ4l4YWEa3VO6dXnIdoe/c
THdYobue6ft5E7d7Eez4is6++d8SuboxJMmzbDK9U++GoJVARk2FqUpXTqHSIqKt
y8eFhYJfV0a59E5TasHlIT/HLcdlvISQ0/lBoPOwtKDbFuZvqQwWKEsCAwEAAQ==
-----END RSA PUBLIC KEY-----
    """)

    await verify_crypto_keys(
        private_key_filename = private_key_filename,
        public_key_filename = public_key_filename,
        private_key_format = EncryptionKeyFormat.pem,
        public_key_format = EncryptionKeyFormat.pem,
        algorithm = getattr(JWTAlgorithm, "RS256"),
        passphrase = PASSPHRASE
    )

@pytest.mark.asyncio
async def test_encryption_keys_X509_SPKI_format_with_passphrase_hardcoded_keys(tmp_path):
    """
    these hardcoded keys are for test purposes only - NEVER use them!!!!
    """
    # creates the keys under temp paths that are auto-deleted after the test
    private_key_filename = Path(os.path.join(tmp_path, KEY_FILENAME))
    public_key_filename = Path(f"{private_key_filename}.pub")

    open(private_key_filename, 'w').write("""
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,B0E9701EF36B6D18081BE93E446F7DAC

y5H7rhvE9fImdwr/vIiJWsxqzxWnEs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LIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA3dPvy1zGdxMRf06+KYbk
/OW73J8t1eX4Nb3E5w5GV6gdt1KKFMD7WOy9wPFNUS1k9o7WhW1giQGSIE1NuShH
Y8x3yvYnPHVptrWFmKZMTVb8jytmEtLT0tHfJjCJKjPUqUT2Xli/Lyg/MHz0zqPb
b+vlXFBujI+3u1em6DUMP5Qao3rq0qzdD2fmBVsXrcOhAL9GwgyHTFVON/PvBKXU
MvseZ+FAqydBdG95b+DKG4eEzjz0CV3SXhMx4orPUsa9VupAbve3MMGYyXB51yYh
lDyTnFiAChhIzU99pgg5Uhx8YX/hFEAoATwbv6pmliFmUzuTs5sLP9DP+56FGye8
s1wxIMBMAMzBTMKnsJlpIOyEBq8tI0UiSM76jP6cAdK/JgZ+tHi2HJXbtm+Gc02F
2syHJI7lryQNfbPqgn8QXJNVMiCSnmqmXfEoz2cWkqTn9siIovnrOsQDN4nfiLGs
tjxiX307tP6CjNFl24/olZdan6D4jxskI1cgXxL53tjdXASbJ5Z3M/xJmm5P/eGv
GKe4LpzupEUoDz4UnfgPUsOORe4p49NHm07S3KCouZOAslMAJDqe2qyyPhDnUaTG
0OAmlqa412uGUhmxYbKgyPNALED/9WksFEWDDqt+bq6zwYActCW2203gCRsTbSX9
wo0Src+YUGAdjomgzrt/6CECAwEAAQ==
-----END PUBLIC KEY-----
    """)

    await verify_crypto_keys(
        private_key_filename = private_key_filename,
        public_key_filename = public_key_filename,
        private_key_format = EncryptionKeyFormat.pem,
        public_key_format = EncryptionKeyFormat.pem,
        algorithm = getattr(JWTAlgorithm, "RS256"),
        passphrase = PASSPHRASE
    )