Skip to content

Commit 1d9c6c5

Browse files
Add compatibility for USB and BLE mode
1 parent 16a8a74 commit 1d9c6c5

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Scan the the generated QR code and then confirm the details on screen.
9393

9494
![Jade Confirm Pin Server](docs/images/jade_confirm_pin_server.png)
9595

96-
Note that it really does not matter where the URL is pointed to. The only important parameter here is the public key of the pin server.
96+
Note that if the Jade is only ever meant to be used in QR mode, it does not matter where the URL is pointed to, making the public key of the pin server the only important parameter.
9797

9898
<details>
9999
<summary>Alternative setup via USB</summary>
@@ -109,8 +109,8 @@ python3 set_jade_pinserver.py --serialport <ENTERJADESERIALPORT> --set-pubkey pa
109109

110110
The Jade is now configured with the static server public key of the `SimpleJadePinServer`.
111111

112-
Using SimpleJadePinServer
113-
-------------------------
112+
Using SimpleJadePinServer in QR mode
113+
------------------------------------
114114

115115
Once the Jade is configured to work with `SimpleJadePinServer`, initialize the wallet. When asked to select a connection, choose QR.
116116

@@ -137,3 +137,14 @@ Once scanning is complete, you are done and the wallet is ready to be used.
137137
### Unlocking the wallet
138138

139139
If you want to unlock the wallet at some later point, select "QR Mode" -> "QR PIN Unlock" on the Jade. Enter your PIN and perform the same steps as described before.
140+
141+
Using SimpleJadePinServer in USB or BLE mode
142+
--------------------------------------------
143+
144+
Once the Jade has its blind oracle configured to point to `SimpleJadePinServer`, simply use the Jade with Blockstream Green as normal. Blockstream Green might complain the first time, that a non-default blind oracle is being used.
145+
146+
![Blockstream Green non-default blind PIN oracle warning](docs/images/green_non_default_oracle_warning.png)
147+
148+
This can be dismissed by first clicking on "Advanced", then enabling "Don't ask me again for this oracle" and finally clicking on "Allow Non-Default Connection".
149+
150+
![Blockstream Green non-default blind PIN oracle warning - advanced view](docs/images/green_non_default_oracle_warning_advanced.png)

SimpleJadePinServer.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import signal
1111
import ssl
1212
import sys
13+
import json
1314

1415
tls_cert_path = "key_data/server.pem"
1516
server_keys_path = "key_data/server_keys"
@@ -27,12 +28,18 @@ def graceful_shutdown(self, signum, frame):
2728
sys.exit(0)
2829

2930
class MyServer(BaseHTTPRequestHandler):
30-
def do_GET(self):
31+
def do_POST(self):
32+
content_len = int(self.headers.get('Content-length', '0'))
33+
post_body = self.rfile.read(content_len)
34+
try:
35+
params = json.loads(post_body)
36+
except json.JSONDecodeError:
37+
params = {}
38+
3139
request = urllib.parse.urlparse(self.path)
3240

3341
if request.path == "/set_pin":
3442
print("set_pin")
35-
params = urllib.parse.parse_qs(request.query)
3643

3744
if not 'data' in params:
3845
self.send_response(400)
@@ -41,7 +48,7 @@ def do_GET(self):
4148
self.wfile.write(bytes("<html><head><title>Bad request</title></head><body>Bad request</body></html>", "utf-8"))
4249
return
4350

44-
data = base64.b64decode(params['data'][0].replace(' ', '+'))
51+
data = base64.b64decode(params['data'])
4552
assert len(data) > 37
4653
cke = data[:33]
4754
replay_counter = data[33:37]
@@ -89,7 +96,6 @@ def do_GET(self):
8996
self.wfile.write(b'{"data":"' + base64.b64encode(encrypted_key) + b'"}')
9097
elif request.path == "/get_pin":
9198
print("get_pin")
92-
params = urllib.parse.parse_qs(request.query)
9399

94100
if not 'data' in params:
95101
self.send_response(400)
@@ -98,7 +104,7 @@ def do_GET(self):
98104
self.wfile.write(bytes("<html><head><title>Bad request</title></head><body>Bad request</body></html>", "utf-8"))
99105
return
100106

101-
data = base64.b64decode(params['data'][0].replace(' ', '+'))
107+
data = base64.b64decode(params['data'])
102108
assert len(data) > 37
103109
cke = data[:33]
104110
replay_counter = data[33:37]
@@ -154,7 +160,16 @@ def do_GET(self):
154160
self.send_header("Content-type", "application/json")
155161
self.end_headers()
156162
self.wfile.write(b'{"data":"' + base64.b64encode(encrypted_key) + b'"}')
157-
elif request.path == "/qrcode.js":
163+
else:
164+
self.send_response(404)
165+
self.send_header("Content-type", "text/html")
166+
self.end_headers()
167+
self.wfile.write(bytes("<html><head><title>Not found</title></head><body>Not found</body></html>", "utf-8"))
168+
169+
def do_GET(self):
170+
request = urllib.parse.urlparse(self.path)
171+
172+
if request.path == "/qrcode.js":
158173
self.send_response(200)
159174
self.send_header("Content-type", "text/javascript")
160175
self.end_headers()
16 KB
Loading
15.5 KB
Loading

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@
607607
bcur2_index++;
608608
}, 1000);
609609
};
610-
xhttp.open("GET", "set_pin?data=" + request_data);
611-
xhttp.send();
610+
xhttp.open("POST", "set_pin");
611+
xhttp.send('{"data": "' + request_data + '"}');
612612
}
613613

614614
function get_pin() {
@@ -641,8 +641,8 @@
641641
bcur2_index++;
642642
}, 1000);
643643
};
644-
xhttp.open("GET", "get_pin?data=" + request_data);
645-
xhttp.send();
644+
xhttp.open("POST", "get_pin");
645+
xhttp.send('{"data": "' + request_data + '"}');
646646
}
647647
</script>
648648
</head>

0 commit comments

Comments
 (0)