コード例 #1
0
 public global::System.Collections.IEnumerable GetSignatures()
 {
     global::System.Collections.IList list = subSigs;
     if (list == null)
     {
         list = Platform.CreateArrayList((global::System.Collections.ICollection)keySigs);
         {
             global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)idSigs).GetEnumerator();
             try
             {
                 while (enumerator.MoveNext())
                 {
                     global::System.Collections.ICollection range = (global::System.Collections.ICollection)enumerator.get_Current();
                     CollectionUtilities.AddRange(list, (global::System.Collections.IEnumerable)range);
                 }
             }
             finally
             {
                 global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                 if (disposable != null)
                 {
                     disposable.Dispose();
                 }
             }
         }
     }
     return(new EnumerableProxy((global::System.Collections.IEnumerable)list));
 }
コード例 #2
0
        public void TestMultiply()
        {
            ArrayList nameList = new ArrayList();

            CollectionUtilities.AddRange(nameList, ECNamedCurveTable.Names);
            CollectionUtilities.AddRange(nameList, CustomNamedCurves.Names);

            string[] names = (string[])nameList.ToArray(typeof(string));
            Array.Sort(names);
            ISet oids = new HashSet();

            foreach (string name in names)
            {
                DerObjectIdentifier oid = ECNamedCurveTable.GetOid(name);
                if (oid == null)
                {
                    oid = CustomNamedCurves.GetOid(name);
                }
                if (oid != null)
                {
                    if (oids.Contains(oid))
                    {
                        continue;
                    }

                    oids.Add(oid);
                }

                RandMult(name);
            }
        }
コード例 #3
0
 public void CollectionUtilities_AddRange_Test2()
 {
     using (var verify = new Verify())
     {
         List <string> target = null;
         List <string> list   = null;
         verify.ArgumentNullException("target", () => CollectionUtilities.AddRange(target, list));
     }
 }
コード例 #4
0
        public void CollectionUtilities_AddRange_Test6()
        {
            using (var verify = new Verify())
            {
                List <string> target = new List <string>();

                CollectionUtilities.AddRange(target, "AAA", "BBB", "CCC");
                verify.ItemsAreEqual(new[] { "AAA", "BBB", "CCC" }, target, "AddRange should have added 3 items");
            }
        }
コード例 #5
0
 public void CollectionUtilities_AddRange_Test11()
 {
     using (var verify = new Verify())
     {
         var list = (new List <int> {
             1, 2, 3
         }).Where(x => true);
         ICollection <int> target = new ReadOnlyCollection <int>(new List <int>());
         verify.ArgumentException("target", () => CollectionUtilities.AddRange(target, list), "read-only list");
         verify.ArgumentException("target", () => CollectionUtilities.AddRange(target, 1, 2, 3), "read-only list");
     }
 }
コード例 #6
0
 public void CollectionUtilities_AddRange_Test10()
 {
     using (var verify = new Verify())
     {
         IEnumerable <int> list = new List <int> {
             1, 2, 3
         };
         ICollection <int> target = new ReadOnlyCollection <int>(new List <int>());
         verify.ArgumentException("target", () => CollectionUtilities.AddRange(target, list), "read-only list");
         verify.ArgumentException("target", () => CollectionUtilities.AddRange(target, 1, 2, 3), "read-only list");
     }
 }
