Example #1
0
		private static bool MatchesFilter(X509Certificate2 cert, CertificateFilterInfo filter)
		{
			if (filter == null || filter.Purpose == CertificatePurpose.All)
			{
				return true;
			}
			else
			{
				CertificatePurpose purpose = filter.Purpose;
				if (purpose != CertificatePurpose.CodeSigning || !SecuritySupport.CertIsGoodForSigning(cert))
				{
					return false;
				}
				else
				{
					return true;
				}
			}
		}
Example #2
0
		private void GetStoresOrNames(string path, bool recurse, bool returnNames, CertificateFilterInfo filter)
		{
			object obj;
			X509StoreLocation storeLocation = this.GetStoreLocation(path);
			foreach (string key in storeLocation.StoreNames.Keys)
			{
				string str = this.MakePath(path, key);
				if (!returnNames)
				{
					X509NativeStore store = this.GetStore(str, key, storeLocation);
					X509Store x509Store = new X509Store(store.StoreName, store.Location.Location);
					obj = x509Store;
				}
				else
				{
					obj = key;
				}
				if (filter == null || returnNames)
				{
					base.WriteItemObject(obj, key, true);
				}
				if (!recurse)
				{
					continue;
				}
				string[] pathElements = CertificateProvider.GetPathElements(str);
				this.GetCertificatesOrNames(str, pathElements, returnNames, filter);
			}
		}
Example #3
0
		private CertificateFilterInfo GetFilter()
		{
			CertificateFilterInfo certificateFilterInfo = null;
			if (base.DynamicParameters != null)
			{
				if (!CertificateProvider.fIsWin8AndAbove)
				{
					CertificateProviderCodeSigningDynamicParameters dynamicParameters = base.DynamicParameters as CertificateProviderCodeSigningDynamicParameters;
					if (dynamicParameters != null && dynamicParameters.CodeSigningCert)
					{
						certificateFilterInfo = new CertificateFilterInfo();
						certificateFilterInfo.Purpose = CertificatePurpose.CodeSigning;
					}
				}
				else
				{
					CertificateProviderDynamicParameters certificateProviderDynamicParameter = base.DynamicParameters as CertificateProviderDynamicParameters;
					if (certificateProviderDynamicParameter != null)
					{
						bool flag = false;
						certificateFilterInfo = new CertificateFilterInfo();
						if (certificateProviderDynamicParameter.CodeSigningCert)
						{
							certificateFilterInfo.Purpose = CertificatePurpose.CodeSigning;
							flag = true;
						}
						if (certificateProviderDynamicParameter.SSLServerAuthentication)
						{
							certificateFilterInfo.SSLServerAuthentication = true;
							flag = true;
						}
						DnsNameRepresentation dnsName = certificateProviderDynamicParameter.DnsName;
						if (dnsName.Punycode != null)
						{
							DnsNameRepresentation dnsNameRepresentation = certificateProviderDynamicParameter.DnsName;
							certificateFilterInfo.DnsName = dnsNameRepresentation.Punycode;
							flag = true;
						}
						if (certificateProviderDynamicParameter.Eku != null)
						{
							certificateFilterInfo.Eku = certificateProviderDynamicParameter.Eku;
							flag = true;
						}
						if (certificateProviderDynamicParameter.ExpiringInDays >= 0)
						{
							certificateFilterInfo.ExpiringInDays = certificateProviderDynamicParameter.ExpiringInDays;
							flag = true;
						}
						if (!flag)
						{
							certificateFilterInfo = null;
						}
					}
				}
			}
			return certificateFilterInfo;
		}
Example #4
0
		private void GetChildItemsOrNames(string path, bool recurse, ReturnContainers returnContainers, bool returnNames, CertificateFilterInfo filter)
		{
			object locationName;
			Utils.CheckArgForNull(path, "path");
			if (path.Length != 0)
			{
				string[] pathElements = CertificateProvider.GetPathElements(path);
				if ((int)pathElements.Length != 1)
				{
					if ((int)pathElements.Length != 2)
					{
						this.ThrowItemNotFound(path, CertificateProviderItem.Certificate);
					}
					else
					{
						this.GetCertificatesOrNames(path, pathElements, returnNames, filter);
						return;
					}
				}
				else
				{
					this.GetStoresOrNames(pathElements[0], recurse, returnNames, filter);
					return;
				}
			}
			else
			{
				foreach (X509StoreLocation storeLocation in CertificateProvider.storeLocations)
				{
					if (returnNames)
					{
						locationName = storeLocation.LocationName;
					}
					else
					{
						locationName = storeLocation;
					}
					object obj = locationName;
					if (filter == null || returnNames)
					{
						base.WriteItemObject(obj, storeLocation.LocationName, true);
					}
					string str = storeLocation.LocationName;
					if (!recurse)
					{
						continue;
					}
					this.GetChildItemsOrNames(str, recurse, returnContainers, returnNames, filter);
				}
			}
		}
Example #5
0
		private void GetCertificatesOrNames(string path, string[] pathElements, bool returnNames, CertificateFilterInfo filter)
		{
			object obj;
			X509NativeStore store = this.GetStore(path, pathElements);
			store.Open(this.IncludeArchivedCerts());
			for (IntPtr i = store.GetFirstCert(filter); IntPtr.Zero != i; i = store.GetNextCert(i))
			{
				X509Certificate2 x509Certificate2 = new X509Certificate2(i);
				if (CertificateProvider.fIsWin8AndAbove || CertificateProvider.MatchesFilter(x509Certificate2, filter))
				{
					string certName = CertificateProvider.GetCertName(x509Certificate2);
					string str = this.MakePath(path, certName);
					if (!returnNames)
					{
						X509Certificate2 x509Certificate21 = new X509Certificate2(x509Certificate2);
						PSObject pSObject = new PSObject(x509Certificate21);
						obj = pSObject;
					}
					else
					{
						obj = certName;
					}
					base.WriteItemObject(obj, str, false);
				}
			}
		}
Example #6
0
		public IntPtr GetFirstCert(CertificateFilterInfo filter)
		{
			this.filterHandle = null;
			if (X509NativeStore.fIsWin8AndAbove && filter != null)
			{
				IntPtr zero = IntPtr.Zero;
				this.filterHandle = new CertificateFilterHandle();
				int num = NativeMethods.CCFindCertificateBuildFilter(filter.FilterString, ref zero);
				if (num == 0)
				{
					this.filterHandle.Handle = zero;
				}
				else
				{
					this.filterHandle = null;
					throw new Win32Exception(num);
				}
			}
			return this.GetNextCert(IntPtr.Zero);
		}