Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise error on invalid pcrs #73

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Raise error on invalid PCRs
  • Loading branch information
hanneary committed Sep 20, 2023
commit 42bf9e6a978d8b769e0d06e7a4770d99edfb0737
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
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)