Skip to content

Commit 934abe4

Browse files
authored
Update System.IdentityModel.Tokens.Jwt and xunit (#431)
* Update System.IdentityModel.Tokens.Jwt and react to serialization changes * Make tests async * Update xunit * Update Test.Sdk * Prefer async Task to async void * Format code * Disable formatting for non-standard comment format
1 parent 11c78ce commit 934abe4

File tree

12 files changed

+503
-491
lines changed

12 files changed

+503
-491
lines changed

Src/Fido2/Fido2.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
2323
<PackageReference Include="NSec.Cryptography" Version="22.4.0" />
2424
<PackageReference Include="System.Formats.Cbor" Version="6.0.0" />
25-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.32.1" />
25+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.0.2" />
2626
</ItemGroup>
2727

2828
<ItemGroup>

Src/Fido2/Metadata/Fido2MetadataServiceRepository.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ private async Task<MetadataBLOBPayload> DeserializeAndValidateBlobAsync(string r
163163
if (blobCerts.Length > 1)
164164
{
165165
certChain.ChainPolicy.ExtraStore.AddRange(blobCerts.Skip(1).ToArray());
166-
}
167-
166+
}
167+
168168
var certChainIsValid = certChain.Build(blobCerts[0]);
169169
// if the root is trusted in the context we are running in, valid should be true here
170170
if (!certChainIsValid)
@@ -180,22 +180,24 @@ private async Task<MetadataBLOBPayload> DeserializeAndValidateBlobAsync(string r
180180
}
181181
}
182182

183+
#pragma warning disable format
183184
// otherwise we have to manually validate that the root in the chain we are testing is the root we downloaded
184-
if (rootCert.Thumbprint == certChain.ChainElements[^1].Certificate.Thumbprint &&
185-
// and that the number of elements in the chain accounts for what was in x5c plus the root we added
186-
certChain.ChainElements.Count == (x5cRawKeys.Length + 1) &&
187-
// and that the root cert has exactly one status with the value of UntrustedRoot
185+
if (rootCert.Thumbprint == certChain.ChainElements[^1].Certificate.Thumbprint &&
186+
// and that the number of elements in the chain accounts for what was in x5c plus the root we added
187+
certChain.ChainElements.Count == (x5cRawKeys.Length + 1) &&
188+
// and that the root cert has exactly one status with the value of UntrustedRoot
188189
certChain.ChainElements[^1].ChainElementStatus is [{ Status: X509ChainStatusFlags.UntrustedRoot }])
189190
{
190191
// if we are good so far, that is a good sign
191192
certChainIsValid = true;
192-
for (var i = 0; i < certChain.ChainElements.Count - 1; i++)
193+
for (int i = 0; i < certChain.ChainElements.Count - 1; i++)
193194
{
194195
// check each non-root cert to verify zero status listed against it, otherwise, invalidate chain
195-
if (0 != certChain.ChainElements[i].ChainElementStatus.Length)
196+
if (certChain.ChainElements[i].ChainElementStatus.Length != 0)
196197
certChainIsValid = false;
197198
}
198199
}
200+
#pragma warning restore format
199201
}
200202

201203
if (!certChainIsValid)

Test/Attestation/AndroidKey.cs

Lines changed: 47 additions & 47 deletions
Large diffs are not rendered by default.

Test/Attestation/AndroidSafetyNet.cs

Lines changed: 110 additions & 92 deletions
Large diffs are not rendered by default.

Test/Attestation/Apple.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public async Task TestAppleMissingX5c()
8080
{
8181
var attStmt = (CborMap)_attestationObject["attStmt"];
8282
attStmt.Set("x5c", CborNull.Instance);
83-
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
83+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
8484
Assert.Equal(Fido2ErrorMessages.MalformedX5c_AppleAttestation, ex.Message);
8585
}
8686

