Exemplo n.º 1
0
        void decode(Byte[] rawData)
        {
            Asn1Reader asn = new Asn1Reader(rawData);

            asn.MoveNext();
            if (asn.PayloadLength == 0)
            {
                return;
            }
            do
            {
                switch (asn.Tag)
                {
                case 0xA0:
                    Asn1Reader distName = new Asn1Reader(asn.GetPayload());
                    do
                    {
                        switch (distName.Tag)
                        {
                        case 0xA0:
                            // full name
                            _fullNames.Decode(Asn1Utils.Encode(distName.GetPayload(), 48));
                            break;

                        case 0xA1:
                            // relative to issuer name
                            Byte[] relativeName = Asn1Utils.Encode(distName.GetPayload(), 48);
                            RelativeToIssuerName = new X500DistinguishedName(relativeName);
                            break;

                        default:
                            throw new InvalidDataException("The data is invalid");
                        }
                    } while (distName.MoveNextSibling());
                    break;

                case 0xA1:
                    // reasons
                    Asn1BitString bs = new Asn1BitString(asn.GetPayload());
                    if (bs.Value[0] == 0)
                    {
                        Reasons = X509RevocationReasonFlag.Unspecified;
                    }
                    else
                    {
                        Reasons = (X509RevocationReasonFlag)bs.Value[0];
                    }
                    break;

                case 0xA2:
                    // crl issuer
                    _crlIssuers.Decode(Asn1Utils.Encode(asn.GetPayload(), 48));
                    break;

                default:
                    throw new InvalidDataException("The data is invalid.");
                }
            } while (asn.MoveNextSibling());
            _rawData.AddRange(rawData);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="X509IssuingDistributionPointsExtension"/> class using an
        /// distribution point and partitioned CRL configuration.
        /// </summary>
        /// <param name="distributionPoint">Specifies an instance of <see cref="X509DistributionPoint"/> that contains CRL location.</param>
        /// <param name="indirect">Specifies whether the CRL is indirect CRL.</param>
        /// <param name="reasons">Specifies whether the CRL is partitioned by a subset of revocation reasons.</param>
        /// <param name="scope">Specifies the scope for CRL.</param>
        /// <exception cref="ArgumentNullException"><strong>distributionPoint</strong> parameter is NULL.</exception>
        public X509IssuingDistributionPointsExtension(
            X509DistributionPoint distributionPoint,
            Boolean indirect = false,
            X509RevocationReasonFlag reasons    = X509RevocationReasonFlag.None,
            IssuingDistributionPointScope scope = IssuingDistributionPointScope.None)
        {
            if (distributionPoint == null)
            {
                throw new ArgumentNullException(nameof(distributionPoint));
            }

            encode(distributionPoint, indirect, reasons, scope);
        }
Exemplo n.º 3
0
        void encode(X509DistributionPoint distributionPoint, Boolean indirect, X509RevocationReasonFlag reasons, IssuingDistributionPointScope scope)
        {
            Oid      = _oid;
            Critical = true;

            var builder = Asn1Builder.Create();

            if (distributionPoint != null)
            {
                DistributionPoint = distributionPoint;
                builder.AddExplicit(0, distributionPoint.RawData, true);
            }
            if (scope == IssuingDistributionPointScope.OnlyUserCerts)
            {
                OnlyUserCerts = true;
                builder.AddImplicit(1, new Asn1Boolean(true).RawData, false);
            }
            else if (scope == IssuingDistributionPointScope.OnlyCaCerts)
            {
                OnlyCaCerts = true;
                builder.AddImplicit(2, new Asn1Boolean(true).RawData, false);
            }
            if (reasons != X509RevocationReasonFlag.None)
            {
                Reasons = reasons;
                // do encoding trick since encoding matches the Key Usage extension encoding
                builder.AddExplicit(3, x => x.AddDerData(new X509KeyUsageExtension((X509KeyUsageFlags)reasons, false).RawData));
            }
            if (indirect)
            {
                IndirectCRL = true;
                builder.AddImplicit(4, new Asn1Boolean(true).RawData, false);
            }
            if (scope == IssuingDistributionPointScope.OnlyAttributeCerts)
            {
                OnlyAttributeCerts = true;
                builder.AddImplicit(5, new Asn1Boolean(true).RawData, false);
            }

            RawData = builder.GetEncoded();
        }