From 6797cf997cbd7bde9cb8f24731c7c23415d99463 Mon Sep 17 00:00:00 2001 From: Alex Seigler Date: Sun, 15 Sep 2024 06:04:33 -0400 Subject: [PATCH] Add EdDSA support (#14) Adde EdDSA to the API and UI. --- .../ApiMapperTester.cs | 5 ++-- .../WebAuthnApiAdapterTester.cs | 1 + ...ublicKeyCredentialCreationOptionsTester.cs | 7 +++++- .../AlgorithmSelectorView.xaml | 1 + .../AlgorithmSelectorViewModel.cs | 23 +++++++++++++++++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Src/DSInternals.Win32.WebAuthn.Adapter.Tests/ApiMapperTester.cs b/Src/DSInternals.Win32.WebAuthn.Adapter.Tests/ApiMapperTester.cs index 4650eec..c5db02b 100644 --- a/Src/DSInternals.Win32.WebAuthn.Adapter.Tests/ApiMapperTester.cs +++ b/Src/DSInternals.Win32.WebAuthn.Adapter.Tests/ApiMapperTester.cs @@ -34,10 +34,11 @@ public void ApiMapper_Translate_PubKeyCredParams_Input1() var input = new List() { new PubKeyCredParam(Fido2NetLib.Objects.COSE.Algorithm.ES256, PublicKeyCredentialType.PublicKey), - new PubKeyCredParam(Fido2NetLib.Objects.COSE.Algorithm.RS256, PublicKeyCredentialType.PublicKey) + new PubKeyCredParam(Fido2NetLib.Objects.COSE.Algorithm.RS256, PublicKeyCredentialType.PublicKey), + new PubKeyCredParam(Fido2NetLib.Objects.COSE.Algorithm.EdDSA, PublicKeyCredentialType.PublicKey) }; - var expected = new[] { Algorithm.ES256, Algorithm.RS256 }; + var expected = new[] { Algorithm.ES256, Algorithm.RS256, Algorithm.EdDSA }; var result = ApiMapper.Translate(input); CollectionAssert.AreEqual(expected, result); diff --git a/Src/DSInternals.Win32.WebAuthn.Adapter.Tests/WebAuthnApiAdapterTester.cs b/Src/DSInternals.Win32.WebAuthn.Adapter.Tests/WebAuthnApiAdapterTester.cs index 8412ca5..44e545a 100644 --- a/Src/DSInternals.Win32.WebAuthn.Adapter.Tests/WebAuthnApiAdapterTester.cs +++ b/Src/DSInternals.Win32.WebAuthn.Adapter.Tests/WebAuthnApiAdapterTester.cs @@ -74,6 +74,7 @@ public void WebAuthN_MakeCredential_MSAccount() options.PubKeyCredParams = [ + new(Fido2NetLib.Objects.COSE.Algorithm.EdDSA, PublicKeyCredentialType.PublicKey), new(Fido2NetLib.Objects.COSE.Algorithm.ES256, PublicKeyCredentialType.PublicKey), new(Fido2NetLib.Objects.COSE.Algorithm.RS256, PublicKeyCredentialType.PublicKey) ]; diff --git a/Src/DSInternals.Win32.WebAuthn.Tests/PublicKeyCredentialCreationOptionsTester.cs b/Src/DSInternals.Win32.WebAuthn.Tests/PublicKeyCredentialCreationOptionsTester.cs index c7506aa..ba97a24 100644 --- a/Src/DSInternals.Win32.WebAuthn.Tests/PublicKeyCredentialCreationOptionsTester.cs +++ b/Src/DSInternals.Win32.WebAuthn.Tests/PublicKeyCredentialCreationOptionsTester.cs @@ -28,6 +28,10 @@ public void PublicKeyCredentialCreationOptions_Deserialize() { ""type"": ""public-key"", ""alg"": -257 + }, + { + ""type"": ""public-key"", + ""alg"": -8 } ], ""timeout"": 60000, @@ -73,9 +77,10 @@ public void PublicKeyCredentialCreationOptions_Deserialize() Assert.IsTrue(options.AuthenticatorSelection.RequireResidentKey); Assert.AreEqual(AuthenticatorAttachment.CrossPlatform, options.AuthenticatorSelection.AuthenticatorAttachment); Assert.AreEqual(UserVerificationRequirement.Required, options.AuthenticatorSelection.UserVerificationRequirement); - Assert.AreEqual(2, options.PublicKeyCredentialParameters.Count); + Assert.AreEqual(3, options.PublicKeyCredentialParameters.Count); Assert.AreEqual(COSE.Algorithm.ES256, options.PublicKeyCredentialParameters[0].Algorithm); Assert.AreEqual(COSE.Algorithm.RS256, options.PublicKeyCredentialParameters[1].Algorithm); + Assert.AreEqual(COSE.Algorithm.EdDSA, options.PublicKeyCredentialParameters[2].Algorithm); } } } diff --git a/Src/Fido2UI/Views/AlgorithmSelector/AlgorithmSelectorView.xaml b/Src/Fido2UI/Views/AlgorithmSelector/AlgorithmSelectorView.xaml index ef282c5..0138724 100644 --- a/Src/Fido2UI/Views/AlgorithmSelector/AlgorithmSelectorView.xaml +++ b/Src/Fido2UI/Views/AlgorithmSelector/AlgorithmSelectorView.xaml @@ -19,5 +19,6 @@ + diff --git a/Src/Fido2UI/Views/AlgorithmSelector/AlgorithmSelectorViewModel.cs b/Src/Fido2UI/Views/AlgorithmSelector/AlgorithmSelectorViewModel.cs index 5147c22..865c8ea 100644 --- a/Src/Fido2UI/Views/AlgorithmSelector/AlgorithmSelectorViewModel.cs +++ b/Src/Fido2UI/Views/AlgorithmSelector/AlgorithmSelectorViewModel.cs @@ -47,6 +47,9 @@ public List SelectedAlgorithms if (AlgorithmPS512Enabled) result.Add(Algorithm.PS512); + if (AlgorithmEdDSAEnabled) + result.Add(Algorithm.EdDSA); + return result; } set @@ -91,6 +94,9 @@ public List SelectedAlgorithms case Algorithm.PS512: AlgorithmPS512Enabled = true; break; + case Algorithm.EdDSA: + AlgorithmEdDSAEnabled = true; + break; } } } @@ -217,6 +223,21 @@ public bool AlgorithmES256Enabled set { bool changed = SetProperty(ref _algorithmES256Enabled, value); + if (changed) + { + RaisePropertyChanged(nameof(SelectedAlgorithms)); + } + } + } + + private bool _algorithmEdDSAEnabled; + public bool AlgorithmEdDSAEnabled + { + get => _algorithmEdDSAEnabled; + set + { + bool changed = SetProperty(ref _algorithmEdDSAEnabled, value); + if (changed) { RaisePropertyChanged(nameof(SelectedAlgorithms)); @@ -235,6 +256,7 @@ private void ClearSelectedAlgorithms() AlgorithmRS256Enabled = false; AlgorithmRS384Enabled = false; AlgorithmRS512Enabled = false; + AlgorithmEdDSAEnabled = false; } private void SelectDefaultAlgorithms() @@ -242,6 +264,7 @@ private void SelectDefaultAlgorithms() ClearSelectedAlgorithms(); AlgorithmRS256Enabled = true; AlgorithmES256Enabled = true; + AlgorithmEdDSAEnabled = true; } } }