// Create a root CVCA
try {
adminGroupSession.init(admin, rootcadn.hashCode(), DEFAULT_SUPERADMIN_CN);
CVCCAInfo cvccainfo = new CVCCAInfo(rootcadn, rootcaname, SecConst.CA_ACTIVE, new Date(), SecConst.CERTPROFILE_FIXED_ROOTCA, 3650, null, // Expiretime
CAInfo.CATYPE_CVC, CAInfo.SELFSIGNED, null, catokeninfo, "JUnit CVC CA", -1, null, 24, // CRLPeriod
0, // CRLIssueInterval
10, // CRLOverlapTime
10, // Delta CRL period
new ArrayList<Integer>(), // CRL publishers
true, // Finish User
extendedcaservices, new ArrayList<Integer>(), // Approvals Settings
1, // Number of Req approvals
true, // Include in health check
true, // isDoEnforceUniquePublicKeys
true, // isDoEnforceUniqueDistinguishedName
false, // isDoEnforceUniqueSubjectDNSerialnumber
true, // useCertReqHistory
true, // useUserStorage
true // useCertificateStorage
);
caAdminSession.createCA(admin, cvccainfo);
cvcainfo = caAdminSession.getCAInfo(admin, rootcaname);
assertEquals(CAInfo.CATYPE_CVC, cvcainfo.getCAType());
Certificate cert = (Certificate) cvcainfo.getCertificateChain().iterator().next();
String sigAlg = CertTools.getSignatureAlgorithm(cert);
assertEquals(AlgorithmConstants.SIGALG_SHA256_WITH_RSA_AND_MGF1, sigAlg);
assertEquals("CVC", cert.getType());
assertEquals(rootcadn, CertTools.getSubjectDN(cert));
assertEquals(rootcadn, CertTools.getIssuerDN(cert));
assertEquals(rootcadn, cvcainfo.getSubjectDN());
PublicKey pk = cert.getPublicKey();
if (pk instanceof RSAPublicKey) {
RSAPublicKey rsapk = (RSAPublicKey) pk;
assertEquals(rsapk.getAlgorithm(), "RSA");
BigInteger modulus = rsapk.getModulus();
int len = modulus.bitLength();
assertEquals(1024, len);
} else {
assertTrue("Public key is not RSA", false);
}
assertTrue("CA is not valid for the specified duration.", CertTools.getNotAfter(cert).after(
new Date(new Date().getTime() + 10 * 364 * 24 * 60 * 60 * 1000L))
&& CertTools.getNotAfter(cert).before(new Date(new Date().getTime() + 10 * 366 * 24 * 60 * 60 * 1000L)));
// Check role
CardVerifiableCertificate cvcert = (CardVerifiableCertificate) cert;
String role = cvcert.getCVCertificate().getCertificateBody().getAuthorizationTemplate().getAuthorizationField().getRole().name();
assertEquals("SETESTCVCA00001", cvcert.getCVCertificate().getCertificateBody().getHolderReference().getConcatenated());
assertEquals("CVCA", role);
ret = true;
} catch (CAExistsException pee) {
log.info("CA exists.");
}
assertTrue(ret);
// Create a Sub DV domestic
ret = false;
try {
adminGroupSession.init(admin, dvddn.hashCode(), DEFAULT_SUPERADMIN_CN);
// Create a Certificate profile
CertificateProfile profile = new CACertificateProfile();
profile.setType(CertificateProfile.TYPE_SUBCA);
certificateProfileSession.addCertificateProfile(admin, "TESTCVCDV", profile);
int profileid = certificateProfileSession.getCertificateProfileId(admin, "TESTCVCDV");
CVCCAInfo cvccainfo = new CVCCAInfo(dvddn, dvdcaname, SecConst.CA_ACTIVE, new Date(), profileid, 3650, null, // Expiretime
CAInfo.CATYPE_CVC, rootcadn.hashCode(), null, catokeninfo, "JUnit CVC CA", -1, null, 24, // CRLPeriod
0, // CRLIssueInterval
10, // CRLOverlapTime
10, // Delta CRL period
new ArrayList<Integer>(), // CRL publishers
true, // Finish User
extendedcaservices, new ArrayList<Integer>(), // Approvals Settings
1, // Number of Req approvals
true, // Include in health check
true, // isDoEnforceUniquePublicKeys
true, // isDoEnforceUniqueDistinguishedName
false, // isDoEnforceUniqueSubjectDNSerialnumber
true, // useCertReqHistory
true, // useUserStorage
true // useCertificateStorage
);
caAdminSession.createCA(admin, cvccainfo);
dvdcainfo = caAdminSession.getCAInfo(admin, dvdcaname);
assertEquals(CAInfo.CATYPE_CVC, dvdcainfo.getCAType());
Certificate cert = (Certificate) dvdcainfo.getCertificateChain().iterator().next();
assertEquals("CVC", cert.getType());
assertEquals(CertTools.getSubjectDN(cert), dvddn);
assertEquals(CertTools.getIssuerDN(cert), rootcadn);
assertEquals(dvdcainfo.getSubjectDN(), dvddn);
PublicKey pk = cert.getPublicKey();
if (pk instanceof RSAPublicKey) {
RSAPublicKey rsapk = (RSAPublicKey) pk;
assertEquals(rsapk.getAlgorithm(), "RSA");
BigInteger modulus = rsapk.getModulus();
int len = modulus.bitLength();
assertEquals(1024, len);
} else {
assertTrue("Public key is not RSA", false);
}
assertTrue("CA is not valid for the specified duration.", CertTools.getNotAfter(cert).after(
new Date(new Date().getTime() + 10 * 364 * 24 * 60 * 60 * 1000L))
&& CertTools.getNotAfter(cert).before(new Date(new Date().getTime() + 10 * 366 * 24 * 60 * 60 * 1000L)));
// Check role
CardVerifiableCertificate cvcert = (CardVerifiableCertificate) cert;
assertEquals("SETESTDV-D00001", cvcert.getCVCertificate().getCertificateBody().getHolderReference().getConcatenated());
String role = cvcert.getCVCertificate().getCertificateBody().getAuthorizationTemplate().getAuthorizationField().getRole().name();
assertEquals("DV_D", role);
String accessRights = cvcert.getCVCertificate().getCertificateBody().getAuthorizationTemplate().getAuthorizationField().getAccessRight()
.name();
assertEquals("READ_ACCESS_DG3_AND_DG4", accessRights);
ret = true;
} catch (CAExistsException pee) {
log.info("CA exists.");
}
assertTrue(ret);
// Create a Sub DV foreign
ret = false;
try {
adminGroupSession.init(admin, dvfdn.hashCode(), DEFAULT_SUPERADMIN_CN);
CVCCAInfo cvccainfo = new CVCCAInfo(dvfdn, dvfcaname, SecConst.CA_ACTIVE, new Date(), SecConst.CERTPROFILE_FIXED_SUBCA, 3650, null, // Expiretime
CAInfo.CATYPE_CVC, rootcadn.hashCode(), null, catokeninfo, "JUnit CVC CA", -1, null, 24, // CRLPeriod
0, // CRLIssueInterval
10, // CRLOverlapTime
10, // Delta CRL period
new ArrayList<Integer>(), // CRL publishers