Пример #1
0
        private unsafe void CreateAuthentication(ApplicationProtocols.ProtocolIds alpnSupportedProtocols)
        {
            int         numberOfPackages;
            SecPkgInfo *secPointer = null;

            if (alpnSupportedProtocols > 0)
            {
                _alpnSupportedProtocols = ApplicationProtocols.GetBufferForProtocolId(alpnSupportedProtocols);
                _alpnHandle             = GCHandle.Alloc(_alpnSupportedProtocols, GCHandleType.Pinned);
            }
            try
            {
                if (InteropSspi.EnumerateSecurityPackagesW(out numberOfPackages, out secPointer) != 0)
                {
                    throw new InvalidOperationException("Unable to enumerate security packages");
                }
                var size = sizeof(SecPkgInfo);

                for (int i = 0; i < numberOfPackages; i++)
                {
                    var package = secPointer[i];
                    var name    = Marshal.PtrToStringUni(package.Name);
                    if (name == SecurityPackage)
                    {
                        _maxTokenSize = package.cbMaxToken;

                        //The correct security package is available
                        _initOkay = true;
                        GetCredentials();
                        return;
                    }
                }
                throw new InvalidOperationException($"Unable to find the security package named {SecurityPackage}");
            }
            finally
            {
                if (secPointer != null)
                {
                    InteropSspi.FreeContextBuffer((IntPtr)secPointer);
                }
            }
        }
Пример #2
0
 internal static extern int EnumerateSecurityPackagesW([Out] out int pkgnum, [Out] out SecPkgInfo *info);