Skip to content

Commit f8471ac

Browse files
authored
Allow customised pubKeyCredParams (#579)
* Allow customised pubKeyCredParams * format
1 parent c393286 commit f8471ac

7 files changed

+45
-26
lines changed

Demo/TestController.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ public OkObjectResult MakeCredentialOptionsTest([FromBody] TEST_MakeCredentialPa
7474
ExcludeCredentials = existingKeys,
7575
AuthenticatorSelection = opts.AuthenticatorSelection,
7676
AttestationPreference = opts.Attestation,
77-
Extensions = exts
78-
});
79-
80-
// 4. Temporarily store options, session/in-memory cache/redis/db
77+
Extensions = exts,
78+
// Conformance tools requires RS1, but it's deprecated
79+
PubKeyCredParams = [.. PubKeyCredParam.Defaults, PubKeyCredParam.RS1]
80+
});
81+
82+
// 4. Temporarily store options, session/in-memory cache/redis/db
8183
HttpContext.Session.SetString("fido2.attestationOptions", options.ToJson());
8284

8385
// 5. return options to client

Src/Fido2.Models/CredentialCreateOptions.cs

+24-18
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public sealed class CredentialCreateOptions
3535
/// This member contains information about the desired properties of the credential to be created. The sequence is ordered from most preferred to least preferred. The platform makes a best-effort to create the most preferred credential that it can.
3636
/// </summary>
3737
[JsonPropertyName("pubKeyCredParams")]
38-
public List<PubKeyCredParam> PubKeyCredParams { get; set; }
38+
public IReadOnlyList<PubKeyCredParam> PubKeyCredParams { get; set; }
3939

