Beispiel #1
0
 void initialize(IdentityReference sid)
 {
     SecurityIdentifier = sid.Value;
     Byte[] sidBytes = Encoding.ASCII.GetBytes(SecurityIdentifier);
     RawData = Asn1Builder.Create()
               .AddExplicit(0, x => {
         x.AddObjectIdentifier(new Oid("1.3.6.1.4.1.311.25.2.1"));
         return(x.AddExplicit(0, y => y.AddOctetString(sidBytes)));
     }).GetEncoded();
 }
Beispiel #2
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();
        }
Beispiel #3
0
        /// <summary>
        /// Encodes revocation entry to a ASN.1-encoded byte array.
        /// </summary>
        /// <returns>ASN.1-encoded byte array</returns>
        public Byte[] Encode()
        {
            if (String.IsNullOrEmpty(SerialNumber))
            {
                throw new UninitializedObjectException();
            }
            // TODO:  verify this
            Asn1Builder builder = Asn1Builder.Create()
                                  .AddInteger(BigInteger.Parse(SerialNumber, NumberStyles.AllowHexSpecifier))
                                  .AddRfcDateTime(RevocationDate);

            if (ReasonCode > 0)
            {
                builder.AddSequence(x =>
                                    x.AddSequence(y => {
                    y.AddObjectIdentifier(new Oid(X509ExtensionOid.CRLReasonCode));
                    return(y.AddOctetString(z => z.AddEnumerated((UInt64)ReasonCode)));
                }));
            }
            return(builder.GetEncoded());
        }