Skip to content

Commit 086a0f8

Browse files
committed
Add Ed25519 to PubKeyCredParams
Use COSE.Algorithm for PubKeyCredParam.Alg instead of hardcoding alg values. Fixes #192.
1 parent 843807e commit 086a0f8

File tree

5 files changed

+32
-26
lines changed

5 files changed

+32
-26
lines changed

Src/Fido2.Models/CredentialCreateOptions.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public static CredentialCreateOptions Create(Fido2Configuration config, byte[] c
8787
ES512,
8888
RS512,
8989
PS512,
90+
Ed25519,
9091
},
9192
AuthenticatorSelection = authenticatorSelection,
9293
Attestation = attestationConveyancePreference,
@@ -109,48 +110,53 @@ public static CredentialCreateOptions FromJson(string json)
109110
{
110111
// External authenticators support the ES256 algorithm
111112
Type = PublicKeyCredentialType.PublicKey,
112-
Alg = -7
113+
Alg = COSE.Algorithm.ES256,
113114
};
114115
private static PubKeyCredParam ES384 = new PubKeyCredParam()
115116
{
116117
Type = PublicKeyCredentialType.PublicKey,
117-
Alg = -35
118+
Alg = COSE.Algorithm.ES384,
118119
};
119120
private static PubKeyCredParam ES512 = new PubKeyCredParam()
120121
{
121122
Type = PublicKeyCredentialType.PublicKey,
122-
Alg = -36
123+
Alg = COSE.Algorithm.ES512,
123124
};
124125
private static PubKeyCredParam RS256 = new PubKeyCredParam()
125126
{
126127
// Windows Hello supports the RS256 algorithm
127128
Type = PublicKeyCredentialType.PublicKey,
128-
Alg = -257
129+
Alg = COSE.Algorithm.RS256,
129130
};
130131
private static PubKeyCredParam RS384 = new PubKeyCredParam()
131132
{
132133
Type = PublicKeyCredentialType.PublicKey,
133-
Alg = -258
134+
Alg = COSE.Algorithm.RS384,
134135
};
135136
private static PubKeyCredParam RS512 = new PubKeyCredParam()
136137
{
137138
Type = PublicKeyCredentialType.PublicKey,
138-
Alg = -259
139+
Alg = COSE.Algorithm.RS512,
139140
};
140141
private static PubKeyCredParam PS256 = new PubKeyCredParam()
141142
{
142143
Type = PublicKeyCredentialType.PublicKey,
143-
Alg = -37
144+
Alg = COSE.Algorithm.PS256,
144145
};
145146
private static PubKeyCredParam PS384 = new PubKeyCredParam()
146147
{
147148
Type = PublicKeyCredentialType.PublicKey,
148-
Alg = -38
149+
Alg = COSE.Algorithm.PS384,
149150
};
150151
private static PubKeyCredParam PS512 = new PubKeyCredParam()
151152
{
152153
Type = PublicKeyCredentialType.PublicKey,
153-
Alg = -39
154+
Alg = COSE.Algorithm.PS512,
155+
};
156+
private static PubKeyCredParam Ed25519 = new PubKeyCredParam()
157+
{
158+
Type = PublicKeyCredentialType.PublicKey,
159+
Alg = COSE.Algorithm.EdDSA,
154160
};
155161
}
156162

@@ -166,7 +172,7 @@ public class PubKeyCredParam
166172
/// The alg member specifies the cryptographic signature algorithm with which the newly generated credential will be used, and thus also the type of asymmetric key pair to be generated, e.g., RSA or Elliptic Curve.
167173
/// </summary>
168174
[JsonProperty("alg")]
169-
public long Alg { get; set; }
175+
public COSE.Algorithm Alg { get; set; }
170176
}
171177

172178
/// <summary>

Test/Attestation/Apple.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public void TestApplePublicKeyMismatch()
192192
{
193193
new PubKeyCredParam
194194
{
195-
Alg = -7,
195+
Alg = COSE.Algorithm.ES256,
196196
Type = PublicKeyCredentialType.PublicKey,
197197
}
198198
},

Test/AuthenticatorResponse.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public void TestAuthenticatorAttestationResponseInvalidType()
195195
{
196196
new PubKeyCredParam
197197
{
198-
Alg = -7,
198+
Alg = COSE.Algorithm.ES256,
199199
Type = PublicKeyCredentialType.PublicKey,
200200
}
201201
},
@@ -271,7 +271,7 @@ public void TestAuthenticatorAttestationResponseInvalidRawId(byte[] value)
271271
{
272272
new PubKeyCredParam
273273
{
274-
Alg = -7,
274+
Alg = COSE.Algorithm.ES256,
275275
Type = PublicKeyCredentialType.PublicKey,
276276
}
277277
},
@@ -345,7 +345,7 @@ public void TestAuthenticatorAttestationResponseInvalidRawType()
345345
{
346346
new PubKeyCredParam
347347
{
348-
Alg = -7,
348+
Alg = COSE.Algorithm.ES256,
349349
Type = PublicKeyCredentialType.PublicKey,
350350
}
351351
},
@@ -426,7 +426,7 @@ public void TestAuthenticatorAttestationResponseRpidMismatch()
426426
{
427427
new PubKeyCredParam
428428
{
429-
Alg = -7,
429+
Alg = COSE.Algorithm.ES256,
430430
Type = PublicKeyCredentialType.PublicKey,
431431
}
432432
},
@@ -507,7 +507,7 @@ public void TestAuthenticatorAttestationResponseNotUserPresent()
507507
{
508508
new PubKeyCredParam
509509
{
510-
Alg = -7,
510+
Alg = COSE.Algorithm.ES256,
511511
Type = PublicKeyCredentialType.PublicKey,
512512
}
513513
},
@@ -588,7 +588,7 @@ public void TestAuthenticatorAttestationResponseNoAttestedCredentialData()
588588
{
589589
new PubKeyCredParam
590590
{
591-
Alg = -7,
591+
Alg = COSE.Algorithm.ES256,
592592
Type = PublicKeyCredentialType.PublicKey,
593593
}
594594
},
@@ -670,7 +670,7 @@ public void TestAuthenticatorAttestationResponseUnknownAttestationType()
670670
{
671671
new PubKeyCredParam
672672
{
673-
Alg = -7,
673+
Alg = COSE.Algorithm.ES256,
674674
Type = PublicKeyCredentialType.PublicKey,
675675
}
676676
},
@@ -752,7 +752,7 @@ public void TestAuthenticatorAttestationResponseNotUniqueCredId()
752752
{
753753
new PubKeyCredParam
754754
{
755-
Alg = -7,
755+
Alg = COSE.Algorithm.ES256,
756756
Type = PublicKeyCredentialType.PublicKey,
757757
}
758758
},

Test/Fido2Tests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ public Attestation()
250250
Challenge = _challenge,
251251
ErrorMessage = "",
252252
PubKeyCredParams = new List<PubKeyCredParam>()
253-
{
254-
new PubKeyCredParam
255-
{
256-
Alg = -7,
257-
Type = PublicKeyCredentialType.PublicKey,
258-
}
259-
},
253+
{
254+
new PubKeyCredParam
255+
{
256+
Alg = COSE.Algorithm.ES256,
257+
Type = PublicKeyCredentialType.PublicKey,
258+
}
259+
},
260260
Rp = new PublicKeyCredentialRpEntity(rp, rp, ""),
261261
Status = "ok",
262262
User = new Fido2User

0 commit comments

Comments
 (0)