コード例 #7
0
        /// <summary>
        /// Realiza la contrafirma de una firma CAdES existente
        /// </summary>
        /// <param name="sigDocument"></param>
        /// <param name="signerInfoNode"></param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public SignatureDocument CounterSign(SignatureDocument sigDocument, SignerInfoNode signerInfoNode, SignatureParameters parameters)
        {
            if (sigDocument == null)
            {
                throw new Exception("Se necesita una firma previa para poder realizar la cofirma");
            }

            if (signerInfoNode == null)
            {
                throw new Exception("Se necesita especificar el nodo de firma para aplicar la contrafirma");
            }

            CheckParameters(parameters);

            byte[] signature = null;

            using (MemoryStream ms = new MemoryStream(signerInfoNode.SignerInformation.GetSignature()))
            {
                byte[] toBeSigned = ToBeSigned(new CmsProcessableInputStream(ms), parameters, null, true);
                signature = parameters.Signer.SignData(toBeSigned, parameters.DigestMethod);
            }

            CustomCMSSignedDataGenerator generator = CreateSignedGenerator(new PreComputedSigner(signature), parameters, null);

            var result = generator.GenerateCounterSigners(signerInfoNode.SignerInformation);

            SignerInformation updatedSI = SignerInformation.AddCounterSigners(signerInfoNode.SignerInformation, result);

            List <X509Certificate> certs             = new List <X509Certificate>();
            IX509Store             originalCertStore = sigDocument.SignedData.GetCertificates("Collection");

            signerInfoNode.SignerInformation = updatedSI;

            CollectionUtilities.AddRange(certs, GetCertificatesFromStore(originalCertStore));

            X509CertificateParser parser = new X509CertificateParser();
            var signerCertificate        = parser.ReadCertificate(parameters.Certificate.GetRawCertData());

            if (!CheckCertExists(signerCertificate, originalCertStore))
            {
                certs.Add(signerCertificate);
            }

            IX509Store certStore = X509StoreFactory.Create("Certificate/Collection", new X509CollectionStoreParameters(certs));

            CmsSignedData newSignedData = CmsSignedData.ReplaceCertificatesAndCrls(sigDocument.SignedData, certStore, sigDocument.SignedData.GetCrls("Collection"), null);

            return(new SignatureDocument(newSignedData));
        }
コード例 #8
0
        public void CollectionUtilities_AddRange_Test3b()
        {
            using (var verify = new Verify())
            {
                List <string> target = new List <string>();
                List <string> list   = new List <string>();
                target.Add("AAA");
                list.Add("BBB");
                list.Add("CCC");

                CollectionUtilities.AddRange((ICollection <string>)target, (IEnumerable <string>)list);
                verify.AreEqual(3, target.Count, "AddRange should have added 3 items");
                verify.ItemsAreEqual(new[] { "AAA", "BBB", "CCC" }, target, "AddRange should have added 3 items");
            }
        }
コード例 #9
0
        /// <summary>Allows enumeration of all signatures/certifications associated with this key.</summary>
        /// <returns>An <c>IEnumerable</c> with all signatures/certifications.</returns>
        public IEnumerable GetSignatures()
        {
            IList sigs = subSigs;

            if (sigs == null)
            {
                sigs = Platform.CreateArrayList(keySigs);

                foreach (ICollection extraSigs in idSigs)
                {
                    CollectionUtilities.AddRange(sigs, extraSigs);
                }
            }

            return(new EnumerableProxy(sigs));
        }
コード例 #10
0
        public void TestAddSubtractMultiplyTwiceEncoding()
        {
            ArrayList names = new ArrayList();

            CollectionUtilities.AddRange(names, ECNamedCurveTable.Names);
            CollectionUtilities.AddRange(names, CustomNamedCurves.Names);

            ISet uniqNames = new HashSet(names);

            foreach (string name in uniqNames)
            {
                X9ECParameters x9A = ECNamedCurveTable.GetByName(name);
                X9ECParameters x9B = CustomNamedCurves.GetByName(name);

                if (x9A != null && x9B != null)
                {
                    Assert.AreEqual(x9A.Curve.Field, x9B.Curve.Field);
                    Assert.AreEqual(x9A.Curve.A.ToBigInteger(), x9B.Curve.A.ToBigInteger());
                    Assert.AreEqual(x9A.Curve.B.ToBigInteger(), x9B.Curve.B.ToBigInteger());
                    AssertOptionalValuesAgree(x9A.Curve.Cofactor, x9B.Curve.Cofactor);
                    AssertOptionalValuesAgree(x9A.Curve.Order, x9B.Curve.Order);

                    AssertPointsEqual("Custom curve base-point inconsistency", x9A.G, x9B.G);

                    Assert.AreEqual(x9A.H, x9B.H);
                    Assert.AreEqual(x9A.N, x9B.N);
                    AssertOptionalValuesAgree(x9A.GetSeed(), x9B.GetSeed());

                    BigInteger k  = new BigInteger(x9A.N.BitLength, secRand);
                    ECPoint    pA = x9A.G.Multiply(k);
                    ECPoint    pB = x9B.G.Multiply(k);
                    AssertPointsEqual("Custom curve multiplication inconsistency", pA, pB);
                }

                if (x9A != null)
                {
                    ImplAddSubtractMultiplyTwiceEncodingTestAllCoords(x9A);
                }

                if (x9B != null)
                {
                    ImplAddSubtractMultiplyTwiceEncodingTestAllCoords(x9B);
                }
            }
        }
