Skip to content

Commit

Permalink
Merge pull request #195 from eyakubovich/ey/generate-data-key-pair
Browse files Browse the repository at this point in the history
Add DeriveSharedSecret & GenerateDataKeyPair
  • Loading branch information
eyakubovich authored Sep 9, 2024
2 parents 20f9196 + 7a31dee commit 7e855ec
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 35 deletions.
6 changes: 3 additions & 3 deletions enclaver/src/bin/enclaver-run/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use enclaver::constants::{MANIFEST_FILE_NAME, RELEASE_BUNDLE_DIR, EIF_FILE_NAME};
use enclaver::run::{Enclave, EnclaveExitStatus, EnclaveOpts};
use enclaver::constants::{EIF_FILE_NAME, MANIFEST_FILE_NAME, RELEASE_BUNDLE_DIR};
use enclaver::manifest::load_manifest_raw;
use enclaver::nitro_cli::NitroCLI;
use enclaver::run::{Enclave, EnclaveExitStatus, EnclaveOpts};
use enclaver::utils;
use log::info;
use std::{
path::PathBuf,
process::{ExitCode, Termination},
};
use tokio_util::sync::CancellationToken;
use tokio::io::{stdout, AsyncWriteExt};
use tokio_util::sync::CancellationToken;

const ENCLAVE_SIGNALED_EXIT_CODE: u8 = 107;
const ENCLAVE_FATAL: u8 = 108;
Expand Down
6 changes: 1 addition & 5 deletions enclaver/src/bin/odyn/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,7 @@ impl KmsEndpointProvider for Configuration {
.manifest
.kms_proxy
.as_ref()
.and_then(|kp| {
kp.endpoints
.as_ref()
.map(|eps| eps.get(region).cloned())
})
.and_then(|kp| kp.endpoints.as_ref().map(|eps| eps.get(region).cloned()))
.flatten();

ep.unwrap_or_else(|| format!("kms.{region}.amazonaws.com"))
Expand Down
3 changes: 1 addition & 2 deletions enclaver/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ impl EnclaveArtifactBuilder {
}

// If we make it this far, do a little bit of cleanup
self
.docker
self.docker
.remove_container(&build_container_id, None)
.await?;
let _ = self.docker.remove_image(&img_tag, None, None).await?;
Expand Down
5 changes: 1 addition & 4 deletions enclaver/src/proxy/egress_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ struct ConnectRequest {

impl ConnectRequest {
fn new(host: String, port: u16) -> Self {
Self {
host,
port,
}
Self { host, port }
}
}

Expand Down
8 changes: 5 additions & 3 deletions enclaver/src/proxy/kms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ static X_AMZ_JSON: HeaderValue = HeaderValue::from_static("application/x-amz-jso

const X_AMZ_CREDENTIAL: &str = "X-Amz-Credential";

const ATTESTING_ACTIONS: [&str; 3] = [
const ATTESTING_ACTIONS: [&str; 5] = [
"TrentService.Decrypt",
"TrentService.DeriveSharedSecret",
"TrentService.GenerateDataKey",
"TrentService.GenerateDataKeyPair",
"TrentService.GenerateRandom",
];

Expand Down Expand Up @@ -203,8 +205,8 @@ impl KmsRequestOutgoing {
);

// Sign and then apply the signature to the request
let signed = aws_sigv4::http_request::sign(signable_request, &signing_params)
.map_err(Error::msg)?;
let signed =
aws_sigv4::http_request::sign(signable_request, &signing_params).map_err(Error::msg)?;

let (signing_instructions, _signature) = signed.into_parts();
signing_instructions.apply_to_request(&mut self.inner);
Expand Down
3 changes: 1 addition & 2 deletions enclaver/src/proxy/pkcs7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ impl<'a> ContentInfo<'a> {

pub fn decrypt_content(&self, priv_key: &RsaPrivateKey) -> Result<Vec<u8>> {
let datakey = self.decrypt_key(priv_key)?;
self
.content
self.content
.encrypted_content_info
.decrypt_content(&datakey)
}
Expand Down
33 changes: 17 additions & 16 deletions enclaver/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,25 @@ impl Enclave {
}

fn start_odyn_log_stream(&mut self, cid: u32) -> Result<()> {
self.tasks.push(utils::spawn!("odyn log stream", async move {
info!("waiting for enclave to boot to stream logs");
let conn = loop {
match VsockStream::connect(cid, APP_LOG_PORT).await {
Ok(conn) => break conn,

// TODO: improve the polling frequency / backoff / timeout
Err(_) => {
tokio::time::sleep(LOG_VSOCK_RETRY_INTERVAL).await;
self.tasks
.push(utils::spawn!("odyn log stream", async move {
info!("waiting for enclave to boot to stream logs");
let conn = loop {
match VsockStream::connect(cid, APP_LOG_PORT).await {
Ok(conn) => break conn,

// TODO: improve the polling frequency / backoff / timeout
Err(_) => {
tokio::time::sleep(LOG_VSOCK_RETRY_INTERVAL).await;
}
}
}
};
};

info!("connected to enclave, starting log stream");
if let Err(e) = utils::log_lines_from_stream("enclave", conn).await {
error!("error reading log lines from enclave: {e}");
}
})?);
info!("connected to enclave, starting log stream");
if let Err(e) = utils::log_lines_from_stream("enclave", conn).await {
error!("error reading log lines from enclave: {e}");
}
})?);

Ok(())
}
Expand Down

0 comments on commit 7e855ec

Please sign in to comment.