public EnhancedKeyUsageProperty(X509Certificate2 cert)
		{
			EnhancedKeyUsageRepresentation enhancedKeyUsageRepresentation;
			this.ekuList = new List<EnhancedKeyUsageRepresentation>();
			if (DownLevelHelper.IsWin8AndAbove())
			{
				Collection<string> certEKU = SecuritySupport.GetCertEKU(cert);
				foreach (string str in certEKU)
				{
					if (string.IsNullOrEmpty(str))
					{
						continue;
					}
					IntPtr hGlobalAnsi = Marshal.StringToHGlobalAnsi(str);
					IntPtr intPtr = NativeMethods.CryptFindOIDInfo(1, hGlobalAnsi, 0);
					if (intPtr == IntPtr.Zero)
					{
						enhancedKeyUsageRepresentation = new EnhancedKeyUsageRepresentation(null, str);
					}
					else
					{
						NativeMethods.CRYPT_OID_INFO structure = (NativeMethods.CRYPT_OID_INFO)Marshal.PtrToStructure(intPtr, typeof(NativeMethods.CRYPT_OID_INFO));
						enhancedKeyUsageRepresentation = new EnhancedKeyUsageRepresentation(structure.pwszName, str);
					}
					this.ekuList.Add(enhancedKeyUsageRepresentation);
				}
			}
		}
Example #2
0
        public EnhancedKeyUsageProperty(X509Certificate2 cert)
        {
            EnhancedKeyUsageRepresentation enhancedKeyUsageRepresentation;

            this.ekuList = new List <EnhancedKeyUsageRepresentation>();
            if (DownLevelHelper.IsWin8AndAbove())
            {
                Collection <string> certEKU = SecuritySupport.GetCertEKU(cert);
                foreach (string str in certEKU)
                {
                    if (string.IsNullOrEmpty(str))
                    {
                        continue;
                    }
                    IntPtr hGlobalAnsi = Marshal.StringToHGlobalAnsi(str);
                    IntPtr intPtr      = NativeMethods.CryptFindOIDInfo(1, hGlobalAnsi, 0);
                    if (intPtr == IntPtr.Zero)
                    {
                        enhancedKeyUsageRepresentation = new EnhancedKeyUsageRepresentation(null, str);
                    }
                    else
                    {
                        NativeMethods.CRYPT_OID_INFO structure = (NativeMethods.CRYPT_OID_INFO)Marshal.PtrToStructure(intPtr, typeof(NativeMethods.CRYPT_OID_INFO));
                        enhancedKeyUsageRepresentation = new EnhancedKeyUsageRepresentation(structure.pwszName, str);
                    }
                    this.ekuList.Add(enhancedKeyUsageRepresentation);
                }
            }
        }
		public bool Equals(EnhancedKeyUsageRepresentation keyUsage)
		{
			bool flag = false;
			if (this.oid == null || keyUsage.oid == null)
			{
				if (this.oid == null && keyUsage.oid == null)
				{
					flag = true;
				}
			}
			else
			{
				if (string.Equals(this.oid, keyUsage.oid, StringComparison.Ordinal))
				{
					flag = true;
				}
			}
			return flag;
		}
Example #4
0
        public bool Equals(EnhancedKeyUsageRepresentation keyUsage)
        {
            bool flag = false;

            if (this.oid == null || keyUsage.oid == null)
            {
                if (this.oid == null && keyUsage.oid == null)
                {
                    flag = true;
                }
            }
            else
            {
                if (string.Equals(this.oid, keyUsage.oid, StringComparison.Ordinal))
                {
                    flag = true;
                }
            }
            return(flag);
        }
Example #5
0
        /// <summary>
        /// constructor for  EnhancedKeyUsageProperty
        /// </summary> 
        public EnhancedKeyUsageProperty(X509Certificate2 cert)
        {
            if (DownLevelHelper.NativeFilteringSupported())
            {
                Collection<string> ekuCollection = System.Management.Automation.Internal.SecuritySupport.GetCertEKU(cert);

                foreach (string oidString in ekuCollection)
                {
                    if (!String.IsNullOrEmpty(oidString))
                    {
                        IntPtr stringAnsi = (IntPtr)Marshal.StringToHGlobalAnsi(oidString);

                        EnhancedKeyUsageRepresentation ekuString;
                        IntPtr oidPtr = Security.NativeMethods.CryptFindOIDInfo(
                                            Security.NativeConstants.CRYPT_OID_INFO_OID_KEY,
                                            stringAnsi,
                                            0);
                        if (oidPtr != IntPtr.Zero)
                        {
                            Security.NativeMethods.CRYPT_OID_INFO oidInfo =
                                ClrFacade.PtrToStructure<Security.NativeMethods.CRYPT_OID_INFO>(oidPtr);
                            ekuString = new EnhancedKeyUsageRepresentation(oidInfo.pwszName, oidString);
                        }
                        else //if oidInfo is not available
                        {
                            ekuString = new EnhancedKeyUsageRepresentation(null, oidString);
                        }

                        _ekuList.Add(ekuString);
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// value comparison
        /// </summary>   
        public bool Equals(EnhancedKeyUsageRepresentation keyUsage)
        {
            bool match = false;

            if (_oid != null && keyUsage._oid != null)
            {
                // OID strings only contain numbers and periods

                if (String.Equals(_oid, keyUsage._oid, StringComparison.Ordinal))
                {
                    match = true;
                }
            }
            else if (_oid == null && keyUsage._oid == null)
            {
                match = true;
            }
            return match;
        }