@@ -89,7 +89,7 @@ public async Task TestAppleX5cNotArray()
8989
{
9090
var attStmt = (CborMap)_attestationObject["attStmt"];
9191
attStmt.Set("x5c", new CborTextString("boomerang"));
92-
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
92+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
9393

9494
Assert.Equal(Fido2ErrorCode.InvalidAttestation, ex.Code);
9595
Assert.Equal(Fido2ErrorMessages.MalformedX5c_AppleAttestation, ex.Message);
@@ -101,7 +101,7 @@ public async Task TestAppleX5cCountNotOne()
101101
var emptyX5c = new CborArray { new byte[0], new byte[0] };
102102
var attStmt = (CborMap)_attestationObject["attStmt"];
103103
attStmt.Set("x5c", emptyX5c);
104-
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
104+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
105105

106106
Assert.Equal(Fido2ErrorCode.InvalidAttestation, ex.Code);
107107
Assert.Equal(Fido2ErrorMessages.MalformedX5c_AppleAttestation, ex.Message);
@@ -112,7 +112,7 @@ public async Task TestAppleX5cValueNotByteString()
112112
{
113113
var attStmt = (CborMap)_attestationObject["attStmt"];
114114
attStmt.Set("x5c", new CborTextString("x"));
115-
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
115+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
116116

117117
Assert.Equal(Fido2ErrorCode.InvalidAttestation, ex.Code);
118118
Assert.Equal(Fido2ErrorMessages.MalformedX5c_AppleAttestation, ex.Message);
@@ -123,14 +123,14 @@ public async Task TestAppleX5cValueZeroLengthByteString()
123123
{
124124
var attStmt = (CborMap)_attestationObject["attStmt"];
125125
attStmt.Set("x5c", new CborArray { new byte[0] });
126-
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
126+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
127127

128128
Assert.Equal(Fido2ErrorCode.InvalidAttestation, ex.Code);
129129
Assert.Equal(Fido2ErrorMessages.MalformedX5c_AppleAttestation, ex.Message);
130130
}
131131

132132
[Fact]
133-
public void TestAppleCertMissingExtension()
133+
public async Task TestAppleCertMissingExtension()
134134
{
135135
var invalidX5cStrings = validX5cStrings;
136136
var invalidCert = Convert.FromBase64String(invalidX5cStrings[0]);
@@ -147,8 +147,8 @@ public void TestAppleCertMissingExtension()
147147
};
148148
var attStmt = (CborMap)_attestationObject["attStmt"];
149149
attStmt.Set("x5c", x5c);
150-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
151-
Assert.Equal("Extension with OID 1.2.840.113635.100.8.2 not found on Apple attestation credCert", ex.Result.Message);
150+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
151+
Assert.Equal("Extension with OID 1.2.840.113635.100.8.2 not found on Apple attestation credCert", ex.Message);
152152
}
153153

154154
[Fact]
@@ -169,14 +169,14 @@ public async Task TestAppleCertCorruptExtension()
169169
};
170170
var attStmt = (CborMap)_attestationObject["attStmt"];
171171
attStmt.Set("x5c", x5c);
172-
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
172+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
173173

174174
Assert.Equal(Fido2ErrorCode.InvalidAttestation, ex.Code);
175175
Assert.Equal("Apple attestation extension has invalid data", ex.Message);
176176
}
177177

178178
[Fact]
179-
public void TestAppleInvalidNonce()
179+
public async Task TestAppleInvalidNonce()
180180
{
181181
var trustPath = validX5cStrings
182182
.Select(x => new X509Certificate2(Convert.FromBase64String(x)))
@@ -188,8 +188,8 @@ public void TestAppleInvalidNonce()
188188
};
189189
var attStmt = (CborMap)_attestationObject["attStmt"];
190190
attStmt.Set("x5c", x5c);
191-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
192-
Assert.Equal("Mismatch between nonce and credCert attestation extension in Apple attestation", ex.Result.Message);
191+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
192+
Assert.Equal("Mismatch between nonce and credCert attestation extension in Apple attestation", ex.Message);
193193
}
194194

195195
[Fact]

Test/Attestation/FidoU2f.cs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public FidoU2f()
5353
}
5454

