Example #1
0
        public SecBuffer[] ToArray()
        {
            SecBuffer[] buffers = new SecBuffer[cBuffers];
            int         size    = Marshal.SizeOf(typeof(SecBuffer));

            for (int i = 0; i < cBuffers; ++i)
            {
                buffers[i] = (SecBuffer)Marshal.PtrToStructure(pBuffers + (i * size), typeof(SecBuffer));
            }
            return(buffers);
        }
        private bool GenClientContext(byte[] token)
        {
            using (DisposableList list = new DisposableList())
            {
                SecStatusCode result = 0;

                SecBuffer     out_sec_buffer  = list.AddResource(new SecBuffer(SecBufferType.Token, 8192));
                SecBufferDesc out_buffer_desc = list.AddResource(new SecBufferDesc(out_sec_buffer));

                InitializeContextRetFlags flags;
                LargeInteger expiry = new LargeInteger();
                if (token != null)
                {
                    SecBuffer     in_sec_buffer  = list.AddResource(new SecBuffer(SecBufferType.Token, token));
                    SecBufferDesc in_buffer_desc = list.AddResource(new SecBufferDesc(in_sec_buffer));
                    result = SecurityNativeMethods.InitializeSecurityContext(_creds.CredHandle, _context, _target, _req_attributes, 0,
                                                                             _data_rep, in_buffer_desc, 0, _context, out_buffer_desc, out flags, expiry).CheckResult();
                    Flags = flags;
                }
                else
                {
                    result = SecurityNativeMethods.InitializeSecurityContext(_creds.CredHandle, null, _target,
                                                                             _req_attributes, 0, _data_rep, null, 0, _context,
                                                                             out_buffer_desc, out flags, expiry).CheckResult();
                }

                Expiry = expiry.QuadPart;
                Flags  = flags;
                if (result == SecStatusCode.CompleteNeeded || result == SecStatusCode.CompleteAndContinue)
                {
                    SecurityNativeMethods.CompleteAuthToken(_context, out_buffer_desc).CheckResult();
                }

                Token = out_buffer_desc.ToArray()[0].ToArray();
                return(!(result == SecStatusCode.ContinueNeeded || result == SecStatusCode.CompleteAndContinue));
            }
        }
        private bool GenServerContext(
            bool new_context, byte[] token)
        {
            using (DisposableList list = new DisposableList())
            {
                SecBuffer     out_sec_buffer  = list.AddResource(new SecBuffer(SecBufferType.Token, 8192));
                SecBufferDesc out_buffer_desc = list.AddResource(new SecBufferDesc(out_sec_buffer));
                SecBuffer     in_sec_buffer   = list.AddResource(new SecBuffer(SecBufferType.Token, token));
                SecBufferDesc in_buffer_desc  = list.AddResource(new SecBufferDesc(in_sec_buffer));

                LargeInteger  expiry = new LargeInteger();
                SecStatusCode result = SecurityNativeMethods.AcceptSecurityContext(_creds.CredHandle, new_context ? null : _context,
                                                                                   in_buffer_desc, _req_flags, _data_rep, _context, out_buffer_desc, out AcceptContextRetFlags context_attr, expiry).CheckResult();
                Flags  = context_attr;
                Expiry = expiry.QuadPart;
                if (result == SecStatusCode.CompleteNeeded || result == SecStatusCode.CompleteAndContinue)
                {
                    SecurityNativeMethods.CompleteAuthToken(_context, out_buffer_desc).CheckResult();
                }

                Token = out_buffer_desc.ToArray()[0].ToArray();
                return(!(result == SecStatusCode.ContinueNeeded || result == SecStatusCode.CompleteAndContinue));
            }
        }
Example #4
0
 public SecBufferDesc(SecBuffer buffer) : this(new SecBuffer[] { buffer })
 {
 }