}
public void performTest()
throws Exception
{
X509AttributeCertificate aCert = new X509V2AttributeCertificate(attrCert);
CertificateFactory fact = CertificateFactory.getInstance("X.509","BC");
X509Certificate sCert = (X509Certificate)fact.generateCertificate(new ByteArrayInputStream(signCert));
aCert.verify(sCert.getPublicKey(), "BC");
//
// search test
//
List list = new ArrayList();
list.add(sCert);
CollectionCertStoreParameters ccsp = new CollectionCertStoreParameters(list);
CertStore store = CertStore.getInstance("Collection", ccsp);
Collection certs = store.getCertificates(aCert.getIssuer());
if (certs.size() != 1 || !certs.contains(sCert))
{
fail("sCert not found by issuer");
}
X509Attribute[] attrs = aCert.getAttributes("1.3.6.1.4.1.6760.8.1.1");
if (attrs == null || attrs.length != 1)
{
fail("attribute not found");
}
//
// reencode test
//
aCert = new X509V2AttributeCertificate(aCert.getEncoded());
aCert.verify(sCert.getPublicKey(), "BC");
X509AttributeCertificate saCert = new X509V2AttributeCertificate(new ByteArrayInputStream(aCert.getEncoded()));
if (!aCert.getNotAfter().equals(saCert.getNotAfter()))
{
fail("failed date comparison");
}
// base generator test
//
// a sample key pair.
//
RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(
new BigInteger("b4a7e46170574f16a97082b22be58b6a2a629798419be12872a4bdba626cfae9900f76abfb12139dce5de56564fab2b6543165a040c606887420e33d91ed7ed7", 16),
new BigInteger("11", 16));
RSAPrivateCrtKeySpec privKeySpec = RSA_PRIVATE_KEY_SPEC;
//
// set up the keys
//
PrivateKey privKey;
PublicKey pubKey;
KeyFactory kFact = KeyFactory.getInstance("RSA", "BC");
privKey = kFact.generatePrivate(privKeySpec);
pubKey = kFact.generatePublic(pubKeySpec);
X509V2AttributeCertificateGenerator gen = new X509V2AttributeCertificateGenerator();
gen.addAttribute(attrs[0]);
gen.setHolder(aCert.getHolder());
gen.setIssuer(aCert.getIssuer());
gen.setNotBefore(new Date(System.currentTimeMillis() - 50000));
gen.setNotAfter(new Date(System.currentTimeMillis() + 50000));
gen.setSerialNumber(aCert.getSerialNumber());
gen.setSignatureAlgorithm("SHA1WithRSAEncryption");
aCert = gen.generate(privKey, "BC");
aCert.checkValidity();
aCert.verify(pubKey, "BC");
// as the issuer is the same this should still work (even though it is not
// technically correct
certs = store.getCertificates(aCert.getIssuer());
if (certs.size() != 1 || !certs.contains(sCert))
{
fail("sCert not found by issuer");
}
attrs = aCert.getAttributes("1.3.6.1.4.1.6760.8.1.1");
if (attrs == null || attrs.length != 1)
{
fail("attribute not found");
}
//
// reencode test
//
aCert = new X509V2AttributeCertificate(aCert.getEncoded());
aCert.verify(pubKey, "BC");
AttributeCertificateIssuer issuer = aCert.getIssuer();