Last active
August 13, 2019 04:56
-
-
Save justinmoon/bfe2b76935f54c344c833c802060c7a7 to your computer and use it in GitHub Desktop.
Issue unlocking a trezor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template_string, request, redirect | |
from hwilib import commands | |
from hwilib.devices import trezor | |
app = Flask(__name__) | |
template = """ | |
<div>Locked? {{ locked }}</div> | |
<form action="/" method="post"> | |
<label for="pin">Pin:</label> | |
<input type="text" id="pin" name="pin"> | |
<button type="submit">Unlock Trezor</button> | |
</form> | |
""" | |
@app.route('/', methods=['GET', 'POST']) | |
def home(): | |
devices = commands.enumerate() | |
if request.method == 'GET': | |
for device in devices: | |
if device['type'] == 'trezor': | |
locked = device['needs_pin_sent'] | |
if locked: | |
client = trezor.TrezorClient(device['path']) | |
client.prompt_pin() | |
break | |
return render_template_string(template, locked=locked) | |
else: | |
for device in devices: | |
if device['type'] == 'trezor': | |
client = trezor.TrezorClient(device['path']) | |
result = client.send_pin(request.form['pin'])['success'] | |
print("Unlocked?", result) | |
return redirect('/') | |
if __name__ == '__main__': | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from hwilib import commands | |
from hwilib.devices import trezor | |
devices = commands.enumerate() | |
for device in devices: | |
if device['type'] == 'trezor': | |
client = trezor.TrezorClient(device['path']) | |
print(device['path']) | |
client.prompt_pin() | |
pin = input('enter pin: ') | |
print(client.send_pin(pin)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Threading problem if anyone ever comes across this. Flask runs handlers in threads by default and HWI isn't thread-safe.