byte[] transid = CmpMessageHelper.createSenderNonce();
Date notBefore = new Date();
Date notAfter = new Date(new Date().getTime()+24*3600*1000);
KeyPair keys = KeyTools.genKeys("512", AlgorithmConstants.KEYALGORITHM_RSA);
String subjectDN = "CN=cmpRAAuthenticationTestUser" + RND.nextLong();
PKIMessage one = genCertReq(CertTools.getSubjectDN(caCertificate), subjectDN, keys, caCertificate, nonce, transid, true, null, notBefore, notAfter, null);
PKIMessage req = protectPKIMessage(one, false, pbeSecret, keyId, 567);
assertNotNull("Request was not created properly.", req);
int reqId = req.getBody().getIr().getCertReqMsg(0).getCertReq().getCertReqId().getValue().intValue();
ByteArrayOutputStream bao = new ByteArrayOutputStream();
new DEROutputStream(bao).writeObject(req);
byte[] ba = bao.toByteArray();
byte[] resp = sendCmpHttp(ba, 200);
checkCmpResponseGeneral(resp, CertTools.getSubjectDN(caCertificate), subjectDN, caCertificate, nonce, transid, false, pbeSecret);
X509Certificate cert = checkCmpCertRepMessage(subjectDN, caCertificate, resp, reqId);
// Send a confirm message to the CA
String hash = "foo123";
PKIMessage confirm = genCertConfirm(subjectDN, caCertificate, nonce, transid, hash, reqId);
assertNotNull("Could not create confirmation message.", confirm);
PKIMessage req1 = protectPKIMessage(confirm, false, pbeSecret, keyId, 567);
bao = new ByteArrayOutputStream();
new DEROutputStream(bao).writeObject(req1);
ba = bao.toByteArray();
resp = sendCmpHttp(ba, 200);
checkCmpResponseGeneral(resp, CertTools.getSubjectDN(caCertificate), subjectDN, caCertificate, nonce, transid, false, pbeSecret);
checkCmpPKIConfirmMessage(subjectDN, caCertificate, resp);
// Now revoke the bastard using the CMPv1 reason code!
PKIMessage rev = genRevReq(CertTools.getSubjectDN(caCertificate), subjectDN, cert.getSerialNumber(), caCertificate, nonce, transid, false);
PKIMessage revReq = protectPKIMessage(rev, false, pbeSecret, keyId, 567);
assertNotNull("Could not create revocation message.", revReq);
bao = new ByteArrayOutputStream();
new DEROutputStream(bao).writeObject(revReq);
ba = bao.toByteArray();
resp = sendCmpHttp(ba, 200);