Ejemplo n.º 1
0
 /// <summary>5.2.2 获取证书对象 2011-12-19
 ///
 /// </summary>
 /// <param name="StoreLocation"></param>
 /// <param name="StoreName"></param>
 /// <param name="certType"></param>
 /// <param name="netcaType"></param>
 /// <returns></returns>
 public static SecuInter.X509Certificate getX509Certificate(
     SECUINTER_STORE_LOCATION StoreLocation, SECUINTER_STORE_NAME StoreName, int certType, int netcaType)
 {
     SecuInter.X509Certificates oMyCerts = getX509Certificates(StoreLocation, StoreName, certType, netcaType);
     if (oMyCerts == null)
     {
         return(null);
     }
     if (oMyCerts.Count > 0)
     {
         return((SecuInter.X509Certificate)oMyCerts.SelectCertificate());
     }
     return(null);
 }
Ejemplo n.º 2
0
 /// <summary>5.2.4	根据特定域的值,获取证书对象 2011-12-19
 ///
 /// </summary>
 /// <param name="StoreLocation"></param>
 /// <param name="StoreName"></param>
 /// <param name="certType"></param>
 /// <param name="netcaType"></param>
 /// <returns></returns>
 public static SecuInter.X509Certificate getX509Certificate(
     SECUINTER_STORE_LOCATION StoreLocation, SECUINTER_STORE_NAME StoreName, int certType, int netcaType,
     int iValueType, String certValue)
 {
     SecuInter.X509Certificates oMyCerts = getX509Certificates(StoreLocation, StoreName, certType, netcaType);
     if (oMyCerts == null)
     {
         return(null);
     }
     if (oMyCerts.Count > 0)
     {
         IEnumerator oEnum = oMyCerts.GetEnumerator();
         while (oEnum.MoveNext())
         {
             SecuInter.X509Certificate oCert = (SecuInter.X509Certificate)oEnum.Current;
             if (getX509CertificateInfo(oCert, iValueType).Equals(certValue))
             {
                 return(oCert);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
        /// <summary>5.2.1 获取证书集 2011-12-19
        /// </summary>
        /// <param name="StoreLocation">SECUINTER_LOCAL_MACHINE_STORE = 0;SECUINTER_CURRENT_USER_STORE= 1;</param>
        /// <param name="StoreName">SECUINTER_MY_STORE=0(个人);SECUINTER_OTHER_STORE:1(其他人);SECUINTER_CA_STORE= 2;SECUINTER_ROOT_STORE= 3;</param>
        /// <param name="certType">SECUINTER_CERTTYPE_ALL= 0;SECUINTER_CERTTYPE_SIGN= 1;SECUINTER_CERTTYPE_ENV= 2;</param>
        /// <param name="netcaType">SECUINTER_NETCA_ALL= 0;SECUINTER_NETCA_YES= 1;SECUINTER_NETCA_NO= 2;SECUINTER_NETCA_OTHER=3</param>
        /// <returns></returns>
        public static SecuInter.X509Certificates getX509Certificates(
            SECUINTER_STORE_LOCATION StoreLocation, SECUINTER_STORE_NAME StoreName, int certType, int netcaType)
        {
            SecuInter.Store            oMyStore  = new SecuInter.Store();
            SecuInter.X509Certificates oMyCerts  = new SecuInter.X509Certificates();
            SecuInter.Utilities        oUtil     = new Utilities();
            SecuInter.Store            oMyStore2 = oUtil.CreateStoreObject();

            try
            {
                oMyStore.Open(StoreLocation, StoreName);
            }
            catch (Exception)
            {
                throw new Exception("打开证书库失败");
            }
            SecuInter.X509Certificates certs = (SecuInter.X509Certificates)oMyStore.X509Certificates;
            oMyStore.Close();
            oMyStore = null;


            IEnumerator oEnum = certs.GetEnumerator();

            while (oEnum.MoveNext())
            {
                SecuInter.X509Certificate oCert = (SecuInter.X509Certificate)oEnum.Current;

                String issuer = oCert.get_Issuer(SECUINTER_NAMESTRING_TYPE.SECUINTER_X500_NAMESTRING);
                if (certType == SECUINTER_CERTTYPE_ALL)
                {
                    if (netcaType == SECUINTER_NETCA_ALL)
                    {
                        oMyCerts.Add(oCert);
                    }
                    else if (netcaType == SECUINTER_NETCA_YES)
                    {
                        if (issuer.IndexOf("CN=NETCA") >= 0)
                        {
                            oMyCerts.Add(oCert);
                        }
                    }
                    else if (netcaType == SECUINTER_NETCA_NO)
                    {
                        if (issuer.IndexOf("CN=NETCA") < 0)
                        {
                            oMyCerts.Add(oCert);
                        }
                    }
                    //限制可以使用NETCA证书和其他CA证书
                    else if (netcaType == SECUINTER_NETCA_OTHER)
                    {
                        for (int j = 0; j < CASTR.Length; j++)
                        {
                            if (issuer.IndexOf(CASTR[j]) >= 0)
                            {
                                oMyCerts.Add(oCert);
                            }
                        }
                    }
                }
                else if (certType == SECUINTER_CERTTYPE_SIGN)
                {
                    if (netcaType == SECUINTER_NETCA_ALL)
                    {
                        if (oCert.KeyUsage == 3)
                        {
                            oMyCerts.Add(oCert);
                        }
                        if (oCert.KeyUsage == -1)
                        {
                            oMyCerts.Add(oCert);
                        }
                    }
                    else if (netcaType == SECUINTER_NETCA_YES)
                    {
                        if (issuer.IndexOf("CN=NETCA") >= 0)
                        {
                            if (oCert.KeyUsage == 3)
                            {
                                oMyCerts.Add(oCert);
                            }
                            if (oCert.KeyUsage == -1)
                            {
                                oMyCerts.Add(oCert);
                            }
                        }
                    }
                    else if (netcaType == SECUINTER_NETCA_NO)
                    {
                        if (issuer.IndexOf("CN=NETCA") < 0)
                        {
                            if (oCert.KeyUsage == 3)
                            {
                                oMyCerts.Add(oCert);
                            }
                            if (oCert.KeyUsage == -1)
                            {
                                oMyCerts.Add(oCert);
                            }
                        }
                    }

                    //限制可以使用NETCA证书和其他CA证书
                    else if (netcaType == SECUINTER_NETCA_OTHER)
                    {
                        for (int j = 0; j < CASTR.Length; j++)
                        {
                            if (issuer.IndexOf(CASTR[j]) >= 0)
                            {
                                if (oCert.KeyUsage == 3)
                                {
                                    oMyCerts.Add(oCert);
                                }
                                if (oCert.KeyUsage == -1)
                                {
                                    oMyCerts.Add(oCert);
                                }
                            }
                        }
                    }
                }
                else if (certType == SECUINTER_CERTTYPE_ENV)
                {
                    if (netcaType == SECUINTER_NETCA_ALL)
                    {
                        if (oCert.KeyUsage == 12)
                        {
                            oMyCerts.Add(oCert);
                        }
                        if (oCert.KeyUsage == -1)
                        {
                            oMyCerts.Add(oCert);
                        }
                    }
                    else if (netcaType == SECUINTER_NETCA_YES)
                    {
                        if (issuer.IndexOf("CN=NETCA") >= 0)
                        {
                            if (oCert.KeyUsage == 12)
                            {
                                oMyCerts.Add(oCert);
                            }
                            if (oCert.KeyUsage == -1)
                            {
                                oMyCerts.Add(oCert);
                            }
                        }
                    }
                    else if (netcaType == SECUINTER_NETCA_NO)
                    {
                        if (issuer.IndexOf("CN=NETCA") < 0)
                        {
                            if (oCert.KeyUsage == 12)
                            {
                                oMyCerts.Add(oCert);
                            }
                            if (oCert.KeyUsage == -1)
                            {
                                oMyCerts.Add(oCert);
                            }
                        }
                    }

                    //限制可以使用NETCA证书和其他CA证书
                    else if (netcaType == SECUINTER_NETCA_OTHER)
                    {
                        for (int j = 0; j < CASTR.Length; j++)
                        {
                            if (issuer.IndexOf(CASTR[j]) >= 0)
                            {
                                if (oCert.KeyUsage == 12)
                                {
                                    oMyCerts.Add(oCert);
                                }
                                if (oCert.KeyUsage == -1)
                                {
                                    oMyCerts.Add(oCert);
                                }
                            }
                        }
                    }
                }
            }//END FOR
            return(oMyCerts);
        }