|
7 | 7 | using System.Runtime.CompilerServices;
|
8 | 8 | using System.Runtime.ExceptionServices;
|
9 | 9 | using System.Runtime.InteropServices;
|
| 10 | +using System.Security.Authentication; |
10 | 11 | using System.Security.Cryptography.X509Certificates;
|
11 | 12 | using System.Threading;
|
12 | 13 | using System.Threading.Channels;
|
13 | 14 | using System.Threading.Tasks;
|
14 | 15 | using Microsoft.Quic;
|
15 | 16 | using static Microsoft.Quic.MsQuic;
|
| 17 | +using static Microsoft.Quic.QUIC_CIPHER_ALGORITHM; |
| 18 | +using static Microsoft.Quic.QUIC_CIPHER_SUITE; |
| 19 | +using static Microsoft.Quic.QUIC_HASH_ALGORITHM; |
| 20 | +using static Microsoft.Quic.QUIC_KEY_EXCHANGE_ALGORITHM; |
| 21 | +using static Microsoft.Quic.QUIC_TLS_PROTOCOL_VERSION; |
| 22 | + |
16 | 23 | using CONNECTED_DATA = Microsoft.Quic.QUIC_CONNECTION_EVENT._Anonymous_e__Union._CONNECTED_e__Struct;
|
17 | 24 | using LOCAL_ADDRESS_CHANGED_DATA = Microsoft.Quic.QUIC_CONNECTION_EVENT._Anonymous_e__Union._LOCAL_ADDRESS_CHANGED_e__Struct;
|
18 | 25 | using PEER_ADDRESS_CHANGED_DATA = Microsoft.Quic.QUIC_CONNECTION_EVENT._Anonymous_e__Union._PEER_ADDRESS_CHANGED_e__Struct;
|
@@ -223,6 +230,40 @@ public X509Certificate? RemoteCertificate
|
223 | 230 | }
|
224 | 231 | }
|
225 | 232 |
|
| 233 | + /// <summary> |
| 234 | + /// Gets the <see cref="SslProtocols" /> corresponding to the TLS version used during the connection handshake. |
| 235 | + /// </summary> |
| 236 | + public SslProtocols SslProtocol { get; private set; } |
| 237 | + |
| 238 | + /// <summary> |
| 239 | + /// Gets the cipher suite which was negotiated for this connection. |
| 240 | + /// </summary> |
| 241 | + [CLSCompliant(false)] |
| 242 | + public TlsCipherSuite NegotiatedCipherSuite { get; private set; } |
| 243 | + |
| 244 | + /// <summary> |
| 245 | + /// Gets a value that identifies the bulk encryption algorithm used by this connection. |
| 246 | + /// </summary> |
| 247 | + public CipherAlgorithmType CipherAlgorithm { get; private set; } |
| 248 | + |
| 249 | + /// <summary> |
| 250 | + /// Gets a value that identifies the strength of the cipher algorithm used by this connection. |
| 251 | + /// </summary> |
| 252 | + public int CipherStrength { get; private set; } |
| 253 | + |
| 254 | + // |
| 255 | + // defined in SslStream but we don't need it as QUIC uses AEAD which don't use the hash algorithm |
| 256 | + // from the cipher suite |
| 257 | + // |
| 258 | + public HashAlgorithmType HashAlgorithm { get; private set; } |
| 259 | + public int HashStrength { get; private set; } |
| 260 | + |
| 261 | + // |
| 262 | + // based on SslConnectionInfo.Unix.cs it would return 0/None in all cases |
| 263 | + // |
| 264 | + public ExchangeAlgorithmType KeyExchangeAlgorithm { get; private set; } |
| 265 | + public int KeyExchangeStrength { get; private set; } |
| 266 | + |
226 | 267 | /// <summary>
|
227 | 268 | /// Final, negotiated application protocol.
|
228 | 269 | /// </summary>
|
@@ -514,6 +555,45 @@ private unsafe int HandleEventConnected(ref CONNECTED_DATA data)
|
514 | 555 | _tlsSecret?.WriteSecret();
|
515 | 556 | #endif
|
516 | 557 |
|
| 558 | + QUIC_HANDSHAKE_INFO handshakeInfo = MsQuicHelpers.GetMsQuicParameter<QUIC_HANDSHAKE_INFO>(_handle, QUIC_PARAM_TLS_HANDSHAKE_INFO); |
| 559 | + |
| 560 | + SslProtocol = handshakeInfo.TlsProtocolVersion switch |
| 561 | + { |
| 562 | + QUIC_TLS_PROTOCOL_VERSION.TLS_1_3 => SslProtocols.Tls13, |
| 563 | + _ => SslProtocols.None, |
| 564 | + }; |
| 565 | + |
| 566 | + CipherAlgorithm = handshakeInfo.CipherAlgorithm switch |
| 567 | + { |
| 568 | + QUIC_CIPHER_ALGORITHM.AES_128 => CipherAlgorithmType.Aes128, |
| 569 | + QUIC_CIPHER_ALGORITHM.AES_256 => CipherAlgorithmType.Aes256, |
| 570 | + QUIC_CIPHER_ALGORITHM.CHACHA20 => CipherAlgorithmType.None, // TODO: CipherAlgorithmType.ChaCha20, |
| 571 | + _ => CipherAlgorithmType.None, |
| 572 | + }; |
| 573 | + CipherStrength = handshakeInfo.CipherStrength; |
| 574 | + |
| 575 | + HashAlgorithm = handshakeInfo.Hash switch |
| 576 | + { |
| 577 | + QUIC_HASH_ALGORITHM.SHA_256 => HashAlgorithmType.Sha256, |
| 578 | + QUIC_HASH_ALGORITHM.SHA_384 => HashAlgorithmType.Sha384, |
| 579 | + _ => HashAlgorithmType.None, |
| 580 | + }; |
| 581 | + HashStrength = handshakeInfo.HashStrength; |
| 582 | + |
| 583 | + KeyExchangeAlgorithm = handshakeInfo.KeyExchangeAlgorithm switch |
| 584 | + { |
| 585 | + _ => ExchangeAlgorithmType.None, |
| 586 | + }; |
| 587 | + KeyExchangeStrength = handshakeInfo.KeyExchangeStrength; |
| 588 | + |
| 589 | + NegotiatedCipherSuite = handshakeInfo.CipherSuite switch |
| 590 | + { |
| 591 | + QUIC_CIPHER_SUITE.TLS_AES_128_GCM_SHA256 => TlsCipherSuite.TLS_AES_128_GCM_SHA256, |
| 592 | + QUIC_CIPHER_SUITE.TLS_AES_256_GCM_SHA384 => TlsCipherSuite.TLS_AES_256_GCM_SHA384, |
| 593 | + QUIC_CIPHER_SUITE.TLS_CHACHA20_POLY1305_SHA256 => TlsCipherSuite.TLS_CHACHA20_POLY1305_SHA256, |
| 594 | + _ => TlsCipherSuite.TLS_AES_128_GCM_SHA256, |
| 595 | + }; |
| 596 | + |
517 | 597 | if (NetEventSource.Log.IsEnabled())
|
518 | 598 | {
|
519 | 599 | NetEventSource.Info(this, $"{this} Connection connected {LocalEndPoint} -> {RemoteEndPoint} for {_negotiatedApplicationProtocol} protocol");
|
|
0 commit comments