FileDocCategorySizeDatePackage
CertPathValidatorTestPKIX.javaAPI DocAndroid 1.5 API6793Wed May 06 22:41:06 BST 2009tests.targets.security.cert

CertPathValidatorTestPKIX

public class CertPathValidatorTestPKIX extends CertPathValidatorTest

Fields Summary
private CertPath
certPath
private PKIXParameters
params
private String
selfSignedCert
Constructors Summary
public CertPathValidatorTestPKIX()

        super("PKIX");
    
Methods Summary
java.security.cert.CertPathgetCertPath()

        return certPath;
    
java.security.cert.CertPathParametersgetParams()

        return params;
    
protected voidsetUp()

        super.setUp();
        KeyStore keyStore = null;
        try {
            keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        } catch (KeyStoreException e) {
            fail(e.getMessage());
        }

        try {
            keyStore.load(null, null);
        } catch (NoSuchAlgorithmException e) {
            fail(e.getMessage());
        } catch (CertificateException e) {
            fail(e.getMessage());
        } catch (IOException e) {
            fail(e.getMessage());
        }

        CertificateFactory certificateFactory = null;
        try {
            certificateFactory = CertificateFactory.getInstance("X509");
        } catch (CertificateException e) {
            fail(e.getMessage());
        }

        X509Certificate selfSignedcertificate = null;
        try {
            selfSignedcertificate = (X509Certificate) certificateFactory
                    .generateCertificate(new ByteArrayInputStream(
                            selfSignedCert.getBytes()));
        } catch (CertificateException e) {
            fail(e.getMessage());
        }

        try {
            keyStore.setCertificateEntry("selfSignedCert",
                    selfSignedcertificate);
        } catch (KeyStoreException e) {
            fail(e.getMessage());
        }

        X509CertSelector targetConstraints = new X509CertSelector();
        targetConstraints.setCertificate(selfSignedcertificate);

        List<Certificate> certList = new ArrayList<Certificate>();
        certList.add(selfSignedcertificate);
        CertStoreParameters storeParams = new CollectionCertStoreParameters(
                certList);


        CertStore certStore = null;
        try {
            certStore = CertStore.getInstance("Collection", storeParams);
        } catch (InvalidAlgorithmParameterException e) {
            fail(e.getMessage());
        } catch (NoSuchAlgorithmException e) {
            fail(e.getMessage());
        }


        PKIXBuilderParameters parameters = null;
        try {
            parameters = new PKIXBuilderParameters(keyStore, targetConstraints);
            parameters.addCertStore(certStore);
            parameters.setRevocationEnabled(false);
        } catch (KeyStoreException e) {
            fail(e.getMessage());
        } catch (InvalidAlgorithmParameterException e) {
            fail(e.getMessage());
        }

        CertPathBuilder pathBuilder = null;
        try {
            pathBuilder = CertPathBuilder.getInstance("PKIX");
        } catch (NoSuchAlgorithmException e) {
            fail(e.getMessage());
        }
        CertPathBuilderResult builderResult = null;
        try {
            builderResult = pathBuilder.build(parameters);
        } catch (CertPathBuilderException e) {
            fail(e.getMessage());
        } catch (InvalidAlgorithmParameterException e) {
            fail(e.getMessage());
        }

        certPath = builderResult.getCertPath();

        try {
            params = new PKIXParameters(keyStore);
            params.setRevocationEnabled(false);
        } catch (KeyStoreException e) {
            fail(e.getMessage());
        } catch (InvalidAlgorithmParameterException e) {
            fail(e.getMessage());
        }
    
voidvalidateResult(java.security.cert.CertPathValidatorResult validatorResult)

        assertNotNull("validator result is null", validatorResult);
        assertTrue("validator result is not PKIX",
                validatorResult instanceof PKIXCertPathValidatorResult);