< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 91
Coverable lines: 91
Total lines: 156
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/Common/src/Interop/Windows/SspiCli/SSPISecureChannelType.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.Net.Security;
 5using System.Runtime.InteropServices;
 6
 7namespace System.Net
 8{
 9    // Schannel SSPI interface.
 10    internal sealed class SSPISecureChannelType : ISSPIInterface
 11    {
 12        private static volatile SecurityPackageInfoClass[]? s_securityPackages;
 13
 14        public SecurityPackageInfoClass[]? SecurityPackages
 15        {
 16            get
 017            {
 018                return s_securityPackages;
 019            }
 20            set
 021            {
 022                s_securityPackages = value;
 023            }
 24        }
 25
 26        public int EnumerateSecurityPackages(out int pkgnum, out SafeFreeContextBuffer pkgArray)
 027        {
 028            if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this);
 029            return SafeFreeContextBuffer.EnumeratePackages(out pkgnum, out pkgArray);
 030        }
 31
 32        public int AcquireCredentialsHandle(string moduleName, Interop.SspiCli.CredentialUse usage, ref SafeSspiAuthData
 033        {
 034            return SafeFreeCredentials.AcquireCredentialsHandle(moduleName, usage, ref authdata, out outCredential);
 035        }
 36
 37        public int AcquireDefaultCredential(string moduleName, Interop.SspiCli.CredentialUse usage, out SafeFreeCredenti
 038        {
 039            return SafeFreeCredentials.AcquireDefaultCredential(moduleName, usage, out outCredential);
 040        }
 41
 42        public unsafe int AcquireCredentialsHandle(string moduleName, Interop.SspiCli.CredentialUse usage, Interop.SspiC
 043        {
 044            return SafeFreeCredentials.AcquireCredentialsHandle(moduleName, usage, authdata, out outCredential);
 045        }
 46
 47        public unsafe int AcquireCredentialsHandle(string moduleName, Interop.SspiCli.CredentialUse usage, Interop.SspiC
 048        {
 049            return SafeFreeCredentials.AcquireCredentialsHandle(moduleName, usage, authdata, out outCredential);
 050        }
 51
 52        public int AcceptSecurityContext(SafeFreeCredentials? credential, ref SafeDeleteSslContext? context, ref InputSe
 053        {
 054            return SafeDeleteContext.AcceptSecurityContext(ref credential, ref context, inFlags, endianness, ref inputBu
 055        }
 56
 57        public int InitializeSecurityContext(ref SafeFreeCredentials? credential, ref SafeDeleteSslContext? context, str
 058        {
 059            return SafeDeleteContext.InitializeSecurityContext(ref credential, ref context, targetName, inFlags, endiann
 060        }
 61
 62        public int EncryptMessage(SafeDeleteContext context, ref Interop.SspiCli.SecBufferDesc inputOutput, uint qop)
 063        {
 064            bool mustRelease = false;
 65            try
 066            {
 067                context.DangerousAddRef(ref mustRelease);
 068                return Interop.SspiCli.EncryptMessage(ref context._handle, qop, ref inputOutput, 0);
 69            }
 70            finally
 071            {
 072                if (mustRelease)
 073                {
 074                    context.DangerousRelease();
 075                }
 076            }
 077        }
 78
 79        public unsafe int DecryptMessage(SafeDeleteContext context, ref Interop.SspiCli.SecBufferDesc inputOutput, out u
 080        {
 081            int status = (int)Interop.SECURITY_STATUS.InvalidHandle;
 082            uint qopTemp = 0;
 83
 084            bool mustRelease = false;
 85            try
 086            {
 087                context.DangerousAddRef(ref mustRelease);
 088                status = Interop.SspiCli.DecryptMessage(ref context._handle, ref inputOutput, 0, &qopTemp);
 089            }
 90            finally
 091            {
 092                if (mustRelease)
 093                {
 094                    context.DangerousRelease();
 095                }
 096            }
 97
 098            qop = qopTemp;
 099            return status;
 0100        }
 101
 102        public unsafe int QueryContextChannelBinding(SafeDeleteContext phContext, Interop.SspiCli.ContextAttribute attri
 0103        {
 0104            refHandle = SafeFreeContextBufferChannelBinding.CreateEmptyHandle();
 105
 106            // Bindings is on the stack, so there's no need for a fixed block.
 0107            SecPkgContext_Bindings bindings = default;
 0108            return SafeFreeContextBufferChannelBinding.QueryContextChannelBinding(phContext, attribute, &bindings, refHa
 0109        }
 110
 111        public unsafe int QueryContextAttributes(SafeDeleteContext phContext, Interop.SspiCli.ContextAttribute attribute
 0112        {
 0113            return SafeFreeContextBuffer.QueryContextAttributes(phContext, attribute, refHandle);
 0114        }
 115
 116        public unsafe int QueryContextAttributes(SafeDeleteContext phContext, Interop.SspiCli.ContextAttribute attribute
 0117        {
 0118            refHandle = null;
 0119            if (handleType != null)
 0120            {
 0121                if (handleType == typeof(SafeFreeContextBuffer))
 0122                {
 0123                    refHandle = SafeFreeContextBuffer.CreateEmptyHandle();
 0124                }
 0125                else if (handleType == typeof(SafeFreeCertContext))
 0126                {
 0127                    refHandle = new SafeFreeCertContext();
 0128                }
 129                else
 0130                {
 0131                    throw new ArgumentException(SR.Format(SR.SSPIInvalidHandleType, handleType.FullName), nameof(handleT
 132                }
 0133            }
 0134            fixed (byte* bufferPtr = buffer)
 0135            {
 0136                return SafeFreeContextBuffer.QueryContextAttributes(phContext, attribute, bufferPtr, refHandle);
 137            }
 0138        }
 139
 140        public int QuerySecurityContextToken(SafeDeleteContext phContext, out SecurityContextTokenHandle phToken)
 0141        {
 0142            throw new NotSupportedException();
 143        }
 144
 145        public int CompleteAuthToken(ref SafeDeleteSslContext? refContext, in InputSecurityBuffer inputBuffer)
 0146        {
 0147            throw new NotSupportedException();
 148        }
 149
 150        public int ApplyControlToken(ref SafeDeleteSslContext? refContext, in SecurityBuffer inputBuffer)
 0151        {
 0152            return SafeDeleteContext.ApplyControlToken(ref refContext, in inputBuffer);
 0153        }
 154    }
 155}
 156

Methods/Properties

SecurityPackages()
SecurityPackages(System.Net.SecurityPackageInfoClass[])
EnumerateSecurityPackages(System.Int32&,System.Net.Security.SafeFreeContextBuffer&)
AcquireCredentialsHandle(System.String,Interop/SspiCli/CredentialUse,System.Net.Security.SafeSspiAuthDataHandle&,System.Net.Security.SafeFreeCredentials&)
AcquireDefaultCredential(System.String,Interop/SspiCli/CredentialUse,System.Net.Security.SafeFreeCredentials&)
AcquireCredentialsHandle(System.String,Interop/SspiCli/CredentialUse,Interop/SspiCli/SCHANNEL_CRED*,System.Net.Security.SafeFreeCredentials&)
AcquireCredentialsHandle(System.String,Interop/SspiCli/CredentialUse,Interop/SspiCli/SCH_CREDENTIALS*,System.Net.Security.SafeFreeCredentials&)
AcceptSecurityContext(System.Net.Security.SafeFreeCredentials,System.Net.Security.SafeDeleteSslContext&,System.Net.Security.InputSecurityBuffers&,Interop/SspiCli/ContextFlags,Interop/SspiCli/Endianness,System.Net.Security.ProtocolToken&,Interop/SspiCli/ContextFlags&)
InitializeSecurityContext(System.Net.Security.SafeFreeCredentials&,System.Net.Security.SafeDeleteSslContext&,System.String,Interop/SspiCli/ContextFlags,Interop/SspiCli/Endianness,System.Net.Security.InputSecurityBuffers&,System.Net.Security.ProtocolToken&,Interop/SspiCli/ContextFlags&)
EncryptMessage(System.Net.Security.SafeDeleteContext,Interop/SspiCli/SecBufferDesc&,System.UInt32)
DecryptMessage(System.Net.Security.SafeDeleteContext,Interop/SspiCli/SecBufferDesc&,System.UInt32&)
QueryContextChannelBinding(System.Net.Security.SafeDeleteContext,Interop/SspiCli/ContextAttribute,System.Net.Security.SafeFreeContextBufferChannelBinding&)
QueryContextAttributes(System.Net.Security.SafeDeleteContext,Interop/SspiCli/ContextAttribute,System.IntPtr*)
QueryContextAttributes(System.Net.Security.SafeDeleteContext,Interop/SspiCli/ContextAttribute,System.Span`1<System.Byte>,System.Type,System.Runtime.InteropServices.SafeHandle&)
QuerySecurityContextToken(System.Net.Security.SafeDeleteContext,System.Net.Security.SecurityContextTokenHandle&)
CompleteAuthToken(System.Net.Security.SafeDeleteSslContext&,System.Net.Security.InputSecurityBuffer&)
ApplyControlToken(System.Net.Security.SafeDeleteSslContext&,System.Net.Security.SecurityBuffer&)