Skip to content

Commit f5fff26

Browse files
committed
React to QuicException API changes and CertificateChainPolicy
1 parent 0379622 commit f5fff26

File tree

9 files changed

+52
-38
lines changed

9 files changed

+52
-38
lines changed

src/Servers/Kestrel/Core/src/Internal/SniOptionsSelector.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ internal static SslServerAuthenticationOptions CloneSslOptions(SslServerAuthenti
194194
ServerCertificate = sslOptions.ServerCertificate,
195195
ServerCertificateContext = sslOptions.ServerCertificateContext,
196196
ServerCertificateSelectionCallback = sslOptions.ServerCertificateSelectionCallback,
197+
CertificateChainPolicy = sslOptions.CertificateChainPolicy,
197198
};
198199

199200
private sealed class SniOptions

src/Servers/Kestrel/Core/test/SniOptionsSelectorTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ public void CloneSslOptionsClonesAllProperties()
794794
ServerCertificateContext = SslStreamCertificateContext.Create(_x509Certificate2, additionalCertificates: null, offline: true),
795795
// Defaults to null
796796
ServerCertificateSelectionCallback = (sender, serverName) => null,
797+
// Defaults to null
798+
CertificateChainPolicy = new X509ChainPolicy(),
797799
};
798800

799801
var clonedOptions = SniOptionsSelector.CloneSslOptions(options);
@@ -836,6 +838,9 @@ public void CloneSslOptionsClonesAllProperties()
836838
Assert.Same(options.ServerCertificateSelectionCallback, clonedOptions.ServerCertificateSelectionCallback);
837839
Assert.True(propertyNames.Remove(nameof(options.ServerCertificateSelectionCallback)));
838840

841+
Assert.Same(options.CertificateChainPolicy, clonedOptions.CertificateChainPolicy);
842+
Assert.True(propertyNames.Remove(nameof(options.CertificateChainPolicy)));
843+
839844
// Ensure we've checked every property. When new properties get added, we'll have to update this test along with the CloneSslOptions implementation.
840845
Assert.Empty(propertyNames);
841846
}

src/Servers/Kestrel/Kestrel.slnf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"src\\Servers\\Kestrel\\test\\Interop.FunctionalTests\\Interop.FunctionalTests.csproj",
4545
"src\\Servers\\Kestrel\\test\\Sockets.BindTests\\Sockets.BindTests.csproj",
4646
"src\\Servers\\Kestrel\\test\\Sockets.FunctionalTests\\Sockets.FunctionalTests.csproj",
47-
"src\\Servers\\Kestrel\\tools\\CodeGenerator\\CodeGenerator.csproj"
47+
"src\\Servers\\Kestrel\\tools\\CodeGenerator\\CodeGenerator.csproj",
48+
"src\\Testing\\src\\Microsoft.AspNetCore.Testing.csproj"
4849
]
4950
}
5051
}

src/Servers/Kestrel/Transport.Quic/src/Internal/QuicConnectionContext.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ public override void Abort(ConnectionAbortedException abortReason)
122122