4040
/// <summary>
4141
/// This member specifies a time, in milliseconds, that the caller is willing to wait for the call to complete. This is treated as a hint, and MAY be overridden by the platform.
@@ -122,29 +122,17 @@ public static CredentialCreateOptions Create(
122122
AuthenticatorSelection authenticatorSelection,
123123
AttestationConveyancePreference attestationConveyancePreference,
124124
IReadOnlyList<PublicKeyCredentialDescriptor> excludeCredentials,
125-
AuthenticationExtensionsClientInputs extensions)
125+
AuthenticationExtensionsClientInputs extensions,
126+
IReadOnlyList<PubKeyCredParam> pubKeyCredParams)
127+
126128
{
127129
return new CredentialCreateOptions
128130
{
129131
Challenge = challenge,
130132
Rp = new PublicKeyCredentialRpEntity(config.ServerDomain, config.ServerName, config.ServerIcon),
131133
Timeout = config.Timeout,
132134
User = user,
133-
PubKeyCredParams =
134-
[
135-
// Add additional as appropriate
136-
PubKeyCredParam.Ed25519,
137-
PubKeyCredParam.ES256,
138-
PubKeyCredParam.RS256,
139-
PubKeyCredParam.PS256,
140-
PubKeyCredParam.ES384,
141-
PubKeyCredParam.RS384,
142-
PubKeyCredParam.PS384,
143-
PubKeyCredParam.ES512,
144-
PubKeyCredParam.RS512,
145-
PubKeyCredParam.PS512,
146-
PubKeyCredParam.RS1
147-
],
135+
PubKeyCredParams = pubKeyCredParams,
148136
AuthenticatorSelection = authenticatorSelection,
149137
Attestation = attestationConveyancePreference,
150138
ExcludeCredentials = excludeCredentials,
@@ -195,7 +183,25 @@ public sealed class PubKeyCredParam(
195183
public static readonly PubKeyCredParam PS384 = new(COSE.Algorithm.PS384);
196184
public static readonly PubKeyCredParam PS512 = new(COSE.Algorithm.PS512);
197185
public static readonly PubKeyCredParam Ed25519 = new(COSE.Algorithm.EdDSA);
198-
public static readonly PubKeyCredParam RS1 = new(COSE.Algorithm.RS1);
186+
public static readonly PubKeyCredParam RS1 = new(COSE.Algorithm.RS1);
187+
188+
/// <summary>
189+
/// The default algorithms supported by the library
190+
/// </summary>
191+
public static IReadOnlyList<PubKeyCredParam> Defaults =>
192+
[
193+
// Add additional as appropriate
194+
Ed25519,
195+
ES256,
196+
RS256,
197+
PS256,
198+
ES384,
199+
RS384,
200+
PS384,
201+
ES512,
202+
RS512,
203+
PS512
204+
];
199205
}
200206

201207
/// <summary>

Src/Fido2/Fido2.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Fido2(
3131
public CredentialCreateOptions RequestNewCredential(RequestNewCredentialParams requestNewCredentialParams)
3232
{
3333
var challenge = RandomNumberGenerator.GetBytes(_config.ChallengeSize);
34-
return CredentialCreateOptions.Create(_config, challenge, requestNewCredentialParams.User, requestNewCredentialParams.AuthenticatorSelection, requestNewCredentialParams.AttestationPreference, requestNewCredentialParams.ExcludeCredentials, requestNewCredentialParams.Extensions);
34+
return CredentialCreateOptions.Create(_config, challenge, requestNewCredentialParams.User, requestNewCredentialParams.AuthenticatorSelection, requestNewCredentialParams.AttestationPreference, requestNewCredentialParams.ExcludeCredentials, requestNewCredentialParams.Extensions, requestNewCredentialParams.PubKeyCredParams);
3535

3636
}
3737

Src/Fido2/RequestNewCredentialParams.cs

+5
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ public sealed class RequestNewCredentialParams
3434
/// The Relying Party MAY use this OPTIONAL member to provide client extension inputs requesting additional processing by the client and authenticator. For example, the Relying Party may request that the client returns additional information about the credential that was created.
3535
/// </summary>
3636
public AuthenticationExtensionsClientInputs? Extensions { get; init; }
37+
38+
/// <summary>
39+
/// For advanced use cases. This member lists the key types and signature algorithms the Relying Party supports, ordered from most preferred to least preferred. The client and authenticator make a best-effort to create a credential of the most preferred type possible. If none of the listed types can be created, the create() operation fails.
40+
/// </summary>
41+
public IReadOnlyList<PubKeyCredParam> PubKeyCredParams { get; init; } = PubKeyCredParam.Defaults;
3742
}

Tests/Fido2.Tests/Fido2Tests.cs

-2
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,6 @@ public async Task TestPackedAttestationAsync()
611611
var jsonPost = JsonSerializer.Deserialize<AuthenticatorAttestationRawResponse>(await File.ReadAllTextAsync("./attestationResultsPacked.json"));
612612
var options = JsonSerializer.Deserialize<CredentialCreateOptions>(await File.ReadAllTextAsync("./attestationOptionsPacked.json"));
613613
var o = AuthenticatorAttestationResponse.Parse(jsonPost);
614-
options.PubKeyCredParams.Add(new PubKeyCredParam(COSE.Algorithm.RS1, PublicKeyCredentialType.PublicKey));
615614
await o.VerifyAsync(options, _config, (x, cancellationToken) => Task.FromResult(true), _metadataService, null, CancellationToken.None);
616615
var authData = o.AttestationObject.AuthData;
617616
var acdBytes = authData.AttestedCredentialData.ToByteArray();
@@ -644,7 +643,6 @@ public async Task TestTPMSHA1AttestationAsync()
644643
var jsonPost = JsonSerializer.Deserialize<AuthenticatorAttestationRawResponse>(await File.ReadAllTextAsync("./attestationTPMSHA1Response.json"));
645644
var options = JsonSerializer.Deserialize<CredentialCreateOptions>(await File.ReadAllTextAsync("./attestationTPMSHA1Options.json"));
646645
var o = AuthenticatorAttestationResponse.Parse(jsonPost);
647-
options.PubKeyCredParams.Add(new PubKeyCredParam(COSE.Algorithm.RS1, PublicKeyCredentialType.PublicKey));
648646
await o.VerifyAsync(options, _config, (x, cancellationToken) => Task.FromResult(true), _metadataService, null, CancellationToken.None);
649647
}
650648

Tests/Fido2.Tests/TestFiles/attestationOptionsPacked.json

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
{
1616
"type": "public-key",
1717
"alg": -7
18+
},
19+
{
20+
"type": "public-key",
21+
"alg": -65535
1822
}
1923
],
2024
"timeout": 0

Tests/Fido2.Tests/TestFiles/attestationTPMSHA1Options.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
{
2020
"type": "public-key",
2121
"alg": -257
22-
}
22+
},
23+
{
24+
"type": "public-key",
25+
"alg": -65535
26+
}
2327
],
2428
"timeout": 60000,
2529
"attestation": "direct",

0 commit comments

Comments
 (0)