|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
| 4 | +using System.Net.Security; |
4 | 5 | using System.Runtime.InteropServices;
|
5 | 6 | using System.Security.Principal;
|
6 | 7 | using Microsoft.AspNetCore.Http;
|
@@ -219,6 +220,45 @@ internal void ForceCancelRequest()
|
219 | 220 | }
|
220 | 221 | }
|
221 | 222 |
|
| 223 | + /// <summary> |
| 224 | + /// Gets TLS cipher suite used for the request, if supported by the OS and http.sys. |
| 225 | + /// </summary> |
| 226 | + /// <returns> |
| 227 | + /// null, if query of TlsCipherSuite is not supported or the query failed. |
| 228 | + /// TlsCipherSuite value, if query is successful. |
| 229 | + /// </returns> |
| 230 | + internal unsafe TlsCipherSuite? GetTlsCipherSuite() |
| 231 | + { |
| 232 | + if (!HttpApi.SupportsQueryTlsCipherInfo) |
| 233 | + { |
| 234 | + return default; |
| 235 | + } |
| 236 | + |
| 237 | + var requestId = PinsReleased ? Request.RequestId : RequestId; |
| 238 | + |
| 239 | + SecPkgContext_CipherInfo cipherInfo = default; |
| 240 | + |
| 241 | + var statusCode = HttpApi.HttpGetRequestProperty( |
| 242 | + requestQueueHandle: Server.RequestQueue.Handle, |
| 243 | + requestId, |
| 244 | + propertyId: (HTTP_REQUEST_PROPERTY)14 /* HTTP_REQUEST_PROPERTY.HttpRequestPropertyTlsCipherInfo */, |
| 245 | + qualifier: null, |
| 246 | + qualifierSize: 0, |
| 247 | + output: &cipherInfo, |
| 248 | + outputSize: (uint)sizeof(SecPkgContext_CipherInfo), |
| 249 | + bytesReturned: IntPtr.Zero, |
| 250 | + overlapped: IntPtr.Zero); |
| 251 | + |
| 252 | + if (statusCode is ErrorCodes.ERROR_SUCCESS) |
| 253 | + { |
| 254 | + return checked((TlsCipherSuite)cipherInfo.dwCipherSuite); |
| 255 | + } |
| 256 | + |
| 257 | + // OS supports querying TlsCipherSuite, but request failed. |
| 258 | + Log.QueryTlsCipherSuiteError(Logger, requestId, statusCode); |
| 259 | + return null; |
| 260 | + } |
| 261 | + |
222 | 262 | /// <summary>
|
223 | 263 | /// Attempts to get the client hello message bytes from the http.sys.
|
224 | 264 | /// If successful writes the bytes into <paramref name="destination"/>, and shows how many bytes were written in <paramref name="bytesReturned"/>.
|
|
0 commit comments