public InfoCardKeyedHashAlgorithm(SymmetricCryptoHandle cryptoHandle)
        {
            InternalRefCountedHandle nativeHashHandle = null;

            try
            {
                int status = CardSpaceSelector.GetShim().m_csShimGetKeyedHash(cryptoHandle.InternalHandle, out nativeHashHandle);
                if (status != 0)
                {
                    InfoCardTrace.CloseInvalidOutSafeHandle(nativeHashHandle);
                    ExceptionHelper.ThrowIfCardSpaceException(status);
                    throw InfoCardTrace.ThrowHelperError(new Win32Exception(status));
                }
                this.m_cryptoHandle = (HashCryptoHandle)CryptoHandle.Create(nativeHashHandle);
                this.m_param        = (RpcHashCryptoParameters)this.m_cryptoHandle.Parameters;
            }
            catch
            {
                if (this.m_cryptoHandle != null)
                {
                    this.m_cryptoHandle.Dispose();
                }
                throw;
            }
        }
 private void ThrowIfInvalid()
 {
     if (this.IsInvalid)
     {
         throw InfoCardTrace.ThrowHelperError(new ObjectDisposedException("InternalRefCountedHandle"));
     }
 }
 public override byte[] GenerateDerivedKey(string algorithmUri, byte[] label, byte[] nonce, int derivedKeyLength, int offset)
 {
     if (!this.IsSupportedAlgorithm(algorithmUri))
     {
         throw InfoCardTrace.ThrowHelperError(new NotSupportedException(Microsoft.InfoCards.SR.GetString("ClientUnsupportedCryptoAlgorithm", new object[] { algorithmUri })));
     }
     byte[] destination = null;
     using (HGlobalSafeHandle handle = HGlobalSafeHandle.Construct(label.Length))
     {
         using (HGlobalSafeHandle handle2 = HGlobalSafeHandle.Construct(nonce.Length))
         {
             GlobalAllocSafeHandle pDerivedKey = null;
             int cbDerivedKey = 0;
             Marshal.Copy(label, 0, handle.DangerousGetHandle(), label.Length);
             Marshal.Copy(nonce, 0, handle2.DangerousGetHandle(), nonce.Length);
             int error = CardSpaceSelector.GetShim().m_csShimGenerateDerivedKey(this.m_cryptoHandle.InternalHandle, label.Length, handle, nonce.Length, handle2, derivedKeyLength, offset, algorithmUri, out cbDerivedKey, out pDerivedKey);
             if (error != 0)
             {
                 throw InfoCardTrace.ThrowHelperError(new Win32Exception(error));
             }
             pDerivedKey.Length = cbDerivedKey;
             destination        = new byte[pDerivedKey.Length];
             using (pDerivedKey)
             {
                 Marshal.Copy(pDerivedKey.DangerousGetHandle(), destination, 0, pDerivedKey.Length);
             }
             return(destination);
         }
     }
 }
        private string GetV2ImplementationDllPath()
        {
            string str = string.Empty;

            using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"software\microsoft\cardspace\v1"))
            {
                if (key != null)
                {
                    str = (string)key.GetValue("ImplementationDLL");
                    if (!string.IsNullOrEmpty(str))
                    {
                        string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), str + ".dll");
                        if (!this.IsSafeFile(str) || !File.Exists(path))
                        {
                            str = string.Empty;
                        }
                    }
                }
            }
            if (string.IsNullOrEmpty(str))
            {
                str = "infocardapi2";
            }
            InfoCardTrace.Assert(!string.IsNullOrEmpty(str), "v2AndAboveImplementationDll should not be empty", new object[0]);
            return(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), str + ".dll"));
        }
        public byte[] SignHash(byte[] hash, string hashAlgOid)
        {
            InfoCardTrace.ThrowInvalidArgumentConditional((hash == null) || (0 == hash.Length), "hash");
            InfoCardTrace.ThrowInvalidArgumentConditional(string.IsNullOrEmpty(hashAlgOid), "hashAlgOid");
            int pcbSig = 0;
            GlobalAllocSafeHandle pSig = null;

            using (HGlobalSafeHandle handle2 = HGlobalSafeHandle.Construct(hash.Length))
            {
                using (HGlobalSafeHandle handle3 = HGlobalSafeHandle.Construct(hashAlgOid))
                {
                    Marshal.Copy(hash, 0, handle2.DangerousGetHandle(), hash.Length);
                    RuntimeHelpers.PrepareConstrainedRegions();
                    int status = CardSpaceSelector.GetShim().m_csShimSignHash(this.m_cryptoHandle.InternalHandle, hash.Length, handle2, handle3, out pcbSig, out pSig);
                    if (status != 0)
                    {
                        ExceptionHelper.ThrowIfCardSpaceException(status);
                        throw InfoCardTrace.ThrowHelperError(new Win32Exception(status));
                    }
                    pSig.Length = pcbSig;
                    byte[] destination = DiagnosticUtility.Utility.AllocateByteArray(pSig.Length);
                    using (pSig)
                    {
                        Marshal.Copy(pSig.DangerousGetHandle(), destination, 0, pSig.Length);
                    }
                    return(destination);
                }
            }
        }
        public byte[] Decrypt(byte[] inData, bool fAOEP)
        {
            GlobalAllocSafeHandle pOutData = null;

            byte[] buffer;
            int    pcbOutData = 0;

            InfoCardTrace.ThrowInvalidArgumentConditional(null == inData, "indata");
            using (HGlobalSafeHandle handle2 = HGlobalSafeHandle.Construct(inData.Length))
            {
                Marshal.Copy(inData, 0, handle2.DangerousGetHandle(), inData.Length);
                int status = CardSpaceSelector.GetShim().m_csShimDecrypt(this.m_cryptoHandle.InternalHandle, fAOEP, inData.Length, handle2, out pcbOutData, out pOutData);
                if (status != 0)
                {
                    ExceptionHelper.ThrowIfCardSpaceException(status);
                    throw InfoCardTrace.ThrowHelperError(new Win32Exception(status));
                }
                pOutData.Length = pcbOutData;
                buffer          = DiagnosticUtility.Utility.AllocateByteArray(pOutData.Length);
                using (pOutData)
                {
                    Marshal.Copy(pOutData.DangerousGetHandle(), buffer, 0, pOutData.Length);
                }
            }
            return(buffer);
        }
        public bool VerifyHash(byte[] hash, string hashAlgOid, byte[] sig)
        {
            InfoCardTrace.ThrowInvalidArgumentConditional((hash == null) || (0 == hash.Length), "hash");
            InfoCardTrace.ThrowInvalidArgumentConditional(string.IsNullOrEmpty(hashAlgOid), "hashAlgOid");
            InfoCardTrace.ThrowInvalidArgumentConditional((sig == null) || (0 == sig.Length), "sig");
            bool verified = false;

            using (HGlobalSafeHandle handle = HGlobalSafeHandle.Construct(hash.Length))
            {
                using (HGlobalSafeHandle handle2 = HGlobalSafeHandle.Construct(hashAlgOid))
                {
                    Marshal.Copy(hash, 0, handle.DangerousGetHandle(), hash.Length);
                    int status = 0;
                    using (HGlobalSafeHandle handle3 = HGlobalSafeHandle.Construct(sig.Length))
                    {
                        Marshal.Copy(sig, 0, handle3.DangerousGetHandle(), sig.Length);
                        status = CardSpaceSelector.GetShim().m_csShimVerifyHash(this.m_cryptoHandle.InternalHandle, hash.Length, handle, handle2, sig.Length, handle3, out verified);
                    }
                    if (status != 0)
                    {
                        ExceptionHelper.ThrowIfCardSpaceException(status);
                        throw InfoCardTrace.ThrowHelperError(new Win32Exception(status));
                    }
                }
            }
            return(verified);
        }
            public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
            {
                GlobalAllocSafeHandle pOutData = null;

                byte[] buffer;
                int    cbOutData = 0;

                using (HGlobalSafeHandle handle2 = HGlobalSafeHandle.Construct(inputCount))
                {
                    Marshal.Copy(inputBuffer, inputOffset, handle2.DangerousGetHandle(), inputCount);
                    int status = CardSpaceSelector.GetShim().m_csShimTransformFinalBlock(this.m_transCryptoHandle.InternalHandle, inputCount, handle2, out cbOutData, out pOutData);
                    if (status != 0)
                    {
                        ExceptionHelper.ThrowIfCardSpaceException(status);
                        throw InfoCardTrace.ThrowHelperError(new Win32Exception(status));
                    }
                    pOutData.Length = cbOutData;
                    buffer          = DiagnosticUtility.Utility.AllocateByteArray(pOutData.Length);
                    using (pOutData)
                    {
                        Marshal.Copy(pOutData.DangerousGetHandle(), buffer, 0, pOutData.Length);
                    }
                }
                return(buffer);
            }
 protected override void HashCore(byte[] array, int ibStart, int cbSize)
 {
     if (this.m_cachedBlock != null)
     {
         using (HGlobalSafeHandle handle = null)
         {
             if (this.m_cachedBlock.Length != 0)
             {
                 handle = HGlobalSafeHandle.Construct(this.m_cachedBlock.Length);
                 Marshal.Copy(this.m_cachedBlock, 0, handle.DangerousGetHandle(), this.m_cachedBlock.Length);
             }
             int status = CardSpaceSelector.GetShim().m_csShimHashCore(this.m_cryptoHandle.InternalHandle, this.m_cachedBlock.Length, (handle != null) ? handle : HGlobalSafeHandle.Construct());
             if (status != 0)
             {
                 ExceptionHelper.ThrowIfCardSpaceException(status);
                 throw InfoCardTrace.ThrowHelperError(new Win32Exception(status));
             }
         }
     }
     if (this.m_cachedBlock != null)
     {
         Array.Clear(this.m_cachedBlock, 0, this.m_cachedBlock.Length);
     }
     this.m_cachedBlock = DiagnosticUtility.Utility.AllocateByteArray(cbSize);
     Array.Copy(array, ibStart, this.m_cachedBlock, 0, cbSize);
 }
 protected void ThrowIfDisposed()
 {
     if (this.m_isDisposed)
     {
         throw InfoCardTrace.ThrowHelperError(new ObjectDisposedException(Microsoft.InfoCards.SR.GetString("ClientCryptoSessionDisposed")));
     }
 }
 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;
             }
         }
     }
 }
示例#12
0
 public InternalPolicyElement(CardSpacePolicyElement element)
 {
     if (element.Target == null)
     {
         throw InfoCardTrace.ThrowHelperArgumentNull("PolicyElement.Target");
     }
     this.m_element = element;
 }
        public override SymmetricAlgorithm GetSymmetricAlgorithm(string algorithmUri)
        {
            string str;

            if (((str = algorithmUri) == null) || (str != "http://www.w3.org/2001/04/xmlenc#aes128-cbc"))
            {
                throw InfoCardTrace.ThrowHelperError(new NotSupportedException(Microsoft.InfoCards.SR.GetString("ClientUnsupportedCryptoAlgorithm", new object[] { algorithmUri })));
            }
            return(new InfoCardSymmetricAlgorithm(this.m_cryptoHandle));
        }
        public override KeyedHashAlgorithm GetKeyedHashAlgorithm(string algorithmUri)
        {
            string str;

            if (((str = algorithmUri) == null) || (str != "http://www.w3.org/2000/09/xmldsig#hmac-sha1"))
            {
                throw InfoCardTrace.ThrowHelperError(new NotSupportedException(Microsoft.InfoCards.SR.GetString("ClientUnsupportedCryptoAlgorithm", new object[] { algorithmUri })));
            }
            return(new InfoCardKeyedHashAlgorithm(this.m_cryptoHandle));
        }
        public override AsymmetricSignatureFormatter GetSignatureFormatter(string algorithmUri)
        {
            string str;

            if (((str = algorithmUri) == null) || (str != "http://www.w3.org/2000/09/xmldsig#rsa-sha1"))
            {
                throw InfoCardTrace.ThrowHelperError(new NotSupportedException(Microsoft.InfoCards.SR.GetString("ClientUnsupportedCryptoAlgorithm", new object[] { algorithmUri })));
            }
            return(new InfoCardRSAPKCS1SignatureFormatter(this.m_rsa));
        }
        public override HashAlgorithm GetHashAlgorithmForSignature(string algorithmUri)
        {
            string str;

            if (((str = algorithmUri) == null) || (str != "http://www.w3.org/2000/09/xmldsig#rsa-sha1"))
            {
                throw InfoCardTrace.ThrowHelperError(new NotSupportedException(Microsoft.InfoCards.SR.GetString("ClientUnsupportedCryptoAlgorithm", new object[] { algorithmUri })));
            }
            return(new SHA1Managed());
        }
        public override AsymmetricAlgorithm GetAsymmetricAlgorithm(string algorithmUri, bool privateKey)
        {
            string str;

            if (((str = algorithmUri) == null) || (((str != "http://www.w3.org/2000/09/xmldsig#rsa-sha1") && (str != "http://www.w3.org/2001/04/xmlenc#rsa-1_5")) && (str != "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p")))
            {
                throw InfoCardTrace.ThrowHelperError(new NotSupportedException(Microsoft.InfoCards.SR.GetString("ClientUnsupportedCryptoAlgorithm", new object[] { algorithmUri })));
            }
            return(this.m_rsa);
        }
