-
Notifications
You must be signed in to change notification settings - Fork 128
Test remote attestation in UEFI app #2703
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
Merged
jul-sh
merged 32 commits into
project-oak:main
from
jul-sh:uefi-test-remote-attestation
Apr 19, 2022
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9f71461
add remote attestation test inside UEFI app
fb4f905
Stub missing symbols
c4b2bea
improve comment spelling somewhat
63c22a9
Use ___chkstk_ms from go
8c49af0
simplify test to aid debugging: just test ring source of randomness
d73e848
log random data in test
d8111c8
patch rdrand availability check for debuggingnd enable KVM
b20fe50
Merge branch 'main' into uefi-test-remote-attestation
837660c
Add test to check that the byte array has in fact been filled
3227a63
add remote attestation handshake test
d2009a3
Update config to match #2725
d8de7d6
Remoe test of ring, as remote attestation is now tested
7a94c05
remove debugging logs from remote attestation test
2779e2a
wip
e69748c
Merge branch 'main' into uefi-test-remote-attestation
17960fd
Revert "wip"
b458198
Move the UEFI remote attestation test into it's own module
9d43182
remove now unneeded crate imports in the main UEFI app
2e0bc9a
finalize moving remote attestation test
7f0889b
redundant surplus qemu cpu flags
7bb2381
Add anyhow as dev dep for test
56e0e25
Add extra context to ring stubs
6f66c52
Only run remote attestation tests if the hosts supports kvm, and the …
ca2cea7
improve comment for clarity
0c424d5
improve comment copy
8f1e760
Merge branch 'main' into uefi-test-remote-attestation
8d258a5
disable ring default features to fix duplicate lang items
26082d0
bust CI cache
eebf47c
toggle tests that require kvm by disabling a default flag, as xtask e…
6c27bf0
Clarify comment
23a3508
Improve comments for accuracy and clarity
9e03123
Don't lint target subdirectories created by cargo fuzz
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,10 @@ authors = ["Andri Saar <[email protected]>"] | |
| edition = "2021" | ||
| license = "Apache-2.0" | ||
|
|
||
| [features] | ||
| default = ["support_emulated_runner"] | ||
| support_emulated_runner = [] | ||
|
|
||
| [dependencies] | ||
| uefi = { version = "*", features = ["exts"] } | ||
| uefi-services = "*" | ||
|
|
@@ -14,4 +18,5 @@ ciborium-io = "*" | |
| oak_remote_attestation = { path = "../../../remote_attestation/rust" } | ||
|
|
||
| [dev-dependencies] | ||
| anyhow = { version = "*", default-features = false } | ||
| uefi-services = { version = "*", features = ["qemu"] } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Thin shell script invoked as a cargo runner to run the compiled efi firmware | ||
| # in QEMU. Detects if kvm is supported, and sets qemu flags based on that. | ||
| # Instead of this single runner script it would be preferable to use a different | ||
| # runner based on whether the kvm feature is set. However, cargo does not | ||
| # currently allow this. Ref: https://github.com/rust-lang/cargo/issues/8170 | ||
|
|
||
| readonly TARGET=$1 | ||
|
|
||
| qemu_flags=( | ||
| '-nodefaults' | ||
| '-nographic' | ||
| '-bios' '/usr/share/OVMF/OVMF_CODE.fd' | ||
| '-serial' 'file:target/console.log' | ||
| '-serial' 'stdio' | ||
| '-machine' 'q35' | ||
| '-device' 'isa-debug-exit,iobase=0xf4,iosize=0x04' | ||
| ) | ||
|
|
||
| # Use kvm if supported, as it is required for certain features. Note | ||
| # that hosts that support kvm still need to disable the default | ||
| # `support_emulated_runner` feature in cargo to include code that requires kvm | ||
| # in the compiled firmware. Ideally this check would rely on the cargo | ||
| # flag itself, enabling kvm if it is disabled. However cargo does not expose | ||
| # which flags are set to the runner. Ref: https://doc.rust-lang.org/cargo/reference/environment-variables.html | ||
| if [[ -e "/dev/kvm" ]]; then | ||
| qemu_flags+=( | ||
| '-enable-kvm' | ||
| '-cpu' 'Broadwell-IBRS' | ||
| ) | ||
| fi | ||
|
|
||
| qemu-system-x86_64 "${qemu_flags[@]}" -kernel "${TARGET}" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,3 +109,6 @@ fn test_simple() { | |
| let x = 1; | ||
| assert_eq!(x, 1); | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // | ||
| // Copyright 2022 The Project Oak Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
|
|
||
| // Uses advanced CPU features not available when using running tests in qemu | ||
| // with CPU emulation. | ||
| #[cfg(not(feature = "support_emulated_runner"))] | ||
| mod remote_attestation; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // | ||
| // Copyright 2022 The Project Oak Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
|
|
||
| //! Integration Test of Remote Attestation in UEFI. | ||
| //! | ||
| //! This tests that remote attestion works inside the UEFI app. While the test | ||
| //! code is identical to (a subset of) the tests in the remote attestation crate | ||
| //! they here utilize the qemu runner configured in the UEFI app. This means | ||
| //! that test code actually compiled to a UEFI target, which changes the | ||
| //! underlying implementation of the remote attestation crate. | ||
| //! TODO(#2654): It would be preferable to remove the test here, and instead | ||
| //! run the tests in the oak_remote_attestation crate itself for both standard | ||
| //! and UEFI targets. Due to concerns related to the workspace this is presently | ||
| //! not possible. Ref: https://github.com/project-oak/oak/issues/2654 | ||
|
|
||
| extern crate alloc; | ||
|
|
||
| use alloc::{boxed::Box, sync::Arc}; | ||
| use oak_remote_attestation::handshaker::{AttestationBehavior, ClientHandshaker, ServerHandshaker}; | ||
|
|
||
| const TEE_MEASUREMENT: &str = "Test TEE measurement"; | ||
| const DATA: [u8; 10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | ||
|
|
||
| fn create_handshakers() -> (ClientHandshaker, ServerHandshaker) { | ||
| let bidirectional_attestation = | ||
| AttestationBehavior::create_bidirectional_attestation(&[], TEE_MEASUREMENT.as_bytes()) | ||
| .unwrap(); | ||
| let client_handshaker = ClientHandshaker::new( | ||
| bidirectional_attestation, | ||
| Box::new(|server_identity| { | ||
| if !server_identity.additional_info.is_empty() { | ||
| Ok(()) | ||
| } else { | ||
| anyhow::bail!("No additional info provided.") | ||
| } | ||
| }), | ||
| ); | ||
|
|
||
| let bidirectional_attestation = | ||
| AttestationBehavior::create_bidirectional_attestation(&[], TEE_MEASUREMENT.as_bytes()) | ||
| .unwrap(); | ||
|
|
||
| let additional_info = br"Additional Info".to_vec(); | ||
| let server_handshaker = | ||
| ServerHandshaker::new(bidirectional_attestation, Arc::new(additional_info)); | ||
|
|
||
| (client_handshaker, server_handshaker) | ||
| } | ||
|
|
||
| #[test_case] | ||
| fn test_handshake() { | ||
| let (mut client_handshaker, mut server_handshaker) = create_handshakers(); | ||
|
|
||
| let client_hello = client_handshaker | ||
| .create_client_hello() | ||
| .expect("Couldn't create client hello message"); | ||
|
|
||
| let server_identity = server_handshaker | ||
| .next_step(&client_hello) | ||
| .expect("Couldn't process client hello message") | ||
| .expect("Empty server identity message"); | ||
|
|
||
| let client_identity = client_handshaker | ||
| .next_step(&server_identity) | ||
| .expect("Couldn't process server identity message") | ||
| .expect("Empty client identity message"); | ||
| assert!(client_handshaker.is_completed()); | ||
|
|
||
| let result = server_handshaker | ||
| .next_step(&client_identity) | ||
| .expect("Couldn't process client identity message"); | ||
| assert_eq!(result, None); | ||
| assert!(server_handshaker.is_completed()); | ||
|
|
||
| let mut client_encryptor = client_handshaker | ||
| .get_encryptor() | ||
| .expect("Couldn't get client encryptor"); | ||
| let mut server_encryptor = server_handshaker | ||
| .get_encryptor() | ||
| .expect("Couldn't get server encryptor"); | ||
|
|
||
| let encrypted_client_data = client_encryptor | ||
| .encrypt(&DATA) | ||
| .expect("Couldn't encrypt client data"); | ||
| let decrypted_client_data = server_encryptor | ||
| .decrypt(&encrypted_client_data) | ||
| .expect("Couldn't decrypt client data"); | ||
| assert_eq!(decrypted_client_data, DATA); | ||
|
|
||
| let encrypted_server_data = server_encryptor | ||
| .encrypt(&DATA) | ||
| .expect("Couldn't encrypt server data"); | ||
| let decrypted_server_data = client_encryptor | ||
| .decrypt(&encrypted_server_data) | ||
| .expect("Couldn't decrypt server data"); | ||
| assert_eq!(decrypted_server_data, DATA); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #include <stddef.h> | ||
|
|
||
| /** | ||
| * | ||
| Stub function for win64 error handler API call inserted by nasm. | ||
| Stubbed as it is unavailable in UEFI. It appears unlikely this call will | ||
| ever be invoked in deployment. | ||
| Ref: https://github.com/openssl/openssl/issues/12712. | ||
| Inspired by: https://github.com/tianocore/edk2/blob/7c0ad2c33810ead45b7919f8f8d0e282dae52e71/CryptoPkg/Library/OpensslLib/X64/ApiHooks.c | ||
| **/ | ||
| void * | ||
| __imp_RtlVirtualUnwind ( | ||
| void *Args | ||
| ) | ||
| { | ||
| return NULL; | ||
| } | ||
|
|
||
| /** | ||
| Stub function for win64 routine used for exceedingly large variables. | ||
| Inserted nasm, stubbed as it is unavailable in UEFI. Given that this | ||
| routine is used for very large variable it appears unlikely to ever be | ||
| invoked in deployment. | ||
| Ref: https://github.com/golang/go/issues/6305 | ||
| Inspired by: https://android.googlesource.com/platform/external/compiler-rt/+/ccaafe6%5E%21/#F1 | ||
| **/ | ||
| void ___chkstk_ms(void) | ||
| { | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of this solution, but there does not currently seem to be a better way to do this. As long as we want this crate to run in GitHub CI we'll need to support hosts that do not support kvm.
Perhaps once we add a CI runner that supports virtualization we can remove this, only leaving the kvm reliant runner.