emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Small patch to enable use of gpg-agent with pgg


From: Sascha Wilde
Subject: Re: Small patch to enable use of gpg-agent with pgg
Date: Sun, 19 Mar 2006 18:30:10 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Sascha Wilde <address@hidden> wrote:
> Daniel Pittman <address@hidden> wrote:
>>> Sascha Wilde <address@hidden> writes:
>>
>>> I wrote a small patch, which makes it possible to use the GnuPG agent
>>> (which is part of gpg 1.9 and considered ready to use by Werner) with
>>> the GnuPG backend of pgg.
> [...]
>> I am not convinced that this is the best idea -- so far as I can see, if
>> I were to set `pgg-gpg-use-agent' to `t' then I *must* use the agent.
>>
>> Is it not possible to enable gpg to try the agent first, then to prompt
>> for a passphrase?
>
> Yes, that would be good.  I'll try to implement it.

I attached a patch which performs a test if gpg-agent is really
available when pgg-gpg-use-agent is set to t.

Please note, this new patch also fixees a bug, which was introduced
by the original patch and broke non agent use...

cheers
sascha

*** pgg-gpg.el  11 Feb 2006 17:01:56 +0100      1.4
--- pgg-gpg.el  19 Mär 2006 17:05:38 +0100      
***************
*** 4,10 ****
  ;;   2005, 2006 Free Software Foundation, Inc.
  
  ;; Author: Daiki Ueno <address@hidden>
! ;; Symmetric encryption added by: Sascha Wilde <address@hidden>
  ;; Created: 1999/10/28
  ;; Keywords: PGP, OpenPGP, GnuPG
  
--- 4,11 ----
  ;;   2005, 2006 Free Software Foundation, Inc.
  
  ;; Author: Daiki Ueno <address@hidden>
! ;; Symmetric encryption and gpg-agent support added by: 
! ;;   Sascha Wilde <address@hidden>
  ;; Created: 1999/10/28
  ;; Keywords: PGP, OpenPGP, GnuPG
  
***************
*** 51,64 ****
    :type '(choice (const :tag "New `--recipient' option" "--recipient")
                 (const :tag "Old `--remote-user' option" "--remote-user")))
  
  (defvar pgg-gpg-user-id nil
    "GnuPG ID of your default identity.")
  
  (defun pgg-gpg-process-region (start end passphrase program args)
!   (let* ((output-file-name (pgg-make-temp-file "pgg-output"))
         (args
          `("--status-fd" "2"
!           ,@(if passphrase '("--passphrase-fd" "0"))
            "--yes" ; overwrite
            "--output" ,output-file-name
            ,@pgg-gpg-extra-args ,@args))
--- 52,73 ----
    :type '(choice (const :tag "New `--recipient' option" "--recipient")
                 (const :tag "Old `--remote-user' option" "--remote-user")))
  
+ (defcustom pgg-gpg-use-agent nil
+   "Whether to use gnupg agent for key caching."
+   :group 'pgg-gpg
+   :type 'boolean)
+ 
  (defvar pgg-gpg-user-id nil
    "GnuPG ID of your default identity.")
  
  (defun pgg-gpg-process-region (start end passphrase program args)
!   (let* ((use-agent (pgg-gpg-use-agent-p)) 
!        (output-file-name (pgg-make-temp-file "pgg-output"))
         (args
          `("--status-fd" "2"
!           ,@(if (and passphrase (not use-agent)) 
!                 '("--passphrase-fd" "0"))
!           ,@(if use-agent '("--use-agent"))
            "--yes" ; overwrite
            "--output" ,output-file-name
            ,@pgg-gpg-extra-args ,@args))
***************
*** 77,83 ****
                (input (buffer-substring-no-properties start end))
                (default-enable-multibyte-characters nil))
            (with-temp-buffer
!             (when passphrase
                (insert passphrase "\n"))
              (insert input)
              (setq exit-status
--- 86,92 ----
                (input (buffer-substring-no-properties start end))
                (default-enable-multibyte-characters nil))
            (with-temp-buffer
!             (when (and passphrase (not (pgg-gpg-use-agent-p)))
                (insert passphrase "\n"))
              (insert input)
              (setq exit-status
***************
*** 181,187 ****
  If optional PASSPHRASE is not specified, it will be obtained from the
  passphrase cache or user."
    (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
!        (passphrase (or passphrase
                           (when sign
                             (pgg-read-passphrase
                              (format "GnuPG passphrase for %s: "
--- 190,197 ----
  If optional PASSPHRASE is not specified, it will be obtained from the
  passphrase cache or user."
    (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
!        (passphrase (or (pgg-gpg-use-agent-p)
!                        passphrase
                           (when sign
                             (pgg-read-passphrase
                              (format "GnuPG passphrase for %s: "
***************
*** 213,219 ****
  
  If optional PASSPHRASE is not specified, it will be obtained from the
  passphrase cache or user."
!   (let* ((passphrase (or passphrase
                           (pgg-read-passphrase
                            "GnuPG passphrase for symmetric encryption: ")))
         (args
--- 223,230 ----
  
  If optional PASSPHRASE is not specified, it will be obtained from the
  passphrase cache or user."
!   (let* ((passphrase (or (pgg-gpg-use-agent-p)
!                        passphrase
                           (pgg-read-passphrase
                            "GnuPG passphrase for symmetric encryption: ")))
         (args
***************
*** 241,247 ****
         (key-id (pgg-gpg-key-id-from-key-owner key-owner))
         (pgg-gpg-user-id (or key-id key
                              pgg-gpg-user-id pgg-default-user-id))
!        (passphrase (or passphrase
                           (pgg-read-passphrase
                            (format (if (pgg-gpg-symmetric-key-p message-keys)
                                        "Passphrase for symmetric decryption: "
--- 252,259 ----
         (key-id (pgg-gpg-key-id-from-key-owner key-owner))
         (pgg-gpg-user-id (or key-id key
                              pgg-gpg-user-id pgg-default-user-id))
!        (passphrase (or (pgg-gpg-use-agent-p)
!                        passphrase
                           (pgg-read-passphrase
                            (format (if (pgg-gpg-symmetric-key-p message-keys)
                                        "Passphrase for symmetric decryption: "
***************
*** 276,282 ****
  (defun pgg-gpg-sign-region (start end &optional cleartext passphrase)
    "Make detached signature from text between START and END."
    (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
!        (passphrase (or passphrase
                           (pgg-read-passphrase
                            (format "GnuPG passphrase for %s: " pgg-gpg-user-id)
                            pgg-gpg-user-id)))
--- 288,295 ----
  (defun pgg-gpg-sign-region (start end &optional cleartext passphrase)
    "Make detached signature from text between START and END."
    (let* ((pgg-gpg-user-id (or pgg-gpg-user-id pgg-default-user-id))
!        (passphrase (or (pgg-gpg-use-agent-p)
!                        passphrase
                           (pgg-read-passphrase
                            (format "GnuPG passphrase for %s: " pgg-gpg-user-id)
                            pgg-gpg-user-id)))
***************
*** 345,350 ****
--- 358,382 ----
      (append-to-buffer pgg-output-buffer (point-min)(point-max))
      (pgg-process-when-success)))
  
+ (defun pgg-gpg-update-agent ()
+   "Try to connet to gpg-agent and send UPDATESTARTUPTTY."
+   (let* ((agent-info (getenv "GPG_AGENT_INFO")) 
+        (socket (and agent-info
+                     (string-match "^\\([^:]*\\)" agent-info)
+                     (match-string 1 agent-info)))
+        (conn (and socket
+                   (make-network-process :name "gpg-agent-process"
+                                         :host 'local :family 'local
+                                         :service socket))))
+     (when (and conn (eq (process-status conn) 'open))
+       (process-send-string conn "UPDATESTARTUPTTY\n")
+       (delete-process conn)
+       t)))
+ 
+ (defun pgg-gpg-use-agent-p ()
+   "Return t if `pgg-gpg-use-agent' is t and gpg-agent is available."
+   (and pgg-gpg-use-agent (pgg-gpg-update-agent)))
+ 
  (provide 'pgg-gpg)
  
  ;;; arch-tag: 2aa5d5d8-93a0-4865-9312-33e29830e000
-- 
Sascha Wilde : VI is to EMACS as masturbation is to making love:
             : effective and always available but probably not your
             : first choice...

Attachment: pgpdyzmpuQZ_P.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]