adds product key to error message in setup flow when there is mismatch

This commit is contained in:
Keagan McClelland
2022-05-09 17:28:11 -06:00
parent e41b2f6ca9
commit a6234e4507
3 changed files with 29 additions and 18 deletions

View File

@@ -40,6 +40,7 @@ path = "src/bin/embassy-cli.rs"
avahi = ["avahi-sys"]
beta = []
default = ["avahi", "sound", "metal"]
dev = []
metal = []
sound = []
unstable = ["patch-db/unstable"]

View File

@@ -11,18 +11,21 @@ fi
alias 'rust-arm64-builder'='docker run --rm -it -v "$HOME/.cargo/registry":/root/.cargo/registry -v "$(pwd)":/home/rust/src start9/rust-arm-cross:aarch64'
cd ..
FLAGS=""
if [[ "$ENVIRONMENT" =~ (^|-)unstable($|-) ]]; then
if [[ "$ENVIRONMENT" =~ (^|-)beta($|-) ]]; then
rust-arm64-builder sh -c "(cd backend && cargo build --release --features beta,unstable)"
else
rust-arm64-builder sh -c "(cd backend && cargo build --release --features unstable)"
fi
else
if [[ "$ENVIRONMENT" =~ (^|-)beta($|-) ]]; then
rust-arm64-builder sh -c "(cd backend && cargo build --release --features beta)"
else
FLAGS="unstable,$FLAGS"
fi
if [[ "$ENVIRONMENT" =~ (^|-)beta($|-) ]]; then
FLAGS="beta,$FLAGS"
fi
if [[ "$ENVIRONMENT" =~ (^|-)dev($|-) ]]; then
FLAGS="dev,$FLAGS"
fi
if [[ "$FLAGS" = "" ]]; then
rust-arm64-builder sh -c "(cd backend && cargo build --release)"
fi
else
echo "FLAGS=$FLAGS"
rust-arm64-builder sh -c "(cd backend && cargo build --release --features $FLAGS)"
fi
cd backend
#rust-arm64-builder aarch64-linux-gnu-strip target/aarch64-unknown-linux-gnu/release/embassyd

View File

@@ -75,9 +75,7 @@ pub struct StatusRes {
#[command(rpc_only, metadata(authenticated = false))]
pub async fn status(#[context] ctx: SetupContext) -> Result<StatusRes, Error> {
Ok(StatusRes {
product_key: tokio::fs::metadata("/embassy-os/product_key.txt")
.await
.is_ok(),
product_key: tokio::fs::metadata(PRODUCT_KEY_PATH).await.is_ok(),
migrating: ctx.recovery_status.read().await.is_some(),
})
}
@@ -104,20 +102,29 @@ pub async fn attach(
DEFAULT_PASSWORD,
)
.await?;
let mut product_key = ctx.product_key().await?;
let product_key_path = Path::new("/embassy-data/main/product_key.txt");
if tokio::fs::metadata(product_key_path).await.is_ok() {
let pkey = tokio::fs::read_to_string(product_key_path).await?;
if pkey.trim() != &*ctx.product_key().await? {
let pkey = Arc::new(
tokio::fs::read_to_string(product_key_path)
.await?
.trim()
.to_owned(),
);
if pkey != product_key {
crate::disk::main::export(&*guid, &ctx.datadir).await?;
return Err(Error::new(
eyre!("The EmbassyOS product key does not match the supplied drive"),
eyre!(
"The EmbassyOS product key does not match the supplied drive: {}",
pkey
),
ErrorKind::ProductKeyMismatch,
));
}
}
init(
&RpcContextConfig::load(ctx.config_path.as_ref()).await?,
&*ctx.product_key().await?,
&*product_key,
)
.await?;
let secrets = ctx.secret_store().await?;
@@ -127,7 +134,7 @@ pub async fn attach(
tor_address: format!("http://{}", tor_key.public().get_onion_address()),
lan_address: format!(
"https://embassy-{}.local",
crate::hostname::derive_id(&*ctx.product_key().await?)
crate::hostname::derive_id(&*product_key)
),
root_ca: String::from_utf8(root_ca.to_pem()?)?,
};