Skip to content

Commit 7e855ec

Browse files
authored
Merge pull request #195 from eyakubovich/ey/generate-data-key-pair
Add DeriveSharedSecret & GenerateDataKeyPair
2 parents 20f9196 + 7a31dee commit 7e855ec

File tree

7 files changed

+29
-35
lines changed

7 files changed

+29
-35
lines changed

enclaver/src/bin/enclaver-run/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use anyhow::Result;
22
use clap::{Parser, Subcommand};
3-
use enclaver::constants::{MANIFEST_FILE_NAME, RELEASE_BUNDLE_DIR, EIF_FILE_NAME};
4-
use enclaver::run::{Enclave, EnclaveExitStatus, EnclaveOpts};
3+
use enclaver::constants::{EIF_FILE_NAME, MANIFEST_FILE_NAME, RELEASE_BUNDLE_DIR};
54
use enclaver::manifest::load_manifest_raw;
65
use enclaver::nitro_cli::NitroCLI;
6+
use enclaver::run::{Enclave, EnclaveExitStatus, EnclaveOpts};
77
use enclaver::utils;
88
use log::info;
99
use std::{
1010
path::PathBuf,
1111
process::{ExitCode, Termination},
1212
};
13-
use tokio_util::sync::CancellationToken;
1413
use tokio::io::{stdout, AsyncWriteExt};
14+
use tokio_util::sync::CancellationToken;
1515

1616
const ENCLAVE_SIGNALED_EXIT_CODE: u8 = 107;
1717
const ENCLAVE_FATAL: u8 = 108;

enclaver/src/bin/odyn/config.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,7 @@ impl KmsEndpointProvider for Configuration {
121121
.manifest
122122
.kms_proxy
123123
.as_ref()
124-
.and_then(|kp| {
125-
kp.endpoints
126-
.as_ref()
127-
.map(|eps| eps.get(region).cloned())
128-
})
124+
.and_then(|kp| kp.endpoints.as_ref().map(|eps| eps.get(region).cloned()))
129125
.flatten();
130126

131127
ep.unwrap_or_else(|| format!("kms.{region}.amazonaws.com"))

enclaver/src/build.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,7 @@ impl EnclaveArtifactBuilder {
350350
}
351351

352352
// If we make it this far, do a little bit of cleanup
353-
self
354-
.docker
353+
self.docker
355354
.remove_container(&build_container_id, None)
356355
.await?;
357356
let _ = self.docker.remove_image(&img_tag, None, None).await?;

enclaver/src/proxy/egress_http.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ struct ConnectRequest {
6161

6262
impl ConnectRequest {
6363
fn new(host: String, port: u16) -> Self {
64-
Self {
65-
host,
66-
port,
67-
}
64+
Self { host, port }
6865
}
6966
}
7067

enclaver/src/proxy/kms.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ static X_AMZ_JSON: HeaderValue = HeaderValue::from_static("application/x-amz-jso
2525

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

28-
const ATTESTING_ACTIONS: [&str; 3] = [
28+
const ATTESTING_ACTIONS: [&str; 5] = [
2929
"TrentService.Decrypt",
30+
"TrentService.DeriveSharedSecret",
3031
"TrentService.GenerateDataKey",
32+
"TrentService.GenerateDataKeyPair",
3133
"TrentService.GenerateRandom",
3234
];
3335

@@ -203,8 +205,8 @@ impl KmsRequestOutgoing {
203205
);
204206

205207
// Sign and then apply the signature to the request
206-
let signed = aws_sigv4::http_request::sign(signable_request, &signing_params)
207-
.map_err(Error::msg)?;
208+
let signed =
209+
aws_sigv4::http_request::sign(signable_request, &signing_params).map_err(Error::msg)?;
208210

209211
let (signing_instructions, _signature) = signed.into_parts();
210212
signing_instructions.apply_to_request(&mut self.inner);

enclaver/src/proxy/pkcs7.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ impl<'a> ContentInfo<'a> {
6262

6363
pub fn decrypt_content(&self, priv_key: &RsaPrivateKey) -> Result<Vec<u8>> {
6464
let datakey = self.decrypt_key(priv_key)?;
65-
self
66-
.content
65+
self.content
6766
.encrypted_content_info
6867
.decrypt_content(&datakey)
6968
}

enclaver/src/run.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -214,24 +214,25 @@ impl Enclave {
214214
}
215215

216216
fn start_odyn_log_stream(&mut self, cid: u32) -> Result<()> {
217-
self.tasks.push(utils::spawn!("odyn log stream", async move {
218-
info!("waiting for enclave to boot to stream logs");
219-
let conn = loop {
220-
match VsockStream::connect(cid, APP_LOG_PORT).await {
221-
Ok(conn) => break conn,
222-
223-
// TODO: improve the polling frequency / backoff / timeout
224-
Err(_) => {
225-
tokio::time::sleep(LOG_VSOCK_RETRY_INTERVAL).await;
217+
self.tasks
218+
.push(utils::spawn!("odyn log stream", async move {
219+
info!("waiting for enclave to boot to stream logs");
220+
let conn = loop {
221+
match VsockStream::connect(cid, APP_LOG_PORT).await {
222+
Ok(conn) => break conn,
223+
224+
// TODO: improve the polling frequency / backoff / timeout
225+
Err(_) => {
226+
tokio::time::sleep(LOG_VSOCK_RETRY_INTERVAL).await;
227+
}
226228
}
227-
}
228-
};
229+
};
229230

230-
info!("connected to enclave, starting log stream");
231-
if let Err(e) = utils::log_lines_from_stream("enclave", conn).await {
232-
error!("error reading log lines from enclave: {e}");
233-
}
234-
})?);
231+
info!("connected to enclave, starting log stream");
232+
if let Err(e) = utils::log_lines_from_stream("enclave", conn).await {
233+
error!("error reading log lines from enclave: {e}");
234+
}
235+
})?);
235236

236237
Ok(())
237238
}

0 commit comments

Comments
 (0)