You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Server Name Indication (SNI)](https://tools.ietf.org/html/rfc6066#section-3) can be used to host multiple domains on the same IP address and port. For SNI to function, the client sends the host name for the secure session to the server during the TLS handshake so that the server can provide the correct certificate. The client uses the furnished certificate for encrypted communication with the server during the secure session that follows the TLS handshake.
274
274
275
+
SNI can be configured in two ways:
276
+
277
+
* Create an endpoint in code and select a certificate using the host name with the `ServerCertificateSelector` callback.
278
+
* Configure a mapping between host names and HTTPS options in configuration. For example, JSON in `appsettings.json`.
279
+
280
+
### SNI with `ServerCertificateSelector`
281
+
275
282
Kestrel supports SNI via the `ServerCertificateSelector` callback. The callback is invoked once per connection to allow the app to inspect the host name and select the appropriate certificate. The following callback code can be used in the `ConfigureWebHostDefaults` method call of a project's *Program.cs* file:
Kestrel supports SNI defined in configuration. An endpoint can be configured with an `Sni` object that contains a mapping between host names and HTTPS options. The connection host name is matched to the options and they are used for that connection.
327
+
328
+
The following configuration adds an endpoint named `MySniEndpoint` that uses SNI to select HTTPS options based on the host name:
329
+
330
+
```json
331
+
{
332
+
"Kestrel": {
333
+
"Endpoints": {
334
+
"MySniEndpoint": {
335
+
"Url": "https://*",
336
+
"SslProtocols": ["Tls11", "Tls12"],
337
+
"Sni": {
338
+
"a.example.org": {
339
+
"Protocols": "Http1AndHttp2",
340
+
"SslProtocols": ["Tls11", "Tls12", "Tls13"],
341
+
"Certificate": {
342
+
"Subject": "<subject; required>",
343
+
"Store": "<certificate store; required>",
344
+
},
345
+
"ClientCertificateMode" : "NoCertificate"
346
+
},
347
+
"*.example.org": {
348
+
"Certificate": {
349
+
"Path": "<path to .pfx file>",
350
+
"Password": "<certificate password>"
351
+
}
352
+
},
353
+
"*": {
354
+
// At least one subproperty needs to exist per SNI section or it
355
+
// cannot be discovered via IConfiguration
356
+
"Protocols": "Http1",
357
+
}
358
+
}
359
+
}
360
+
},
361
+
"Certificates": {
362
+
"Default": {
363
+
"Path": "<path to .pfx file>",
364
+
"Password": "<certificate password>"
365
+
}
366
+
}
367
+
}
368
+
}
369
+
```
370
+
371
+
HTTPS options that can be overridden by SNI:
372
+
373
+
*`Certificate` configures the [certificate source](#certificate-sources).
374
+
*`Protocols` configures the allowed [HTTP protocols](xref:Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols).
375
+
*`SslProtocols` configures the allowed [SSL protocols](xref:System.Security.Authentication.SslProtocols).
376
+
*`ClientCertificateMode` configures the [client certificate requirements](xref:Microsoft.AspNetCore.Server.Kestrel.Https.ClientCertificateMode).
377
+
378
+
The host name supports wildcard matching:
379
+
380
+
* Exact match. For example, `a.example.org` matches `a.example.org`.
381
+
* Wildcard prefix. If there are multiple wildcard matches then the longest pattern is chosen. For example, `*.example.org` matches `b.example.org` and `c.example.org`.
382
+
* Full wildcard. `*` matches everything else, including clients that aren't using SNI and don't send a host name.
383
+
384
+
The matched SNI configuration is applied to the endpoint for the connection, overriding values on the endpoint. If a connection doesn't match a configured SNI host name then the connection is refused.
385
+
386
+
### SNI requirements
318
387
319
388
* Running on target framework `netcoreapp2.1` or later. On `net461` or later, the callback is invoked but the `name` is always `null`. The `name` is also `null` if the client doesn't provide the host name parameter in the TLS handshake.
320
389
* All websites run on the same Kestrel instance. Kestrel doesn't support sharing an IP address and port across multiple instances without a reverse proxy.
The default value, `SslProtocols.None`, causes Kestrel to use the operating system defaults to choose the best protocol. Unless you have a specific reason to select a protocol, use the default.
406
+
337
407
## Connection logging
338
408
339
409
Call <xref:Microsoft.AspNetCore.Hosting.ListenOptionsConnectionLoggingExtensions.UseConnectionLogging%2A> to emit Debug level logs for byte-level communication on a connection. Connection logging is helpful for troubleshooting problems in low-level communication, such as during TLS encryption and behind proxies. If `UseConnectionLogging` is placed before `UseHttps`, encrypted traffic is logged. If `UseConnectionLogging` is placed after `UseHttps`, decrypted traffic is logged. This is built-in [Connection Middleware](#connection-middleware).
0 commit comments