From d55b993452e8d6f3086cda1f4a388f90b68ad7aa Mon Sep 17 00:00:00 2001 From: Brandon Invergo Date: Wed, 10 Jul 2019 22:14:03 +0100 Subject: [PATCH] Add gnu-pw-mgr password-management utility --- README.org | 1 + util/gnu-pw-mgr/README.md | 21 ++++++++ util/gnu-pw-mgr/gnu-pw-mgr.asd | 10 ++++ util/gnu-pw-mgr/gnu-pw-mgr.lisp | 92 +++++++++++++++++++++++++++++++++ util/gnu-pw-mgr/package.lisp | 5 ++ 5 files changed, 129 insertions(+) create mode 100644 util/gnu-pw-mgr/README.md create mode 100644 util/gnu-pw-mgr/gnu-pw-mgr.asd create mode 100644 util/gnu-pw-mgr/gnu-pw-mgr.lisp create mode 100644 util/gnu-pw-mgr/package.lisp diff --git a/README.org b/README.org index 2853ab1..3cd7cfa 100644 --- a/README.org +++ b/README.org @@ -93,6 +93,7 @@ to the world! - [[./util/desktop-entry/README.org][desktop-entry]] :: desktop-entry - [[./util/end-session/README.org][end-session]] :: Provides commands to stumpwm that allow the user to shutdown, restart, and logoff through the stumpwm UI - [[./util/globalwindows/README.org][globalwindows]] :: Manipulate all windows in the current X session +- [[./util/gnu-pw-mgr/README.org][gnu-pw-mgr]] :: Reconstruct passwords with gnu-pw-mgr - [[./util/kbd-layouts/README.org][kbd-layouts]] :: Keyboard layout switcher for StumpWM - [[./util/logitech-g15-keysyms/README.org][logitech-g15-keysyms]] :: Describe logitech-g15-keysyms here - [[./util/notify/README.org][notify]] :: DBus-based notification server part diff --git a/util/gnu-pw-mgr/README.md b/util/gnu-pw-mgr/README.md new file mode 100644 index 0000000..132eb6d --- /dev/null +++ b/util/gnu-pw-mgr/README.md @@ -0,0 +1,21 @@ +# gnu-pw-mgr + +This provides an interface to `gnu-pw-mgr`, GNU's password manager. +Specifically, this provides a command, `password-to-selection`, that +prompts you to enter a password ID and then offers a menu of seed +IDs. Upon selecting a seed ID, the (re-)generated password is copied +to the X selection (regardless of whether or not the password ID that +you entered is linked to an actual password that you use). + +No further configuration is necessary within Stumpwm. You must use +the `gnu-pw-mgr` command-line tool to perform any password +manipulations; this package is only for retrieving passwords. + +## Author + +_Brandon Invergo _ + +## License + +GPL version 3 or, at your option, any later version. + diff --git a/util/gnu-pw-mgr/gnu-pw-mgr.asd b/util/gnu-pw-mgr/gnu-pw-mgr.asd new file mode 100644 index 0000000..c123474 --- /dev/null +++ b/util/gnu-pw-mgr/gnu-pw-mgr.asd @@ -0,0 +1,10 @@ +(asdf:defsystem "gnu-pw-mgr" + :description "Reconstruct passwords with gnu-pw-mgr" + :author "Brandon Invergo " + :license "GPLv3" + :version "0.1" + :serial t + :depends-on ("stumpwm" + "cl-ppcre") + :components ((:file "package") + (:file "gnu-pw-mgr"))) diff --git a/util/gnu-pw-mgr/gnu-pw-mgr.lisp b/util/gnu-pw-mgr/gnu-pw-mgr.lisp new file mode 100644 index 0000000..49a4518 --- /dev/null +++ b/util/gnu-pw-mgr/gnu-pw-mgr.lisp @@ -0,0 +1,92 @@ +;;;; gnu-pw-mgr.lisp +;; Copyright (C) 2019 Brandon Invergo + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +(in-package #:gnu-pw-mgr) + +;; All timer code is blatantly stolen^H^H^H^H^H^Hborrowed from the +;; passwd module. +(defvar *password-id-remember-timeout* 0 + "How long will the password-id be remembered (in minutes)") +(defvar *clipboard-clear-timeout* 10 + "How long will the password-id be remembered (in seconds)") + +(defvar *password-id* nil) + +(defvar *password-id-timer* + (sb-ext:make-timer (lambda () + (setf *password-id* nil)))) + +(defvar *old-clipboard* nil) + +(defvar *clipboard-timer* + (sb-ext:make-timer (lambda () + (set-x-selection *old-clipboard*) + (setf *old-clipboard* nil)))) + +(defun reset-timer (timer timeout) + (when (sb-ext:timer-scheduled-p timer) + (sb-ext:unschedule-timer timer)) + (sb-ext:schedule-timer timer timeout)) + +(stumpwm:define-stumpwm-type :gpw-password-id (input prompt) + (or *password-id* + (setf *password-id* + (or (argument-pop-rest input) + (read-one-line (current-screen) prompt :password t))))) + +;; The tag lines look like: +;; +(defun parse-tags (lines) + (loop :for index :from 1 + :for tag-line :in lines + :collect (let ((passl (cl-ppcre:split " +" tag-line))) + (cons (first passl) (second passl))))) + +;; Normally we could run gnu-pw-mgr with the '-H/--no-header' option +;; to parse the output more easily, however we want to capture the +;; login-id hint, which is omitted when -H is used. So, we have to +;; filter out a bunch of junk header lines when trying to isolate the +;; seed-tag/password lines. +(defun header-line-p (line) + (cl-ppcre:scan "^$|^seed-tag|^login id hint:" line)) + +(stumpwm:defcommand password-to-selection (pwid) + ((:gpw-password-id "Password ID: ")) + "Prompt for a password ID and a seed tag and set the X selection to +the resulting password." + (let* ((cmd (format nil "exec gnu-pw-mgr '~A'" pwid)) + (output (stumpwm:run-shell-command cmd t)) + (lines (remove-if 'header-line-p (cl-ppcre:split "\\n" output))) + (passes (parse-tags lines)) + (tags (mapcar #'first passes)) + (tag-sel (select-from-menu (stumpwm:current-screen) + tags + "seed tag:")) + (pass (when tag-sel + (cdr (assoc tag-sel passes :test #'string=))))) + (unless *old-clipboard* + (setf *old-clipboard* (get-x-selection))) + (when (and *clipboard-clear-timeout* + (> *clipboard-clear-timeout* 0)) + (reset-timer *clipboard-timer* *clipboard-clear-timeout*)) + (if (and *password-id-remember-timeout* + (> *password-id-remember-timeout* 0)) + (reset-timer *password-id-timer* (* *password-id-remember-timeout* 60)) + (setf *password-id* nil)) + (when pass + (stumpwm:set-x-selection pass) + (alexandria:when-let ((string (cl-ppcre:scan-to-strings "login id hint: .+\\n" output))) + (stumpwm:message string))))) diff --git a/util/gnu-pw-mgr/package.lisp b/util/gnu-pw-mgr/package.lisp new file mode 100644 index 0000000..af24179 --- /dev/null +++ b/util/gnu-pw-mgr/package.lisp @@ -0,0 +1,5 @@ +(defpackage #:gnu-pw-mgr + (:use #:cl #:stumpwm) + (:export #:password-to-selection + #:*password-id-remember-timeout* + #:*clipboard-clear-timeout*))