5555
[Fact]
56-
public async void TestU2f()
56+
public async Task TestU2f()
5757
{
5858
var res = await MakeAttestationResponseAsync();
5959
Assert.Equal(string.Empty, res.ErrorMessage);
@@ -74,54 +74,54 @@ public async void TestU2f()
7474
public async Task TestU2fWithAaguid()
7575
{
7676
_aaguid = new Guid("F1D0F1D0-F1D0-F1D0-F1D0-F1D0F1D0F1D0");
77-
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
77+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
7878

7979
Assert.Equal(Fido2ErrorCode.InvalidAttestation, ex.Code);
8080
Assert.Equal("Aaguid was not empty parsing fido-u2f attestation statement", ex.Message);
8181
}
8282

8383
[Fact]
84-
public void TestU2fMissingX5c()
84+
public async Task TestU2fMissingX5c()
8585
{
8686
((CborMap)_attestationObject["attStmt"]).Set("x5c", CborNull.Instance);
87-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
88-
Assert.Equal("Malformed x5c in fido-u2f attestation", ex.Result.Message);
87+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
88+
Assert.Equal("Malformed x5c in fido-u2f attestation", ex.Message);
8989
}
9090

9191
[Fact]
92-
public void TestU2fX5cNotArray()
92+
public async Task TestU2fX5cNotArray()
9393
{
9494
((CborMap)_attestationObject["attStmt"]).Set("x5c", new CborTextString("boomerang"));
95-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
96-
Assert.Equal("Malformed x5c in fido-u2f attestation", ex.Result.Message);
95+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
96+
Assert.Equal("Malformed x5c in fido-u2f attestation", ex.Message);
9797
}
9898

9999
[Fact]
100-
public void TestU2fX5cCountNotOne()
100+
public async Task TestU2fX5cCountNotOne()
101101
{
102102
((CborMap)_attestationObject["attStmt"]).Set("x5c", new CborArray { new byte[0], new byte[0] });
103-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
104-
Assert.Equal("Malformed x5c in fido-u2f attestation", ex.Result.Message);
103+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
104+
Assert.Equal("Malformed x5c in fido-u2f attestation", ex.Message);
105105
}
106106

107107
[Fact]
108-
public void TestU2fX5cValueNotByteString()
108+
public async Task TestU2fX5cValueNotByteString()
109109
{
110110
((CborMap)_attestationObject["attStmt"]).Set("x5c", new CborTextString("x"));
111-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
112-
Assert.Equal("Malformed x5c in fido-u2f attestation", ex.Result.Message);
111+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
112+
Assert.Equal("Malformed x5c in fido-u2f attestation", ex.Message);
113113
}
114114

115115
[Fact]
116-
public void TestU2fX5cValueZeroLengthByteString()
116+
public async Task TestU2fX5cValueZeroLengthByteString()
117117
{
118118
((CborMap)_attestationObject["attStmt"]).Set("x5c", new CborArray { new byte[0] });
119-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
120-
Assert.Equal("Malformed x5c in fido-u2f attestation", ex.Result.Message);
119+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
120+
Assert.Equal("Malformed x5c in fido-u2f attestation", ex.Message);
121121
}
122122

123123
[Fact]
124-
public void TestU2fAttCertNotP256()
124+
public async Task TestU2fAttCertNotP256()
125125
{
126126
using (var ecdsaAtt = ECDsa.Create(ECCurve.NamedCurves.nistP384))
127127
{
@@ -135,46 +135,46 @@ public void TestU2fAttCertNotP256()
135135
attnStmt.Set("x5c", new CborArray { attestnCert.RawData });
136136
}
137137

138-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
139-
Assert.Equal("Attestation certificate public key is not an Elliptic Curve (EC) public key over the P-256 curve", ex.Result.Message);
138+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
139+
Assert.Equal("Attestation certificate public key is not an Elliptic Curve (EC) public key over the P-256 curve", ex.Message);
140140
}
141141

142142
[Fact]
143-
public void TestU2fSigNull()
143+
public async Task TestU2fSigNull()
144144
{
145145
((CborMap)_attestationObject["attStmt"]).Set("sig", CborNull.Instance);
146-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
147-
Assert.Equal("Invalid fido-u2f attestation signature", ex.Result.Message);
146+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
147+
Assert.Equal("Invalid fido-u2f attestation signature", ex.Message);
148148
}
149149
[Fact]
150-
public void TestU2fSigNotByteString()
150+
public async Task TestU2fSigNotByteString()
151151
{
152152
((CborMap)_attestationObject["attStmt"]).Set("sig", new CborTextString("walrus"));
153-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
154-
Assert.Equal("Invalid fido-u2f attestation signature", ex.Result.Message);
153+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
154+
Assert.Equal("Invalid fido-u2f attestation signature", ex.Message);
155155
}
156156
[Fact]
157-
public void TestU2fSigByteStringZeroLen()
157+
public async Task TestU2fSigByteStringZeroLen()
158158
{
159159
((CborMap)_attestationObject["attStmt"]).Set("sig", new CborByteString(new byte[0]));
160-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
161-
Assert.Equal("Invalid fido-u2f attestation signature", ex.Result.Message);
160+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
161+
Assert.Equal("Invalid fido-u2f attestation signature", ex.Message);
162162
}
163163
[Fact]
164-
public void TestU2fSigNotASN1()
164+
public async Task TestU2fSigNotASN1()
165165
{
166166
((CborMap)_attestationObject["attStmt"]).Set("sig", new CborByteString(new byte[] { 0xf1, 0xd0 }));
167-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
168-
Assert.Equal("Failed to decode fido-u2f attestation signature from ASN.1 encoded form", ex.Result.Message);
167+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
168+
Assert.Equal("Failed to decode fido-u2f attestation signature from ASN.1 encoded form", ex.Message);
169169
}
170170
[Fact]
171-
public void TestU2fBadSig()
171+
public async Task TestU2fBadSig()
172172
{
173173
var attnStmt = (CborMap)_attestationObject["attStmt"];
174174
var sig = (byte[])attnStmt["sig"];
175175
sig[^1] ^= 0xff;
176176
attnStmt.Set("sig", new CborByteString(sig));
177-
var ex = Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
178-
Assert.Equal("Invalid fido-u2f attestation signature", ex.Result.Message);
177+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
178+
Assert.Equal("Invalid fido-u2f attestation signature", ex.Message);
179179
}
180180
}

Test/Attestation/None.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public async Task TestNoneWithAttStmt()
5151
_attestationObject.Add("attStmt", new CborMap { { "foo", "bar" } });
5252
_credentialPublicKey = Fido2Tests.MakeCredentialPublicKey(Fido2Tests._validCOSEParameters[0]);
5353

54-
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(() => MakeAttestationResponseAsync());
54+
var ex = await Assert.ThrowsAsync<Fido2VerificationException>(MakeAttestationResponseAsync);
5555

5656
Assert.Equal(Fido2ErrorCode.InvalidAttestation, ex.Code);
5757
Assert.Equal("Attestation format none should have no attestation statement", ex.Message);

0 commit comments

Comments
 (0)