public void InitializeIfNecessary()
 {
     if (!this.m_isInitialized)
     {
         lock (this.m_syncRoot)
         {
             if (!this.m_isInitialized)
             {
                 string cardSpaceImplementationDll = this.GetCardSpaceImplementationDll();
                 this.m_implementationDll = System.IdentityModel.Selectors.SafeLibraryHandle.LoadLibraryW(cardSpaceImplementationDll);
                 if (this.m_implementationDll.IsInvalid)
                 {
                     throw System.IdentityModel.Selectors.NativeMethods.ThrowWin32ExceptionWithContext(new Win32Exception(), cardSpaceImplementationDll);
                 }
                 try
                 {
                     IntPtr procAddressWrapper = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "CloseCryptoHandle");
                     this.m_csShimCloseCryptoHandle = (CsV2CloseCryptoHandle)Marshal.GetDelegateForFunctionPointer(procAddressWrapper, typeof(CsV2CloseCryptoHandle));
                     IntPtr ptr = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "Decrypt");
                     this.m_csShimDecrypt = (CsV2Decrypt)Marshal.GetDelegateForFunctionPointer(ptr, typeof(CsV2Decrypt));
                     IntPtr ptr3 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "Encrypt");
                     this.m_csShimEncrypt = (CsV2Encrypt)Marshal.GetDelegateForFunctionPointer(ptr3, typeof(CsV2Encrypt));
                     IntPtr ptr4 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "FreeToken");
                     this.m_csShimFreeToken = (CsV2FreeToken)Marshal.GetDelegateForFunctionPointer(ptr4, typeof(CsV2FreeToken));
                     IntPtr ptr5 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "GenerateDerivedKey");
                     this.m_csShimGenerateDerivedKey = (CsV2GenerateDerivedKey)Marshal.GetDelegateForFunctionPointer(ptr5, typeof(CsV2GenerateDerivedKey));
                     IntPtr ptr6 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "GetCryptoTransform");
                     this.m_csShimGetCryptoTransform = (CsV2GetCryptoTransform)Marshal.GetDelegateForFunctionPointer(ptr6, typeof(CsV2GetCryptoTransform));
                     IntPtr ptr7 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "GetKeyedHash");
                     this.m_csShimGetKeyedHash = (CsV2GetKeyedHash)Marshal.GetDelegateForFunctionPointer(ptr7, typeof(CsV2GetKeyedHash));
                     IntPtr ptr8 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "GetToken");
                     this.m_csShimGetToken = (CsV2GetToken)Marshal.GetDelegateForFunctionPointer(ptr8, typeof(CsV2GetToken));
                     IntPtr ptr9 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "HashCore");
                     this.m_csShimHashCore = (CsV2HashCore)Marshal.GetDelegateForFunctionPointer(ptr9, typeof(CsV2HashCore));
                     IntPtr ptr10 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "HashFinal");
                     this.m_csShimHashFinal = (CsV2HashFinal)Marshal.GetDelegateForFunctionPointer(ptr10, typeof(CsV2HashFinal));
                     IntPtr ptr11 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "ImportInformationCard");
                     this.m_csShimImportInformationCard = (CsV2ImportInformationCard)Marshal.GetDelegateForFunctionPointer(ptr11, typeof(CsV2ImportInformationCard));
                     IntPtr ptr12 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "ManageCardSpace");
                     this.m_csShimManageCardSpace = (CsV2ManageCardSpace)Marshal.GetDelegateForFunctionPointer(ptr12, typeof(CsV2ManageCardSpace));
                     IntPtr ptr13 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "SignHash");
                     this.m_csShimSignHash = (CsV2SignHash)Marshal.GetDelegateForFunctionPointer(ptr13, typeof(CsV2SignHash));
                     IntPtr ptr14 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "TransformBlock");
                     this.m_csShimTransformBlock = (CsV2TransformBlock)Marshal.GetDelegateForFunctionPointer(ptr14, typeof(CsV2TransformBlock));
                     IntPtr ptr15 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "TransformFinalBlock");
                     this.m_csShimTransformFinalBlock = (CsV2TransformFinalBlock)Marshal.GetDelegateForFunctionPointer(ptr15, typeof(CsV2TransformFinalBlock));
                     IntPtr ptr16 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "VerifyHash");
                     this.m_csShimVerifyHash = (CsV2VerifyHash)Marshal.GetDelegateForFunctionPointer(ptr16, typeof(CsV2VerifyHash));
                 }
                 catch (Win32Exception)
                 {
                     InfoCardTrace.Assert(!this.m_isInitialized, "If an exception occurred, we expect this to be false", new object[0]);
                     throw;
                 }
                 this.m_isInitialized = true;
             }
         }
     }
 }