123123
return context;
124124
}
125-
catch (QuicConnectionAbortedException ex)
125+
catch (QuicException ex) when (ex.QuicError == QuicError.ConnectionAborted)
126126
{
127127
// Shutdown initiated by peer, abortive.
128-
_error = ex.ErrorCode;
129-
QuicLog.ConnectionAborted(_log, this, ex.ErrorCode, ex);
128+
_error = ex.ApplicationErrorCode;
129+
QuicLog.ConnectionAborted(_log, this, ex.ApplicationErrorCode.GetValueOrDefault(), ex);
130130

131131
ThreadPool.UnsafeQueueUserWorkItem(state =>
132132
{
@@ -138,7 +138,7 @@ public override void Abort(ConnectionAbortedException abortReason)
138138
// Throw error so consumer sees the connection is aborted by peer.
139139
throw new ConnectionResetException(ex.Message, ex);
140140
}
141-
catch (QuicOperationAbortedException ex)
141+
catch (QuicException ex) when (ex.QuicError == QuicError.OperationAborted)
142142
{
143143
lock (_shutdownLock)
144144
{

src/Servers/Kestrel/Transport.Quic/src/Internal/QuicConnectionListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public async ValueTask CreateListenerAsync()
8989

9090
return connectionContext;
9191
}
92-
catch (QuicOperationAbortedException ex)
92+
catch (QuicException ex) when (ex.QuicError == QuicError.OperationAborted)
9393
{
9494
_log.LogDebug("Listener has aborted with exception: {Message}", ex.Message);
9595
}

src/Servers/Kestrel/Transport.Quic/src/Internal/QuicStreamContext.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,29 +258,29 @@ private async Task DoReceive()
258258
}
259259
}
260260
}
261-
catch (QuicStreamAbortedException ex)
261+
catch (QuicException ex) when (ex.QuicError == QuicError.StreamAborted)
262262
{
263263
// Abort from peer.
264-
_error = ex.ErrorCode;
265-
QuicLog.StreamAbortedRead(_log, this, ex.ErrorCode);
264+
_error = ex.ApplicationErrorCode;
265+
QuicLog.StreamAbortedRead(_log, this, ex.ApplicationErrorCode.GetValueOrDefault());
266266

267267
// This could be ignored if _shutdownReason is already set.
268268
error = new ConnectionResetException(ex.Message, ex);
269269

270270
_clientAbort = true;
271271
}
272-
catch (QuicConnectionAbortedException ex)
272+
catch (QuicException ex) when (ex.QuicError == QuicError.ConnectionAborted)
273273
{
274274
// Abort from peer.
275-
_error = ex.ErrorCode;
276-
QuicLog.StreamAbortedRead(_log, this, ex.ErrorCode);
275+
_error = ex.ApplicationErrorCode;
276+
QuicLog.StreamAbortedRead(_log, this, ex.ApplicationErrorCode.GetValueOrDefault());
277277

278278
// This could be ignored if _shutdownReason is already set.
279279
error = new ConnectionResetException(ex.Message, ex);
280280

281281
_clientAbort = true;
282282
}
283-
catch (QuicOperationAbortedException ex)
283+
catch (QuicException ex) when (ex.QuicError == QuicError.OperationAborted)
284284
{
285285
// AbortRead has been called for the stream.
286286
error = new ConnectionAbortedException(ex.Message, ex);
@@ -409,29 +409,29 @@ private async Task DoSend()
409409
}
410410
}
411411
}
412-
catch (QuicStreamAbortedException ex)
412+
catch (QuicException ex) when (ex.QuicError == QuicError.StreamAborted)
413413
{
414414
// Abort from peer.
415-
_error = ex.ErrorCode;
416-
QuicLog.StreamAbortedWrite(_log, this, ex.ErrorCode);
415+
_error = ex.ApplicationErrorCode;
416+
QuicLog.StreamAbortedWrite(_log, this, ex.ApplicationErrorCode.GetValueOrDefault());
417417

418418
// This could be ignored if _shutdownReason is already set.
419419
shutdownReason = new ConnectionResetException(ex.Message, ex);
420420

421421
_clientAbort = true;
422422
}
423-
catch (QuicConnectionAbortedException ex)
423+
catch (QuicException ex) when (ex.QuicError == QuicError.ConnectionAborted)
424424
{
425425
// Abort from peer.
426-
_error = ex.ErrorCode;
427-
QuicLog.StreamAbortedWrite(_log, this, ex.ErrorCode);
426+
_error = ex.ApplicationErrorCode;
427+
QuicLog.StreamAbortedWrite(_log, this, ex.ApplicationErrorCode.GetValueOrDefault());
428428

429429
// This could be ignored if _shutdownReason is already set.
430430
shutdownReason = new ConnectionResetException(ex.Message, ex);
431431

432432
_clientAbort = true;
433433
}
434-
catch (QuicOperationAbortedException ex)
434+
catch (QuicException ex) when (ex.QuicError == QuicError.OperationAborted)
435435
{
436436
// AbortWrite has been called for the stream.
437437
// Possibily might also get here from connection closing.

src/Servers/Kestrel/Transport.Quic/test/QuicConnectionContextTests.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ public async Task AcceptAsync_ClientClosesConnection_ServerNotified()
8686

8787
// Assert
8888
var ex = await Assert.ThrowsAsync<ConnectionResetException>(() => acceptStreamTask.AsTask()).DefaultTimeout();
89-
var innerEx = Assert.IsType<QuicConnectionAbortedException>(ex.InnerException);
90-
Assert.Equal(256, innerEx.ErrorCode);
89+
var innerEx = Assert.IsType<QuicException>(ex.InnerException);
90+
Assert.Equal(QuicError.ConnectionAborted, innerEx.QuicError);
91+
Assert.Equal(256, innerEx.ApplicationErrorCode.Value);
9192

9293
await connectionClosedTcs.Task.DefaultTimeout();
9394
}
@@ -252,8 +253,9 @@ public async Task AcceptAsync_ClientClosesConnection_ExceptionThrown()
252253

