Esempio n. 1
0
        /// <summary>
        /// Initializes the client-side security context from a credental handle.
        /// </summary>
        /// <param name="outputBuffer">The buffer that will hold the output token.</param>
        /// <param name="serverBuffer">The buffer containing the input data from the server.</param>
        /// <param name="credential">The credential handle.</param>
        /// <param name="serverPrincipal">The server principal.</param>
        /// <param name="requestedAttributes">The requested attributes.</param>
        /// <returns>A <see cref="SecurityStatus" /> representing the result of the operation.</returns>
        public SecurityStatus InitializeSecurityContext(SecureBuffer outputBuffer, SecureBuffer serverBuffer, SafeCredentialHandle credential, string serverPrincipal, SecurityContextAttributes requestedAttributes)
        {
            SecurityContextAttributes finalAttributes = SecurityContextAttributes.None;
            Timestamp expiry = new Timestamp();

            using (SecureBufferAdapter outputAdapter = new SecureBufferAdapter(outputBuffer))
            {
                using (SecureBufferAdapter serverAdapter = new SecureBufferAdapter(serverBuffer))
                {
                    return(NativeMethods.InitializeSecurityContext_2
                           (
                               ref credential.RawHandle,
                               ref RawHandle,
                               serverPrincipal,
                               requestedAttributes,
                               0,
                               NativeMethods.SecureBufferDataRep.Network,
                               serverAdapter.Handle,
                               0,
                               ref RawHandle,
                               outputAdapter.Handle,
                               ref finalAttributes,
                               ref expiry
                           ));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Establishes a security context between the server and a remote client.
        /// </summary>
        /// <param name="outputBuffer">The buffer that will hold the output token.</param>
        /// <param name="clientBuffer">The buffer containing the input data from the client.</param>
        /// <param name="credential">The credential handle.</param>
        /// <param name="requestedAttributes">The requested attributes.</param>
        /// <returns>A <see cref="SecurityStatus" /> representing the result of the operation.</returns>
        public SecurityStatus AcceptSecurityContext(SecureBuffer outputBuffer, SecureBuffer clientBuffer, SafeCredentialHandle credential, SecurityContextAttributes requestedAttributes)
        {
            SecurityContextAttributes finalAttributes = SecurityContextAttributes.None;
            Timestamp expiry = new Timestamp();

            using (SecureBufferAdapter outputAdapter = new SecureBufferAdapter(outputBuffer))
            {
                using (SecureBufferAdapter clientAdapter = new SecureBufferAdapter(clientBuffer))
                {
                    if (this.IsInvalid)
                    {
                        return(NativeMethods.AcceptSecurityContext_1
                               (
                                   ref credential.RawHandle,
                                   IntPtr.Zero,
                                   clientAdapter.Handle,
                                   requestedAttributes,
                                   NativeMethods.SecureBufferDataRep.Network,
                                   ref RawHandle,
                                   outputAdapter.Handle,
                                   ref finalAttributes,
                                   ref expiry
                               ));
                    }
                    else
                    {
                        return(NativeMethods.AcceptSecurityContext_2
                               (
                                   ref credential.RawHandle,
                                   ref RawHandle,
                                   clientAdapter.Handle,
                                   requestedAttributes,
                                   NativeMethods.SecureBufferDataRep.Network,
                                   ref RawHandle,
                                   outputAdapter.Handle,
                                   ref finalAttributes,
                                   ref expiry
                               ));
                    }
                }
            }
        }