Skip to content

Commit

Permalink
fix: fix tee sign in
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Jan 19, 2025
1 parent d681be7 commit 794274e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ strip = true
opt-level = 's'

[workspace.package]
version = "0.2.8"
version = "0.2.9"
edition = "2021"
repository = "https://github.com/ldclabs/ic-tee"
keywords = ["tee", "canister", "icp", "nitro"]
Expand Down
3 changes: 1 addition & 2 deletions src/ic_tee_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use std::{path::Path, sync::Arc};

static LOCAL_HOST: &str = "http://127.0.0.1:4943";
static IC_HOST: &str = "https://icp-api.io";
static SETTING_KEY_ID: &str = "id_ed25519";
static SETTING_KEY_TLS: &str = "tls";
static COSE_SECRET_PERMANENT_KEY: &str = "v1";

Expand Down Expand Up @@ -68,7 +67,7 @@ pub enum Commands {
/// derive the principal with canister and seeds
IdentityDerive {
/// TEE kind to derive the principal
#[arg(long, default_value = "Nitro")]
#[arg(long, default_value = "NITRO")]
kind: String,

#[arg(long)]
Expand Down
2 changes: 1 addition & 1 deletion src/ic_tee_identity/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn whoami() -> Principal {
fn sign_in(kind: String, attestation: ByteBuf) -> Result<SignInResponse, String> {
let attestation = match kind.as_str() {
"NITRO" => parse_and_verify(attestation.as_slice())?,
_ => Err("unsupported attestation kind".to_string())?,
_ => Err(format!("unsupported attestation kind: {}", kind))?,
};

let now_ms = ic_cdk::api::time() / MILLISECONDS;
Expand Down
22 changes: 16 additions & 6 deletions src/ic_tee_nitro_gateway/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,24 +216,33 @@ async fn bootstrap(cli: Cli) -> Result<(), BoxError> {
};

let principal = tee_agent.get_principal();
log::info!(target: LOG_TARGET, "start to get master_secret");
log::info!(target: LOG_TARGET, "start to get my_master_secret");
// should replace with vetkey in the future
let master_secret = tee_agent
let admin_master_secret = tee_agent
.get_cose_encrypted_key(&SettingPath {
ns: namespace.clone(),
user_owned: true,
user_owned: false,
key: COSE_SECRET_PERMANENT_KEY.as_bytes().to_vec().into(),
subject: Some(principal),
..Default::default()
})
.await?;
let my_master_secret = tee_agent
.get_cose_encrypted_key(&SettingPath {
ns: namespace.clone(),
user_owned: true, // admin can't read user owned master_secret
key: COSE_SECRET_PERMANENT_KEY.as_bytes().to_vec().into(),
subject: Some(principal),
..Default::default()
})
.await?;
log::info!(target: LOG_TARGET,
elapsed = start.elapsed().as_millis() as u64;
"get master_secret");
"get my_master_secret");

log::info!(target: LOG_TARGET, "start to get_or_set_root_secret");
let root_secret =
get_or_set_root_secret(&tee_agent, &start, namespace.clone(), &master_secret).await?;
get_or_set_root_secret(&tee_agent, &start, namespace.clone(), &my_master_secret).await?;

let info = TEEAppInformation {
id: principal,
Expand Down Expand Up @@ -283,7 +292,8 @@ async fn bootstrap(cli: Cli) -> Result<(), BoxError> {
None
} else {
log::info!(target: LOG_TARGET, "start to get_tls");
let tls = get_tls(&tee_agent, &start, namespace.clone(), &master_secret).await?;
let tls =
get_tls(&tee_agent, &start, namespace.clone(), &admin_master_secret).await?;
let config = RustlsConfig::from_pem(tls.crt.to_vec(), tls.key.to_vec()).await?;
Some(config)
};
Expand Down

0 comments on commit 794274e

Please sign in to comment.