class InternalTlsCertificateService {

    public X509Certificate importInternalTlsCertificate(byte[] certificateBytes) throws InvalidCertificateException {
        X509Certificate x509Certificate = null;
        try {
            x509Certificate = CryptoUtils.readCertificate(certificateBytes);
        } catch (Exception e) {
            throw new InvalidCertificateException("cannot convert bytes to certificate", e);
        }
        auditDataHelper.putCertificateHash(x509Certificate);
        try {
            CertUtils.writePemToFile(certificateBytes, internalCertPath);
            CertUtils.createPkcs12(internalKeyPath, internalCertPath, internalKeystorePath);
        } catch (Exception e) {
            log.error("Failed to import internal TLS cert", e);
            throw new DeviationAwareRuntimeException("cannot import internal tls cert", e,
                    new ErrorDeviation(IMPORT_INTERNAL_CERT_FAILED));
        }
        return x509Certificate;
    }

    @Autowired public  InternalTlsCertificateService(InternalTlsCertificateRepository internalTlsCertificateRepository,
            ExternalProcessRunner externalProcessRunner,
            @Value("${script.generate-certificate.path}") String generateCertScriptPath,
            @Value("${script.generate-certificate.args}") String generateCertScriptArgs,
            AuditDataHelper auditDataHelper);

}