示例#18
0
        public static void Manage()
        {
            int status = GetShim().m_csShimManageCardSpace();

            if (status != 0)
            {
                ExceptionHelper.ThrowIfCardSpaceException(status);
                throw InfoCardTrace.ThrowHelperError(new CardSpaceException(Microsoft.InfoCards.SR.GetString("ClientAPIInfocardError")));
            }
        }
示例#19
0
 public CardSpacePolicyElement(XmlElement target, XmlElement issuer, Collection <XmlElement> parameters, Uri privacyNoticeLink, int privacyNoticeVersion, bool isManagedIssuer)
 {
     InfoCardTrace.ThrowInvalidArgumentConditional((privacyNoticeVersion == 0) && (null != privacyNoticeLink), "privacyNoticeVersion");
     InfoCardTrace.ThrowInvalidArgumentConditional((privacyNoticeVersion != 0) && (null == privacyNoticeLink), "privacyNoticeLink");
     this.m_target              = target;
     this.m_issuer              = issuer;
     this.m_parameters          = parameters;
     this.m_policyNoticeLink    = privacyNoticeLink;
     this.m_policyNoticeVersion = privacyNoticeVersion;
     this.m_isManagedIssuer     = isManagedIssuer;
 }
        public override int GetIVSize(string algorithmUri)
        {
            string str;

            if (((str = algorithmUri) == null) || (str != "http://www.w3.org/2001/04/xmlenc#aes128-cbc"))
            {
                throw InfoCardTrace.ThrowHelperError(new NotSupportedException(Microsoft.InfoCards.SR.GetString("ClientUnsupportedCryptoAlgorithm", new object[] { algorithmUri })));
            }
            RpcSymmetricCryptoParameters parameters = (RpcSymmetricCryptoParameters)this.m_cryptoHandle.Parameters;

            return(parameters.blockSize);
        }
        private string GetCardSpaceImplementationDll()
        {
            string path = this.GetV2ImplementationDllPath();

            if (!File.Exists(path))
            {
                path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "infocardapi.dll");
                if (!File.Exists(path))
                {
                    throw InfoCardTrace.ThrowHelperError(new CardSpaceException(Microsoft.InfoCards.SR.GetString("ClientAPIServiceNotInstalledError")));
                }
            }
            return(path);
        }
