Skip to content

Commit

Permalink
fix: kill yubikey-agent if it is installed during init
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusZoppelt committed Jan 27, 2023
1 parent ad76cc1 commit e23f426
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ animal! `yubikey-otp` has a nicer UX imho. Try it out! ;)
#### Conflict with yubikey-agent

[`yubikey-agent` takes a persistent transaction so the YubiKey will cache the PIN after first use](https://github.com/FiloSottile/yubikey-agent#conflicts-with-gpg-agent-and-yubikey-manager).
In that case, kill `yubikey-agent` and try again.

killall -HUP yubikey-agent
To mitigate that issue, `yubikey-otp` will run `killall -HUP yubikey-agent`
during init.

Don't worry, `yubikey-agent` will restart the next time you want to use it.
19 changes: 10 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ searchable list. Select the code you want to copy to the clipboard.`,
accounts, err := accounts.GetOTPAccountsFromYubiKey(deviceID)
if err != nil {
fmt.Println("Please make sure that the YubiKey is connected and that ykman is installed.")

// if the user has yubikey-agent installed, the error might be related to that
// so we check if yubikey-agent is installed and if so, we print a hint
_, err = exec.LookPath("yubikey-agent")
if err == nil {
fmt.Println()
fmt.Println("If you are using yubikey-agent, you may try to kill it with")
fmt.Println("`killall -HUP yubikey-agent` and try again.")
}
os.Exit(1)
}

Expand Down Expand Up @@ -117,6 +108,16 @@ func init() {
os.Exit(1)
}

// if yubikey-agent is installed. we might need to kill it
// otherwise the ykman command will fail
_, err = exec.LookPath("yubikey-agent")
if err == nil {
err = exec.Command("killall", "-HUP", "yubikey-agent").Run()
if err != nil {
fmt.Println("Error killing yubikey-agent:", err)
}
}

flag.String("device", "", "YubiKey device ID")
flag.Bool("verbose", false, "Enable verbose logging")

Expand Down

0 comments on commit e23f426

Please sign in to comment.