简体   繁体   English

如何在ASP.NET Core中获取TLS / SSL相关信息?

[英]How to get TLS/SSL related information in ASP.NET Core?

I would like to gain more information of a current TLS/SSL request in an ASP.NET Core MVC Controller. 我想获得有关ASP.NET核心MVC控制器中当前TLS / SSL请求的更多信息。

using Microsoft.AspNetCore.Mvc;

namespace WebApp.Controllers
{
    public class HomeController : Controller
    {        
        public IActionResult About()
        {
            if (HttpContext.Request.IsHttps)
            {
                // How to get more information about the transport layer ?

                ViewData["Message"] = "Connection via TLS/SSL - ... missing details ...";
            }

            return View();
        }        
    }
}

Is there a way to access the properties like used TLS version, cipher and so on ? 有没有办法访问使用TLS版本,密码等属性?

I know that this is not possible in ASP.NET MVC as stated in Check ssl protocol, cipher & other properties in an asp.net mvc 4 application . 我知道在ASP.NET MVC中这是不可能的,如在asp.net mvc 4应用程序检查ssl协议,密码和其他属性中所述 Perhaps the new framework with Kestrel offers this kind of information I was not able to find so far. 也许与Kestrel的新框架提供了迄今为止我无法找到的这种信息。

You can get those values using the Features property from the HttpContext . 您可以使用HttpContextFeatures属性获取这些值。 If you call: 如果你打电话:

var tlsHandshakeFeature = request.HttpContext.Features.Get<ITlsHandshakeFeature>();

ITlsHandshakeFeature will give you the TLS version (Protocol property), the CipherAlgorithm, among many other things. ITlsHandshakeFeature将为您提供TLS版本(协议属性),CipherAlgorithm以及许多其他功能。
You can also Get the ITlsConnectionFeature which will give you the certificates. 您还可以Get将为您提供证书的ITlsConnectionFeature

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM