Esempio n. 1
0
 static extern uint AcquireCredentialsHandle(
     string pszPrincipal,              //SEC_CHAR*
     string pszPackage,                //SEC_CHAR* //"Kerberos","NTLM","Negotiative"
     int fCredentialUse,
     IntPtr PAuthenticationID,         //_LUID AuthenticationID,//pvLogonID, //PLUID
     IntPtr pAuthData,                 //PVOID
     int pGetKeyFn,                    //SEC_GET_KEY_FN
     IntPtr pvGetKeyArgument,          //PVOID
     ref SECURITY_HANDLE phCredential, //SecHandle //PCtxtHandle ref
     ref SECURITY_INTEGER ptsExpiry);  //PTimeStamp //TimeStamp ref
Esempio n. 2
0
 static extern uint InitializeSecurityContext(
     ref SECURITY_HANDLE phCredential, //PCredHandle
     ref SECURITY_HANDLE phContext,    //PCtxtHandle
     string pszTargetName,
     int fContextReq,
     int Reserved1,
     int TargetDataRep,
     ref SecBufferDesc SecBufferDesc,  //PSecBufferDesc SecBufferDesc
     int Reserved2,
     out SECURITY_HANDLE phNewContext, //PCtxtHandle
     out SecBufferDesc pOutput,        //PSecBufferDesc SecBufferDesc
     out uint pfContextAttr,           //managed ulong == 64 bits!!!
     out SECURITY_INTEGER ptsExpiry);  //PTimeStamp
Esempio n. 3
0
        public void EncryptMessage(byte[] message, out byte[] encryptedBuffer)
        {
            encryptedBuffer = null;

            SECURITY_HANDLE EncryptionContext = _hClientContext;

            SecPkgContext_Sizes ContextSizes;

            if (QueryContextAttributes(ref EncryptionContext,
                                       SECPKG_ATTR_SIZES, out ContextSizes) != SEC_E_OK)
            {
                throw new Exception("QueryContextAttribute() failed!!!");
            }

            MultipleSecBufferHelper[] ThisSecHelper = new MultipleSecBufferHelper[]
            {
                new MultipleSecBufferHelper(new byte[ContextSizes.cbSecurityTrailer],
                                            SecBufferType.SECBUFFER_TOKEN),
                new MultipleSecBufferHelper(message, SecBufferType.SECBUFFER_DATA),
                new MultipleSecBufferHelper(new byte[ContextSizes.cbBlockSize],
                                            SecBufferType.SECBUFFER_PADDING)
            };

            SecBufferDesc DescBuffer = new SecBufferDesc(ThisSecHelper);

            try
            {
                if (EncryptMessage(ref EncryptionContext,
                                   SECQOP_WRAP_NO_ENCRYPT, ref DescBuffer, 0) != SEC_E_OK)
                {
                    throw new Exception("EncryptMessage() failed!!!");
                }

                encryptedBuffer = DescBuffer.GetSecBufferByteArray();
            }
            finally
            {
                DescBuffer.Dispose();
            }
        }
Esempio n. 4
0
        public void DecryptMessage(int messageLength, byte[] encryptedBuffer, out byte[] decryptedBuffer)
        {
            decryptedBuffer = null;

            SECURITY_HANDLE DecryptionContext = _hClientContext;

            byte[] EncryptedMessage = new byte[messageLength];
            Array.Copy(encryptedBuffer, 0, EncryptedMessage, 0, messageLength);

            int SecurityTrailerLength = encryptedBuffer.Length - messageLength;

            byte[] SecurityTrailer = new byte[SecurityTrailerLength];
            Array.Copy(encryptedBuffer, messageLength, SecurityTrailer, 0, SecurityTrailerLength);

            MultipleSecBufferHelper[] ThisSecHelper = new MultipleSecBufferHelper[]
            {
                new MultipleSecBufferHelper(EncryptedMessage, SecBufferType.SECBUFFER_DATA),
                new MultipleSecBufferHelper(SecurityTrailer, SecBufferType.SECBUFFER_STREAM)
            };

            SecBufferDesc DescBuffer = new SecBufferDesc(ThisSecHelper);

            try
            {
                uint EncryptionQuality;

                if (DecryptMessage(ref DecryptionContext, ref DescBuffer, 0, out EncryptionQuality) != SEC_E_OK)
                {
                    throw new Exception("DecryptMessage() failed!!!");
                }

                decryptedBuffer = new byte[messageLength];
                Array.Copy(DescBuffer.GetSecBufferByteArray(), 0, decryptedBuffer, 0, messageLength);
            }
            finally
            {
                DescBuffer.Dispose();
            }
        }
