-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Support querying TlsCipherSuite
on Http.Sys / IIS
#63685
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 4 commits
31e84e1
6ab0544
a423dbc
fadb012
64352f9
818ab5a
0f4976d
5b06331
6f26645
4ee2c06
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.AspNetCore.Server.HttpSys.NativeInterop.Types; | ||
|
||
// From Schannel.h | ||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
internal unsafe struct SecPkgContext_CipherInfo | ||
{ | ||
private const int SZ_ALG_MAX_SIZE = 64; | ||
|
||
private readonly int dwVersion; | ||
private readonly int dwProtocol; | ||
public readonly int dwCipherSuite; | ||
private readonly int dwBaseCipherSuite; | ||
private fixed char szCipherSuite[SZ_ALG_MAX_SIZE]; | ||
private fixed char szCipher[SZ_ALG_MAX_SIZE]; | ||
private readonly int dwCipherLen; | ||
private readonly int dwCipherBlockLen; // in bytes | ||
private fixed char szHash[SZ_ALG_MAX_SIZE]; | ||
private readonly int dwHashLen; | ||
private fixed char szExchange[SZ_ALG_MAX_SIZE]; | ||
private readonly int dwMinExchangeLen; | ||
private readonly int dwMaxExchangeLen; | ||
private fixed char szCertificate[SZ_ALG_MAX_SIZE]; | ||
private readonly int dwKeyType; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
using Microsoft.AspNetCore.Http.Features; | ||
using Microsoft.AspNetCore.HttpSys.Internal; | ||
using Microsoft.AspNetCore.Server.IIS.Core.IO; | ||
using Microsoft.AspNetCore.Server.IIS.Core.Native; | ||
using Microsoft.AspNetCore.Shared; | ||
using Microsoft.AspNetCore.WebUtilities; | ||
using Microsoft.Extensions.Logging; | ||
|
@@ -402,6 +403,8 @@ private void GetTlsHandshakeResults() | |
{ | ||
var handshake = GetTlsHandshake(); | ||
Protocol = (SslProtocols)handshake.Protocol; | ||
|
||
NegotiatedCipherSuite = GetTlsCipherSuite(); | ||
#pragma warning disable SYSLIB0058 // Type or member is obsolete | ||
CipherAlgorithm = (CipherAlgorithmType)handshake.CipherType; | ||
CipherStrength = (int)handshake.CipherStrength; | ||
|
@@ -415,6 +418,33 @@ private void GetTlsHandshakeResults() | |
SniHostName = sni.Hostname.ToString(); | ||
} | ||
|
||
private unsafe TlsCipherSuite? GetTlsCipherSuite() | ||
{ | ||
var size = sizeof(SecPkgContext_CipherInfo); | ||
var buffer = new byte[size]; | ||
DeagleGross marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
fixed (byte* pBuffer = buffer) | ||
{ | ||
var statusCode = NativeMethods.HttpQueryRequestProperty( | ||
RequestId, | ||
(HTTP_REQUEST_PROPERTY)14 /* HTTP_REQUEST_PROPERTY.HttpRequestPropertyTlsCipherInfo */, | ||
qualifier: null, | ||
qualifierSize: 0, | ||
(void*)pBuffer, | ||
(uint)buffer.Length, | ||
bytesReturned: null, | ||
IntPtr.Zero); | ||
|
||
if (statusCode == NativeMethods.HR_OK) | ||
{ | ||
var cipherInfo = Marshal.PtrToStructure<SecPkgContext_CipherInfo>((IntPtr)pBuffer); | ||
return (TlsCipherSuite)cipherInfo.dwCipherSuite; | ||
|
||
} | ||
|
||
return default; | ||
} | ||
} | ||
|
||
private unsafe HTTP_REQUEST_PROPERTY_SNI GetClientSni() | ||
{ | ||
var buffer = new byte[HttpApiTypes.SniPropertySizeInBytes]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.AspNetCore.Server.IIS.Core.Native; | ||
|
||
// From Schannel.h | ||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
internal unsafe struct SecPkgContext_CipherInfo | ||
DeagleGross marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
private const int SZ_ALG_MAX_SIZE = 64; | ||
|
||
private readonly int dwVersion; | ||
private readonly int dwProtocol; | ||
public readonly int dwCipherSuite; | ||
DeagleGross marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private readonly int dwBaseCipherSuite; | ||
private fixed char szCipherSuite[SZ_ALG_MAX_SIZE]; | ||
private fixed char szCipher[SZ_ALG_MAX_SIZE]; | ||
private readonly int dwCipherLen; | ||
private readonly int dwCipherBlockLen; // in bytes | ||
private fixed char szHash[SZ_ALG_MAX_SIZE]; | ||
private readonly int dwHashLen; | ||
private fixed char szExchange[SZ_ALG_MAX_SIZE]; | ||
private readonly int dwMinExchangeLen; | ||
private readonly int dwMaxExchangeLen; | ||
private fixed char szCertificate[SZ_ALG_MAX_SIZE]; | ||
private readonly int dwKeyType; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.