示例#22
0
        internal static string XmlToString(IEnumerable <XmlElement> xml)
        {
            StringBuilder builder = new StringBuilder();

            foreach (XmlElement element in xml)
            {
                if (element == null)
                {
                    throw InfoCardTrace.ThrowHelperError(new ArgumentException(Microsoft.InfoCards.SR.GetString("ClientAPIInvalidPolicy")));
                }
                builder.Append(element.OuterXml);
            }
            return(builder.ToString());
        }
示例#23
0
        public static void Import(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw InfoCardTrace.ThrowHelperArgumentNull("fileName");
            }
            int status = GetShim().m_csShimImportInformationCard(fileName);

            if (status != 0)
            {
                ExceptionHelper.ThrowIfCardSpaceException(status);
                throw InfoCardTrace.ThrowHelperError(new CardSpaceException(Microsoft.InfoCards.SR.GetString("ClientAPIInfocardError")));
            }
        }
        public override ICryptoTransform GetEncryptionTransform(string algorithmUri, byte[] iv)
        {
            string str;

            if (((str = algorithmUri) != null) && (str == "http://www.w3.org/2001/04/xmlenc#aes128-cbc"))
            {
                using (InfoCardSymmetricAlgorithm algorithm = new InfoCardSymmetricAlgorithm(this.m_cryptoHandle))
                {
                    algorithm.IV = iv;
                    return(algorithm.CreateEncryptor());
                }
            }
            throw InfoCardTrace.ThrowHelperError(new NotSupportedException(Microsoft.InfoCards.SR.GetString("ClientUnsupportedCryptoAlgorithm", new object[] { algorithmUri })));
        }
        public override byte[] EncryptKey(string algorithmUri, byte[] keyData)
        {
            AsymmetricKeyExchangeFormatter formatter;

            switch (algorithmUri)
            {
            case "http://www.w3.org/2001/04/xmlenc#rsa-1_5":
                formatter = new InfoCardRSAPKCS1KeyExchangeFormatter(this.m_rsa);
                return(formatter.CreateKeyExchange(keyData));

            case "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p":
                formatter = new InfoCardRSAOAEPKeyExchangeFormatter(this.m_rsa);
                return(formatter.CreateKeyExchange(keyData));
            }
            throw InfoCardTrace.ThrowHelperError(new NotSupportedException(Microsoft.InfoCards.SR.GetString("ClientUnsupportedCryptoAlgorithm", new object[] { algorithmUri })));
        }
