// Check card number extension as well
String cardNumber = SeisCardNumberExtension.getSeisCardNumber(cert);
assertEquals("123456789", cardNumber);
// Change so that we allow override of validity time
CertificateProfile prof = certificateProfileSession.getCertificateProfile(admin, cprofile);
prof.setAllowValidityOverride(true);
prof.setValidity(3065);
prof.setUseCardNumber(false);
certificateProfileSession.changeCertificateProfile(admin, "TESTVALOVERRIDE", prof);
cal = Calendar.getInstance();
Calendar notBefore = Calendar.getInstance();
notBefore.add(Calendar.DAY_OF_MONTH, 2);
cal.add(Calendar.DAY_OF_MONTH, 10);
userAdminSession.setUserStatus(admin, "foo", UserDataConstants.STATUS_NEW);
cert = (X509Certificate) signSession.createCertificate(admin, "foo", "foo123", rsakeys.getPublic(), -1, notBefore.getTime(), cal.getTime());
assertNotNull("Failed to create certificate", cert);
assertEquals(CertTools.stringToBCDNString("cn=validityoverride,c=SE"), CertTools.stringToBCDNString(dn));
notAfter = cert.getNotAfter();
cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, 11);
// Override was enabled, the cert should have notAfter less than 11 days
// in the future (10 to be exact)
assertTrue(notAfter.compareTo(cal.getTime()) < 0);
notAfter = cert.getNotBefore();
cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, 1);
// Override was enabled, the cert should have notBefore more than 1 days
// in the future (2 to be exact)
assertTrue(notAfter.compareTo(cal.getTime()) > 0);
cal.add(Calendar.DAY_OF_MONTH, 2);
assertTrue(notAfter.compareTo(cal.getTime()) < 0);
// Check that card number extension is not present
cardNumber = SeisCardNumberExtension.getSeisCardNumber(cert);
assertNull(cardNumber);
// Verify that we can not get a certificate that has notBefore befor the
// current time
// and that we can not get a certificate valid longer than the
// certificate profile allows.
prof = certificateProfileSession.getCertificateProfile(admin, cprofile);
prof.setValidity(50);
certificateProfileSession.changeCertificateProfile(admin, "TESTVALOVERRIDE", prof);
notBefore = Calendar.getInstance();
notBefore.add(Calendar.DAY_OF_MONTH, -2);
cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, 200);