List<Extension> orderedExtensions = getExtensionsWithoutPoison(
parsedPreCertificate.getTBSCertificate().getExtensions(),
issuerInformation.getX509authorityKeyIdentifier());
V3TBSCertificateGenerator tbsCertificateGenerator = new V3TBSCertificateGenerator();
TBSCertificate tbsPart = parsedPreCertificate.getTBSCertificate();
// Copy certificate.
// Version 3 is implied by the generator.
tbsCertificateGenerator.setSerialNumber(tbsPart.getSerialNumber());
tbsCertificateGenerator.setSignature(tbsPart.getSignature());
if (issuerInformation.getName() != null) {
tbsCertificateGenerator.setIssuer(issuerInformation.getName());
} else {
tbsCertificateGenerator.setIssuer(tbsPart.getIssuer());
}
tbsCertificateGenerator.setStartDate(tbsPart.getStartDate());
tbsCertificateGenerator.setEndDate(tbsPart.getEndDate());
tbsCertificateGenerator.setSubject(tbsPart.getSubject());
tbsCertificateGenerator.setSubjectPublicKeyInfo(tbsPart.getSubjectPublicKeyInfo());
tbsCertificateGenerator.setIssuerUniqueID(tbsPart.getIssuerUniqueId());
tbsCertificateGenerator.setSubjectUniqueID(tbsPart.getSubjectUniqueId());
tbsCertificateGenerator.setExtensions(
new Extensions(orderedExtensions.toArray(new Extension[]{})));
return tbsCertificateGenerator.generateTBSCertificate();
} catch (CertificateException e) {
throw new CertificateTransparencyException("Certificate error: " + e.getMessage(), e);
} catch (IOException e) {
throw new CertificateTransparencyException("Error deleting extension: " + e.getMessage(), e);
}