From 9b6438aa72872fc9479fdc052b81e6bed58a5c07 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 13 Feb 2017 12:12:24 -0800 Subject: [PATCH] pinentry.py: Show errors in GETPIN handling GnuPG 2.1.15 has exchanges like: ... C: SETDESC Please enter the passphrase to unlock the OpenPGP secret key... S: OK C: SETPROMPT Passphrase: S: OK C: GETPIN S: D foo S: OK C: SETERROR Bad Passphrase (try 2 of 3) S: OK C: GETPIN ... with this commit we show those errors to the user. --- bin/pinentry.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/pinentry.py b/bin/pinentry.py index 50cf332..8ed3b4d 100755 --- a/bin/pinentry.py +++ b/bin/pinentry.py @@ -218,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() @@ -317,7 +320,10 @@ class PinEntry (_server.AssuanServer): 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')) -- 2.26.2