Implementing org.jscep.server.ScepServlet I need to provide an implementation for the method doEnroll ( List<X509Certificate> doEnroll(CertificationRequest certificationRequest) ).
How do I get from the provided CertificationRequest to return a X509Certificate?
Besides the CertificationRequest I also have the certificate I need to use for signing
It will suffice with a way to get the public key from the certification request, since I have the rest of the code for generating the certificate.
What I have up till now:
protected List<X509Certificate> doEnroll(CertificationRequest certificationRequest) throws OperationFailureException, Exception {
CaCertificate caCertificate = getSelfSignedCertificate();
X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
certGen.setIssuerDN(caCertificate.getCertificate().getSubjectX500Principal());
certGen.setNotBefore(notBefore);
certGen.setNotAfter(notAfter);
certGen.setSubjectDN(certificationRequest.getCertificationRequestInfo().getSubject());
certGen.setPublicKey(publicKey); // this is basically what I need
X509Certificate issuedCert = certGen.generate(caCertificate.getKeypair().getPrivate());
List<X509Certificate> x509Certificates = new ArrayList<X509Certificate>();
x509Certificates.add(issuedCert);
return x509Certificates;
}
Found this method in an jscep test class: