Beispiel #1
0
        public override void PerformTest()
        {
            AlgorithmIdentifier algId = new AlgorithmIdentifier(new DerObjectIdentifier("1.2.2.3"));

            byte[]       digest       = new byte[20];
            OtherHash    otherHash    = new OtherHash(new OtherHashAlgAndValue(algId, digest));
            IssuerSerial issuerSerial = new IssuerSerial(new GeneralNames(new GeneralName(new X509Name("CN=test"))), new DerInteger(1));

            OtherCertID certID = new OtherCertID(otherHash);

            checkConstruction(certID, algId, digest, null);

            certID = new OtherCertID(otherHash, issuerSerial);

            checkConstruction(certID, algId, digest, issuerSerial);

            certID = OtherCertID.GetInstance(null);

            if (certID != null)
            {
                Fail("null GetInstance() failed.");
            }

            try
            {
                OtherCertID.GetInstance(new Object());

                Fail("GetInstance() failed to detect bad object.");
            }
            catch (ArgumentException)
            {
                // expected
            }
        }
        private EssCertIDv2(
            Asn1Sequence seq)
        {
            if (seq.Count != 2 && seq.Count != 3)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
            }

            int count = 0;

            if (seq[0] is Asn1OctetString)
            {
                // Default value
                this.hashAlgorithm = DefaultAlgID;
            }
            else
            {
                this.hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[count++].ToAsn1Object());
            }

            this.certHash = Asn1OctetString.GetInstance(seq[count++].ToAsn1Object()).GetOctets();

            if (seq.Count > count)
            {
                this.issuerSerial = IssuerSerial.GetInstance(
                    Asn1Sequence.GetInstance(seq[count].ToAsn1Object()));
            }
        }
 public ProcurationSyntax(string country, DirectoryString typeOfSubstitution, IssuerSerial certRef)
 {
     this.country            = country;
     this.typeOfSubstitution = typeOfSubstitution;
     thirdPerson             = null;
     this.certRef            = certRef;
 }
Beispiel #4
0
    private Holder(Asn1Sequence seq)
    {
        if (seq.Count > 3)
        {
            throw new ArgumentException("Bad sequence size: " + seq.Count);
        }
        for (int i = 0; i != seq.Count; i++)
        {
            Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(seq[i]);
            switch (instance.TagNo)
            {
            case 0:
                baseCertificateID = IssuerSerial.GetInstance(instance, explicitly: false);
                break;

            case 1:
                entityName = GeneralNames.GetInstance(instance, explicitly: false);
                break;

            case 2:
                objectDigestInfo = ObjectDigestInfo.GetInstance(instance, isExplicit: false);
                break;

            default:
                throw new ArgumentException("unknown tag in Holder");
            }
        }
        version = 1;
    }
 public ProcurationSyntax(string country, DirectoryString typeOfSubstitution, GeneralName thirdPerson)
 {
     this.country            = country;
     this.typeOfSubstitution = typeOfSubstitution;
     this.thirdPerson        = thirdPerson;
     certRef = null;
 }
Beispiel #6
0
 public EssCertID(
     byte[]                  hash,
     IssuerSerial issuerSerial)
 {
     this.certHash     = new DerOctetString(hash);
     this.issuerSerial = issuerSerial;
 }
Beispiel #7
0
 public OtherCertID(
     AlgorithmIdentifier algId,
     byte[]                          digest,
     IssuerSerial issuerSerial)
 {
     this.otherCertHash = new DigestInfo(algId, digest);
     this.issuerSerial  = issuerSerial;
 }
Beispiel #8
0
        internal static void VerifySerialNumber(X509Certificate2 certificate, IssuerSerial issuerSerial)
        {
            var serialNumber = certificate.GetSerialNumber();

            // Convert from little endian to big endian.
            Array.Reverse(serialNumber);

            VerifyByteArrays(serialNumber, issuerSerial.SerialNumber);
        }
Beispiel #9
0
 public OtherCertID(OtherHash otherCertHash, IssuerSerial issuerSerial)
 {
     if (otherCertHash == null)
     {
         throw new ArgumentNullException("otherCertHash");
     }
     this.otherCertHash = otherCertHash;
     this.issuerSerial  = issuerSerial;
 }
Beispiel #10
0
 public OtherCertID(OtherHash otherCertHash, IssuerSerial issuerSerial)
 {
     //IL_000e: Unknown result type (might be due to invalid IL or missing references)
     if (otherCertHash == null)
     {
         throw new ArgumentNullException("otherCertHash");
     }
     this.otherCertHash = otherCertHash;
     this.issuerSerial  = issuerSerial;
 }
Beispiel #11
0
        private void checkValues(
            OtherCertID certID,
            AlgorithmIdentifier algId,
            byte[]                          digest,
            IssuerSerial issuerSerial)
        {
            checkMandatoryField("hashAlgorithm", algId, certID.OtherCertHash.HashAlgorithm);
            checkMandatoryField("hashValue", digest, certID.OtherCertHash.GetHashValue());

            checkOptionalField("issuerSerial", issuerSerial, certID.IssuerSerial);
        }
Beispiel #12
0
 public EssCertID(Asn1Sequence seq)
 {
     if (seq.Count < 1 || seq.Count > 2)
     {
         throw new ArgumentException("Bad sequence size: " + seq.Count);
     }
     this.certHash = Asn1OctetString.GetInstance(seq[0]);
     if (seq.Count > 1)
     {
         this.issuerSerial = IssuerSerial.GetInstance(seq[1]);
     }
 }
Beispiel #13
0
 private void checkValues(
     ProcurationSyntax procuration,
     string country,
     DirectoryString typeOfSubstitution,
     GeneralName thirdPerson,
     IssuerSerial certRef)
 {
     checkOptionalField("country", country, procuration.Country);
     checkOptionalField("typeOfSubstitution", typeOfSubstitution, procuration.TypeOfSubstitution);
     checkOptionalField("thirdPerson", thirdPerson, procuration.ThirdPerson);
     checkOptionalField("certRef", certRef, procuration.CertRef);
 }
Beispiel #14
0
 public EssCertID(Asn1Sequence seq)
 {
     //IL_002d: Unknown result type (might be due to invalid IL or missing references)
     if (seq.Count < 1 || seq.Count > 2)
     {
         throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count));
     }
     certHash = Asn1OctetString.GetInstance(seq[0]);
     if (seq.Count > 1)
     {
         issuerSerial = IssuerSerial.GetInstance(seq[1]);
     }
 }
Beispiel #15
0
 public EssCertIDv2(AlgorithmIdentifier algId, byte[] certHash, IssuerSerial issuerSerial)
 {
     if (algId == null)
     {
         this.hashAlgorithm = EssCertIDv2.DefaultAlgID;
     }
     else
     {
         this.hashAlgorithm = algId;
     }
     this.certHash     = certHash;
     this.issuerSerial = issuerSerial;
 }
Beispiel #16
0
        public void IssuerSerial_ListCollectionTests()
        {
            var issuerSerial       = new IssuerSerial(string.Empty, string.Empty);
            var secondIssuerSerial = new IssuerSerial("issuerName", "serialNumber");

            var list = new List <IssuerSerial> {
                issuerSerial, secondIssuerSerial
            };
            var secondList = new List <IssuerSerial> {
                issuerSerial, secondIssuerSerial
            };

            Assert.True(Enumerable.SequenceEqual(list, secondList));
        }
Beispiel #17
0
 private OtherCertID(Asn1Sequence seq)
 {
     if (seq == null)
     {
         throw new ArgumentNullException("seq");
     }
     if (seq.Count < 1 || seq.Count > 2)
     {
         throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
     }
     this.otherCertHash = OtherHash.GetInstance(seq[0].ToAsn1Object());
     if (seq.Count > 1)
     {
         this.issuerSerial = IssuerSerial.GetInstance(seq[1].ToAsn1Object());
     }
 }
Beispiel #18
0
    public Holder(Asn1TaggedObject tagObj)
    {
        switch (tagObj.TagNo)
        {
        case 0:
            baseCertificateID = IssuerSerial.GetInstance(tagObj, explicitly: false);
            break;

        case 1:
            entityName = GeneralNames.GetInstance(tagObj, explicitly: false);
            break;

        default:
            throw new ArgumentException("unknown tag in Holder");
        }
        version = 0;
    }
Beispiel #19
0
 private OtherCertID(Asn1Sequence seq)
 {
     //IL_000e: Unknown result type (might be due to invalid IL or missing references)
     //IL_0040: Unknown result type (might be due to invalid IL or missing references)
     if (seq == null)
     {
         throw new ArgumentNullException("seq");
     }
     if (seq.Count < 1 || seq.Count > 2)
     {
         throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count), "seq");
     }
     otherCertHash = OtherHash.GetInstance(seq[0].ToAsn1Object());
     if (seq.Count > 1)
     {
         issuerSerial = IssuerSerial.GetInstance(seq[1].ToAsn1Object());
     }
 }
Beispiel #20
0
        public void IssuerSerial_HashSetCollectionTests()
        {
            var set = new HashSet <IssuerSerial>();

            var issuerSerial = new IssuerSerial(string.Empty, string.Empty);

            set.Add(issuerSerial);

            bool inCollection = set.Contains(issuerSerial);

            Assert.True(inCollection);

            var secondIssuerSerial = new IssuerSerial(string.Empty, string.Empty);

            // hashcode is determined by immutable values, not reference
            inCollection = set.Contains(secondIssuerSerial);
            Assert.True(inCollection);
        }
 public OtherCertID(Asn1Sequence seq)
 {
     if (seq.Count < 1 || seq.Count > 2)
     {
         throw new ArgumentException("Bad sequence size: " + seq.Count);
     }
     if (seq[0].ToAsn1Object() is Asn1OctetString)
     {
         otherCertHash = Asn1OctetString.GetInstance(seq[0]);
     }
     else
     {
         otherCertHash = DigestInfo.GetInstance(seq[0]);
     }
     if (seq.Count > 1)
     {
         issuerSerial = IssuerSerial.GetInstance(Asn1Sequence.GetInstance(seq[1]));
     }
 }
Beispiel #22
0
        /// <summary>
        /// Método para crear el atributo que contiene la información del certificado empleado para la firma
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        private BcCms.Attribute MakeSigningCertificateAttribute(SignatureParameters parameters)
        {
            X509Certificate         certificate = new X509CertificateParser().ReadCertificate(parameters.Certificate.GetRawCertData());
            TbsCertificateStructure tbs         = TbsCertificateStructure.GetInstance(
                Asn1Object.FromByteArray(
                    certificate.GetTbsCertificate()));
            GeneralName  gn           = new GeneralName(tbs.Issuer);
            GeneralNames gns          = new GeneralNames(gn);
            IssuerSerial issuerSerial = new IssuerSerial(gns, tbs.SerialNumber);

            byte[] certHash = DigestUtilities.CalculateDigest(parameters.DigestMethod.Name, certificate.GetEncoded());

            var policies = GetPolicyInformation(certificate);

            if (parameters.DigestMethod == DigestMethod.SHA1)
            {
                SigningCertificate sc = null;

                if (policies != null)
                {
                    Asn1EncodableVector v = new Asn1EncodableVector();
                    v.Add(new DerSequence(new EssCertID(certHash, issuerSerial)));
                    v.Add(new DerSequence(policies));
                    sc = SigningCertificate.GetInstance(new DerSequence(v));
                }
                else
                {
                    sc = new SigningCertificate(new EssCertID(certHash, issuerSerial));
                }

                return(new BcCms.Attribute(PkcsObjectIdentifiers.IdAASigningCertificate, new DerSet(sc)));
            }
            else
            {
                EssCertIDv2 essCert = new EssCertIDv2(new AlgorithmIdentifier(parameters.DigestMethod
                                                                              .Oid), certHash, issuerSerial);

                SigningCertificateV2 scv2 = new SigningCertificateV2(new EssCertIDv2[] { essCert }, policies);

                return(new BcCms.Attribute(PkcsObjectIdentifiers.IdAASigningCertificateV2, new DerSet
                                               (scv2)));
            }
        }
Beispiel #23
0
        private void checkConstruction(
            OtherCertID certID,
            AlgorithmIdentifier algId,
            byte[]                          digest,
            IssuerSerial issuerSerial)
        {
            checkValues(certID, algId, digest, issuerSerial);

            certID = OtherCertID.GetInstance(certID);

            checkValues(certID, algId, digest, issuerSerial);

            Asn1InputStream aIn = new Asn1InputStream(certID.ToAsn1Object().GetEncoded());

            Asn1Sequence seq = (Asn1Sequence)aIn.ReadObject();

            certID = OtherCertID.GetInstance(seq);

            checkValues(certID, algId, digest, issuerSerial);
        }
