From db96c4a4ebc05c8e4f1b427074fc5fe61c026998 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 19 Dec 2023 14:59:04 +0100 Subject: [PATCH] minor bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- flake.nix | 4 ++-- src/main.rs | 13 +++++++++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5fa1ae1..9c4f75e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -403,7 +403,7 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "gnome-autounlock-keyring" -version = "0.1.1" +version = "0.2.0" dependencies = [ "base64 0.21.5", "clap", diff --git a/Cargo.toml b/Cargo.toml index 2380e83..5706c83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gnome-autounlock-keyring" -version = "0.1.1" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/flake.nix b/flake.nix index 42b04cc..34e4981 100644 --- a/flake.nix +++ b/flake.nix @@ -7,7 +7,7 @@ outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let - cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml)); + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); pkgs = nixpkgs.legacyPackages.${system}; inherit (pkgs) stdenv lib; in rec { @@ -75,7 +75,7 @@ script = '' ${self.packages.${pkgs.system}.default}/bin/gnome-autounlock-keyring unlock ''; - serviceConfig = { Type = "oneshot"; }; + serviceConfig.Type = "oneshot"; }; }; }; diff --git a/src/main.rs b/src/main.rs index 9b0a758..16a5098 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,6 @@ use std::fs::{read_to_string, File}; use std::io::{Read, Write}; use std::os::unix::net::UnixStream; use std::path::PathBuf; -use std::process::exit; use std::thread::sleep; use std::time::Duration; use tpm::tpm_objects::TPM2Config; @@ -152,10 +151,12 @@ fn main() -> color_eyre::Result<()> { if token_path.exists() { let token = read_to_string(token_path)?; + let mut res = ControlResult::NoDaemon; + for _ in 0..tries { let password = tpm::perform_decrypt(token.as_bytes()).map_err(|err| eyre!("{err:?}"))?; - let res = unlock_keyring(password.as_slice())?; + res = unlock_keyring(password.as_slice())?; if res == ControlResult::Ok { break; } else { @@ -164,6 +165,11 @@ fn main() -> color_eyre::Result<()> { sleep(Duration::from_secs(timeout)); } + + if res != ControlResult::Ok { + bail!("Unlocking failed after {tries}: {res:?}"); + } + } else { bail!("password token file not found") } @@ -173,8 +179,7 @@ fn main() -> color_eyre::Result<()> { let password = rpassword::prompt_password("Password: ")?; if unlock_keyring(password.as_bytes())? != ControlResult::Ok { - eprintln!("invalid password"); - exit(3); + bail!("invalid password"); } let token = tpm::perform_encrypt(TPM2Config::default(), password.as_bytes())