|
71 | 71 | except ImportError: |
72 | 72 | PCSC = False |
73 | 73 |
|
| 74 | +def get_possible_error_cause(sw): |
| 75 | + cause_map = { |
| 76 | + 0x6982: "Have you uninstalled the existing CA with resetCustomCA first?", |
| 77 | + 0x6985: "Condition of use not satisfied (denied by the user?)", |
| 78 | + 0x6a84: "Not enough space?", |
| 79 | + 0x6a85: "Not enough space?", |
| 80 | + 0x6a83: "Maybe this app requires a library to be installed first?", |
| 81 | + 0x6484: "Are you using the correct targetId?", |
| 82 | + 0x6d00: "Unexpected state of device: verify that the right application is opened?", |
| 83 | + 0x6e00: "Unexpected state of device: verify that the right application is opened?", |
| 84 | + 0x5515: "Did you unlock the device?", |
| 85 | + 0x6814: "Unexpected target device: verify that you are using the right device?", |
| 86 | + 0x511F: "The OS version on your device does not seem compatible with the SDK version used to build the app", |
| 87 | + 0x5120: "Sideload is not supported on Nano X", |
| 88 | + } |
| 89 | + |
| 90 | + # If the status word is in the map, return the corresponding cause, otherwise return a default message |
| 91 | + return cause_map.get(sw, "Unknown reason") |
| 92 | + |
| 93 | + |
74 | 94 | class HIDDongleHIDAPI(Dongle, DongleWait): |
75 | 95 |
|
76 | 96 | def __init__(self, device, ledger=False, debug=False): |
@@ -139,21 +159,7 @@ def exchange(self, apdu, timeout=TIMEOUT): |
139 | 159 | if self.debug: |
140 | 160 | print("HID <= %s%.2x" % (response.hex(), sw)) |
141 | 161 | if sw != 0x9000 and (sw & 0xFF00) != 0x6100 and (sw & 0xFF00) != 0x6C00: |
142 | | - possibleCause = "Unknown reason" |
143 | | - if sw == 0x6982: |
144 | | - possibleCause = "Have you uninstalled the existing CA with resetCustomCA first?" |
145 | | - if sw == 0x6985: |
146 | | - possibleCause = "Condition of use not satisfied (denied by the user?)" |
147 | | - if sw == 0x6a84 or sw == 0x6a85: |
148 | | - possibleCause = "Not enough space?" |
149 | | - if sw == 0x6a83: |
150 | | - possibleCause = "Maybe this app requires a library to be installed first?" |
151 | | - if sw == 0x6484: |
152 | | - possibleCause = "Are you using the correct targetId?" |
153 | | - if sw == 0x6d00: |
154 | | - possibleCause = "Unexpected state of device: verify that the right application is opened?" |
155 | | - if sw == 0x6e00: |
156 | | - possibleCause = "Unexpected state of device: verify that the right application is opened?" |
| 162 | + possibleCause = get_possible_error_cause(sw) |
157 | 163 | raise CommException("Invalid status %04x (%s)" % (sw, possibleCause), sw, response) |
158 | 164 | return response |
159 | 165 |
|
@@ -194,21 +200,8 @@ def exchange(self, apdu, timeout=TIMEOUT): |
194 | 200 | response = self.tag.transceive(apdu, 5.0) |
195 | 201 | sw = (response[-2] << 8) + response[-1] |
196 | 202 | if sw != 0x9000 and (sw & 0xFF00) != 0x6100 and (sw & 0xFF00) != 0x6C00: |
197 | | - possibleCause = "Unknown reason" |
198 | | - if sw == 0x6982: |
199 | | - possibleCause = "Have you uninstalled the existing CA with resetCustomCA first?" |
200 | | - if sw == 0x6985: |
201 | | - possibleCause = "Condition of use not satisfied (denied by the user?)" |
202 | | - if sw == 0x6a84 or sw == 0x6a85: |
203 | | - possibleCause = "Not enough space?" |
204 | | - if sw == 0x6a83: |
205 | | - possibleCause = "Maybe this app requires a library to be installed first?" |
206 | | - if sw == 0x6484: |
207 | | - possibleCause = "Are you using the correct targetId?" |
208 | | - if sw == 0x6d00: |
209 | | - possibleCause = "Unexpected state of device: verify that the right application is opened?" |
210 | | - if sw == 0x6e00: |
211 | | - possibleCause = "Unexpected state of device: verify that the right application is opened?" |
| 203 | + possibleCause = get_possible_error_cause(sw) |
| 204 | + self.close() |
212 | 205 | raise CommException("Invalid status %04x (%s)" % (sw, possibleCause), sw, response) |
213 | 206 | if self.debug: |
214 | 207 | print(f"[NFC] <= {response.hex()}") |
@@ -241,21 +234,7 @@ def exchange(self, apdu, timeout=TIMEOUT): |
241 | 234 | if self.debug: |
242 | 235 | print("[BLE] <= %s%.2x" % (response.hex(), sw)) |
243 | 236 | if sw != 0x9000 and (sw & 0xFF00) != 0x6100 and (sw & 0xFF00) != 0x6C00: |
244 | | - possibleCause = "Unknown reason" |
245 | | - if sw == 0x6982: |
246 | | - possibleCause = "Have you uninstalled the existing CA with resetCustomCA first?" |
247 | | - if sw == 0x6985: |
248 | | - possibleCause = "Condition of use not satisfied (denied by the user?)" |
249 | | - if sw == 0x6a84 or sw == 0x6a85: |
250 | | - possibleCause = "Not enough space?" |
251 | | - if sw == 0x6a83: |
252 | | - possibleCause = "Maybe this app requires a library to be installed first?" |
253 | | - if sw == 0x6484: |
254 | | - possibleCause = "Are you using the correct targetId?" |
255 | | - if sw == 0x6d00: |
256 | | - possibleCause = "Unexpected state of device: verify that the right application is opened?" |
257 | | - if sw == 0x6e00: |
258 | | - possibleCause = "Unexpected state of device: verify that the right application is opened?" |
| 237 | + possibleCause = get_possible_error_cause(sw) |
259 | 238 | self.close() |
260 | 239 | raise CommException("Invalid status %04x (%s)" % (sw, possibleCause), sw, response) |
261 | 240 | return response |
|
0 commit comments