Skip to content

Commit

Permalink
Raise error on invalid pcrs (#73)
Browse files Browse the repository at this point in the history
* Raise error on invalid PCRs

* bump version
  • Loading branch information
hanneary authored Sep 20, 2023
1 parent 6e47738 commit 9cbe9b1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ pcrs = python_attestation_bindings.PCRs("<pcr0>","<pcr1>","<pcr2>","<pcr8>")
python_attestation_bindings.attest_connection(<cert>, pcrs)
```

To run tests
```sh
maturin develop && pytest
```

## Makefile

Each project has some useful tasks defined in their `Makefile.toml`:
Expand Down
2 changes: 1 addition & 1 deletion python-attestation-bindings/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 2 additions & 9 deletions python-attestation-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions python-attestation-bindings/tests/test_attestation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 9cbe9b1

Please sign in to comment.