< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 97
Coverable lines: 97
Total lines: 168
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/SSPIAuthType.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.Net.Security;
 6using System.Runtime.InteropServices;
 7
 8namespace System.Net
 9{
 10    // Authentication SSPI (Kerberos, NTLM, Negotiate and WDigest):
 11    internal sealed class SSPIAuthType : ISSPIInterface
 12    {
 13        private static volatile SecurityPackageInfoClass[]? s_securityPackages;
 14
 15        public SecurityPackageInfoClass[]? SecurityPackages
 16        {
 17            get
 018            {
 019                return s_securityPackages;
 020            }
 21            set
 022            {
 023                s_securityPackages = value;
 024            }
 25        }
 26
 27        public int EnumerateSecurityPackages(out int pkgnum, out SafeFreeContextBuffer pkgArray)
 028        {
 029            if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this);
 030            return SafeFreeContextBuffer.EnumeratePackages(out pkgnum, out pkgArray);
 031        }
 32
 33        public int AcquireCredentialsHandle(string moduleName, Interop.SspiCli.CredentialUse usage, ref SafeSspiAuthData
 034        {
 035            return SafeFreeCredentials.AcquireCredentialsHandle(moduleName, usage, ref authdata, out outCredential);
 036        }
 37
 38        public int AcquireDefaultCredential(string moduleName, Interop.SspiCli.CredentialUse usage, out SafeFreeCredenti
 039        {
 040            return SafeFreeCredentials.AcquireDefaultCredential(moduleName, usage, out outCredential);
 041        }
 42
 43        public unsafe int AcquireCredentialsHandle(string moduleName, Interop.SspiCli.CredentialUse usage, Interop.SspiC
 044        {
 045            return SafeFreeCredentials.AcquireCredentialsHandle(moduleName, usage, authdata, out outCredential);
 046        }
 47
 48        public unsafe int AcquireCredentialsHandle(string moduleName, Interop.SspiCli.CredentialUse usage, Interop.SspiC
 049        {
 050            return SafeFreeCredentials.AcquireCredentialsHandle(moduleName, usage, authdata, out outCredential);
 051        }
 52
 53        public int AcceptSecurityContext(SafeFreeCredentials? credential, ref SafeDeleteSslContext? context, ref InputSe
 054        {
 055            return SafeDeleteContext.AcceptSecurityContext(ref credential, ref context, inFlags, endianness, ref inputBu
 056        }
 57
 58        public int InitializeSecurityContext(ref SafeFreeCredentials? credential, ref SafeDeleteSslContext? context, str
 059        {
 060            return SafeDeleteContext.InitializeSecurityContext(ref credential, ref context, targetName, inFlags, endiann
 061        }
 62
 63        public int EncryptMessage(SafeDeleteContext context, ref Interop.SspiCli.SecBufferDesc inputOutput, uint qop)
 064        {
 065            bool mustRelease = false;
 66            try
 067            {
 068                context.DangerousAddRef(ref mustRelease);
 069                return Interop.SspiCli.EncryptMessage(ref context._handle, qop, ref inputOutput, 0);
 70            }
 71            finally
 072            {
 073                if (mustRelease)
 074                {
 075                    context.DangerousRelease();
 076                }
 077            }
 078        }
 79
 80        public unsafe int DecryptMessage(SafeDeleteContext context, ref Interop.SspiCli.SecBufferDesc inputOutput, out u
 081        {
 082            int status = (int)Interop.SECURITY_STATUS.InvalidHandle;
 083            uint qopTemp = 0;
 84
 085            bool mustRelease = false;
 86            try
 087            {
 088                context.DangerousAddRef(ref mustRelease);
 089                status = Interop.SspiCli.DecryptMessage(ref context._handle, ref inputOutput, 0, &qopTemp);
 090            }
 91            finally
 092            {
 093                if (mustRelease)
 094                {
 095                    context.DangerousRelease();
 096                }
 097            }
 98
 099            qop = qopTemp;
 0100            return status;
 0101        }
 102
 103        public int QueryContextChannelBinding(SafeDeleteContext context, Interop.SspiCli.ContextAttribute attribute, out
 0104        {
 105            // Querying an auth SSP for a CBT is not supported.
 0106            throw new NotSupportedException();
 107        }
 108
 109        public unsafe int QueryContextAttributes(SafeDeleteContext context, Interop.SspiCli.ContextAttribute attribute, 
 0110        {
 0111            return SafeFreeContextBuffer.QueryContextAttributes(context, attribute, refHandle);
 0112        }
 113
 114        public unsafe int QueryContextAttributes(SafeDeleteContext context, Interop.SspiCli.ContextAttribute attribute, 
 0115        {
 0116            refHandle = null;
 0117            if (handleType != null)
 0118            {
 0119                if (handleType == typeof(SafeFreeContextBuffer))
 0120                {
 0121                    refHandle = SafeFreeContextBuffer.CreateEmptyHandle();
 0122                }
 123                else
 0124                {
 0125                    throw new ArgumentException(SR.Format(SR.SSPIInvalidHandleType, handleType.FullName), nameof(handleT
 126                }
 0127            }
 128
 0129            fixed (byte* bufferPtr = buffer)
 0130            {
 0131                return SafeFreeContextBuffer.QueryContextAttributes(context, attribute, bufferPtr, refHandle);
 132            }
 0133        }
 134
 135        public int QuerySecurityContextToken(SafeDeleteContext phContext, out SecurityContextTokenHandle phToken)
 0136        {
 0137            return GetSecurityContextToken(phContext, out phToken);
 0138        }
 139
 140        public int CompleteAuthToken(ref SafeDeleteSslContext? refContext, in InputSecurityBuffer inputBuffer)
 0141        {
 0142            return SafeDeleteContext.CompleteAuthToken(ref refContext, in inputBuffer);
 0143        }
 144
 145        private static int GetSecurityContextToken(SafeDeleteContext phContext, out SecurityContextTokenHandle safeHandl
 0146        {
 0147            bool mustRelease = false;
 148            try
 0149            {
 0150                phContext.DangerousAddRef(ref mustRelease);
 0151                return Interop.SspiCli.QuerySecurityContextToken(ref phContext._handle, out safeHandle);
 152            }
 153            finally
 0154            {
 0155                if (mustRelease)
 0156                {
 0157                    phContext.DangerousRelease();
 0158                }
 0159            }
 0160        }
 161
 162        public int ApplyControlToken(ref SafeDeleteSslContext? refContext, in SecurityBuffer inputBuffers)
 0163        {
 0164            throw new NotSupportedException();
 165        }
 166    }
 167}
 168

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&)
GetSecurityContextToken(System.Net.Security.SafeDeleteContext,System.Net.Security.SecurityContextTokenHandle&)
ApplyControlToken(System.Net.Security.SafeDeleteSslContext&,System.Net.Security.SecurityBuffer&)