Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NegotiateAuthentication"/>
        /// for client-side authentication session.
        /// </summary>
        /// <param name="clientOptions">The property bag for the authentication options.</param>
        public NegotiateAuthentication(NegotiateAuthenticationClientOptions clientOptions)
        {
            ArgumentNullException.ThrowIfNull(clientOptions);

            ContextFlagsPal contextFlags = clientOptions.RequiredProtectionLevel switch
            {
                ProtectionLevel.Sign => ContextFlagsPal.InitIntegrity,
                ProtectionLevel.EncryptAndSign => ContextFlagsPal.InitIntegrity | ContextFlagsPal.Confidentiality,
                _ => 0
            } | ContextFlagsPal.Connection;
        /// <summary>
        /// Initializes a new instance of the <see cref="NegotiateAuthentication"/>
        /// for client-side authentication session.
        /// </summary>
        /// <param name="clientOptions">The property bag for the authentication options.</param>
        public NegotiateAuthentication(NegotiateAuthenticationClientOptions clientOptions)
        {
            ArgumentNullException.ThrowIfNull(clientOptions);

            ContextFlagsPal contextFlags = ContextFlagsPal.Connection;

            contextFlags |= clientOptions.RequiredProtectionLevel switch
            {
                ProtectionLevel.Sign => ContextFlagsPal.InitIntegrity,
                ProtectionLevel.EncryptAndSign => ContextFlagsPal.InitIntegrity | ContextFlagsPal.Confidentiality,
                _ => 0
            };

            contextFlags |= clientOptions.RequireMutualAuthentication ? ContextFlagsPal.MutualAuth : 0;

            contextFlags |= clientOptions.AllowedImpersonationLevel switch
            {
                TokenImpersonationLevel.Identification => ContextFlagsPal.InitIdentify,
                TokenImpersonationLevel.Delegation => ContextFlagsPal.Delegate,
                _ => 0
            };

            _isServer                   = false;
            _requestedPackage           = clientOptions.Package;
            _requiredImpersonationLevel = TokenImpersonationLevel.None;
            _requiredProtectionLevel    = clientOptions.RequiredProtectionLevel;
            try
            {
                _ntAuthentication = new NTAuthentication(
                    isServer: false,
                    clientOptions.Package,
                    clientOptions.Credential,
                    clientOptions.TargetName,
                    contextFlags,
                    clientOptions.Binding);
            }
            catch (PlatformNotSupportedException) // Managed implementation, Unix
            {
            }
            catch (NotSupportedException) // Windows implementation
            {
            }
            catch (Win32Exception) // Unix implementation in native layer
            {
            }
        }