コード例 #11
0
        /// <summary>Allows enumeration of all signatures/certifications associated with this key.</summary>
        /// <returns>An <c>IEnumerable</c> with all signatures/certifications.</returns>
        public IEnumerable <IPgpSignature> GetSignatures()
        {
            IList <IPgpSignature> sigs;

            if (_subSigs != null)
            {
                sigs = _subSigs;
            }
            else
            {
                sigs = Platform.CreateArrayList(_keySigs);

                foreach (var extraSigs in _idSigs)
                {
                    CollectionUtilities.AddRange(sigs, extraSigs);
                }
            }

            return(sigs);
        }
コード例 #12
0
        public void TestAddSubtractMultiplyTwiceEncoding()
        {
            ArrayList names = new ArrayList();

            CollectionUtilities.AddRange(names, ECNamedCurveTable.Names);
            CollectionUtilities.AddRange(names, CustomNamedCurves.Names);

            foreach (string name in names)
            {
                X9ECParameters x9ECParameters = ECNamedCurveTable.GetByName(name);
                if (x9ECParameters != null)
                {
                    ImplAddSubtractMultiplyTwiceEncodingTestAllCoords(x9ECParameters);
                }

                x9ECParameters = CustomNamedCurves.GetByName(name);
                if (x9ECParameters != null)
                {
                    ImplAddSubtractMultiplyTwiceEncodingTestAllCoords(x9ECParameters);
                }
            }
        }
コード例 #13
0
        private IList GetTestCurves()
        {
            ArrayList x9s   = new ArrayList();
            ArrayList names = new ArrayList();

            CollectionUtilities.AddRange(names, ECNamedCurveTable.Names);
            CollectionUtilities.AddRange(names, CustomNamedCurves.Names);
            foreach (string name in names)
            {
                X9ECParameters x9 = ECNamedCurveTable.GetByName(name);
                if (x9 != null)
                {
                    AddTestCurves(x9s, x9);
                }

                x9 = CustomNamedCurves.GetByName(name);
                if (x9 != null)
                {
                    AddTestCurves(x9s, x9);
                }
            }
            return(x9s);
        }
コード例 #14
0
        public void TestFixedPointMultiplier()
        {
            FixedPointCombMultiplier M = new FixedPointCombMultiplier();

            ArrayList names = new ArrayList();

            CollectionUtilities.AddRange(names, ECNamedCurveTable.Names);
            CollectionUtilities.AddRange(names, CustomNamedCurves.Names);

            ISet uniqNames = new HashSet(names);

            foreach (string name in uniqNames)
            {
                X9ECParameters x9A = ECNamedCurveTable.GetByName(name);
                X9ECParameters x9B = CustomNamedCurves.GetByName(name);

                X9ECParameters x9 = x9B != null ? x9B : x9A;

                for (int i = 0; i < TestsPerCurve; ++i)
                {
                    BigInteger k    = new BigInteger(x9.N.BitLength, Random);
                    ECPoint    pRef = ECAlgorithms.ReferenceMultiply(x9.G, k);

                    if (x9A != null)
                    {
                        ECPoint pA = M.Multiply(x9A.G, k);
                        AssertPointsEqual("Standard curve fixed-point failure", pRef, pA);
                    }

                    if (x9B != null)
                    {
                        ECPoint pB = M.Multiply(x9B.G, k);
                        AssertPointsEqual("Custom curve fixed-point failure", pRef, pB);
                    }
                }
            }
        }
コード例 #15
0
 public void AddCertificates(IX509Store certStore)
 {
     CollectionUtilities.AddRange(_certs, (global::System.Collections.IEnumerable)CmsUtilities.GetCertificatesFromStore(certStore));
 }
コード例 #16
0
 public void AddCertificates(
     IX509Store certStore)
 {
     CollectionUtilities.AddRange(_certs, CmsUtilities.GetCertificatesFromStore(certStore));
 }
コード例 #17
0
 public void AddCrls(
     IX509Store crlStore)
 {
     CollectionUtilities.AddRange(_crls, CmsUtilities.GetCrlsFromStore(crlStore));
 }
コード例 #18
0
 public void AddCrls(IX509Store crlStore)
 {
     CollectionUtilities.AddRange(_crls, (global::System.Collections.IEnumerable)CmsUtilities.GetCrlsFromStore(crlStore));
 }