btcpayserver/BTCPayServer/Fido2/FidoExtensions.cs
Andrew Camilleri 02bf5afe0b
Migrate existing U2F to Fido2 (#2484)
* Migrate existing U2F to Fido2

This seamlessly switches all u2f registrations over to the new FIDO2 support. Please note that I have not yet added a way to drop the u2f DB and its UI so that we can test the migration works properly for all.

* add testing logic

* fix u2f tests

* remove duplicate status message

* fix test and namespaces

* fix test
2021-04-28 13:14:15 +09:00

32 lines
1012 B
C#

using BTCPayServer.Data;
using BTCPayServer.Fido2.Models;
using NBXplorer;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Fido2
{
public static class Fido2Extensions
{
public static Fido2CredentialBlob GetBlob(this Fido2Credential credential)
{
var result = credential.Blob == null
? new Fido2CredentialBlob()
: JObject.Parse(ZipUtils.Unzip(credential.Blob)).ToObject<Fido2CredentialBlob>();
return result;
}
public static bool SetBlob(this Fido2Credential credential, Fido2CredentialBlob descriptor)
{
var original = new Serializer(null).ToString(credential.GetBlob());
var newBlob = new Serializer(null).ToString(descriptor);
if (original == newBlob)
return false;
credential.Type = Fido2Credential.CredentialType.FIDO2;
credential.Blob = ZipUtils.Zip(newBlob);
return true;
}
}
}