Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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 ?

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. Perhaps the new framework with Kestrel offers this kind of information I was not able to find so far.

like image 766
Ralf Bönning Avatar asked Aug 18 '16 09:08

Ralf Bönning


1 Answers

You can get those values using the Features property from the HttpContext. 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.
You can also Get the ITlsConnectionFeature which will give you the certificates.

like image 128
hardkoded Avatar answered Sep 18 '22 15:09

hardkoded