Skip to content

Commit 95352fe

Browse files
committed
Use default CertificateRevocationCheckMode for SNI endpoints
1 parent 566d793 commit 95352fe

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,19 @@ public SniOptionsSelector(
4545
{
4646
var sslOptions = new SslServerAuthenticationOptions
4747
{
48-
ServerCertificate = configLoader.LoadCertificate(sniConfig.Certificate, endpointConfig.Name),
48+
ServerCertificate = configLoader.LoadCertificate(sniConfig.Certificate, $"{endpointConfig.Name}:SNI:{name}"),
4949
EnabledSslProtocols = sniConfig.SslProtocols ?? fallbackOptions.SslProtocols,
50+
CertificateRevocationCheckMode = fallbackOptions.CheckCertificateRevocation ? X509RevocationMode.Online : X509RevocationMode.NoCheck,
5051
};
5152

5253
if (sslOptions.ServerCertificate is null)
5354
{
54-
if (fallbackOptions.ServerCertificate is null && fallbackOptions.ServerCertificateSelector is null)
55+
if (fallbackOptions.ServerCertificate is null && _fallbackServerCertificateSelector is null)
5556
{
5657
throw new InvalidOperationException(CoreStrings.NoCertSpecifiedNoDevelopmentCertificateFound);
5758
}
5859

59-
if (fallbackOptions.ServerCertificateSelector is null)
60+
if (_fallbackServerCertificateSelector is null)
6061
{
6162
// Cache the fallback ServerCertificate since there's no fallback ServerCertificateSelector taking precedence.
6263
sslOptions.ServerCertificate = fallbackOptions.ServerCertificate;
@@ -138,9 +139,8 @@ public SslServerAuthenticationOptions GetOptions(ConnectionContext connection, s
138139

139140
if (_onAuthenticateCallback != null)
140141
{
141-
sslOptions = CloneSslOptions(sslOptions);
142-
143142
// From doc comments: "This is called after all of the other settings have already been applied."
143+
sslOptions = CloneSslOptions(sslOptions);
144144
_onAuthenticateCallback(connection, sslOptions);
145145
}
146146

@@ -158,8 +158,8 @@ private bool TryGetWildcardPrefixedOptions(string serverName, out SniOptions sni
158158
{
159159
ReadOnlySpan<char> nameCandidateSpan = nameCandidate;
160160

161-
// Note that we only slice off the `*`. We want to match the leading `.` also.
162-
if (serverNameSpan.EndsWith(nameCandidateSpan.Slice(wildcardHost.Length), StringComparison.OrdinalIgnoreCase) &&
161+
// Only slice off 1 character, the `*`. We want to match the leading `.` also.
162+
if (serverNameSpan.EndsWith(nameCandidateSpan.Slice(1), StringComparison.OrdinalIgnoreCase) &&
163163
nameCandidateSpan.Length > matchedNameLength)
164164
{
165165
matchedNameLength = nameCandidateSpan.Length;
@@ -171,6 +171,8 @@ private bool TryGetWildcardPrefixedOptions(string serverName, out SniOptions sni
171171
}
172172

173173
// TODO: Reflection based test to ensure we clone everything!
174+
// This won't catch issues related to mutable subproperties, but the existing subproperties look like they're mosly immutable.
175+
// The exception are the ApplicationProtocols list which we clone and the ServerCertificate because of methods like Import() and Reset() :(
174176
internal static SslServerAuthenticationOptions CloneSslOptions(SslServerAuthenticationOptions sslOptions) =>
175177
new SslServerAuthenticationOptions
176178
{

0 commit comments

Comments
 (0)