Beispiel #24
0
        public override void PerformTest()
        {
            string          country            = "AU";
            DirectoryString typeOfSubstitution = new DirectoryString("substitution");
            GeneralName     thirdPerson        = new GeneralName(new X509Name("CN=thirdPerson"));
            IssuerSerial    certRef            = new IssuerSerial(new GeneralNames(new GeneralName(new X509Name("CN=test"))), new DerInteger(1));

            ProcurationSyntax procuration = new ProcurationSyntax(country, typeOfSubstitution, thirdPerson);

            checkConstruction(procuration, country, typeOfSubstitution, thirdPerson, null);

            procuration = new ProcurationSyntax(country, typeOfSubstitution, certRef);

            checkConstruction(procuration, country, typeOfSubstitution, null, certRef);

            procuration = new ProcurationSyntax(null, typeOfSubstitution, certRef);

            checkConstruction(procuration, null, typeOfSubstitution, null, certRef);

            procuration = new ProcurationSyntax(country, null, certRef);

            checkConstruction(procuration, country, null, null, certRef);

            procuration = ProcurationSyntax.GetInstance(null);

            if (procuration != null)
            {
                Fail("null GetInstance() failed.");
            }

            try
            {
                ProcurationSyntax.GetInstance(new Object());

                Fail("GetInstance() failed to detect bad object.");
            }
            catch (ArgumentException)
            {
                // expected
            }
        }
        private ProcurationSyntax(Asn1Sequence seq)
        {
            //IL_002d: Unknown result type (might be due to invalid IL or missing references)
            //IL_00cb: Unknown result type (might be due to invalid IL or missing references)
            if (seq.Count < 1 || seq.Count > 3)
            {
                throw new ArgumentException(string.Concat((object)"Bad sequence size: ", (object)seq.Count));
            }
            global::System.Collections.IEnumerator enumerator = seq.GetEnumerator();
            while (enumerator.MoveNext())
            {
                Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(enumerator.get_Current());
                switch (instance.TagNo)
                {
                case 1:
                    country = DerPrintableString.GetInstance(instance, isExplicit: true).GetString();
                    break;

                case 2:
                    typeOfSubstitution = DirectoryString.GetInstance(instance, isExplicit: true);
                    break;

                case 3:
                {
                    Asn1Object @object = instance.GetObject();
                    if (@object is Asn1TaggedObject)
                    {
                        thirdPerson = GeneralName.GetInstance(@object);
                    }
                    else
                    {
                        certRef = IssuerSerial.GetInstance(@object);
                    }
                    break;
                }

                default:
                    throw new ArgumentException(string.Concat((object)"Bad tag number: ", (object)instance.TagNo));
                }
            }
        }
Beispiel #26
0
        private void checkConstruction(
            ProcurationSyntax procuration,
            string country,
            DirectoryString typeOfSubstitution,
            GeneralName thirdPerson,
            IssuerSerial certRef)
        {
            checkValues(procuration, country, typeOfSubstitution, thirdPerson, certRef);

            procuration = ProcurationSyntax.GetInstance(procuration);

            checkValues(procuration, country, typeOfSubstitution, thirdPerson, certRef);

            Asn1InputStream aIn = new Asn1InputStream(procuration.ToAsn1Object().GetEncoded());

            Asn1Sequence seq = (Asn1Sequence)aIn.ReadObject();

            procuration = ProcurationSyntax.GetInstance(seq);

            checkValues(procuration, country, typeOfSubstitution, thirdPerson, certRef);
        }
