From 603315e5b158ced2c05e736067004832cd6a4e06 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sun, 9 Jul 2023 17:55:19 +0200 Subject: [PATCH] Delay computation of SSH-Key password until start of `ssh-add` This is to prepare computing the password only when needed, i.e., when the key is not already included in the running agent. We are not there yet, though. --- site-lisp/db-utils.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/site-lisp/db-utils.el b/site-lisp/db-utils.el index 43def10..111ef9b 100644 --- a/site-lisp/db-utils.el +++ b/site-lisp/db-utils.el @@ -836,11 +836,15 @@ This is `db-light' and `solarized-light'." ;;; SSH-Key-Handling -(defun db/add-ssh-key-with-password (key-file password) - "Add key in KEY-FILE with PASSWORD to currently running ssh-agent." +(defun db/add-ssh-key-with-password (key-file password-fn) + "Add key in KEY-FILE to currently running ssh-agent. + +PASSWORD-FN is supposed to be a function returning the password +for KEY-FILE." (with-environment-variables (("SSH_ASKPASS_REQUIRE" "never")) (with-temp-buffer - (unless (zerop (call-process-region password nil ; XXX: only compute password when it's needed? + (unless (zerop (call-process-region (funcall password-fn) ; XXX: only compute password when it's needed? + nil "ssh-add" ; XXX: generalize to also allow pageant? nil t nil (expand-file-name key-file))) @@ -868,7 +872,9 @@ holding the password to unlock the key." ;; XXX: error handling (interactive) (pcase-dolist (`(,ssh-key . ,pass-entry) db/known-ssh-keys) - (db/add-ssh-key-with-password ssh-key (apply #'db/password-from-storage pass-entry)))) + (db/add-ssh-key-with-password ssh-key + #'(lambda () + (apply #'db/password-from-storage pass-entry))))) (cl-defgeneric db/password-from-storage (type entry-key) "Retrieve password from storage of type TYPE with lookup key ENTRY-KEY.")