// Extract request in a format that EJBCA can process
CertReqMessages certReqMessages = CertReqMessages.getInstance(new ASN1InputStream(submessage.getRequestData()).readObject());
PKIMessage msg = new PKIMessage(new PKIHeader(
new DERInteger(2), new GeneralName(new X509Name("CN=unused")), new GeneralName(new X509Name("CN=unused"))),
new PKIBody(certReqMessages, 2)); // [2] CertReqMessages --Certification Request
CrmfRequestMessage crmfReq = new CrmfRequestMessage(msg, null, true, null);
crmfReq.setUsername(submessage.getUsername());
crmfReq.setPassword(submessage.getPassword());
// Request and extract certificate from response
IResponseMessage response = signSession.createCertificate(admin, crmfReq, org.ejbca.core.protocol.cmp.CmpResponseMessage.class, null);
ASN1InputStream ais = new ASN1InputStream(new ByteArrayInputStream(response.getResponseMessage()));
CertRepMessage certRepMessage = PKIMessage.getInstance(ais.readObject()).getBody().getCp();
InputStream inStream = new ByteArrayInputStream(certRepMessage.getResponse(0).getCertifiedKeyPair().getCertOrEncCert().getCertificate().getEncoded());