Skip to content

Commit

Permalink
Add EdDSA support (#14)
Browse files Browse the repository at this point in the history
Adde EdDSA to the API and UI.
  • Loading branch information
aseigler authored Sep 15, 2024
1 parent c90018e commit 6797cf9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ public void ApiMapper_Translate_PubKeyCredParams_Input1()
var input = new List<PubKeyCredParam>()
{
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public void PublicKeyCredentialCreationOptions_Deserialize()
{
""type"": ""public-key"",
""alg"": -257
},
{
""type"": ""public-key"",
""alg"": -8
}
],
""timeout"": 60000,
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<CheckBox x:Name="ES512CheckBox" Content="ES512" ToolTip="ECDSA P-521 with SHA-512" IsChecked="{Binding AlgorithmES512Enabled, Mode=TwoWay}" VerticalAlignment="Center" TabIndex="2" />
<CheckBox x:Name="RS512CheckBox" Content="RS512" ToolTip="RSASSA-PKCS1-v1_5 with SHA-512" IsChecked="{Binding AlgorithmRS512Enabled, Mode=TwoWay}" VerticalAlignment="Center" TabIndex="5" />
<CheckBox x:Name="PS512CheckBox" Content="PS512" ToolTip="RSASSA-PSS with SHA-512" IsChecked="{Binding AlgorithmPS512Enabled, Mode=TwoWay}" VerticalAlignment="Center" TabIndex="8" />
<CheckBox x:Name="EdDSACheckBox" Content="EdDSA" ToolTip="EdDSA" IsChecked="{Binding AlgorithmEdDSAEnabled, Mode=TwoWay}" VerticalAlignment="Center" TabIndex="9" />
</UniformGrid>
</UserControl>
23 changes: 23 additions & 0 deletions Src/Fido2UI/Views/AlgorithmSelector/AlgorithmSelectorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public List<Algorithm> SelectedAlgorithms
if (AlgorithmPS512Enabled)
result.Add(Algorithm.PS512);

if (AlgorithmEdDSAEnabled)
result.Add(Algorithm.EdDSA);

return result;
}
set
Expand Down Expand Up @@ -91,6 +94,9 @@ public List<Algorithm> SelectedAlgorithms
case Algorithm.PS512:
AlgorithmPS512Enabled = true;
break;
case Algorithm.EdDSA:
AlgorithmEdDSAEnabled = true;
break;
}
}
}
Expand Down Expand Up @@ -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));
Expand All @@ -235,13 +256,15 @@ private void ClearSelectedAlgorithms()
AlgorithmRS256Enabled = false;
AlgorithmRS384Enabled = false;
AlgorithmRS512Enabled = false;
AlgorithmEdDSAEnabled = false;
}

private void SelectDefaultAlgorithms()
{
ClearSelectedAlgorithms();
AlgorithmRS256Enabled = true;
AlgorithmES256Enabled = true;
AlgorithmEdDSAEnabled = true;
}
}
}

0 comments on commit 6797cf9

Please sign in to comment.