[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/base32 94f41a945e 028/103: Implement auto-copying of TOTP
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/base32 94f41a945e 028/103: Implement auto-copying of TOTP tokens |
Date: |
Sat, 10 Feb 2024 13:00:02 -0500 (EST) |
branch: elpa/base32
commit 94f41a945ee5d21b2b18c3fd8015b58800efdff8
Author: Vivek Das Mohapatra <vivek@collabora.co.uk>
Commit: Vivek Das Mohapatra <vivek@collabora.co.uk>
Implement auto-copying of TOTP tokens
Allow user-configurable paste buffers (see totp-auto-copy-password)
which will be automatically and continuously updated to hold the
current value of the last interactively generated TOTP token until
the TOTP buffer is closed or the user copies some other content manually.
---
totp.el | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/totp.el b/totp.el
index bf037b7b2a..c7ec9098de 100644
--- a/totp.el
+++ b/totp.el
@@ -66,11 +66,28 @@ a secret if you ever re-import it."
:group 'totp
:type 'boolean)
+(defcustom totp-auto-copy-password nil
+ "If set then ‘totp’ and other interactive functions that generate
+TOTP tokens will automatically copy the generated token into the selected
+copy/paste backends, ready for pasting (eg into other applications or buffers).
+The behaviour is as follows:
+ - When the token is generated, it is placed in the selected copy areas
+ - If the copy area still contains the previous value when the token
+ expires and is regenerated, it is replaced with the new value."
+ :group 'totp
+ :type '(choice
+ (const :tag "Off" nil)
+ (set :tag "Choose Copy Method(s)"
+ (const :tag "Primary (middle-click etc)" PRIMARY)
+ (const :tag "Clipboard (Paste, c-y, V-v)" CLIPBOARD)
+ (const :tag "Secondary" SECONDARY))))
+
(defcustom totp-auth-sources nil
"Serves the same purpose as ‘auth-sources’, but for the TOTP
package. If unset (the default) this will be initialised to a list
consisting of the contents of ‘auth-sources’ with the freedesktop
secrets service login session prepended to it, if it is available."
+ :group 'totp
:type `(repeat :tag "Authentication Sources"
(choice
(string :tag "Just a file")
@@ -481,6 +498,18 @@ and EXPIRY is the seconds after the epoch when the TOTP
expires."
(defvar totp-display-label nil)
(defvar totp-display-expiry nil)
(defvar totp-display-secret nil)
+(defvar totp-display-oldpwd nil)
+
+(defun totp-update-paste-buffers (old new)
+ "For each copy/paste buffer selected by ‘totp-auto-copy-password’
+update the contents to password NEW (if it contains password OLD,
+or if OLD is unset)."
+ ;;(message "totp-update-paste-buffers %S (%S)" old new
totp-auto-copy-password)
+ (mapc (lambda (type &optional ok)
+ (with-demoted-errors "gui get/set selection error: %S"
+ (setq ok (if old (equal old (gui-get-selection type)) t))
+ (if ok (gui-set-selection type (or new "")))))
+ totp-auto-copy-password))
(defun totp-cancel-this-timer ()
"Cancel the timer whose callback this is called from."
@@ -518,6 +547,10 @@ and EXPIRY is the seconds after the epoch when the TOTP
expires."
token (nth 0 otp)
totp-display-ttl (nth 1 otp)
totp-display-expiry (nth 2 otp)))
+ ;; update the copy/paste buffers if necessary:
+ (totp-update-paste-buffers totp-display-oldpwd token)
+ (setq totp-display-oldpwd token)
+ ;; display the current token
(insert (format "TOTP %s [%02ds]: %s\n"
totp-display-label totp-display-ttl token)))
(totp-cancel-this-timer)))
@@ -531,9 +564,11 @@ and EXPIRY is the seconds after the epoch when the TOTP
expires."
(mapc 'make-local-variable '(totp-display-ttl
totp-display-label
totp-display-expiry
+ totp-display-oldpwd
totp-display-secret))
(setq totp-display-label label
totp-display-secret (cdr (assq :secret secret))
+ totp-display-oldpwd nil
totp-display-ttl nil
totp-display-expiry nil)
(pop-to-buffer ui-buffer)
- [nongnu] elpa/base32 0146fe6b91 010/103: Minor formatting trivia in the test file, (continued)
- [nongnu] elpa/base32 0146fe6b91 010/103: Minor formatting trivia in the test file, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 b7e1daca76 009/103: Comment out some spurious calls in the test file, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 4432d44bce 012/103: Trivia: clean up some docstrings, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 a683df1a74 013/103: Add a separate instance of an `auth-sources' list just for TOTP, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 5c902928f7 017/103: Fix bug in otpauth-migration URL decoder, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 f27043d432 019/103: Fix some byte compilation warnings, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 417a3d03f6 020/103: Dedup secrets manually instead of relying on freedesktop secrets API, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 800de931a0 023/103: Autoload totp-import-file and update its docstring, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 3e5a779479 022/103: Reduce totp-minimum-ui-grace default value to 3 from 5, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 0feadbc485 025/103: Make the cancel-this-timer function more generic, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 94f41a945e 028/103: Implement auto-copying of TOTP tokens,
ELPA Syncer <=
- [nongnu] elpa/base32 a61f9c27b1 032/103: Remove unnecessary file, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 e9c9329661 033/103: Prepare for package archive inclusion, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 e18cb077d7 035/103: Note in TODO that we may be able to drop custom hmac support now, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 ff7061d7ef 036/103: Bump version to 0.2 for release attempt, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 1e14f7c45f 016/103: Remove references to debug function that doesn't exist anymore, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 c29822d2f1 015/103: Add totp-pkg.el in preparation for publishing to a package archive, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 47bcc107b8 021/103: Enable substring matching for TOTP secret selection, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 9b6ac038a1 018/103: Eliminate reference to obsolete internal variable in an error path, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 8925afa85b 027/103: Clarify that totp-alt-xdg-schemas is used only to read secrets, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 982c418361 026/103: Docstring style trivia, ELPA Syncer, 2024/02/10