Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void parse(byte[] encoded) throws java.io.IOException
        private void Parse(sbyte[] encoded)
        {
            DerInputStream attributeValue = new DerInputStream(encoded);

            DerValue[]       attrSeq     = attributeValue.getSequence(2);
            ObjectIdentifier type        = attrSeq[0].OID;
            DerInputStream   attrContent = new DerInputStream(attrSeq[1].toByteArray());

            DerValue[] attrValueSet = attrContent.getSet(1);
            String[]   values       = new String[attrValueSet.Length];
            String     printableString;

            for (int i = 0; i < attrValueSet.Length; i++)
            {
                if (attrValueSet[i].tag == DerValue.tag_OctetString)
                {
                    values[i] = Debug.ToString(attrValueSet[i].OctetString);
                }
                else if ((printableString = attrValueSet[i].AsString) != null)
                {
                    values[i] = printableString;
                }
                else if (attrValueSet[i].tag == DerValue.tag_ObjectId)
                {
                    values[i] = attrValueSet[i].OID.ToString();
                }
                else if (attrValueSet[i].tag == DerValue.tag_GeneralizedTime)
                {
                    values[i] = attrValueSet[i].GeneralizedTime.ToString();
                }
                else if (attrValueSet[i].tag == DerValue.tag_UtcTime)
                {
                    values[i] = attrValueSet[i].UTCTime.ToString();
                }
                else if (attrValueSet[i].tag == DerValue.tag_Integer)
                {
                    values[i] = attrValueSet[i].BigInteger.ToString();
                }
                else if (attrValueSet[i].tag == DerValue.tag_Boolean)
                {
                    values[i] = Convert.ToString(attrValueSet[i].Boolean);
                }
                else
                {
                    values[i] = Debug.ToString(attrValueSet[i].DataBytes);
                }
            }

            this.Name_Renamed  = type.ToString();
            this.Value_Renamed = values.Length == 1 ? values[0] : Arrays.ToString(values);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Decides whether a {@code CRL} should be selected.
        /// </summary>
        /// <param name="crl"> the {@code CRL} to be checked </param>
        /// <returns> {@code true} if the {@code CRL} should be selected,
        ///         {@code false} otherwise </returns>
        public virtual bool Match(CRL crl)
        {
            if (!(crl is X509CRL))
            {
                return(false);
            }
            X509CRL xcrl = (X509CRL)crl;

            /* match on issuer name */
            if (IssuerNames_Renamed != null)
            {
                X500Principal            issuer = xcrl.IssuerX500Principal;
                Iterator <X500Principal> i      = IssuerX500Principals.Iterator();
                bool found = false;
                while (!found && i.HasNext())
                {
                    if (i.Next().Equals(issuer))
                    {
                        found = true;
                    }
                }
                if (!found)
                {
                    if (Debug != null)
                    {
                        Debug.println("X509CRLSelector.match: issuer DNs " + "don't match");
                    }
                    return(false);
                }
            }

            if ((MinCRL_Renamed != null) || (MaxCRL_Renamed != null))
            {
                /* Get CRL number extension from CRL */
                sbyte[] crlNumExtVal = xcrl.GetExtensionValue("2.5.29.20");
                if (crlNumExtVal == null)
                {
                    if (Debug != null)
                    {
                        Debug.println("X509CRLSelector.match: no CRLNumber");
                    }
                }
                System.Numerics.BigInteger crlNum;
                try
                {
                    DerInputStream     @in       = new DerInputStream(crlNumExtVal);
                    sbyte[]            encoded   = @in.OctetString;
                    CRLNumberExtension crlNumExt = new CRLNumberExtension(false, encoded);
                    crlNum = crlNumExt.get(CRLNumberExtension.NUMBER);
                }
                catch (IOException)
                {
                    if (Debug != null)
                    {
                        Debug.println("X509CRLSelector.match: exception in " + "decoding CRL number");
                    }
                    return(false);
                }

                /* match on minCRLNumber */
                if (MinCRL_Renamed != null)
                {
                    if (crlNum.CompareTo(MinCRL_Renamed) < 0)
                    {
                        if (Debug != null)
                        {
                            Debug.println("X509CRLSelector.match: CRLNumber too small");
                        }
                        return(false);
                    }
                }

                /* match on maxCRLNumber */
                if (MaxCRL_Renamed != null)
                {
                    if (crlNum.CompareTo(MaxCRL_Renamed) > 0)
                    {
                        if (Debug != null)
                        {
                            Debug.println("X509CRLSelector.match: CRLNumber too large");
                        }
                        return(false);
                    }
                }
            }


            /* match on dateAndTime */
            if (DateAndTime_Renamed != null)
            {
                Date crlThisUpdate = xcrl.ThisUpdate;
                Date nextUpdate    = xcrl.NextUpdate;
                if (nextUpdate == null)
                {
                    if (Debug != null)
                    {
                        Debug.println("X509CRLSelector.match: nextUpdate null");
                    }
                    return(false);
                }
                Date nowPlusSkew  = DateAndTime_Renamed;
                Date nowMinusSkew = DateAndTime_Renamed;
                if (Skew > 0)
                {
                    nowPlusSkew  = new Date(DateAndTime_Renamed.Time + Skew);
                    nowMinusSkew = new Date(DateAndTime_Renamed.Time - Skew);
                }

                // Check that the test date is within the validity interval:
                //   [ thisUpdate - MAX_CLOCK_SKEW,
                //     nextUpdate + MAX_CLOCK_SKEW ]
                if (nowMinusSkew.After(nextUpdate) || nowPlusSkew.Before(crlThisUpdate))
                {
                    if (Debug != null)
                    {
                        Debug.println("X509CRLSelector.match: update out-of-range");
                    }
                    return(false);
                }
            }

            return(true);
        }