253254
// Assert
254255
var ex = await Assert.ThrowsAsync<ConnectionResetException>(() => acceptTask).DefaultTimeout();
255-
var innerEx = Assert.IsType<QuicConnectionAbortedException>(ex.InnerException);
256-
Assert.Equal((long)Http3ErrorCode.NoError, innerEx.ErrorCode);
256+
var innerEx = Assert.IsType<QuicException>(ex.InnerException);
257+
Assert.Equal(QuicError.ConnectionAborted, innerEx.QuicError);
258+
Assert.Equal((long)Http3ErrorCode.NoError, innerEx.ApplicationErrorCode.Value);
257259

258260
Assert.Equal((long)Http3ErrorCode.NoError, serverConnection.Features.Get<IProtocolErrorCodeFeature>().Error);
259261
}
@@ -380,7 +382,7 @@ public async Task StreamPool_StreamAbortedOnClient_NotPooled()
380382
// Receive abort form client.
381383
var ex = await Assert.ThrowsAsync<ConnectionResetException>(() => serverStream.Transport.Input.ReadAsync().AsTask()).DefaultTimeout();
382384
Assert.Equal("Stream aborted by peer (258).", ex.Message);
383-
Assert.Equal((long)Http3ErrorCode.InternalError, ((QuicStreamAbortedException)ex.InnerException).ErrorCode);
385+
Assert.Equal((long)Http3ErrorCode.InternalError, ((QuicException)ex.InnerException).ApplicationErrorCode.Value);
384386

385387
// Complete reading and then abort.
386388
await serverStream.Transport.Input.CompleteAsync();
@@ -428,7 +430,7 @@ public async Task StreamPool_StreamAbortedOnClientAndServer_NotPooled()
428430
// Receive abort form client.
429431
var serverEx = await Assert.ThrowsAsync<ConnectionResetException>(() => serverStream.Transport.Input.ReadAsync().AsTask()).DefaultTimeout();
430432
Assert.Equal("Stream aborted by peer (258).", serverEx.Message);
431-
Assert.Equal((long)Http3ErrorCode.InternalError, ((QuicStreamAbortedException)serverEx.InnerException).ErrorCode);
433+
Assert.Equal((long)Http3ErrorCode.InternalError, ((QuicException)serverEx.InnerException).ApplicationErrorCode.Value);
432434

433435
serverStream.Features.Get<IProtocolErrorCodeFeature>().Error = (long)Http3ErrorCode.RequestRejected;
434436
serverStream.Abort(new ConnectionAbortedException("Test message."));
@@ -438,8 +440,9 @@ public async Task StreamPool_StreamAbortedOnClientAndServer_NotPooled()
438440
await serverStream.Transport.Output.CompleteAsync();
439441

440442
var buffer = new byte[1024];
441-
var clientEx = await Assert.ThrowsAsync<QuicStreamAbortedException>(() => clientStream.ReadAsync(buffer).AsTask()).DefaultTimeout();
442-
Assert.Equal((long)Http3ErrorCode.RequestRejected, clientEx.ErrorCode);
443+
var clientEx = await Assert.ThrowsAsync<QuicException>(() => clientStream.ReadAsync(buffer).AsTask()).DefaultTimeout();
444+
Assert.Equal(QuicError.StreamAborted, clientEx.QuicError);
445+
Assert.Equal((long)Http3ErrorCode.RequestRejected, clientEx.ApplicationErrorCode.Value);
443446

444447
var quicStreamContext = Assert.IsType<QuicStreamContext>(serverStream);
445448

src/Servers/Kestrel/Transport.Quic/test/QuicStreamContextTests.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public async Task BidirectionalStream_ClientAbortWrite_ServerReceivesAbort()
269269
await serverStream.Transport.Output.CompleteAsync();
270270

271271
// Assert
272-
Assert.Equal((long)Http3ErrorCode.InternalError, ((QuicStreamAbortedException)ex.InnerException).ErrorCode);
272+
Assert.Equal((long)Http3ErrorCode.InternalError, ((QuicException)ex.InnerException).ApplicationErrorCode.Value);
273273

274274
var quicStreamContext = Assert.IsType<QuicStreamContext>(serverStream);
275275

@@ -346,7 +346,7 @@ public async Task ClientToServerUnidirectionalStream_ClientAbort_ServerReceivesA
346346
var ex = await Assert.ThrowsAsync<ConnectionResetException>(() => serverStream.Transport.Input.ReadAsync().AsTask()).DefaultTimeout();
347347

