/// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="creds">Credential handle.</param>
 /// <param name="req_attributes">Request attribute flags.</param>
 /// <param name="channel_binding">Optional channel binding token.</param>
 /// <param name="data_rep">Data representation.</param>
 public ServerAuthenticationContext(CredentialHandle creds, AcceptContextReqFlags req_attributes,
                                    byte[] channel_binding, SecDataRep data_rep)
 {
     _creds             = creds;
     RequestAttributes  = req_attributes & ~AcceptContextReqFlags.AllocateMemory;
     DataRepresentation = data_rep;
     _token_count       = 0;
     ChannelBinding     = channel_binding;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="creds">Credential handle.</param>
 /// <param name="req_attributes">Request attribute flags.</param>
 /// <param name="channel_binding">Optional channel binding token.</param>
 /// <param name="data_rep">Data representation.</param>
 public ServerAuthenticationContext(CredentialHandle creds, AcceptContextReqFlags req_attributes,
                                    byte[] channel_binding, SecDataRep data_rep)
 {
     _creds           = creds;
     _context         = new SecHandle();
     _req_flags       = req_attributes & ~AcceptContextReqFlags.AllocateMemory;
     _data_rep        = data_rep;
     _new_context     = true;
     _token_count     = 0;
     _channel_binding = channel_binding;
 }
Пример #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="creds">Credential handle.</param>
 /// <param name="req_attributes">Request attribute flags.</param>
 /// <param name="target">Target SPN (optional).</param>
 /// <param name="data_rep">Data representation.</param>
 /// <param name="channel_binding">Optional channel binding token.</param>
 public ClientAuthenticationContext(CredentialHandle creds,
                                    InitializeContextReqFlags req_attributes,
                                    string target, byte[] channel_binding, SecDataRep data_rep)
 {
     _creds           = creds;
     _req_attributes  = req_attributes & ~InitializeContextReqFlags.AllocateMemory;
     _context         = new SecHandle();
     _target          = target == string.Empty ? null : target;
     _data_rep        = data_rep;
     _token_count     = 0;
     _channel_binding = channel_binding;
     Continue(null);
 }
        internal static SecStatusCode InitializeSecurityContext(
            CredentialHandle credential,
            SecHandle context,
            string target_name,
            InitializeContextReqFlags req_attributes,
            SecDataRep data_rep,
            IList <SecurityBuffer> input,
            SecHandle new_context,
            IList <SecurityBuffer> output,
            out InitializeContextRetFlags ret_attributes,
            LargeInteger expiry,
            bool throw_on_error)
        {
            using (DisposableList list = new DisposableList())
            {
                var input_buffers  = input?.ToBufferList(list);
                var output_buffers = output?.ToBufferList(list);

                var in_buffer_desc  = input_buffers.ToDesc(list);
                var out_buffer_desc = output_buffers.ToDesc(list);

                var result = SecurityNativeMethods.InitializeSecurityContext(credential.CredHandle,
                                                                             context, target_name, req_attributes, 0, data_rep, in_buffer_desc, 0,
                                                                             new_context, out_buffer_desc, out ret_attributes, expiry).CheckResult(throw_on_error);
                if (!result.IsSuccess())
                {
                    return(result);
                }

                try
                {
                    if (result == SecStatusCode.SEC_I_COMPLETE_NEEDED || result == SecStatusCode.SEC_I_COMPLETE_AND_CONTINUE)
                    {
                        var comp_result = SecurityNativeMethods.CompleteAuthToken(new_context, out_buffer_desc).CheckResult(throw_on_error);
                        if (!comp_result.IsSuccess())
                        {
                            return(comp_result);
                        }
                    }
                }
                finally
                {
                    if (result.IsSuccess())
                    {
                        output?.UpdateBuffers(out_buffer_desc);
                    }
                }

                return(result);
            }
        }
Пример #5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="creds">Credential handle.</param>
 /// <param name="req_attributes">Request attribute flags.</param>
 /// <param name="target">Target SPN (optional).</param>
 /// <param name="data_rep">Data representation.</param>
 /// <param name="channel_binding">Optional channel binding token.</param>
 /// <param name="initialize">Specify to default initialize the context. Must call Continue with an auth token to initialize.</param>
 public ClientAuthenticationContext(CredentialHandle creds,
                                    InitializeContextReqFlags req_attributes,
                                    string target, byte[] channel_binding, SecDataRep data_rep, bool initialize)
 {
     _creds             = creds;
     _token_count       = 0;
     RequestAttributes  = req_attributes;
     Target             = target;
     DataRepresentation = data_rep;
     ChannelBinding     = channel_binding;
     if (initialize)
     {
         Continue();
     }
 }
Пример #6
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="creds">Credential handle.</param>
 public ClientAuthenticationContext(CredentialHandle creds)
     : this(creds, InitializeContextReqFlags.None, SecDataRep.Native)
 {
 }
Пример #7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="creds">Credential handle.</param>
 /// <param name="req_attributes">Request attribute flags.</param>
 /// <param name="data_rep">Data representation.</param>
 public ClientAuthenticationContext(CredentialHandle creds,
                                    InitializeContextReqFlags req_attributes, SecDataRep data_rep)
     : this(creds, req_attributes, null, data_rep)
 {
 }
Пример #8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="creds">Credential handle.</param>
 /// <param name="req_attributes">Request attribute flags.</param>
 /// <param name="target">Target SPN (optional).</param>
 /// <param name="data_rep">Data representation.</param>
 /// <param name="channel_binding">Optional channel binding token.</param>
 public ClientAuthenticationContext(CredentialHandle creds,
                                    InitializeContextReqFlags req_attributes,
                                    string target, byte[] channel_binding, SecDataRep data_rep)
     : this(creds, req_attributes, target, channel_binding, data_rep, true)
 {
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="creds">Credential handle.</param>
 public ServerAuthenticationContext(CredentialHandle creds)
     : this(creds, AcceptContextReqFlags.None, SecDataRep.Native)
 {
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="creds">Credential handle.</param>
 /// <param name="req_attributes">Request attribute flags.</param>
 /// <param name="data_rep">Data representation.</param>
 public ServerAuthenticationContext(CredentialHandle creds,
                                    AcceptContextReqFlags req_attributes, SecDataRep data_rep)
     : this(creds, req_attributes, null, data_rep)
 {
 }