mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Handle "pin already prompted" error. (Fix #1209)
This commit is contained in:
@@ -64,7 +64,7 @@ namespace BTCPayServer.Controllers
|
|||||||
HwiEnumerateEntry deviceEntry = null;
|
HwiEnumerateEntry deviceEntry = null;
|
||||||
HDFingerprint? fingerprint = null;
|
HDFingerprint? fingerprint = null;
|
||||||
string password = null;
|
string password = null;
|
||||||
int? pin = null;
|
bool pinProvided = false;
|
||||||
var websocketHelper = new WebSocketHelper(websocket);
|
var websocketHelper = new WebSocketHelper(websocket);
|
||||||
|
|
||||||
async Task<bool> RequireDeviceUnlocking()
|
async Task<bool> RequireDeviceUnlocking()
|
||||||
@@ -80,7 +80,7 @@ namespace BTCPayServer.Controllers
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((deviceEntry.Code is HwiErrorCode.DeviceNotReady || deviceEntry.NeedsPinSent is true)
|
if ((deviceEntry.Code is HwiErrorCode.DeviceNotReady || deviceEntry.NeedsPinSent is true)
|
||||||
&& pin is null
|
&& !pinProvided
|
||||||
// Trezor T always show the pin on screen
|
// Trezor T always show the pin on screen
|
||||||
&& (deviceEntry.Model != HardwareWalletModels.Trezor_T || deviceEntry.Model != HardwareWalletModels.Trezor_T_Simulator))
|
&& (deviceEntry.Model != HardwareWalletModels.Trezor_T || deviceEntry.Model != HardwareWalletModels.Trezor_T_Simulator))
|
||||||
{
|
{
|
||||||
@@ -157,11 +157,21 @@ namespace BTCPayServer.Controllers
|
|||||||
await websocketHelper.Send("{ \"error\": \"need-device\"}", cancellationToken);
|
await websocketHelper.Send("{ \"error\": \"need-device\"}", cancellationToken);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
await device.PromptPinAsync(cancellationToken);
|
try
|
||||||
await websocketHelper.Send("{ \"info\": \"prompted, please input the pin\"}", cancellationToken);
|
|
||||||
pin = int.Parse(await websocketHelper.NextMessageAsync(cancellationToken), CultureInfo.InvariantCulture);
|
|
||||||
if (await device.SendPinAsync(pin.Value, cancellationToken))
|
|
||||||
{
|
{
|
||||||
|
await device.PromptPinAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
catch (HwiException ex) when (ex.ErrorCode == HwiErrorCode.DeviceAlreadyUnlocked)
|
||||||
|
{
|
||||||
|
pinProvided = true;
|
||||||
|
await websocketHelper.Send("{ \"error\": \"device-already-unlocked\"}", cancellationToken);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
await websocketHelper.Send("{ \"info\": \"prompted, please input the pin\"}", cancellationToken);
|
||||||
|
var pin = int.Parse(await websocketHelper.NextMessageAsync(cancellationToken), CultureInfo.InvariantCulture);
|
||||||
|
if (await device.SendPinAsync(pin, cancellationToken))
|
||||||
|
{
|
||||||
|
pinProvided = true;
|
||||||
await websocketHelper.Send("{ \"info\": \"the pin is correct\"}", cancellationToken);
|
await websocketHelper.Send("{ \"info\": \"the pin is correct\"}", cancellationToken);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -207,7 +217,7 @@ namespace BTCPayServer.Controllers
|
|||||||
break;
|
break;
|
||||||
case "ask-device":
|
case "ask-device":
|
||||||
password = null;
|
password = null;
|
||||||
pin = null;
|
pinProvided = false;
|
||||||
deviceEntry = null;
|
deviceEntry = null;
|
||||||
device = null;
|
device = null;
|
||||||
var entries = (await hwi.EnumerateEntriesAsync(cancellationToken)).ToList();
|
var entries = (await hwi.EnumerateEntriesAsync(cancellationToken)).ToList();
|
||||||
|
|||||||
@@ -728,7 +728,7 @@ namespace BTCPayServer.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return (await wallet.GetBalance(derivationStrategy, cts.Token)).ToString();
|
return (await wallet.GetBalance(derivationStrategy, cts.Token)).ToString(CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -256,6 +256,8 @@ var vaultui = (function () {
|
|||||||
self.bridge.socket.send("ask-pin");
|
self.bridge.socket.send("ask-pin");
|
||||||
var json = await self.bridge.waitBackendMessage();
|
var json = await self.bridge.waitBackendMessage();
|
||||||
if (json.hasOwnProperty("error")) {
|
if (json.hasOwnProperty("error")) {
|
||||||
|
if (json.error == "device-already-unlocked")
|
||||||
|
return true;
|
||||||
if (await needRetry(json))
|
if (await needRetry(json))
|
||||||
return await self.askForPin();
|
return await self.askForPin();
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user