348348
// Assert
349-
Assert.Equal((long)Http3ErrorCode.InternalError, ((QuicStreamAbortedException)ex.InnerException).ErrorCode);
349+
Assert.Equal((long)Http3ErrorCode.InternalError, ((QuicException)ex.InnerException).ApplicationErrorCode.Value);
350350

351351
var quicStreamContext = Assert.IsType<QuicStreamContext>(serverStream);
352352

@@ -459,10 +459,11 @@ public async Task ServerToClientUnidirectionalStream_ServerAborts_ClientGetsAbor
459459
((IProtocolErrorCodeFeature)serverStream).Error = (long)Http3ErrorCode.InternalError;
460460
serverStream.Abort(new ConnectionAbortedException("Test message"));
461461

462-
var ex = await Assert.ThrowsAsync<QuicStreamAbortedException>(() => clientStream.ReadAsync(new byte[1024]).AsTask()).DefaultTimeout();
462+
var ex = await Assert.ThrowsAsync<QuicException>(() => clientStream.ReadAsync(new byte[1024]).AsTask()).DefaultTimeout();
463463

464464
// Assert
465-
Assert.Equal((long)Http3ErrorCode.InternalError, ex.ErrorCode);
465+
Assert.Equal(QuicError.StreamAborted, ex.QuicError);
466+
Assert.Equal((long)Http3ErrorCode.InternalError, ex.ApplicationErrorCode.Value);
466467

467468
var quicStreamContext = Assert.IsType<QuicStreamContext>(serverStream);
468469
Assert.True(quicStreamContext.CanWrite);
@@ -514,8 +515,9 @@ public async Task StreamAbortFeature_AbortWrite_ClientReceivesAbort()
514515
Assert.Equal(TestData, data);
515516

516517
// Client errors when writing
517-
var clientEx = await Assert.ThrowsAsync<QuicStreamAbortedException>(() => clientStream.WriteAsync(data).AsTask()).DefaultTimeout();
518-
Assert.Equal((long)Http3ErrorCode.InternalError, clientEx.ErrorCode);
518+
var clientEx = await Assert.ThrowsAsync<QuicException>(() => clientStream.WriteAsync(data).AsTask()).DefaultTimeout();
519+
Assert.Equal(QuicError.StreamAborted, clientEx.QuicError);
520+
Assert.Equal((long)Http3ErrorCode.InternalError, clientEx.ApplicationErrorCode.Value);
519521

520522
// Server errors when reading
521523
var serverEx = await Assert.ThrowsAsync<ConnectionAbortedException>(() => serverReadTask).DefaultTimeout();

src/Servers/Kestrel/test/Interop.FunctionalTests/Http3/Http3RequestTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,9 @@ public async Task POST_ServerAbort_ClientReceivesAbort(HttpProtocols protocol)
436436
// Assert
437437
if (protocol == HttpProtocols.Http3)
438438
{
439-
var innerEx = Assert.IsType<QuicStreamAbortedException>(ex.InnerException);
440-
Assert.Equal(Http3ErrorCode.InternalError, (Http3ErrorCode)innerEx.ErrorCode);
439+
var innerEx = Assert.IsType<QuicException>(ex.InnerException);
440+
Assert.Equal(QuicError.StreamAborted, innerEx.QuicError);
441+
Assert.Equal(Http3ErrorCode.InternalError, (Http3ErrorCode)innerEx.ApplicationErrorCode.Value);
441442
}
442443

443444
await cancelledTcs.Task.DefaultTimeout();
@@ -493,8 +494,9 @@ public async Task GET_ServerAbort_ClientReceivesAbort(HttpProtocols protocol)
493494
// Assert
494495
if (protocol == HttpProtocols.Http3)
495496
{
496-
var innerEx = Assert.IsType<QuicStreamAbortedException>(ex.InnerException);
497-
Assert.Equal(Http3ErrorCode.InternalError, (Http3ErrorCode)innerEx.ErrorCode);
497+
var innerEx = Assert.IsType<QuicException>(ex.InnerException);
498+
Assert.Equal(QuicError.StreamAborted, innerEx.QuicError);
499+
Assert.Equal(Http3ErrorCode.InternalError, (Http3ErrorCode)innerEx.ApplicationErrorCode.Value);
498500
}
499501

500502
await cancelledTcs.Task.DefaultTimeout();

0 commit comments

Comments
 (0)