예제 #2
0
        //
        // GetBrowserToken not required because that is accomplished via Pheonix bit etc. (not exposed thru
        // managed interface).
        //

        //
        // Summary:
        // Performs initialization of the CardSpaceShim if necessary.
        // The v1 service will only allow one request from the user,
        // however locking anyway in case we change our behavior in v2.
        //
        public void InitializeIfNecessary()
        {
            if (!m_isInitialized)
            {
                lock (m_syncRoot)
                {
                    if (!m_isInitialized)
                    {
                        string implDllPath = GetCardSpaceImplementationDll();

                        m_implementationDll = SafeLibraryHandle.LoadLibraryW(implDllPath);
                        if (m_implementationDll.IsInvalid)
                        {
                            throw NativeMethods.ThrowWin32ExceptionWithContext(new Win32Exception(), implDllPath);
                        }

                        try
                        {
                            //
                            // Functions are listed in alphabetical order
                            //

                            IntPtr procaddr1 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "CloseCryptoHandle");
                            m_csShimCloseCryptoHandle =
                                (CsV2CloseCryptoHandle)Marshal.GetDelegateForFunctionPointer(
                                    procaddr1, typeof(CsV2CloseCryptoHandle));

                            IntPtr procaddr2 = NativeMethods.GetProcAddressWrapper(
                                m_implementationDll, "Decrypt");
                            m_csShimDecrypt =
                                (CsV2Decrypt)Marshal.GetDelegateForFunctionPointer(
                                    procaddr2, typeof(CsV2Decrypt));

                            IntPtr procaddr3 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "Encrypt");
                            m_csShimEncrypt =
                                (CsV2Encrypt)Marshal.GetDelegateForFunctionPointer(
                                    procaddr3, typeof(CsV2Encrypt));

                            IntPtr procaddr4 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "FreeToken");
                            m_csShimFreeToken =
                                (CsV2FreeToken)Marshal.GetDelegateForFunctionPointer(
                                    procaddr4, typeof(CsV2FreeToken));

                            IntPtr procaddr5 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "GenerateDerivedKey");
                            m_csShimGenerateDerivedKey =
                                (CsV2GenerateDerivedKey)Marshal.GetDelegateForFunctionPointer(
                                    procaddr5, typeof(CsV2GenerateDerivedKey));

                            IntPtr procaddr6 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "GetCryptoTransform");
                            m_csShimGetCryptoTransform =
                                (CsV2GetCryptoTransform)Marshal.GetDelegateForFunctionPointer(
                                    procaddr6, typeof(CsV2GetCryptoTransform));

                            IntPtr procaddr7 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "GetKeyedHash");
                            m_csShimGetKeyedHash =
                                (CsV2GetKeyedHash)Marshal.GetDelegateForFunctionPointer(
                                    procaddr7, typeof(CsV2GetKeyedHash));

                            IntPtr procaddr8 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "GetToken");
                            m_csShimGetToken =
                                (CsV2GetToken)Marshal.GetDelegateForFunctionPointer(
                                    procaddr8, typeof(CsV2GetToken));

                            IntPtr procaddr9 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "HashCore");
                            m_csShimHashCore =
                                (CsV2HashCore)Marshal.GetDelegateForFunctionPointer(
                                    procaddr9, typeof(CsV2HashCore));

                            IntPtr procaddr10 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "HashFinal");
                            m_csShimHashFinal =
                                (CsV2HashFinal)Marshal.GetDelegateForFunctionPointer(
                                    procaddr10, typeof(CsV2HashFinal));

                            IntPtr procaddr11 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "ImportInformationCard");
                            m_csShimImportInformationCard =
                                (CsV2ImportInformationCard)Marshal.GetDelegateForFunctionPointer(
                                    procaddr11, typeof(CsV2ImportInformationCard));

                            IntPtr procaddr12 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "ManageCardSpace");
                            m_csShimManageCardSpace =
                                (CsV2ManageCardSpace)Marshal.GetDelegateForFunctionPointer(
                                    procaddr12, typeof(CsV2ManageCardSpace));

                            IntPtr procaddr13 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "SignHash");
                            m_csShimSignHash =
                                (CsV2SignHash)Marshal.GetDelegateForFunctionPointer(
                                    procaddr13, typeof(CsV2SignHash));

                            IntPtr procaddr14 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "TransformBlock");
                            m_csShimTransformBlock =
                                (CsV2TransformBlock)Marshal.GetDelegateForFunctionPointer(
                                    procaddr14, typeof(CsV2TransformBlock));

                            IntPtr procaddr15 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "TransformFinalBlock");
                            m_csShimTransformFinalBlock =
                                (CsV2TransformFinalBlock)Marshal.GetDelegateForFunctionPointer(
                                    procaddr15, typeof(CsV2TransformFinalBlock));


                            IntPtr procaddr16 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "VerifyHash");
                            m_csShimVerifyHash =
                                (CsV2VerifyHash)Marshal.GetDelegateForFunctionPointer(
                                    procaddr16, typeof(CsV2VerifyHash));
                        }
                        catch (Win32Exception)
                        {
                            //
                            // NB: IDT.ThrowHelperError would have logged for the Win32Exception
                            //
                            IDT.Assert(!m_isInitialized, "If an exception occurred, we expect this to be false");
                            throw;
                        }

                        m_isInitialized = true;
                    }
                }
            }
        }