示例#26
0
        public static void ThrowIfCardSpaceException(int status)
        {
            switch (status)
            {
            case -1073413888:
                throw InfoCardTrace.ThrowHelperError(new CardSpaceException(Microsoft.InfoCards.SR.GetString("ClientAPIInfocardError")));

            case -1073413887:
            case -1073413886:
            case -1073413876:
            case -1073413873:
            case -1073413872:
            case -1073413868:
            case -1073413867:
                return;

            case -1073413885:
                throw InfoCardTrace.ThrowHelperError(new IdentityValidationException(Microsoft.InfoCards.SR.GetString("ClientAPIInvalidIdentity")));

            case -1073413884:
                throw InfoCardTrace.ThrowHelperError(new CardSpaceException(Microsoft.InfoCards.SR.GetString("ClientAPICannotImport")));

            case -1073413877:
                throw InfoCardTrace.ThrowHelperError(new PolicyValidationException(Microsoft.InfoCards.SR.GetString("ClientAPIInvalidPolicy")));

            case -1073413875:
                throw InfoCardTrace.ThrowHelperError(new ServiceBusyException(Microsoft.InfoCards.SR.GetString("ClientAPIServiceBusy")));

            case -1073413874:
                throw InfoCardTrace.ThrowHelperError(new ServiceNotStartedException(Microsoft.InfoCards.SR.GetString("ClientAPIServiceNotStartedError")));

            case -1073413871:
                throw InfoCardTrace.ThrowHelperError(new StsCommunicationException(Microsoft.InfoCards.SR.GetString("ClientStsCommunicationException")));

            case -1073413870:
                throw InfoCardTrace.ThrowHelperError(new UntrustedRecipientException(Microsoft.InfoCards.SR.GetString("ClientAPIUntrustedRecipientError")));

            case -1073413869:
                throw InfoCardTrace.ThrowHelperError(new UserCancellationException(Microsoft.InfoCards.SR.GetString("ClientAPIUserCancellationError")));

            case -1073413866:
                throw InfoCardTrace.ThrowHelperError(new UnsupportedPolicyOptionsException(Microsoft.InfoCards.SR.GetString("ClientAPIUnsupportedPolicyOptions")));

            case -1073413862:
                throw InfoCardTrace.ThrowHelperError(new UIInitializationException(Microsoft.InfoCards.SR.GetString("ClientAPIUIInitializationFailed")));
            }
        }
        internal static CryptoHandle Create(InternalRefCountedHandle nativeHandle)
        {
            CryptoHandle handle = null;
            CryptoHandle handle3;
            bool         success = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                nativeHandle.DangerousAddRef(ref success);
                RpcInfoCardCryptoHandle handle2 = (RpcInfoCardCryptoHandle)Marshal.PtrToStructure(nativeHandle.DangerousGetHandle(), typeof(RpcInfoCardCryptoHandle));
                DateTime expiration             = DateTime.FromFileTimeUtc(handle2.expiration);
                switch (handle2.type)
                {
                case RpcInfoCardCryptoHandle.HandleType.Asymmetric:
                    handle = new AsymmetricCryptoHandle(nativeHandle, expiration, handle2.cryptoParameters);
                    break;

                case RpcInfoCardCryptoHandle.HandleType.Symmetric:
                    handle = new SymmetricCryptoHandle(nativeHandle, expiration, handle2.cryptoParameters);
                    break;

                case RpcInfoCardCryptoHandle.HandleType.Transform:
                    handle = new TransformCryptoHandle(nativeHandle, expiration, handle2.cryptoParameters);
                    break;

                case RpcInfoCardCryptoHandle.HandleType.Hash:
                    handle = new HashCryptoHandle(nativeHandle, expiration, handle2.cryptoParameters);
                    break;

                default:
                    throw InfoCardTrace.ThrowHelperError(new InvalidOperationException(Microsoft.InfoCards.SR.GetString("GeneralExceptionMessage")));
                }
                handle3 = handle;
            }
            finally
            {
                if (success)
                {
                    nativeHandle.DangerousRelease();
                }
            }
            return(handle3);
        }
            public CryptoTransform(InfoCardSymmetricAlgorithm symAlgo, Direction cryptoDirection)
            {
                InternalRefCountedHandle nativeTransformHandle = null;

                byte[] iV = symAlgo.IV;
                using (HGlobalSafeHandle handle2 = HGlobalSafeHandle.Construct(iV.Length))
                {
                    Marshal.Copy(iV, 0, handle2.DangerousGetHandle(), iV.Length);
                    int status = CardSpaceSelector.GetShim().m_csShimGetCryptoTransform(symAlgo.m_cryptoHandle.InternalHandle, (int)symAlgo.Mode, (int)symAlgo.Padding, symAlgo.FeedbackSize, (int)cryptoDirection, iV.Length, handle2, out nativeTransformHandle);
                    if (status != 0)
                    {
                        InfoCardTrace.CloseInvalidOutSafeHandle(nativeTransformHandle);
                        ExceptionHelper.ThrowIfCardSpaceException(status);
                        throw InfoCardTrace.ThrowHelperError(new Win32Exception(status));
                    }
                    this.m_transCryptoHandle = (TransformCryptoHandle)CryptoHandle.Create(nativeTransformHandle);
                    this.m_param             = (RpcTransformCryptoParameters)this.m_transCryptoHandle.Parameters;
                }
            }
        protected override byte[] HashFinal()
        {
            byte[]                destination = null;
            int                   cbOutData   = 0;
            HGlobalSafeHandle     handle      = null;
            GlobalAllocSafeHandle pOutData    = null;

            try
            {
                if (this.m_cachedBlock == null)
                {
                    return(destination);
                }
                if (this.m_cachedBlock.Length != 0)
                {
                    handle = HGlobalSafeHandle.Construct(this.m_cachedBlock.Length);
                    Marshal.Copy(this.m_cachedBlock, 0, handle.DangerousGetHandle(), this.m_cachedBlock.Length);
                }
                int status = CardSpaceSelector.GetShim().m_csShimHashFinal(this.m_cryptoHandle.InternalHandle, this.m_cachedBlock.Length, (handle != null) ? handle : HGlobalSafeHandle.Construct(), out cbOutData, out pOutData);
                if (status != 0)
                {
                    ExceptionHelper.ThrowIfCardSpaceException(status);
                    throw InfoCardTrace.ThrowHelperError(new Win32Exception(status));
                }
                pOutData.Length = cbOutData;
                destination     = DiagnosticUtility.Utility.AllocateByteArray(pOutData.Length);
                using (pOutData)
                {
                    Marshal.Copy(pOutData.DangerousGetHandle(), destination, 0, pOutData.Length);
                }
            }
            finally
            {
                if (handle != null)
                {
                    handle.Dispose();
                }
                Array.Clear(this.m_cachedBlock, 0, this.m_cachedBlock.Length);
                this.m_cachedBlock = null;
            }
            return(destination);
        }
示例#30
0
        public static GenericXmlSecurityToken GetToken(XmlElement endpoint, IEnumerable <XmlElement> policy, XmlElement requiredRemoteTokenIssuer, SecurityTokenSerializer tokenSerializer)
        {
            if (endpoint == null)
            {
                throw InfoCardTrace.ThrowHelperArgumentNull("endpoint");
            }
            if (policy == null)
            {
                throw InfoCardTrace.ThrowHelperArgumentNull("policy");
            }
            if (tokenSerializer == null)
            {
                throw InfoCardTrace.ThrowHelperArgumentNull("tokenSerializer");
            }
            Collection <XmlElement> parameters = new Collection <XmlElement>();

            foreach (XmlElement element in policy)
            {
                parameters.Add(element);
            }
            return(GetToken(new CardSpacePolicyElement[] { new CardSpacePolicyElement(endpoint, requiredRemoteTokenIssuer, parameters, null, 0, false) }, tokenSerializer));
        }