예제 #1
0
        public unsafe static void EncryptMessage(
            ref SafeCtxtHandle context,
            ref SecBufferDescEx message,
            uint messageSeqNo,
            void *pfQop)
        {
            try
            {
                message.Pin();

                int error = Secur32Dll.EncryptMessage(
                    ref context._Handle,
                    pfQop,
                    ref message._SecBufferDesc,
                    messageSeqNo);

                if (error != 0)
                {
                    throw new SspiException(error, @"EncryptMessage");
                }
            }
            finally
            {
                message.Free();
            }
        }
예제 #2
0
        public unsafe static SecurityStatus SafeDecryptMessage(
            ref SafeCtxtHandle context,
            ref SecBufferDescEx message,
            uint messageSeqNo,
            void *pfQop)
        {
            try
            {
                message.Pin();

                int error = Secur32Dll.DecryptMessage(
                    ref context._Handle,
                    ref message._SecBufferDesc,
                    messageSeqNo,
                    pfQop);

                return(Convert(error));
            }
            catch
            {
                return(SecurityStatus.SecEUnknowError);
            }
            finally
            {
                message.Free();
            }
        }
예제 #3
0
        public static unsafe void AcquireCredentialsHandle(
            CredentialUse credentialUse,
            SchannelCred authData,
            out SafeCredHandle credential,
            out long expiry)
        {
            CredHandle handle;
            GCHandle   paCredHandle = new GCHandle();

            IntPtr[] paCred = null;

            if (authData.cCreds > 0)
            {
                paCred            = new IntPtr[] { authData.paCreds1 };
                paCredHandle      = GCHandle.Alloc(paCred, GCHandleType.Pinned);
                authData.paCreds1 = paCredHandle.AddrOfPinnedObject();
            }

            try
            {
                int error = Secur32Dll.AcquireCredentialsHandleA(
                    null,
                    Secur32Dll.UnispName,
                    (int)credentialUse,
                    null,
                    &authData,
                    null,
                    null,
                    out handle,
                    out expiry);

                credential = new SafeCredHandle(handle);

                if (error != 0)
                {
                    throw new SspiException(error, @"AcquireCredentialsHandleA");
                }
            }
            finally
            {
                if (paCredHandle.IsAllocated)
                {
                    paCredHandle.Free();
                }

                if (paCred != null)
                {
                    authData.paCreds1 = paCred[0];
                }
            }
        }
예제 #4
0
        public unsafe static void QueryContextAttributes(
            ref SafeCtxtHandle context,
            UlAttribute attribute,
            void *buffer)
        {
            int error = Secur32Dll.QueryContextAttributesA(
                ref context._Handle,
                (uint)attribute,
                buffer);

            if (error != 0)
            {
                throw new SspiException(error, @"QueryContextAttributesA");
            }
        }
예제 #5
0
        public static unsafe SecurityStatus SafeAcceptSecurityContext(
            ref SafeCredHandle credential,
            ref SafeCtxtHandle context,
            ref SecBufferDescEx input,
            int contextReq,
            TargetDataRep targetDataRep,
            ref SafeCtxtHandle newContext,
            ref SecBufferDescEx output,
            out int contextAttr,
            out long timeStamp)
        {
            try
            {
                input.Pin();
                output.Pin();

                fixed(void *fixedContext = &context._Handle)
                {
                    int error = Secur32Dll.AcceptSecurityContext(
                        ref credential._Handle,
                        (context.IsInvalid) ? null : fixedContext,
                        ref input._SecBufferDesc,
                        contextReq,
                        (int)targetDataRep,
                        ref newContext._Handle,
                        ref output._SecBufferDesc,
                        out contextAttr,
                        out timeStamp);

                    return(Convert(error));
                }
            }
            catch
            {
                contextAttr = 0;
                timeStamp   = 0;
                return(SecurityStatus.SecEUnknowError);
            }
            finally
            {
                input.Free();
                output.Free();
            }
        }
예제 #6
0
        public unsafe static SecurityStatus SafeQueryContextAttributes(
            ref SafeCtxtHandle context,
            UlAttribute attribute,
            void *buffer)
        {
            try
            {
                int error = Secur32Dll.QueryContextAttributesA(
                    ref context._Handle,
                    (uint)attribute,
                    buffer);

                return(Convert(error));
            }
            catch
            {
                return(SecurityStatus.SecEUnknowError);
            }
        }
예제 #7
0
 public static SecurityStatus EnumerateSecurityPackages(out int packages, out SafeContextBufferHandle secPkgInfos)
 {
     return(Convert(
                Secur32Dll.EnumerateSecurityPackagesA(out packages, out secPkgInfos)));
 }
예제 #8
0
 override protected bool ReleaseHandle()
 {
     return(Secur32Dll.FreeContextBuffer(handle) == 0);
 }
예제 #9
0
 protected override bool ReleaseHandle()
 {
     return(Secur32Dll.DeleteSecurityContext(ref _Handle) == 0);
 }
예제 #10
0
 protected override bool ReleaseHandle()
 {
     return(Secur32Dll.FreeCredentialsHandle(ref _Handle) == 0);
 }