-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Support client cert negotation #33264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a8b037f
7aa1bd0
6317e8c
5ae7511
c1385e0
920b3f0
6ff5d72
97c7257
c1d2799
ed544ff
0d5103b
9b6878e
3bfcdf0
4f64234
54cf4de
d1362e4
81c6057
0dd4911
5c786a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
using Microsoft.AspNetCore.Connections.Features; | ||
using Microsoft.AspNetCore.Http.Features; | ||
using Microsoft.AspNetCore.Server.Kestrel.Core.Features; | ||
using Microsoft.AspNetCore.Server.Kestrel.Https; | ||
|
||
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal | ||
{ | ||
|
@@ -25,6 +26,7 @@ internal class TlsConnectionFeature : ITlsConnectionFeature, ITlsApplicationProt | |
private int? _hashStrength; | ||
private ExchangeAlgorithmType? _keyExchangeAlgorithm; | ||
private int? _keyExchangeStrength; | ||
private Task<X509Certificate2?>? _clientCertTask; | ||
|
||
public TlsConnectionFeature(SslStream sslStream) | ||
{ | ||
|
@@ -36,6 +38,8 @@ public TlsConnectionFeature(SslStream sslStream) | |
_sslStream = sslStream; | ||
} | ||
|
||
internal ClientCertificateMode ClientCertificateMode { get; set; } | ||
|
||
public X509Certificate2? ClientCertificate | ||
{ | ||
get | ||
|
@@ -99,7 +103,27 @@ public int KeyExchangeStrength | |
|
||
public Task<X509Certificate2?> GetClientCertificateAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult(ClientCertificate); | ||
// Only try once per connection | ||
if (_clientCertTask != null) | ||
{ | ||
return _clientCertTask; | ||
} | ||
|
||
if (ClientCertificate != null | ||
|| ClientCertificateMode != ClientCertificateMode.DelayCertificate | ||
// Delayed client cert negotiation is not allowed on HTTP/2 (or HTTP/3, but that's implemented elsewhere). | ||
|| _sslStream.NegotiatedApplicationProtocol == SslApplicationProtocol.Http2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a test to verify we aren't renegotiating when NegotiatedApplicationProtocol is HTTP/2? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in the HTTP/2 HttpClient interop tests. That's one of the only places we test HTTP/2 over TLS. |
||
{ | ||
return _clientCertTask = Task.FromResult(ClientCertificate); | ||
} | ||
|
||
return _clientCertTask = GetClientCertificateAsyncCore(cancellationToken); | ||
} | ||
|
||
private async Task<X509Certificate2?> GetClientCertificateAsyncCore(CancellationToken cancellationToken) | ||
{ | ||
await _sslStream.NegotiateClientCertificateAsync(cancellationToken); | ||
return ClientCertificate; | ||
} | ||
|
||
private static X509Certificate2? ConvertToX509Certificate2(X509Certificate? certificate) | ||
|
Uh oh!
There was an error while loading. Please reload this page.