Skip to content

Commit

Permalink
Kill scdaemon before each OTP get
Browse files Browse the repository at this point in the history
TODO: Should probably be done on other paths as well.
  • Loading branch information
d-e-s-o committed Sep 20, 2020
1 parent 77df580 commit 92ec9fc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions extensions/otp-cache/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _;

Expand Down Expand Up @@ -153,6 +154,16 @@ fn load_cache(path: &path::Path) -> anyhow::Result<Cache> {
}

fn generate_otp(ctx: &ext::Context, args: &Args, slot: u8) -> anyhow::Result<String> {
// 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())
Expand Down

0 comments on commit 92ec9fc

Please sign in to comment.