protected CertificateResponse buildV3Certificate(final BouncyCastleCertificateRequest request) throws OperatorCreationException, GeneralSecurityException, IOException {
JcaX509v3CertificateBuilder builder = null;
ContentSigner contentSigner = null;
JcaContentSignerBuilder contentSignerBuilder = new JcaContentSignerBuilder(request.getSignAlgorithm());
contentSignerBuilder.setProvider(BouncyCastleProviderHelper.PROVIDER_NAME);
if ((request.getIssuerPrivateKey() != null) && (request.getIssuerCertificate() != null)) {
builder = new JcaX509v3CertificateBuilder(request.getIssuerCertificate(), request.getSerialNumber(), request.getNotBefore(), request.getNotAfter(), request.getSubjectAsX500Principal(), request.getPublicKey());
if (request.isCa()) {
AuthorityKeyIdentifier authorityKeyIdentifier = new JcaX509ExtensionUtils().createAuthorityKeyIdentifier(request.getIssuerCertificate().getPublicKey());
builder.addExtension(X509Extension.authorityKeyIdentifier, false, authorityKeyIdentifier);
}
SubjectKeyIdentifier subjectKeyIdentifier = new JcaX509ExtensionUtils().createSubjectKeyIdentifier(request.getIssuerCertificate().getPublicKey());
builder.addExtension(X509Extension.subjectKeyIdentifier, false, subjectKeyIdentifier);
contentSigner = contentSignerBuilder.build(request.getIssuerPrivateKey());
} else {
builder = new JcaX509v3CertificateBuilder(request.getIssuerAsX500Name(), request.getSerialNumber(), request.getNotBefore(), request.getNotAfter(), request.getSubjectAsX500Name(), request.getPublicKey());
SubjectKeyIdentifier subjectKeyIdentifier = new JcaX509ExtensionUtils().createSubjectKeyIdentifier(request.getPublicKey());
builder.addExtension(X509Extension.subjectKeyIdentifier, false, subjectKeyIdentifier);
contentSigner = contentSignerBuilder.build(request.getPrivateKey());
}
this.addV3KeyUsage(builder, request);
this.addV3ExtendedKeyUsage(builder, request);
this.addV3CertificatePolicies(builder, request);