From 9cbe9b172570bed8f966f3740c97303753c9238d Mon Sep 17 00:00:00 2001 From: Hannah Neary <92307259+hanneary@users.noreply.github.com> Date: Wed, 20 Sep 2023 17:49:45 +0100 Subject: [PATCH] Raise error on invalid pcrs (#73) * Raise error on invalid PCRs * bump version --- README.md | 5 +++++ python-attestation-bindings/pyproject.toml | 2 +- python-attestation-bindings/src/lib.rs | 11 ++--------- python-attestation-bindings/tests/test_attestation.py | 5 ++--- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 974ea11..48bd53a 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ pcrs = python_attestation_bindings.PCRs("","","","") python_attestation_bindings.attest_connection(, pcrs) ``` +To run tests +```sh +maturin develop && pytest +``` + ## Makefile Each project has some useful tasks defined in their `Makefile.toml`: diff --git a/python-attestation-bindings/pyproject.toml b/python-attestation-bindings/pyproject.toml index 35f84ac..62439aa 100644 --- a/python-attestation-bindings/pyproject.toml +++ b/python-attestation-bindings/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "evervault_attestation_bindings" -version = "0.3.0" +version = "0.3.1" requires-python = ">=3.6" classifiers = [ "Programming Language :: Rust", diff --git a/python-attestation-bindings/src/lib.rs b/python-attestation-bindings/src/lib.rs index 0593361..45d0c58 100644 --- a/python-attestation-bindings/src/lib.rs +++ b/python-attestation-bindings/src/lib.rs @@ -134,17 +134,10 @@ pub fn attest_cage( for expected_pcrs in expected_pcrs_list { match validate_expected_pcrs(&validated_attestation_doc, &expected_pcrs) { Ok(_) => return Ok(true), - Err(err) => result = Err(err), - } - } - - match result { - Ok(_) => Ok(true), - Err(e) => { - eprintln!("Failed to validate that PCRs are as expected: {e}"); - Ok(false) + Err(err) => result = Err(PyValueError::new_err(format!("{err}"))), } } + result } /// A small python module offering bindings to the rust attestation doc validation project diff --git a/python-attestation-bindings/tests/test_attestation.py b/python-attestation-bindings/tests/test_attestation.py index 76894e4..628a89a 100644 --- a/python-attestation-bindings/tests/test_attestation.py +++ b/python-attestation-bindings/tests/test_attestation.py @@ -29,6 +29,5 @@ def test_attest_incorrect_pcrs(): "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000050000000", ) - result = evervault_attestation_bindings.attest_cage(cert, [pcrs], attestation_doc) - - assert result == False + with pytest.raises(ValueError, match="The PCRs found were different to the expected values"): + evervault_attestation_bindings.attest_cage(cert, [pcrs], attestation_doc)