mirror of
https://github.com/romanz/amodem.git
synced 2026-04-20 21:26:39 +08:00
gpg: use a separate process for PIN entrering UI
This commit is contained in:
@@ -3,9 +3,9 @@
|
|||||||
import binascii
|
import binascii
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import pymsgbox # pylint: disable=import-error
|
|
||||||
import semver
|
import semver
|
||||||
|
|
||||||
from . import interface
|
from . import interface
|
||||||
@@ -13,6 +13,27 @@ from . import interface
|
|||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def pin_entry_gui(sp=subprocess):
|
||||||
|
"""Launch an external process for PIN entry GUI."""
|
||||||
|
label = ('Use the numeric keypad to describe number positions.\n'
|
||||||
|
'The layout is:\n'
|
||||||
|
' 7 8 9\n'
|
||||||
|
' 4 5 6\n'
|
||||||
|
' 1 2 3\n'
|
||||||
|
'Please enter PIN:').encode('ascii')
|
||||||
|
cmd = ('import sys, pymsgbox; '
|
||||||
|
'sys.stdout.write(pymsgbox.password(sys.stdin.read()))')
|
||||||
|
args = ['python', '-c', cmd]
|
||||||
|
p = sp.Popen(args=args, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)
|
||||||
|
out, err = p.communicate(label)
|
||||||
|
exitcode = p.wait()
|
||||||
|
if exitcode == 0:
|
||||||
|
return out.decode('ascii')
|
||||||
|
else:
|
||||||
|
log.error('PIN entry failed: %r', err)
|
||||||
|
raise sp.CalledProcessError(exitcode, args)
|
||||||
|
|
||||||
|
|
||||||
class Trezor(interface.Device):
|
class Trezor(interface.Device):
|
||||||
"""Connection to TREZOR device."""
|
"""Connection to TREZOR device."""
|
||||||
|
|
||||||
@@ -40,13 +61,7 @@ class Trezor(interface.Device):
|
|||||||
return conn.callback_PinMatrixRequest # CLI-based PIN handler
|
return conn.callback_PinMatrixRequest # CLI-based PIN handler
|
||||||
|
|
||||||
def ui_handler(_):
|
def ui_handler(_):
|
||||||
label = ('Use the numeric keypad to describe number positions.\n'
|
scrambled_pin = pin_entry_gui()
|
||||||
'The layout is:\n'
|
|
||||||
' 7 8 9\n'
|
|
||||||
' 4 5 6\n'
|
|
||||||
' 1 2 3\n'
|
|
||||||
'Please enter PIN:')
|
|
||||||
scrambled_pin = pymsgbox.password(label)
|
|
||||||
return self._defs.PinMatrixAck(pin=scrambled_pin)
|
return self._defs.PinMatrixAck(pin=scrambled_pin)
|
||||||
|
|
||||||
return ui_handler
|
return ui_handler
|
||||||
|
|||||||
Reference in New Issue
Block a user