* @throws Exception
*/
public void testSpkacOneYear() throws Exception {
BouncyKeygenService srvc = new BouncyKeygenService();
srvc.initialize();
Certificate cert = srvc.createFromSpkac(spkac);
PubKey spk = cert.getSubjectPublicKey();
assertNotNull(spk);
assertTrue(spk instanceof RSAPubKey);
assertEquals("the expected and real values don't match",
"c16c47a74f601f081e73df17da1c729f194094df487a24aeed3d424abcb8\r\n" +
"b8c3c292e8e47294e0d27ee87e11ef91efe4c25bfd4292bf2a8e207104c8\r\n" +
"9d6bb74a5e6171174fd4abd14eaf957723e9d105134ad96b8b7b9831970e\r\n" +
"0b9c9716a005572c115af403b4160c62daa929ccaf691a4a2910be969593\r\n" +
"2236ef39281fcb85\r\n", ((RSAPubKey) spk).getHexModulus());
assertEquals("int exponent is not correct", "65537", ((RSAPubKey) spk).getIntExponent());
Date now = new Date();
cert.setSubjectCommonName("Test");
cert.addSubjectAlternativeName(WEBID);
cert.startEarlier("2");
CertSerialisation certByte = cert.getSerialisation();
//test that the returned certificate contains the correct values...
Date endDate = cert.getEndDate();
long end10 = now.getTime() + YEAR + (10 * SECOND);
assertTrue("end date (" + endDate + ") is too late . It should be before " + new Date(end10) + " - we added 10 seconds .",
endDate.getTime() < end10);
end10 = now.getTime() + YEAR - (10 * SECOND);
assertTrue("end date (" + endDate + ") is too early. It should be after " + new Date(end10) + " - we removed 10 seconds .",
endDate.getTime() > end10);
Date startDate = cert.getStartDate();
long start10 = now.getTime() - (2 * HOUR) - (10 * SECOND);
assertTrue("start date (" + startDate + ") is too early. It should be after " + new Date(start10) + "- we removed 2 hours and 10 seconds.",
startDate.getTime() > start10);
assertTrue("start date (" + startDate + ") is too late It should be after " + new Date(start10) + "- we removed 10 secondes short of 2 hours.",
startDate.getTime() < (now.getTime() - (2 * HOUR) + (10 * SECOND)));