-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change moves HPKE encryption handlers out of the `oak_attestation` crate to corresponding SDKs (RKernel and Containers). Later these handlers can be merged with the new Oak SDK. Fixes: 365039516 Change-Id: Ibf8953e05ce54f0605caf355875306113b9c4a93
- Loading branch information
Showing
13 changed files
with
63 additions
and
45 deletions.
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 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 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 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 |
---|---|---|
|
@@ -20,4 +20,3 @@ extern crate alloc; | |
|
||
pub mod attester; | ||
pub mod dice; | ||
pub mod handler; |
This file contains 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 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 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 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 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 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 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,55 @@ | ||
// | ||
// 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. | ||
// | ||
|
||
use alloc::{sync::Arc, vec::Vec}; | ||
|
||
use anyhow::Context; | ||
use oak_crypto::{ | ||
encryption_key::EncryptionKeyHandle, encryptor::ServerEncryptor, EMPTY_ASSOCIATED_DATA, | ||
}; | ||
use oak_proto_rust::oak::crypto::v1::{EncryptedRequest, EncryptedResponse}; | ||
|
||
/// Wraps a closure to an underlying function with request encryption and | ||
/// response decryption logic, based on the provided encryption key. | ||
pub struct EncryptionHandler<H: FnOnce(Vec<u8>) -> Vec<u8>> { | ||
encryption_key_handle: Arc<dyn EncryptionKeyHandle>, | ||
request_handler: H, | ||
} | ||
|
||
impl<H: FnOnce(Vec<u8>) -> Vec<u8>> EncryptionHandler<H> { | ||
pub fn create(encryption_key_handle: Arc<dyn EncryptionKeyHandle>, request_handler: H) -> Self { | ||
Self { encryption_key_handle, request_handler } | ||
} | ||
} | ||
|
||
impl<H: FnOnce(Vec<u8>) -> Vec<u8>> EncryptionHandler<H> { | ||
pub fn invoke(self, encrypted_request: &EncryptedRequest) -> anyhow::Result<EncryptedResponse> { | ||
// Decrypt request. | ||
let (server_encryptor, request, _) = | ||
ServerEncryptor::decrypt(encrypted_request, self.encryption_key_handle.as_ref()) | ||
.context("couldn't create server encryptor")?; | ||
|
||
// Handle request. | ||
let response = (self.request_handler)(request); | ||
|
||
// Encrypt and serialize response. | ||
// The resulting decryptor for subsequent requests is discarded because we don't | ||
// expect another message from the stream. | ||
server_encryptor | ||
.encrypt(&response, EMPTY_ASSOCIATED_DATA) | ||
.context("couldn't encrypt response") | ||
} | ||
} |
This file contains 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