Rewrite the CanUseHotWallet, check if the derivationscheme is actually a hotwallet, before retrieving the seed

This commit is contained in:
nicolas.dorier
2021-03-11 21:46:32 +09:00
parent cdfdad3e3d
commit c2b85779c3
2 changed files with 17 additions and 15 deletions

View File

@@ -1,9 +1,11 @@
using System.Security.Claims;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Constants;
using BTCPayServer.Client;
using BTCPayServer.Security.Bitpay;
using BTCPayServer.Security.GreenField;
using BTCPayServer.Services;
using CsvHelper.Configuration.Attributes;
using Microsoft.AspNetCore.Authorization;
namespace BTCPayServer
@@ -15,8 +17,19 @@ namespace BTCPayServer
PoliciesSettings policiesSettings,
ClaimsPrincipal user)
{
return (await authorizationService.AuthorizeAsync(user, Policies.CanModifyServerSettings))
.Succeeded ? (true, true) : (policiesSettings?.AllowHotWalletForAll is true, policiesSettings?.AllowHotWalletRPCImportForAll is true);
if (!user.Identity.IsAuthenticated)
return (false, false);
var claimUser = user.Identity as ClaimsIdentity;
if (claimUser is null)
return (false, false);
bool isAdmin = false;
if (claimUser.AuthenticationType == AuthenticationSchemes.Cookie)
isAdmin = user.IsInRole(Roles.ServerAdmin);
else if (claimUser.AuthenticationType == GreenFieldConstants.AuthenticationType)
isAdmin = (await authorizationService.AuthorizeAsync(user, Policies.CanModifyServerSettings)).Succeeded;
return isAdmin ? (true, true) :
(policiesSettings?.AllowHotWalletForAll is true, policiesSettings?.AllowHotWalletRPCImportForAll is true);
}
}
}