Esempio n. 5
0
 static extern uint AcquireCredentialsHandle(
     string pszPrincipal, //SEC_CHAR*
     string pszPackage, //SEC_CHAR* //"Kerberos","NTLM","Negotiative"
     int fCredentialUse,
     IntPtr PAuthenticationID,//_LUID AuthenticationID,//pvLogonID, //PLUID
     IntPtr pAuthData,//PVOID
     int pGetKeyFn, //SEC_GET_KEY_FN
     IntPtr pvGetKeyArgument, //PVOID
     ref SECURITY_HANDLE phCredential, //SecHandle //PCtxtHandle ref
     ref SECURITY_INTEGER ptsExpiry); //PTimeStamp //TimeStamp ref
Esempio n. 6
0
 public static extern int VerifySignature(ref SECURITY_HANDLE phContext, // Context to use
                                          ref SecBufferDesc pMessage,    // Message to sign
                                          uint MessageSeqNo,             // Message Sequence Num.
                                          out uint pfQOP);               // Quality of Protection
Esempio n. 7
0
 public static extern int ImpersonateSecurityContext(ref SECURITY_HANDLE phContext);
Esempio n. 8
0
 public static extern int DecryptMessage(ref SECURITY_HANDLE phContext,
                                         ref SecBufferDesc pMessage,
                                         uint MessageSeqNo,
                                         out uint pfQOP);
Esempio n. 9
0
 public static extern int MakeSignature(ref SECURITY_HANDLE phContext, // Context to use
                                        uint fQOP,                     // Quality of Protection
                                        ref SecBufferDesc pMessage,    // Message to sign
                                        uint MessageSeqNo);            // Message Sequence Num.
Esempio n. 10
0
 public static extern int QueryContextAttributes(ref SECURITY_HANDLE phContext,
                                                 uint ulAttribute,
                                                 out SecPkgContext_Sizes pContextAttributes);
Esempio n. 11
0
 public static extern int EncryptMessage(ref SECURITY_HANDLE phContext,
                                         uint fQOP,          //managed ulong == 64 bits!!!
                                         ref SecBufferDesc pMessage,
                                         uint MessageSeqNo); //managed ulong == 64 bits!!!
Esempio n. 12
0
 static extern uint InitializeSecurityContext(
     ref SECURITY_HANDLE phCredential,//PCredHandle
     ref SECURITY_HANDLE phContext, //PCtxtHandle
     string pszTargetName,
     int fContextReq,
     int Reserved1,
     int TargetDataRep,
     ref SecBufferDesc SecBufferDesc, //PSecBufferDesc SecBufferDesc
     int Reserved2,
     out SECURITY_HANDLE phNewContext, //PCtxtHandle
     out SecBufferDesc pOutput, //PSecBufferDesc SecBufferDesc
     out uint pfContextAttr, //managed ulong == 64 bits!!!
     out SECURITY_INTEGER ptsExpiry); //PTimeStamp
Esempio n. 13
0
 public static extern int ImpersonateSecurityContext(ref SECURITY_HANDLE phContext);
Esempio n. 14
0
 public static extern int QueryContextAttributes(ref SECURITY_HANDLE phContext,
                                                 uint ulAttribute,
                                                 out SecPkgContext_Sizes pContextAttributes);
Esempio n. 15
0
 public static extern int VerifySignature(ref SECURITY_HANDLE phContext,          // Context to use
                                         ref SecBufferDesc pMessage,        // Message to sign
                                         uint MessageSeqNo,            // Message Sequence Num.
                                         out uint pfQOP);      // Quality of Protection
Esempio n. 16
0
 public static extern int MakeSignature(ref SECURITY_HANDLE phContext,          // Context to use
                                         uint fQOP,         // Quality of Protection
                                         ref SecBufferDesc pMessage,        // Message to sign
                                         uint MessageSeqNo);      // Message Sequence Num.
Esempio n. 17
0
 public static extern int DecryptMessage(ref SECURITY_HANDLE phContext,
                                          ref SecBufferDesc pMessage,
                                          uint MessageSeqNo,
                                          out uint pfQOP);
Esempio n. 18
0
 public static extern int EncryptMessage(ref SECURITY_HANDLE phContext,
                                         uint fQOP,        //managed ulong == 64 bits!!!
                                         ref SecBufferDesc pMessage,
                                         uint MessageSeqNo);    //managed ulong == 64 bits!!!