package org.bouncycastle.jce.provider.test;
import java.io.ByteArrayInputStream;
import java.security.GeneralSecurityException;
import java.security.Security;
import java.security.cert.CertPathBuilder;
import java.security.cert.CertPathBuilderResult;
import java.security.cert.CertStore;
import java.security.cert.CertificateFactory;
import java.security.cert.CollectionCertStoreParameters;
import java.security.cert.PKIXBuilderParameters;
import java.security.cert.TrustAnchor;
import java.security.cert.X509CRL;
import java.security.cert.X509CertSelector;
import java.security.cert.X509Certificate;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.encoders.Base64;
import org.bouncycastle.util.test.SimpleTest;
/*
* These tests are taken from the NIST X.509 Validation Test Suite
* available at: http://csrc.nist.gov/pki/testing/x509paths.html
*
* Only the relevant certificate and crl data has been kept, in order
* to keep the class size to a minimum.
*
*/
public class NISTCertPathTest
extends SimpleTest
{
private static final String TEST_POLICY_1 = "2.16.840.1.101.3.1.48.1";
private static final String TEST_POLICY_2 = "2.16.840.1.101.3.1.48.2";
private static final String TEST_POLICY_3 = "2.16.840.1.101.3.1.48.3";
private static final String TEST_POLICY_4 = "2.16.840.1.101.3.1.48.4";
private static final String TEST_POLICY_5 = "2.16.840.1.101.3.1.48.5";
private static Set ANY;
private static Set TP1;
private static Set TP2;
private static Set TP3;
private static Set TP4;
private static Set TP1_TP2;
static {
ANY = new HashSet();
TP1 = new HashSet();
TP1.add(TEST_POLICY_1);
TP2 = new HashSet();
TP2.add(TEST_POLICY_2);
TP3 = new HashSet();
TP3.add(TEST_POLICY_3);
TP4 = new HashSet();
TP4.add(TEST_POLICY_4);
TP1_TP2 = new HashSet();
TP1_TP2.add(TEST_POLICY_1);
TP1_TP2.add(TEST_POLICY_2);
}
/*
*
* FIELDS
*
*/
private CertificateFactory fact;
private X509Certificate trustedCert;
private X509CRL trustedCRL;
private Set trustedSet;
private int testCount;
private Vector testFail;
private StringBuffer resultBuf;
public String getName()
{
return "NISTCertPathTest";
}
public void performTest()
{
init();
test(" 1", TEST_1_DATA , true , false);
test(" 2", TEST_2_DATA , false, false);
test(" 3", TEST_3_DATA , false, false);
test(" 4", TEST_4_DATA , true , false);
test(" 5", TEST_5_DATA , false, false);
test(" 6", TEST_6_DATA , false, false);
test(" 7", TEST_7_DATA , true , false);
test(" 8", TEST_8_DATA , false, false);
test(" 9", TEST_9_DATA , false, false);
test("10", TEST_10_DATA, false, false);
test("11", TEST_11_DATA, false, false);
test("12", TEST_12_DATA, true , false);
test("13", TEST_13_DATA, false, false);
test("14", TEST_14_DATA, false, false);
test("15", TEST_15_DATA, true , false);
test("16", TEST_16_DATA, true , false);
test("17", TEST_17_DATA, true , false);
test("18", TEST_18_DATA, true , false);
test("19", TEST_19_DATA, false, false);
test("20", TEST_20_DATA, false, false);
test("21", TEST_21_DATA, false, false);
test("22", TEST_22_DATA, false, false);
test("23", TEST_23_DATA, false, false);
test("24", TEST_24_DATA, true , false);
test("25", TEST_25_DATA, false, false);
test("26", TEST_26_DATA, true , false);
test("27", TEST_27_DATA, true , false);
test("28", TEST_28_DATA, false, false);
test("29", TEST_29_DATA, false, false);
test("30", TEST_30_DATA, true , false);
test("31", TEST_31_DATA, false, false);
test("32", TEST_32_DATA, false, false);
test("33", TEST_33_DATA, true , false);
test("34a", TEST_34_DATA, ANY , true , true , false);
test("34b", TEST_34_DATA, ANY , false, true , false);
test("34c", TEST_34_DATA, TP1 , true , true , false);
test("34d", TEST_34_DATA, TP1 , false, true , false);
test("34e", TEST_34_DATA, TP2 , true , false, false);
test("34f", TEST_34_DATA, TP2 , false, true , false);
test("35a", TEST_35_DATA, false, true , false);
test("35b", TEST_35_DATA, true , false, false);
test("36a", TEST_36_DATA, false, true , false);
test("36b", TEST_36_DATA, true , false, false);
test("37a", TEST_37_DATA, false, true , false);
test("37b", TEST_37_DATA, true , false, false);
test("38a", TEST_38_DATA, false, true , false);
test("38b", TEST_38_DATA, true , false, false);
test("39a", TEST_39_DATA, ANY , true , true , false);
test("39b", TEST_39_DATA, ANY , false, true , false);
test("39c", TEST_39_DATA, TP1 , true , true , false);
test("39d", TEST_39_DATA, TP1 , false, true , false);
test("39e", TEST_39_DATA, TP2 , true , false, false);
test("39f", TEST_39_DATA, TP2 , false, true , false);
test("40a", TEST_40_DATA, false, true , false);
test("40b", TEST_40_DATA, true , false, false);
test("41a", TEST_41_DATA, false, true , false);
test("41b", TEST_41_DATA, true , false, false);
test("42a", TEST_42_DATA, false, true , false);
test("42b", TEST_42_DATA, true , false, false);
test("43a", TEST_43_DATA, false, true , false);
test("43b", TEST_43_DATA, true , false, false);
test("44a", TEST_44_DATA, false, true , false);
test("44b", TEST_44_DATA, true , false, false);
test("45a", TEST_45_DATA, false, false, false);
test("45b", TEST_45_DATA, true , false, false);
test("46a", TEST_46_DATA, ANY , false, true , false);
test("46b", TEST_46_DATA, ANY , true , true , false);
test("46c", TEST_46_DATA, TP1 , true , true , false);
test("46d", TEST_46_DATA, TP1 , false, true , false);
test("46e", TEST_46_DATA, TP2 , true , false, false);
test("46f", TEST_46_DATA, TP2 , false, false, false);
test("47a", TEST_47_DATA, false, false, false);
test("47b", TEST_47_DATA, true , false, false);
test("48a", TEST_48_DATA, TP1 , false, true , false);
test("48b", TEST_48_DATA, TP1 , true , true , false);
test("48c", TEST_48_DATA, ANY , false, true , false);
test("48d", TEST_48_DATA, ANY , true , true , false);
test("48e", TEST_48_DATA, TP2 , false, true , false);
test("48f", TEST_48_DATA, TP2 , true , false, false);
test("49a", TEST_49_DATA, TP1 , false, true , false);
test("49b", TEST_49_DATA, TP1 , true , true , false);
test("49c", TEST_49_DATA, TP3 , false, true , false);
test("49d", TEST_49_DATA, TP3 , true , false, false);
test("49e", TEST_49_DATA, ANY , false, true , false);
test("49f", TEST_49_DATA, ANY , true , true , false);
test("50a", TEST_50_DATA, TP1 , false, true , false);
test("50b", TEST_50_DATA, TP1 , true , true , false);
test("50c", TEST_50_DATA, TP1_TP2 , false, true , false);
test("50d", TEST_50_DATA, TP1_TP2 , true , true , false);
test("50e", TEST_50_DATA, ANY , false, true , false);
test("50f", TEST_50_DATA, ANY , true , true , false);