// We need the sequence generated id before we create the EntitlementCertificate,
// otherwise we could have used cascading create
serialCurator.create(serial);
String dn = createDN(consumer);
IdentityCertificate identityCert = new IdentityCertificate();
KeyPair keyPair = keyPairCurator.getConsumerKeyPair(consumer);
X509Certificate x509cert = pki.createX509Certificate(dn, null, null,
startDate, endDate, keyPair, BigInteger.valueOf(serial.getId()),
consumer.getName());
identityCert.setCert(new String(pki.getPemEncoded(x509cert)));
identityCert.setKey(new String(pki.getPemEncoded(keyPair.getPrivate())));
identityCert.setSerial(serial);
identityCert.setConsumer(consumer);
consumer.setIdCert(identityCert);
return idCertCurator.create(identityCert);
}