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());
}