From ec150e5a6c7efc3601eb6d71be65aa7137f9d5c0 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Mon, 22 Jan 2024 17:19:48 +0100 Subject: [PATCH] waybar: Add security key interaction notification --- LICENSES/ISC.txt | 8 ++++ users/simon/modules/gpg.nix | 13 ++++++ users/simon/modules/sway/waybar-interaction | 45 +++++++++++++++++++++ users/simon/modules/sway/waybar.css | 12 +++++- users/simon/modules/sway/waybar.nix | 12 +++++- 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 LICENSES/ISC.txt create mode 100755 users/simon/modules/sway/waybar-interaction diff --git a/LICENSES/ISC.txt b/LICENSES/ISC.txt new file mode 100644 index 0000000..b9c199c --- /dev/null +++ b/LICENSES/ISC.txt @@ -0,0 +1,8 @@ +ISC License: + +Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC") +Copyright (c) 1995-2003 by Internet Software Consortium + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/users/simon/modules/gpg.nix b/users/simon/modules/gpg.nix index 4367dd4..f23e4d3 100644 --- a/users/simon/modules/gpg.nix +++ b/users/simon/modules/gpg.nix @@ -27,4 +27,17 @@ maxCacheTtl = 1800; maxCacheTtlSsh = maxCacheTtl; }; + + systemd.user.services.yubikey-touch-detector = { + Unit.PartOf = [ "sway-session.target" ]; + Install.WantedBy = [ "sway-session.target" ]; + + Service = { + Environment = [ + "PATH=${pkgs.gnupg}/bin" + ]; + ExecStart = "${pkgs.yubikey-touch-detector}/bin/yubikey-touch-detector"; + Restart = "on-failure"; + }; + }; } diff --git a/users/simon/modules/sway/waybar-interaction b/users/simon/modules/sway/waybar-interaction new file mode 100755 index 0000000..c2a08b6 --- /dev/null +++ b/users/simon/modules/sway/waybar-interaction @@ -0,0 +1,45 @@ +#! @bash@/bin/bash +# shellcheck disable=SC2239 +# SPDX-FileCopyrightText: 2020 Maxim Baz +# SPDX-FileCopyrightText: 2023 Matthew Monaco +# SPDX-FileCopyrightText: 2024 Simon Bruder +# +# SPDX-License-Identifier: ISC + +set -euo pipefail + +socket="${XDG_RUNTIME_DIR:-/run/user/$UID}/yubikey-touch-detector.socket" + +while true; do + touch_reasons=() + + if [ ! -e "$socket" ]; then + printf '{"text": "Waiting for socket"}\n' + while [ ! -e "$socket" ]; do sleep 1; done + fi + printf '{"text": ""}\n' + + while read -r -n5 cmd; do + reason="${cmd:0:3}" + + if [ "${cmd:4:1}" = "1" ]; then + touch_reasons+=("$reason") + else + for i in "${!touch_reasons[@]}"; do + if [ "${touch_reasons[i]}" = "$reason" ]; then + unset 'touch_reasons[i]' + break + fi + done + fi + + if [ "${#touch_reasons[@]}" -eq 0 ]; then + printf '{"text": ""}\n' + else + tooltip="Security key is waiting for a touch, reasons: ${touch_reasons[*]}" + printf '{"text": "󰈷", "tooltip": "%s"}\n' "$tooltip" + fi + done < <(@netcat@/bin/nc -U "$socket") + + sleep 1 +done diff --git a/users/simon/modules/sway/waybar.css b/users/simon/modules/sway/waybar.css index 839a002..80de67a 100644 --- a/users/simon/modules/sway/waybar.css +++ b/users/simon/modules/sway/waybar.css @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2022 Simon Bruder + * SPDX-FileCopyrightText: 2020-2024 Simon Bruder * * SPDX-License-Identifier: AGPL-3.0-or-later */ @@ -178,3 +178,13 @@ window#waybar { background-color: @base3@; color: @base00@; } + +#custom-interaction { + background-color: @yellow@; + color: @base03@; + animation-name: blink; + animation-duration: 0.5s; + animation-timing-function: cubic-bezier(1, 0, 0, 1); + animation-iteration-count: infinite; + animation-direction: alternate; +} diff --git a/users/simon/modules/sway/waybar.nix b/users/simon/modules/sway/waybar.nix index b0d969b..94d8fbf 100644 --- a/users/simon/modules/sway/waybar.nix +++ b/users/simon/modules/sway/waybar.nix @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2020-2023 Simon Bruder +# SPDX-FileCopyrightText: 2020-2024 Simon Bruder # # SPDX-License-Identifier: AGPL-3.0-or-later @@ -37,6 +37,7 @@ in ]; modules-right = [ "tray" + "custom/interaction" "custom/screencast" "custom/redshift" "idle_inhibitor" @@ -81,6 +82,15 @@ in deactivated = "󰈉 "; }; }; + "custom/interaction" = { + exec = pkgs.substituteAll ({ + src = ./waybar-interaction; + } // { + inherit (pkgs) netcat bash; + isExecutable = true; + }); + return-type = "json"; + }; "custom/screencast" = { exec = pkgs.writeScript "screencast-monitor" /* python */ '' #!${pkgs.python3}/bin/python3