// private key
// Simple self signed request
KeyPair keyPair = KeyTools.genKeys(keyspec, keyalg);
CVCertificate isrequest = CertificateGenerator.createRequest(keyPair, signalg, caRef, holderRef);
// Edit our favorite test user
UserDataVOWS user1 = new UserDataVOWS();
user1.setUsername("WSTESTUSER1");
user1.setPassword("foo123");
user1.setClearPwd(true);
user1.setSubjectDN("CN=Test,C=SE");
user1.setCaName(caname);
user1.setStatus(UserDataConstants.STATUS_NEW);
user1.setTokenType("USERGENERATED");
user1.setEndEntityProfileName("EMPTY");
user1.setCertificateProfileName("ENDUSER");
// editUser and set status to new
ejbcaraws.editUser(user1);
List<Certificate> certenv = ejbcaraws.cvcRequest(user1.getUsername(), user1.getPassword(), new String(Base64.encode(isrequest.getDEREncoded())));
assertNotNull(certenv);
Certificate wscert = certenv.get(0);
byte[] b64cert = wscert.getCertificateData();
java.security.cert.Certificate iscert = CertTools.getCertfromByteArray(Base64.decode(b64cert));
obj = CertificateParser.parseCVCObject(Base64.decode(b64cert));
CVCertificate iscvc = (CVCertificate) obj;
assertEquals("Test", iscvc.getCertificateBody().getHolderReference().getMnemonic());
// It must verify using the DVCAs old public key
PublicKey pk = KeyTools.getECPublicKeyWithParams(oldPublicKey, cvcacert.getPublicKey());
iscert.verify(pk);
boolean thrown = false;
try {
// it must not be possible to verify this with the new public key
pk = KeyTools.getECPublicKeyWithParams(newPublicKey, cvcacert.getPublicKey());
iscert.verify(pk);
} catch (SignatureException e) {
thrown = true;
}
assertTrue(thrown);
// Receive the CA certificate response so the DV CA's new key is
// activated
dvholderref = cert.getCertificateBody().getHolderReference();
dvretcert = CertificateGenerator.createTestCertificate(cert.getCertificateBody().getPublicKey(), cvcakeypair.getPrivate(), caRef, dvholderref, signalg,
AuthorizationRoleEnum.DV_D);
// Here we want to activate the new key pair
// System.out.println(dvretcert.getAsText());
ejbcaraws.caCertResponse(caname, dvretcert.getDEREncoded(), cachain, pwd);
// Check that the cert was received and the CA activated
dvinfo = caAdminSessionRemote.getCAInfo(intAdmin, caname);
assertEquals(SecConst.CA_ACTIVE, dvinfo.getStatus());
dvcerts = dvinfo.getCertificateChain();
assertEquals(2, dvcerts.size());
dvcertactive = (CardVerifiableCertificate) dvcerts.iterator().next();
obj = CertificateParser.parseCVCObject(dvcertactive.getEncoded());
// System.out.println(obj.getAsText());
dvcertactive.verify(cvcakeypair.getPublic());
String sequence5 = dvcertactive.getCVCertificate().getCertificateBody().getHolderReference().getSequence();
assertEquals(sequence3, sequence5); // sequence in new certificate
// should be same as sequence in
// request, which was old sequence +
// 1
// Check to see that is really is the new keypair
pubk1 = new String(Base64.encode(dvcertactive.getPublicKey().getEncoded(), false));
pubk2 = new String(Base64.encode(newPublicKey.getEncoded(), false));
assertEquals(pubk1, pubk2);
// Finally verify that we can issue an IS certificate and verify with
// the new public key, i.e. it is signed by the new private key
// Simple self signed request
isrequest = CertificateGenerator.createRequest(keyPair, signalg, caRef, holderRef);
// Edit our favorite test user
user1 = new UserDataVOWS();
user1.setUsername("WSTESTUSER1");
user1.setPassword("foo123");
user1.setClearPwd(true);
user1.setSubjectDN("CN=Test1,C=SE");
user1.setCaName(caname);
user1.setStatus(UserDataConstants.STATUS_NEW);
user1.setTokenType("USERGENERATED");
user1.setEndEntityProfileName("EMPTY");
user1.setCertificateProfileName("ENDUSER");
// editUser and set status to new
ejbcaraws.editUser(user1);
certenv = ejbcaraws.cvcRequest(user1.getUsername(), user1.getPassword(), new String(Base64.encode(isrequest.getDEREncoded())));
assertNotNull(certenv);
wscert = certenv.get(0);
b64cert = wscert.getCertificateData();
iscert = CertTools.getCertfromByteArray(Base64.decode(b64cert));
obj = CertificateParser.parseCVCObject(Base64.decode(b64cert));