gen.setNotBefore(new Date(System.currentTimeMillis() - 50000));
gen.setNotAfter(new Date(System.currentTimeMillis() + 50000));
gen.setSerialNumber(BigInteger.ONE);
gen.setSignatureAlgorithm("SHA1WithRSAEncryption");
X509AttributeCertificate aCert = gen.generate(privKey, "BC");
aCert.checkValidity();
aCert.verify(pubKey, "BC");
AttributeCertificateHolder holder = aCert.getHolder();
if (holder.getEntityNames() != null)
{
fail("entity names set when none expected");
}
if (!holder.getSerialNumber().equals(iCert.getSerialNumber()))
{
fail("holder serial number doesn't match");
}
if (!holder.getIssuer()[0].equals(iCert.getIssuerX500Principal()))
{
fail("holder issuer doesn't match");
}
if (!holder.match(iCert))
{
fail("generated holder not matching holder certificate");
}
X509Attribute[] attrs = aCert.getAttributes("2.5.24.72");
if (attrs == null)
{
fail("attributes related to 2.5.24.72 not found");
}
X509Attribute attr = attrs[0];
if (!attr.getOID().equals("2.5.24.72"))
{
fail("attribute oid mismatch");
}
ASN1Encodable[] values = attr.getValues();
GeneralName role = GeneralNames.getInstance(values[0]).getNames()[0];
if (role.getTagNo() != GeneralName.rfc822Name)
{
fail("wrong general name type found in role");
}
if (!((ASN1String)role.getName()).getString().equals("DAU123456789"))
{
fail("wrong general name value found in role");
}
X509Certificate sCert = (X509Certificate)fact.generateCertificate(new ByteArrayInputStream(holderCertWithBaseCertificateID));
if (holder.match(sCert))
{
fail("generated holder matching wrong certificate");
}
equalityAndHashCodeTest(aCert, aCert.getEncoded());
}