diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2017-09-17 13:27:15 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2017-09-17 13:27:15 +0700 |
commit | 5947e7375fb40a94e705e799b7a3a81c95b1c937 (patch) | |
tree | b1a0892d3665fcd36269035ab452e96a932ab780 /crypto/test/src | |
parent | Avoid infinity appearing in lookup table for FixedPointCombMultiplier (diff) | |
download | BouncyCastle.NET-ed25519-5947e7375fb40a94e705e799b7a3a81c95b1c937.tar.xz |
Port of some newer test cases and data from Java CertTest
Diffstat (limited to 'crypto/test/src')
-rw-r--r-- | crypto/test/src/test/CertTest.cs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/crypto/test/src/test/CertTest.cs b/crypto/test/src/test/CertTest.cs index 72e17e458..d9af06c82 100644 --- a/crypto/test/src/test/CertTest.cs +++ b/crypto/test/src/test/CertTest.cs @@ -19,6 +19,7 @@ using Org.BouncyCastle.Security; using Org.BouncyCastle.Security.Certificates; using Org.BouncyCastle.Utilities.Collections; using Org.BouncyCastle.Utilities.Encoders; +using Org.BouncyCastle.Utilities.IO; using Org.BouncyCastle.Utilities.Test; using Org.BouncyCastle.X509; using Org.BouncyCastle.X509.Extension; @@ -2426,6 +2427,19 @@ namespace Org.BouncyCastle.Tests return new AsymmetricCipherKeyPair(pubKey, privKey); } + private void rfc4491Test() + { + X509CertificateParser certFact = new X509CertificateParser(); + + X509Certificate x509 = certFact.ReadCertificate(new MemoryStream(gostRFC4491_94, false)); + + x509.Verify(x509.GetPublicKey()); + + x509 = (X509Certificate)certFact.ReadCertificate(new MemoryStream(gostRFC4491_2001, false)); + + x509.Verify(x509.GetPublicKey()); + } + private void doTestNullDerNullCert() { AsymmetricCipherKeyPair keyPair = GenerateLongFixedKeys(); @@ -2469,6 +2483,71 @@ namespace Org.BouncyCastle.Tests } } + private void pemFileTest() + { + X509CertificateParser fact = new X509CertificateParser(); + + ICollection certs1 = fact.ReadCertificates(GetTestDataAsStream("cert_chain.data")); + IsTrue("certs wrong <cr><nl>", 2 == certs1.Count); + + MemoryStream input = new MemoryStream(Streams.ReadAll(GetTestDataAsStream("cert_chain.data")), false); + + ISet certs2 = new HashSet(); + while (input.Position < input.Length) + { + X509Certificate c = fact.ReadCertificate(input); + + // this isn't strictly correct with the way it's defined in the Java JavaDoc - need it for backward + // compatibility. + if (c != null) + { + certs2.Add(c); + } + } + IsTrue("certs size <cr><nl>", certs1.Count == certs2.Count); + + certs2.RemoveAll(certs1); + IsTrue("collection not empty", certs2.Count == 0); + } + + private void invalidCrls() + { + X509CrlParser crlParser = new X509CrlParser(); + + ICollection crls = crlParser.ReadCrls(GetTestDataAsStream("cert_chain.data")); + IsTrue("multi crl", crls.Count == 0); + + X509Crl crl = crlParser.ReadCrl(GetTestDataAsStream("cert_chain.data")); + IsTrue("single crl", crl == null); + } + + private void pemFileTestWithNl() + { + X509CertificateParser fact = new X509CertificateParser(); + + ICollection certs1 = fact.ReadCertificates(GetTestDataAsStream("cert_chain_nl.data")); + IsTrue("certs wrong <nl>", 2 == certs1.Count); + + MemoryStream input = new MemoryStream(Streams.ReadAll(GetTestDataAsStream("cert_chain_nl.data")), false); + + ISet certs2 = new HashSet(); + while (input.Position < input.Length) + { + X509Certificate c = fact.ReadCertificate(input); + + // this isn't strictly correct with the way it's defined in the Java JavaDoc - need it for backward + // compatibility. + if (c != null) + { + certs2.Add(c); + } + } + IsTrue("certs size <nl>", certs1.Count == certs2.Count); + + certs2.RemoveAll(certs1); + IsTrue("collection not empty", certs2.Count == 0); + } + public override void PerformTest() { checkCertificate(1, cert1); @@ -2518,7 +2597,12 @@ namespace Org.BouncyCastle.Tests checkCrlCreation3(); pemTest(); + pemFileTest(); + pemFileTestWithNl(); pkcs7Test(); + rfc4491Test(); + + invalidCrls(); doTestForgedSignature(); |