-
Notifications
You must be signed in to change notification settings - Fork 113
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
Test remote attestation in UEFI app #2703
Changes from 19 commits
9f71461
fb4f905
c4b2bea
63c22a9
8c49af0
d73e848
d8111c8
b20fe50
837660c
3227a63
d2009a3
d8de7d6
7a94c05
2779e2a
e69748c
17960fd
b458198
9d43182
2e0bc9a
7f0889b
7bb2381
56e0e25
6f66c52
ca2cea7
0c424d5
8f1e760
8d258a5
26082d0
eebf47c
6c27bf0
23a3508
9e03123
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,3 +130,6 @@ fn test_simple() { | |
let x = 1; | ||
assert_eq!(x, 1); | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// 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. | ||
// | ||
|
||
mod remote_attestation; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// | ||
// 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't love repeating the test here, but imo the pragmatic choice for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that it is a good pragmatic choice for now. Once we have an end-to-end example with a connection from a client that exercises this functionality the test could be removed. |
||
|
||
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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <stddef.h> | ||
|
||
/** | ||
* | ||
Stub function for win64 error handler API call inserted by nasm. | ||
Stubbed as it is unavailable in UEFI. | ||
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 Mby inGW, stubbed as it is unavailable in UEFI. | ||
Ref 1: https://metricpanda.com/rival-fortress-update-45-dealing-with-__chkstk-__chkstk_ms-when-cross-compiling-for-windows/ | ||
Ref 2: 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) | ||
{ | ||
} | ||
|
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.
nit: This line of the comment should end with a
.
and seeing that it looks like a heading it should probably have a blank line after it.