예제 #3
0
        //
        // GetBrowserToken not required because that is accomplished via Pheonix bit etc. (not exposed thru
        // managed interface).
        // 

        //
        // Summary:
        // Performs initialization of the CardSpaceShim if necessary.
        // The v1 service will only allow one request from the user,
        // however locking anyway in case we change our behavior in v2.
        //
        public void InitializeIfNecessary()
        {
            if (!m_isInitialized)
            {
                lock (m_syncRoot)
                {
                    if (!m_isInitialized)
                    {
                        string implDllPath = GetCardSpaceImplementationDll();

                        m_implementationDll = SafeLibraryHandle.LoadLibraryW(implDllPath);
                        if (m_implementationDll.IsInvalid)
                        {
                            throw NativeMethods.ThrowWin32ExceptionWithContext(new Win32Exception(), implDllPath);
                        }

                        try
                        {
                            //
                            // Functions are listed in alphabetical order
                            //

                            IntPtr procaddr1 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "CloseCryptoHandle");
                            m_csShimCloseCryptoHandle =
                                (CsV2CloseCryptoHandle)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr1, typeof(CsV2CloseCryptoHandle));

                            IntPtr procaddr2 = NativeMethods.GetProcAddressWrapper(
                                m_implementationDll, "Decrypt");
                            m_csShimDecrypt =
                                (CsV2Decrypt)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr2, typeof(CsV2Decrypt));

                            IntPtr procaddr3 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "Encrypt");
                            m_csShimEncrypt =
                                (CsV2Encrypt)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr3, typeof(CsV2Encrypt));

                            IntPtr procaddr4 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "FreeToken");
                            m_csShimFreeToken =
                                (CsV2FreeToken)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr4, typeof(CsV2FreeToken));

                            IntPtr procaddr5 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "GenerateDerivedKey");
                            m_csShimGenerateDerivedKey =
                                (CsV2GenerateDerivedKey)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr5, typeof(CsV2GenerateDerivedKey));

                            IntPtr procaddr6 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "GetCryptoTransform");
                            m_csShimGetCryptoTransform =
                                (CsV2GetCryptoTransform)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr6, typeof(CsV2GetCryptoTransform));

                            IntPtr procaddr7 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "GetKeyedHash");
                            m_csShimGetKeyedHash =
                                (CsV2GetKeyedHash)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr7, typeof(CsV2GetKeyedHash));

                            IntPtr procaddr8 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "GetToken");
                            m_csShimGetToken =
                                (CsV2GetToken)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr8, typeof(CsV2GetToken));

                            IntPtr procaddr9 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "HashCore");
                            m_csShimHashCore =
                                (CsV2HashCore)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr9, typeof(CsV2HashCore));

                            IntPtr procaddr10 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "HashFinal");
                            m_csShimHashFinal =
                                (CsV2HashFinal)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr10, typeof(CsV2HashFinal));

                            IntPtr procaddr11 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "ImportInformationCard");
                            m_csShimImportInformationCard =
                                (CsV2ImportInformationCard)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr11, typeof(CsV2ImportInformationCard));

                            IntPtr procaddr12 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "ManageCardSpace");
                            m_csShimManageCardSpace =
                                (CsV2ManageCardSpace)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr12, typeof(CsV2ManageCardSpace));

                            IntPtr procaddr13 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "SignHash");
                            m_csShimSignHash =
                                (CsV2SignHash)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr13, typeof(CsV2SignHash));

                            IntPtr procaddr14 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "TransformBlock");
                            m_csShimTransformBlock =
                                (CsV2TransformBlock)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr14, typeof(CsV2TransformBlock));

                            IntPtr procaddr15 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "TransformFinalBlock");
                            m_csShimTransformFinalBlock =
                                (CsV2TransformFinalBlock)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr15, typeof(CsV2TransformFinalBlock));


                            IntPtr procaddr16 = NativeMethods.GetProcAddressWrapper(m_implementationDll, "VerifyHash");
                            m_csShimVerifyHash =
                                (CsV2VerifyHash)Marshal.GetDelegateForFunctionPointer(
                                                            procaddr16, typeof(CsV2VerifyHash));

                        }
                        catch (Win32Exception)
                        {
                            //
                            // NB: IDT.ThrowHelperError would have logged for the Win32Exception
                            //
                            IDT.Assert(!m_isInitialized, "If an exception occurred, we expect this to be false");
                            throw;
                        }

                        m_isInitialized = true;
                    }
                }
            }
        }
 public void InitializeIfNecessary()
 {
     if (!this.m_isInitialized)
     {
         lock (this.m_syncRoot)
         {
             if (!this.m_isInitialized)
             {
                 string cardSpaceImplementationDll = this.GetCardSpaceImplementationDll();
                 this.m_implementationDll = System.IdentityModel.Selectors.SafeLibraryHandle.LoadLibraryW(cardSpaceImplementationDll);
                 if (this.m_implementationDll.IsInvalid)
                 {
                     throw System.IdentityModel.Selectors.NativeMethods.ThrowWin32ExceptionWithContext(new Win32Exception(), cardSpaceImplementationDll);
                 }
                 try
                 {
                     IntPtr procAddressWrapper = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "CloseCryptoHandle");
                     this.m_csShimCloseCryptoHandle = (CsV2CloseCryptoHandle) Marshal.GetDelegateForFunctionPointer(procAddressWrapper, typeof(CsV2CloseCryptoHandle));
                     IntPtr ptr = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "Decrypt");
                     this.m_csShimDecrypt = (CsV2Decrypt) Marshal.GetDelegateForFunctionPointer(ptr, typeof(CsV2Decrypt));
                     IntPtr ptr3 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "Encrypt");
                     this.m_csShimEncrypt = (CsV2Encrypt) Marshal.GetDelegateForFunctionPointer(ptr3, typeof(CsV2Encrypt));
                     IntPtr ptr4 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "FreeToken");
                     this.m_csShimFreeToken = (CsV2FreeToken) Marshal.GetDelegateForFunctionPointer(ptr4, typeof(CsV2FreeToken));
                     IntPtr ptr5 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "GenerateDerivedKey");
                     this.m_csShimGenerateDerivedKey = (CsV2GenerateDerivedKey) Marshal.GetDelegateForFunctionPointer(ptr5, typeof(CsV2GenerateDerivedKey));
                     IntPtr ptr6 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "GetCryptoTransform");
                     this.m_csShimGetCryptoTransform = (CsV2GetCryptoTransform) Marshal.GetDelegateForFunctionPointer(ptr6, typeof(CsV2GetCryptoTransform));
                     IntPtr ptr7 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "GetKeyedHash");
                     this.m_csShimGetKeyedHash = (CsV2GetKeyedHash) Marshal.GetDelegateForFunctionPointer(ptr7, typeof(CsV2GetKeyedHash));
                     IntPtr ptr8 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "GetToken");
                     this.m_csShimGetToken = (CsV2GetToken) Marshal.GetDelegateForFunctionPointer(ptr8, typeof(CsV2GetToken));
                     IntPtr ptr9 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "HashCore");
                     this.m_csShimHashCore = (CsV2HashCore) Marshal.GetDelegateForFunctionPointer(ptr9, typeof(CsV2HashCore));
                     IntPtr ptr10 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "HashFinal");
                     this.m_csShimHashFinal = (CsV2HashFinal) Marshal.GetDelegateForFunctionPointer(ptr10, typeof(CsV2HashFinal));
                     IntPtr ptr11 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "ImportInformationCard");
                     this.m_csShimImportInformationCard = (CsV2ImportInformationCard) Marshal.GetDelegateForFunctionPointer(ptr11, typeof(CsV2ImportInformationCard));
                     IntPtr ptr12 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "ManageCardSpace");
                     this.m_csShimManageCardSpace = (CsV2ManageCardSpace) Marshal.GetDelegateForFunctionPointer(ptr12, typeof(CsV2ManageCardSpace));
                     IntPtr ptr13 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "SignHash");
                     this.m_csShimSignHash = (CsV2SignHash) Marshal.GetDelegateForFunctionPointer(ptr13, typeof(CsV2SignHash));
                     IntPtr ptr14 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "TransformBlock");
                     this.m_csShimTransformBlock = (CsV2TransformBlock) Marshal.GetDelegateForFunctionPointer(ptr14, typeof(CsV2TransformBlock));
                     IntPtr ptr15 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "TransformFinalBlock");
                     this.m_csShimTransformFinalBlock = (CsV2TransformFinalBlock) Marshal.GetDelegateForFunctionPointer(ptr15, typeof(CsV2TransformFinalBlock));
                     IntPtr ptr16 = System.IdentityModel.Selectors.NativeMethods.GetProcAddressWrapper(this.m_implementationDll, "VerifyHash");
                     this.m_csShimVerifyHash = (CsV2VerifyHash) Marshal.GetDelegateForFunctionPointer(ptr16, typeof(CsV2VerifyHash));
                 }
                 catch (Win32Exception)
                 {
                     InfoCardTrace.Assert(!this.m_isInitialized, "If an exception occurred, we expect this to be false", new object[0]);
                     throw;
                 }
                 this.m_isInitialized = true;
             }
         }
     }
 }