public GetEnumerator ( ) : System.Security.Cryptography.X509Certificates.X509Certificate2Enumerator | ||
리턴 | System.Security.Cryptography.X509Certificates.X509Certificate2Enumerator |
public void RemoveRange(X509Certificate2Collection certificates) { if (certificates == null) { throw new ArgumentNullException("certificates"); } int num = 0; try { X509Certificate2Enumerator enumerator = certificates.GetEnumerator(); while (enumerator.MoveNext()) { X509Certificate2 current = enumerator.Current; this.Remove(current); num++; } } catch { for (int i = 0; i < num; i++) { this.Add(certificates[i]); } throw; } }
public void AddRange(X509Certificate2Collection certificates) { if (certificates == null) { throw new ArgumentNullException("certificates"); } int num = 0; try { X509Certificate2Enumerator enumerator = certificates.GetEnumerator(); while (enumerator.MoveNext()) { X509Certificate2 current = enumerator.Current; this.Add(current); num++; } } catch { for (int i = 0; i < num; i++) { this.Remove(certificates[i]); } throw; } }
private X509Certificate2 SelectBestFromCollection(X509Certificate2 child, X509Certificate2Collection c) { switch (c.Count) { case 0: return(null); case 1: return(c[0]); default: { X509Certificate2Collection x509Certificate2Collection = c.Find(X509FindType.FindByTimeValid, ChainPolicy.VerificationTime, validOnly: false); switch (x509Certificate2Collection.Count) { case 0: x509Certificate2Collection = c; break; case 1: return(x509Certificate2Collection[0]); } string authorityKeyIdentifier = GetAuthorityKeyIdentifier(child); if (string.IsNullOrEmpty(authorityKeyIdentifier)) { return(x509Certificate2Collection[0]); } X509Certificate2Enumerator enumerator = x509Certificate2Collection.GetEnumerator(); while (enumerator.MoveNext()) { X509Certificate2 current = enumerator.Current; string subjectKeyIdentifier = GetSubjectKeyIdentifier(current); if (authorityKeyIdentifier == subjectKeyIdentifier) { return(current); } } return(x509Certificate2Collection[0]); } } }
internal static System.Security.Cryptography.SafeCertStoreHandle ExportToMemoryStore(X509Certificate2Collection collection) { new StorePermission(StorePermissionFlags.AllFlags).Assert(); System.Security.Cryptography.SafeCertStoreHandle invalidHandle = System.Security.Cryptography.SafeCertStoreHandle.InvalidHandle; invalidHandle = CAPI.CertOpenStore(new IntPtr(2L), 0x10001, IntPtr.Zero, 0x2200, null); if ((invalidHandle == null) || invalidHandle.IsInvalid) { throw new CryptographicException(Marshal.GetLastWin32Error()); } X509Certificate2Enumerator enumerator = collection.GetEnumerator(); while (enumerator.MoveNext()) { X509Certificate2 current = enumerator.Current; if (!CAPI.CertAddCertificateLinkToStore(invalidHandle, current.CertContext, 4, System.Security.Cryptography.SafeCertContextHandle.InvalidHandle)) { throw new CryptographicException(Marshal.GetLastWin32Error()); } } return(invalidHandle); }
internal static unsafe uint AddCertsToMessage(System.Security.Cryptography.SafeCryptMsgHandle safeCryptMsgHandle, X509Certificate2Collection bagOfCerts, X509Certificate2Collection chainOfCerts) { uint num = 0; X509Certificate2Enumerator enumerator = chainOfCerts.GetEnumerator(); while (enumerator.MoveNext()) { X509Certificate2 current = enumerator.Current; if (bagOfCerts.Find(X509FindType.FindByThumbprint, current.Thumbprint, false).Count == 0) { System.Security.Cryptography.CAPI.CERT_CONTEXT cert_context = *((System.Security.Cryptography.CAPI.CERT_CONTEXT*) System.Security.Cryptography.X509Certificates.X509Utils.GetCertContext(current).DangerousGetHandle()); System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB cryptoapi_blob = new System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB { cbData = cert_context.cbCertEncoded, pbData = cert_context.pbCertEncoded }; if (!System.Security.Cryptography.CAPI.CryptMsgControl(safeCryptMsgHandle, 0, 10, new IntPtr((long) ((ulong) ((IntPtr) &cryptoapi_blob))))) { throw new CryptographicException(Marshal.GetLastWin32Error()); } num++; } } return num; }
internal X509Certificate2Enumerator(X509Certificate2Collection collection) { Debug.Assert(collection != null); collection.GetEnumerator(out _enumerator); }
internal X509Certificate2Enumerator(X509Certificate2Collection mappings) { this.baseEnumerator = mappings.GetEnumerator(); }
internal X509Certificate2Enumerator(X509Certificate2Collection collection) { Debug.Assert(collection != null); collection.GetEnumerator(out _enumerator); }
internal static unsafe System.Security.Cryptography.SafeLocalAllocHandle CreateEncodedCertBlob(X509Certificate2Collection certificates) { System.Security.Cryptography.SafeLocalAllocHandle invalidHandle = System.Security.Cryptography.SafeLocalAllocHandle.InvalidHandle; if (certificates.Count > 0) { invalidHandle = System.Security.Cryptography.CAPI.LocalAlloc(0, new IntPtr(certificates.Count * Marshal.SizeOf(typeof(System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB)))); System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB* handle = (System.Security.Cryptography.CAPI.CRYPTOAPI_BLOB*) invalidHandle.DangerousGetHandle(); X509Certificate2Enumerator enumerator = certificates.GetEnumerator(); while (enumerator.MoveNext()) { System.Security.Cryptography.CAPI.CERT_CONTEXT cert_context = *((System.Security.Cryptography.CAPI.CERT_CONTEXT*) System.Security.Cryptography.X509Certificates.X509Utils.GetCertContext(enumerator.Current).DangerousGetHandle()); handle->cbData = cert_context.cbCertEncoded; handle->pbData = cert_context.pbCertEncoded; handle++; } } return invalidHandle; }
// // virtual methods // protected virtual AsymmetricAlgorithm GetPublicKey() { if (KeyInfo == null) throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_KeyInfoRequired")); if (m_x509Enum != null) { AsymmetricAlgorithm key = GetNextCertificatePublicKey(); if (key != null) return key; } if (m_keyInfoEnum == null) m_keyInfoEnum = KeyInfo.GetEnumerator(); // In our implementation, we move to the next KeyInfo clause which is an RSAKeyValue, DSAKeyValue or KeyInfoX509Data while (m_keyInfoEnum.MoveNext()) { RSAKeyValue rsaKeyValue = m_keyInfoEnum.Current as RSAKeyValue; if (rsaKeyValue != null) return rsaKeyValue.Key; DSAKeyValue dsaKeyValue = m_keyInfoEnum.Current as DSAKeyValue; if (dsaKeyValue != null) return dsaKeyValue.Key; KeyInfoX509Data x509Data = m_keyInfoEnum.Current as KeyInfoX509Data; if (x509Data != null) { m_x509Collection = Utils.BuildBagOfCerts (x509Data, CertUsageType.Verification); if (m_x509Collection.Count > 0) { m_x509Enum = m_x509Collection.GetEnumerator(); AsymmetricAlgorithm key = GetNextCertificatePublicKey(); if (key != null) return key; } } } return null; }
private static System.IdentityModel.SafeCertStoreHandle ExportToMemoryStore(X509Certificate2Collection collection, IntPtr pCertContext) { System.IdentityModel.CAPI.CERT_CONTEXT cert_context = (System.IdentityModel.CAPI.CERT_CONTEXT) Marshal.PtrToStructure(pCertContext, typeof(System.IdentityModel.CAPI.CERT_CONTEXT)); if (((collection == null) || (collection.Count <= 0)) && (cert_context.hCertStore == IntPtr.Zero)) { return System.IdentityModel.SafeCertStoreHandle.InvalidHandle; } System.IdentityModel.SafeCertStoreHandle hCertStore = System.IdentityModel.CAPI.CertOpenStore(new IntPtr(2L), 0x10001, IntPtr.Zero, 0x2200, null); if ((hCertStore == null) || hCertStore.IsInvalid) { int hr = Marshal.GetLastWin32Error(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(hr)); } if ((collection != null) && (collection.Count > 0)) { X509Certificate2Enumerator enumerator = collection.GetEnumerator(); while (enumerator.MoveNext()) { X509Certificate2 current = enumerator.Current; if (!System.IdentityModel.CAPI.CertAddCertificateLinkToStore(hCertStore, current.Handle, 4, System.IdentityModel.SafeCertContextHandle.InvalidHandle)) { int num2 = Marshal.GetLastWin32Error(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(num2)); } } } if (cert_context.hCertStore != IntPtr.Zero) { X509Store store = new X509Store(cert_context.hCertStore); X509Certificate2Collection certificates = null; try { certificates = store.Certificates; X509Certificate2Enumerator enumerator2 = certificates.GetEnumerator(); while (enumerator2.MoveNext()) { X509Certificate2 certificate2 = enumerator2.Current; if (!System.IdentityModel.CAPI.CertAddCertificateLinkToStore(hCertStore, certificate2.Handle, 4, System.IdentityModel.SafeCertContextHandle.InvalidHandle)) { int num3 = Marshal.GetLastWin32Error(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CryptographicException(num3)); } } } finally { System.IdentityModel.SecurityUtils.ResetAllCertificates(certificates); store.Close(); } } return hCertStore; }
internal X509Certificate2Enumerator(X509Certificate2Collection mappings) { this.baseEnumerator = mappings.GetEnumerator(); }