< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 67
Coverable lines: 67
Total lines: 123
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 20
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
File 1: .cctor()100%110%
File 2: GetNegotiatedApplicationProtocol(...)0%12120%
File 2: UpdateSslConnectionInfo(...)0%880%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Net.Security/src/System/Net/Security/SslConnectionInfo.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4namespace System.Net.Security
 5{
 6    internal partial struct SslConnectionInfo
 7    {
 8#pragma warning disable CA1823
 09        private static readonly byte[] s_http1 = SslApplicationProtocol.Http11.Protocol.ToArray();
 010        private static readonly byte[] s_http2 = SslApplicationProtocol.Http2.Protocol.ToArray();
 011        private static readonly byte[] s_http3 = SslApplicationProtocol.Http3.Protocol.ToArray();
 12#pragma warning restore CA1823
 13
 014        public int Protocol { get; private set; }
 015        public TlsCipherSuite TlsCipherSuite { get; private set; }
 016        public int DataCipherAlg { get; private set; }
 017        public int DataKeySize { get; private set; }
 018        public int DataHashAlg { get; private set; }
 019        public int DataHashKeySize { get; private set; }
 020        public int KeyExchangeAlg { get; private set; }
 021        public int KeyExchKeySize { get; private set; }
 22
 023        public byte[]? ApplicationProtocol { get; internal set; }
 24
 25        // Indicates whether the current TLS session was resumed (abbreviated handshake)
 26        // rather than negotiated via a full handshake. Used to decide whether the peer
 27        // certificate needs to be (re)validated on this connection.
 028        public bool TlsResumed { get; private set; }
 29    }
 30}
 31

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Net.Security/src/System/Net/Security/SslConnectionInfo.Windows.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.Security.Authentication;
 6using static Interop.SspiCli;
 7
 8namespace System.Net.Security
 9{
 10    internal partial struct SslConnectionInfo
 11    {
 12        private static byte[]? GetNegotiatedApplicationProtocol(SafeDeleteContext context)
 013        {
 014            Interop.SecPkgContext_ApplicationProtocol alpnContext = default;
 015            bool success = SSPIWrapper.QueryBlittableContextAttributes(GlobalSSPI.SSPISecureChannel, context, Interop.Ss
 16
 17            // Check if the context returned is alpn data, with successful negotiation.
 018            if (success &&
 019                alpnContext.ProtoNegoExt == Interop.ApplicationProtocolNegotiationExt.ALPN &&
 020                alpnContext.ProtoNegoStatus == Interop.ApplicationProtocolNegotiationStatus.Success)
 021            {
 022                if (alpnContext.Protocol.SequenceEqual(s_http1))
 023                {
 024                    return s_http1;
 25                }
 026                else if (alpnContext.Protocol.SequenceEqual(s_http2))
 027                {
 028                    return s_http2;
 29                }
 030                else if (alpnContext.Protocol.SequenceEqual(s_http3))
 031                {
 032                    return s_http3;
 33                }
 34
 035                return alpnContext.Protocol.ToArray();
 36            }
 37
 038            return null;
 039        }
 40
 41        public void UpdateSslConnectionInfo(SafeDeleteContext securityContext)
 042        {
 043            SecPkgContext_ConnectionInfo interopConnectionInfo = default;
 044            bool success = SSPIWrapper.QueryBlittableContextAttributes(
 045                GlobalSSPI.SSPISecureChannel,
 046                securityContext,
 047                Interop.SspiCli.ContextAttribute.SECPKG_ATTR_CONNECTION_INFO,
 048                ref interopConnectionInfo);
 049            Debug.Assert(success);
 50
 051            TlsCipherSuite cipherSuite = default;
 052            SecPkgContext_CipherInfo cipherInfo = default;
 53
 054            success = SSPIWrapper.QueryBlittableContextAttributes(GlobalSSPI.SSPISecureChannel, securityContext, Interop
 055            if (success)
 056            {
 057                cipherSuite = (TlsCipherSuite)cipherInfo.dwCipherSuite;
 058            }
 59
 060            Protocol = interopConnectionInfo.Protocol;
 061            DataCipherAlg = interopConnectionInfo.DataCipherAlg;
 062            DataKeySize = interopConnectionInfo.DataKeySize;
 063            DataHashAlg = interopConnectionInfo.DataHashAlg;
 064            DataHashKeySize = interopConnectionInfo.DataHashKeySize;
 065            KeyExchangeAlg = interopConnectionInfo.KeyExchangeAlg;
 066            KeyExchKeySize = interopConnectionInfo.KeyExchKeySize;
 67
 068            TlsCipherSuite = cipherSuite;
 69
 70            // In TLS1.3, Schannel may erroneously report empty ALPN after
 71            // receiving resumption ticket (fake Renegotiation). Avoid updating
 72            // ApplicationProtocol in this case if we already have some, TLS1.3
 73            // does not allow ALPN changes after the initial handshake.
 74            //
 75            // TLS 1.2 and below theoretically support ALPN changes during
 76            // Renegotiation.
 077            if (ApplicationProtocol == null || (Protocol & (int)SslProtocols.Tls13) == 0)
 078            {
 079                ApplicationProtocol = GetNegotiatedApplicationProtocol(securityContext);
 080            }
 81
 082            SecPkgContext_SessionInfo info = default;
 083            TlsResumed = SSPIWrapper.QueryBlittableContextAttributes(
 084                                    GlobalSSPI.SSPISecureChannel,
 085                                    securityContext,
 086                                    Interop.SspiCli.ContextAttribute.SECPKG_ATTR_SESSION_INFO,
 087                                    ref info) &&
 088               (info.dwFlags & (uint)SecPkgContext_SessionInfo.Flags.SSL_SESSION_RECONNECT) != 0;
 089        }
 90    }
 91}
 92