Beispiel #27
0
        private ProcurationSyntax(Asn1Sequence seq)
        {
            if (seq.Count < 1 || seq.Count > 3)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }
            IEnumerator enumerator = seq.GetEnumerator();

            while (enumerator.MoveNext())
            {
                Asn1TaggedObject instance = Asn1TaggedObject.GetInstance(enumerator.Current);
                switch (instance.TagNo)
                {
                case 1:
                    this.country = DerPrintableString.GetInstance(instance, true).GetString();
                    break;

                case 2:
                    this.typeOfSubstitution = DirectoryString.GetInstance(instance, true);
                    break;

                case 3:
                {
                    Asn1Object @object = instance.GetObject();
                    if (@object is Asn1TaggedObject)
                    {
                        this.thirdPerson = GeneralName.GetInstance(@object);
                    }
                    else
                    {
                        this.certRef = IssuerSerial.GetInstance(@object);
                    }
                    break;
                }

                default:
                    throw new ArgumentException("Bad tag number: " + instance.TagNo);
                }
            }
        }
Beispiel #28
0
        /**
         * Constructor from Asn1Sequence.
         * <p/>
         * The sequence is of type ProcurationSyntax:
         * <p/>
         * <pre>
         *               ProcurationSyntax ::= SEQUENCE {
         *                 country [1] EXPLICIT PrintableString(SIZE(2)) OPTIONAL,
         *                 typeOfSubstitution [2] EXPLICIT DirectoryString (SIZE(1..128)) OPTIONAL,
         *                 signingFor [3] EXPLICIT SigningFor
         *               }
         * <p/>
         *               SigningFor ::= CHOICE
         *               {
         *                 thirdPerson GeneralName,
         *                 certRef IssuerSerial
         *               }
         * </pre>
         *
         * @param seq The ASN.1 sequence.
         */
        private ProcurationSyntax(
            Asn1Sequence seq)
        {
            if (seq.Count < 1 || seq.Count > 3)
            {
                throw new ArgumentException("Bad sequence size: " + seq.Count);
            }

            IEnumerator e = seq.GetEnumerator();

            while (e.MoveNext())
            {
                Asn1TaggedObject o = Asn1TaggedObject.GetInstance(e.Current);
                switch (o.TagNo)
                {
                case 1:
                    country = DerPrintableString.GetInstance(o, true).GetString();
                    break;

                case 2:
                    typeOfSubstitution = DirectoryString.GetInstance(o, true);
                    break;

                case 3:
                    Asn1Object signingFor = o.GetObject();
                    if (signingFor is Asn1TaggedObject)
                    {
                        thirdPerson = GeneralName.GetInstance(signingFor);
                    }
                    else
                    {
                        certRef = IssuerSerial.GetInstance(signingFor);
                    }
                    break;

                default:
                    throw new ArgumentException("Bad tag number: " + o.TagNo);
                }
            }
        }
Beispiel #29
0
    private V2Form(Asn1Sequence seq)
    {
        if (seq.Count > 3)
        {
            throw new ArgumentException("Bad sequence size: " + seq.Count);
        }
        int num = 0;

        if (!(seq[0] is Asn1TaggedObject))
        {
            num++;
            issuerName = GeneralNames.GetInstance(seq[0]);
        }
        int num2 = num;
        Asn1TaggedObject instance;

        while (true)
        {
            if (num2 == seq.Count)
            {
                return;
            }
            instance = Asn1TaggedObject.GetInstance(seq[num2]);
            if (instance.TagNo == 0)
            {
                baseCertificateID = IssuerSerial.GetInstance(instance, explicitly: false);
            }
            else
            {
                if (instance.TagNo != 1)
                {
                    break;
                }
                objectDigestInfo = ObjectDigestInfo.GetInstance(instance, isExplicit: false);
            }
            num2++;
        }
        throw new ArgumentException("Bad tag number: " + instance.TagNo);
    }
    private EssCertIDv2(Asn1Sequence seq)
    {
        if (seq.Count > 3)
        {
            throw new ArgumentException("Bad sequence size: " + seq.Count, "seq");
        }
        int num = 0;

        if (seq[0] is Asn1OctetString)
        {
            hashAlgorithm = DefaultAlgID;
        }
        else
        {
            hashAlgorithm = AlgorithmIdentifier.GetInstance(seq[num++].ToAsn1Object());
        }
        certHash = Asn1OctetString.GetInstance(seq[num++].ToAsn1Object()).GetOctets();
        if (seq.Count > num)
        {
            issuerSerial = IssuerSerial.GetInstance(Asn1Sequence.GetInstance(seq[num].ToAsn1Object()));
        }
    }