From 92ec9fc448740192f4d22b3f3e6f6e320ef2dd10 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sat, 19 Sep 2020 22:31:20 -0700 Subject: [PATCH] Kill scdaemon before each OTP get TODO: Should probably be done on other paths as well. --- extensions/otp-cache/src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/extensions/otp-cache/src/main.rs b/extensions/otp-cache/src/main.rs index 39505ea7..98e74b1c 100644 --- a/extensions/otp-cache/src/main.rs +++ b/extensions/otp-cache/src/main.rs @@ -9,6 +9,7 @@ use std::collections; use std::fs; use std::io::Write as _; use std::path; +use std::process; use anyhow::Context as _; @@ -153,6 +154,16 @@ fn load_cache(path: &path::Path) -> anyhow::Result { } fn generate_otp(ctx: &ext::Context, args: &Args, slot: u8) -> anyhow::Result { + // Attempt to prevent a "hang" of the Nitrokey by killing any scdaemon + // that could currently have the device opened itself + // (https://github.com/Nitrokey/libnitrokey/issues/137). + let _ = process::Command::new("gpg-connect-agent") + .stdout(process::Stdio::null()) + .stderr(process::Stdio::null()) + .arg("SCD KILLSCD") + .arg("/bye") + .output(); + ext::Nitrocli::from_context(ctx) .args(&["otp", "get"]) .arg(slot.to_string())