Source:
public SimpleCertificateResponseMessageType createCertificate(CreateCertificateRequestMessageType request) { String alias = request.getAlias(); String ou = request.getOrganizationalUnit(); String o = request.getOrganization(); String c = request.getCountryName(); String refNumber = request.getReferenceNumber(); if (StringUtils.isBlank(alias) || StringUtils.isBlank(ou) || StringUtils.isBlank(o) || StringUtils.isBlank(c) || StringUtils.isBlank(refNumber)) { return buildSimpleResponse(false, "alias, Organizational Unit, Organization, Country Name and Reference Number are required."); } if (!copyFile(FILE_JKS_GATEWAY, FILE_JKS_GATEWAY_NEW)) { return buildSimpleResponse(false, "unable to make a copy of gateway-jks."); } try { String dn = MessageFormat.format("CN={0}, OU={1}, O={2}, C={3}", refNumber, ou, o, c); KeyPair pair = CoreHelpUtils.generateKeyPair(getKeySize(), null); X509Certificate x509cert = CoreHelpUtils.generateCertificate(dn, pair, getValidityDays(), ALGORITHM_SHA256_RSA); KeyStore jksGatewayNew = getGatewayNew(); if (jksGatewayNew.containsAlias(alias)) { jksGatewayNew.deleteEntry(alias); } jksGatewayNew.setKeyEntry(alias, pair.getPrivate(), System.getProperty(CertificateManagerImpl.KEY_STORE_PASSWORD_KEY).toCharArray(), CoreHelpUtils.getCertificateChain(x509cert)); CoreHelpUtils.saveJksTo(jksGatewayNew, System.getProperty(CertificateManagerImpl.KEY_STORE_PASSWORD_KEY), FILE_JKS_GATEWAY_NEW); } catch (Exception e) { LOG.error("error while generating the certificate for gateway_new.jks: {}", alias, e); return buildSimpleResponse(false, "fail to generate the certificate: " + alias); } return buildSimpleResponse(true, ACT_SUCCESSFUL); }

Target:
public SimpleCertificateResponseMessageType createCertificate(CreateCertificateRequestMessageType request) { String alias = request.getAlias(); String ou = request.getOrganizationalUnit(); String o = request.getOrganization(); String c = request.getCountryName(); String refNumber = request.getReferenceNumber(); if (StringUtils.isBlank(alias) || StringUtils.isBlank(ou) || StringUtils.isBlank(o) || StringUtils.isBlank(c) || StringUtils.isBlank(refNumber)) { return buildSimpleResponse(false, "Alias, Organizational Unit, Organization, Country Name and Reference Number are required."); } tempKeystore = null; if (!copyFile(FILE_JKS_GATEWAY, FILE_JKS_GATEWAY_NEW)) { return buildSimpleResponse(false, "unable to make a copy of gateway-jks."); } try { String dn = MessageFormat.format("CN={0}, OU={1}, O={2}, C={3}", refNumber, ou, o, c); KeyPair pair = CoreHelpUtils.generateKeyPair(getKeySize(), null); X509Certificate x509cert = generateCertificate(pair, dn, getValidityDays(), ALGORITHM_SHA256_RSA); KeyStore jksGatewayNew = getTempKeystore(); if (jksGatewayNew.containsAlias(alias)) { jksGatewayNew.deleteEntry(alias); } jksGatewayNew.setKeyEntry(alias, pair.getPrivate(), System.getProperty(CertificateManagerImpl.KEY_STORE_PASSWORD_KEY).toCharArray(), CoreHelpUtils.getCertificateChain(x509cert)); CoreHelpUtils.saveJksTo(jksGatewayNew, System.getProperty(CertificateManagerImpl.KEY_STORE_PASSWORD_KEY), FILE_JKS_GATEWAY_NEW); } catch (Exception e) { LOG.error("error while generating the certificate for gateway_new.jks: {}", alias, e); return buildSimpleResponse(false, "fail to generate the certificate: " + alias); } return buildSimpleResponse(true, ACT_SUCCESSFUL); }