Skip to content

About

Waybar/Hyprland-native alert when a YubiKey is waiting for a touch

Resources

Stars

1 star

Watchers

0 watching

Forks

 
 

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

yubi-alerter

Waybar/Hyprland-native alert when your YubiKey is waiting for a touch.

Touch-to-sign YubiKeys blink quietly to themselves when gpg wants a signature (git commits, pulls over ssh, ...). Miss the blink and your command sits there until it times out - and then you get to re-enter your PIN on top. This is annoying interactively, and worse with AI agents committing on your behalf: nobody is watching the key.

yubi-alerter fixes that with an unmissable, flashing waybar module, plus a Hyprland notification and an optional beep that repeats until you touch the key.

How it works

No gpgme, no PC/SC, no config changes to gpg - just two observations:

  1. gpg-agent reads a shadowed private key from $GNUPGHOME/private-keys-v1.d/*.key every time it starts a sign/decrypt/auth operation. An inotify OPEN watch on that directory tells us an operation started.
  2. While the YubiKey blinks for a touch, scdaemon holds the card exclusively. Asking for the card status (SCD LEARN --force over gpg-agent's Assuan socket) then blocks until you touch (or the operation times out). A blocking probe is exactly the "touch requested" signal; when it returns, the wait is over.

The same idea as yubikey-touch-detector, reimplemented as a single small Rust binary that is the waybar module - no daemon, no socket protocol, no systemd unit. It also covers the PIN-entry phase (scdaemon holds the card while pinentry is open), so the alert fires whenever the YubiKey needs attention, not only for touches.

Features

  • Flashing waybar indicator (custom module, JSON return type)
  • Hyprland-native notification via hyprctl notify (falls back to notify-send)
  • Optional beep (self-generated WAV, played via pw-play/paplay/aplay), optionally repeating until you touch
  • Multi-monitor safe: waybar spawns one module instance per output; every bar flashes, but notifications/sounds are de-duplicated with a lock file so they fire exactly once
  • Alerts for gpg sign/decrypt and ssh auth via gpg-agent (e.g. git pull over ssh)

Requirements

  • Linux, gnupg 2.x with a YubiKey (OpenPGP) key whose touch policy is enabled (ykman openpgp keys set-touch sig on, etc.)
  • waybar (for the bar indicator) and/or Hyprland (for hyprctl notify)
  • One of pw-play, paplay, aplay if you want sound

Install

cargo build --release
# binary: target/release/yubi-alerter
# or: cargo install --path .

Nix / NixOS

The repo is a flake:

nix run github:pmembrey/yubi-alerter -- --sound

or reference it from your own flake and use inputs.yubi-alerter.packages.${pkgs.stdenv.hostPlatform.system}.default (e.g. as the waybar exec), which avoids depending on a local cargo build output path.

Waybar setup

config:

"modules-right": [ ..., "custom/yubikey", ... ],
"custom/yubikey": {
    "exec": "yubi-alerter --sound --beep-interval 2",
    "return-type": "json"
}

style.css:

#custom-yubikey.waiting {
    padding: 0 10px;
    border-radius: 4px;
    font-weight: bold;
    color: #1e1e2e;
    background: #ff1744;
    animation: yubi-blink 0.7s steps(2, start) infinite;
}
@keyframes yubi-blink {
    to { background: #1e1e2e; color: #ff1744; }
}

Waybar manages the process lifecycle; no service needed. If you use home-manager, the same two snippets translate directly into programs.waybar.settings / programs.waybar.style.

Options

-v, --verbose            Log detection events to stderr
    --socket PATH        gpg-agent Assuan socket
                         (default: from `gpgconf --list-dirs agent-socket`)
    --gnupghome PATH     GnuPG home (default: $GNUPGHOME or ~/.gnupg)
    --text TEXT          Waybar text while touch is pending
                         (default: "🔑 TOUCH YUBIKEY")
    --busy-ms N          Card query blocking longer than N ms means
                         "waiting for touch" (default: 800)
    --window-secs N      Keep probing for N secs after a key file was
                         opened (default: 4)
    --remind-secs N      Re-notify every N secs while waiting (default: 0 = off)
    --beep-interval N    Beep every N secs while waiting, until the touch
                         happens (implies --sound; default: 0 = off)
    --no-notify          Don't send a Hyprland/libnotify notification
    --sound              Play a beep (generated) on touch request
    --sound-file PATH    Play PATH instead of the generated beep

Development

The crate is Linux-only - inotify fails to compile on macOS and Windows, so cargo test only works on a Linux host. Earthly runs the whole suite in a container from any machine with Docker:

earthly +all       # test, fmt, clippy, deny, build
earthly +test      # just the tests
earthly +build     # release binary -> dist/yubi-alerter

Each target also runs standalone: +fmt, +clippy, +deny.

On a Linux host you can skip the container:

cargo test
cargo fmt --check
cargo clippy --all-targets
cargo deny check   # needs cargo-deny; deny.toml included

License

MIT

About

Waybar/Hyprland-native alert when a YubiKey is waiting for a touch

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages