*: Run update-copyright.py
[pyassuan.git] / bin / pinentry.py
index 36495766e91743ad4f18271ec1d4b8407923b4cc..9a7380a7b4e614e7fd29647f77868ad0831108a9 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 #
-# Copyright (C) 2012 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2012-2017 W. Trevor King <wking@tremily.us>
 #
 # This file is part of pyassuan.
 #
@@ -45,7 +45,7 @@ class PinEntry (_server.AssuanServer):
     for details on the pinentry interface.
 
     Alternatively, you can just watch the logs and guess ;).  Here's a
-    trace when driven by GnuPG 2.0.17 (libgcrypt 1.4.6)::
+    trace when driven by GnuPG 2.0.28 (libgcrypt 1.6.3)::
 
       S: OK Your orders please
       C: OPTION grab
@@ -58,17 +58,31 @@ class PinEntry (_server.AssuanServer):
       S: OK
       C: OPTION lc-messages=en_US.UTF-8
       S: OK
+      C: OPTION allow-external-password-cache
+      S: OK
       C: OPTION default-ok=_OK
       S: OK
       C: OPTION default-cancel=_Cancel
       S: OK
+      C: OPTION default-yes=_Yes
+      S: OK
+      C: OPTION default-no=_No
+      S: OK
       C: OPTION default-prompt=PIN:
       S: OK
-      C: OPTION touch-file=/tmp/gpg-7lElMX/S.gpg-agent
+      C: OPTION default-pwmngr=_Save in password manager
+      S: OK
+      C: OPTION default-cf-visi=Do you really want to make your passphrase visible on the screen?
+      S: OK
+      C: OPTION default-tt-visi=Make passphrase visible
+      S: OK
+      C: OPTION default-tt-hide=Hide passphrase
       S: OK
       C: GETINFO pid
       S: D 14309
       S: OK
+      C: SETKEYINFO u/S9464F2C2825D2FE3
+      S: OK
       C: SETDESC Enter passphrase%0A
       S: OK
       C: SETPROMPT Passphrase
@@ -204,9 +218,12 @@ class PinEntry (_server.AssuanServer):
         # drop trailing newline
         return self.connection['from_user'].readline()[:-1]
 
-    def _prompt(self, prompt='?', add_colon=True):
+    def _prompt(self, prompt='?', error=None, add_colon=True):
         if add_colon:
             prompt += ':'
+        if error:
+            self.connection['to_user'].write(error)
+            self.connection['to_user'].write('\n')
         self.connection['to_user'].write(prompt)
         self.connection['to_user'].write(' ')
         self.connection['to_user'].flush()
@@ -223,6 +240,13 @@ class PinEntry (_server.AssuanServer):
             raise _error.AssuanError(message='Invalid parameter')
         yield _common.Response('OK')
 
+    def _handle_SETKEYINFO(self, arg):
+        self.strings['key info'] = arg
+        yield _common.Response('OK')
+
+    def _handle_CLEARPASSPHRASE(self, arg):
+        yield _common.Response('OK')
+
     def _handle_SETDESC(self, arg):
         self.strings['description'] = arg
         yield _common.Response('OK')
@@ -292,9 +316,14 @@ class PinEntry (_server.AssuanServer):
         try:
             self._connect()
             self._write(self.strings['description'])
+            if 'key info' in self.strings:
+                self._write('key: {}'.format(self.strings['key info']))
             if 'qualitybar' in self.strings:
                 self._write(self.strings['qualitybar'])
-            pin = self._prompt(self.strings['prompt'], add_colon=False)
+            pin = self._prompt(
+                prompt=self.strings['prompt'],
+                error=self.strings.get('error'),
+                add_colon=False)
         finally:
             self._disconnect()
         yield _common.Response('D', pin.encode('ascii'))