(str);
+ }
+ }
+ public DescriptorClass Descriptor { get; set; }
[JsonConverter(typeof(Base64UrlConverter))]
public byte[] PublicKey { get; set; }
[JsonConverter(typeof(Base64UrlConverter))]
diff --git a/BTCPayServer/Fido2/Models/LoginWithFido2ViewModel.cs b/BTCPayServer/Fido2/Models/LoginWithFido2ViewModel.cs
index 23eb1a61a..9142f0261 100644
--- a/BTCPayServer/Fido2/Models/LoginWithFido2ViewModel.cs
+++ b/BTCPayServer/Fido2/Models/LoginWithFido2ViewModel.cs
@@ -1,4 +1,5 @@
using Fido2NetLib;
+using Newtonsoft.Json.Linq;
namespace BTCPayServer.Fido2.Models
{
@@ -7,7 +8,7 @@ namespace BTCPayServer.Fido2.Models
public string UserId { get; set; }
public bool RememberMe { get; set; }
- public AssertionOptions Data { get; set; }
+ public string Data { get; set; }
public string Response { get; set; }
}
}
diff --git a/BTCPayServer/Hosting/MigrationStartupTask.cs b/BTCPayServer/Hosting/MigrationStartupTask.cs
index a45b10b0d..7092b76b8 100644
--- a/BTCPayServer/Hosting/MigrationStartupTask.cs
+++ b/BTCPayServer/Hosting/MigrationStartupTask.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
using BTCPayServer.Abstractions.Contracts;
@@ -22,14 +23,15 @@ using BTCPayServer.Services.Invoices;
using BTCPayServer.Services.Stores;
using BTCPayServer.Storage.Models;
using BTCPayServer.Storage.Services.Providers.FileSystemStorage.Configuration;
+using Fido2NetLib.Cbor;
using Fido2NetLib.Objects;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
-using PeterO.Cbor;
using YamlDotNet.RepresentationModel;
+using static BTCPayServer.Fido2.Models.Fido2CredentialBlob;
using LightningAddressData = BTCPayServer.Data.LightningAddressData;
namespace BTCPayServer.Hosting
@@ -738,9 +740,9 @@ WHERE cte.""Id""=p.""Id""
fido2.SetBlob(new Fido2CredentialBlob()
{
SignatureCounter = (uint)u2FDevice.Counter,
- PublicKey = CreatePublicKeyFromU2fRegistrationData(u2FDevice.PublicKey).EncodeToBytes(),
+ PublicKey = CreatePublicKeyFromU2fRegistrationData(u2FDevice.PublicKey).Encode(),
UserHandle = u2FDevice.KeyHandle,
- Descriptor = new PublicKeyCredentialDescriptor(u2FDevice.KeyHandle),
+ Descriptor = new DescriptorClass(u2FDevice.KeyHandle),
CredType = "u2f"
});
@@ -751,27 +753,29 @@ WHERE cte.""Id""=p.""Id""
await ctx.SaveChangesAsync();
}
//from https://github.com/abergs/fido2-net-lib/blob/0fa7bb4b4a1f33f46c5f7ca4ee489b47680d579b/Test/ExistingU2fRegistrationDataTests.cs#L70
- private static CBORObject CreatePublicKeyFromU2fRegistrationData(byte[] publicKeyData)
+ private static CborMap CreatePublicKeyFromU2fRegistrationData(byte[] publicKeyData)
{
- if (publicKeyData.Length != 65)
- {
- throw new ArgumentException("u2f public key must be 65 bytes", nameof(publicKeyData));
- }
var x = new byte[32];
var y = new byte[32];
Buffer.BlockCopy(publicKeyData, 1, x, 0, 32);
Buffer.BlockCopy(publicKeyData, 33, y, 0, 32);
+ var point = new ECPoint
+ {
+ X = x,
+ Y = y,
+ };
- var coseKey = CBORObject.NewMap();
+ var coseKey = new CborMap
+ {
+ { (long)COSE.KeyCommonParameter.KeyType, (long)COSE.KeyType.EC2 },
+ { (long)COSE.KeyCommonParameter.Alg, -7L },
- coseKey.Add(COSE.KeyCommonParameter.KeyType, COSE.KeyType.EC2);
- coseKey.Add(COSE.KeyCommonParameter.Alg, -7);
+ { (long)COSE.KeyTypeParameter.Crv, (long)COSE.EllipticCurve.P256 },
- coseKey.Add(COSE.KeyTypeParameter.Crv, COSE.EllipticCurve.P256);
-
- coseKey.Add(COSE.KeyTypeParameter.X, x);
- coseKey.Add(COSE.KeyTypeParameter.Y, y);
+ { (long)COSE.KeyTypeParameter.X, point.X },
+ { (long)COSE.KeyTypeParameter.Y, point.Y }
+ };
return coseKey;
}
diff --git a/BTCPayServer/Hosting/Startup.cs b/BTCPayServer/Hosting/Startup.cs
index f98368947..51b59a00d 100644
--- a/BTCPayServer/Hosting/Startup.cs
+++ b/BTCPayServer/Hosting/Startup.cs
@@ -122,8 +122,7 @@ namespace BTCPayServer.Hosting
})
.AddCachedMetadataService(config =>
{
- //They'll be used in a "first match wins" way in the order registered
- config.AddStaticMetadataRepository();
+ config.AddFidoMetadataRepository();
});
var descriptor = services.Single(descriptor => descriptor.ServiceType == typeof(Fido2Configuration));
services.Remove(descriptor);
@@ -133,7 +132,7 @@ namespace BTCPayServer.Hosting
return new Fido2Configuration()
{
ServerName = "BTCPay Server",
- Origin = $"{httpContext.HttpContext.Request.Scheme}://{httpContext.HttpContext.Request.Host}",
+ Origins = new[] { $"{httpContext.HttpContext.Request.Scheme}://{httpContext.HttpContext.Request.Host}" }.ToHashSet(),
ServerDomain = httpContext.HttpContext.Request.Host.Host
};
});
diff --git a/BTCPayServer/Views/UIAccount/LoginWithFido2.cshtml b/BTCPayServer/Views/UIAccount/LoginWithFido2.cshtml
index aaae6e61b..837dacd3b 100644
--- a/BTCPayServer/Views/UIAccount/LoginWithFido2.cshtml
+++ b/BTCPayServer/Views/UIAccount/LoginWithFido2.cshtml
@@ -1,3 +1,4 @@
+@using Newtonsoft.Json.Linq
@model BTCPayServer.Fido2.Models.LoginWithFido2ViewModel
@@ -24,7 +25,7 @@
diff --git a/BTCPayServer/Views/UIFido2/Create.cshtml b/BTCPayServer/Views/UIFido2/Create.cshtml
index c3670e4df..26d01d8e9 100644
--- a/BTCPayServer/Views/UIFido2/Create.cshtml
+++ b/BTCPayServer/Views/UIFido2/Create.cshtml
@@ -1,3 +1,4 @@
+@using Newtonsoft.Json.Linq
@model Fido2NetLib.CredentialCreateOptions
@{
ViewData.SetActivePage(ManageNavPages.TwoFactorAuthentication, StringLocalizer["Register your security device"]);
@@ -42,7 +43,7 @@
diff --git a/BTCPayServer/wwwroot/js/webauthn/login.js b/BTCPayServer/wwwroot/js/webauthn/login.js
index 3ee87ab46..eb7325992 100644
--- a/BTCPayServer/wwwroot/js/webauthn/login.js
+++ b/BTCPayServer/wwwroot/js/webauthn/login.js
@@ -40,7 +40,7 @@ async function verifyAssertionWithServer(assertedCredential) {
extensions: assertedCredential.getClientExtensionResults(),
response: {
authenticatorData: coerceToBase64Url(authData),
- clientDataJson: coerceToBase64Url(clientDataJSON),
+ clientDataJSON: coerceToBase64Url(clientDataJSON),
signature: coerceToBase64Url(sig)
}
};
diff --git a/BTCPayServer/wwwroot/js/webauthn/register.js b/BTCPayServer/wwwroot/js/webauthn/register.js
index b6636625a..e73ad68a5 100644
--- a/BTCPayServer/wwwroot/js/webauthn/register.js
+++ b/BTCPayServer/wwwroot/js/webauthn/register.js
@@ -49,8 +49,8 @@ async function registerNewCredential(newCredential) {
type: newCredential.type,
extensions: newCredential.getClientExtensionResults(),
response: {
- AttestationObject: coerceToBase64Url(attestationObject),
- clientDataJson: coerceToBase64Url(clientDataJSON)
+ attestationObject: coerceToBase64Url(attestationObject),
+ clientDataJSON: coerceToBase64Url(clientDataJSON)
}
};