-
Notifications
You must be signed in to change notification settings - Fork 128
Implement simple remote attestation for the UEFI app #2742
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
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f7894b0
Extract session logic for remote attestion, GH issue ref #2741
211d1ef
Move sessions logic into its own crate
3a39d44
Implement simple remote attestion for the UEFI app
a314564
remove unused dep
03ca895
Update lockfile
ef7cd63
Shutdown with UEFI error code if a remote attestation error occurs
cc8c239
Update method call to match #2751
7d4778f
Merge branch 'main' into handshake
03c977a
Remove erroneous mention of gRPC
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,94 @@ | ||
| // | ||
| // 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. | ||
| // | ||
|
|
||
| //! Server-side implementation of the bidirectional gRPC remote attestation handshake | ||
jul-sh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! protocol. | ||
| //! | ||
| //! A simplified version of the implementation from the `grpc_unary_attestation` | ||
| //! crate. TODO(#2741): Refactor this to share more code between the two runtimes. | ||
| extern crate alloc; | ||
|
|
||
| use alloc::vec::Vec; | ||
| use anyhow::Context; | ||
| use oak_remote_attestation_sessions::{SessionId, SessionState, SessionTracker}; | ||
|
|
||
| /// Number of sessions that will be kept in memory. | ||
| const SESSIONS_CACHE_SIZE: usize = 10000; | ||
|
|
||
| pub struct AttestationHandler<F> { | ||
| session_tracker: SessionTracker, | ||
| request_handler: F, | ||
| } | ||
|
|
||
| const MOCK_TEE_CERTIFICATE: [u8; 0] = []; | ||
| const MOCK_ADDITIONAL_INFO: [u8; 0] = []; | ||
|
|
||
| impl<F> AttestationHandler<F> | ||
| where | ||
| F: Send + Sync + Clone + FnOnce(Vec<u8>) -> Vec<u8>, | ||
| { | ||
| pub fn create(request_handler: F) -> Self { | ||
| let session_tracker = SessionTracker::create( | ||
| SESSIONS_CACHE_SIZE, | ||
| MOCK_TEE_CERTIFICATE.to_vec(), | ||
| MOCK_ADDITIONAL_INFO.to_vec(), | ||
| ); | ||
|
|
||
| Self { | ||
| session_tracker, | ||
| request_handler, | ||
| } | ||
| } | ||
|
|
||
| pub fn message(&mut self, session_id: SessionId, request: Vec<u8>) -> anyhow::Result<Vec<u8>> { | ||
| let mut session_state = { | ||
| self.session_tracker | ||
| .pop_or_create_session_state(session_id) | ||
| .expect("Couldn't pop session state") | ||
| }; | ||
| let response_body = match session_state { | ||
| SessionState::HandshakeInProgress(ref mut handshaker) => { | ||
| handshaker | ||
| .next_step(&request) | ||
| .context("Couldn't process handshake message")? | ||
| // After receiving a valid `ClientIdentity` message | ||
| // (the last step of the key exchange) | ||
| // ServerHandshaker.next_step returns `None`. For unary | ||
| // request we do want to send an explicit confirmation in | ||
| // the form of a status message. Hence in case of `None` | ||
| // fallback to a default (empty) response. | ||
| .unwrap_or_default() | ||
| } | ||
| SessionState::EncryptedMessageExchange(ref mut encryptor) => { | ||
| let decrypted_request = encryptor | ||
| .decrypt(&request) | ||
| .context("Couldn't decrypt response")?; | ||
|
|
||
| let response = (self.request_handler.clone())(decrypted_request); | ||
|
|
||
| encryptor | ||
| .encrypt(&response) | ||
| .context("Couldn't encrypt response")? | ||
| } | ||
| }; | ||
|
|
||
| self.session_tracker | ||
| .put_session_state(session_id, session_state); | ||
|
|
||
| Ok(response_body) | ||
| } | ||
| } | ||
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.
Any particular reason for
Broadwell-IBRS? Granted, I don't know what the default CPU that qemu emulates is, but if you want something with RDRAND I think you can explicitly ask for that with+rdrand, something like "-cpu host,+rdrand". I think explicitly listing that we require rdrand is better than hiding it in the CPU definition.That being said, qemu docs are not the best, so please do check the syntax for the
-cpuflag to see how it works.Uh oh!
There was an error while loading. Please reload this page.
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.
No strong reason for the particular model, other than it supports RDRAND while being old enough that it can hopefully be virtualized by most hosts. This particular line just matches what we went with in #2703.
In general we do want to specify a specific model. The reason is that in virtualization mode, qemu does not use a default CPU. Instead it's either host passthrough (unstable between hosts, not recommended by docs) or a named model. :)
See https://qemu-project.gitlab.io/qemu/system/qemu-cpu-models.html#two-ways-to-configure-cpu-models-with-qemu-kvm for more details