synchronized KeyAndCertificateFactory buildAndSaveCertificates() {
        try {
            // personal keys
            KeyPair keyPair = generateKeyPair(FAKE_KEYSIZE);
            PrivateKey mockServerPrivateKey = keyPair.getPrivate();
            PublicKey mockServerPublicKey = keyPair.getPublic();

            // ca keys
            PrivateKey caPrivateKey = loadPrivateKeyFromPEMFile("org/mockserver/socket/CertificateAuthorityPrivateKey.pem");
            X509Certificate caCert = loadX509FromPEMFile("org/mockserver/socket/CertificateAuthorityCertificate.pem");

            // generate mockServer certificate
            X509Certificate mockServerCert = createCASignedCert(
                mockServerPublicKey,
                caCert,
                caPrivateKey,
                caCert.getPublicKey(),
                ConfigurationProperties.sslCertificateDomainName(),
                ConfigurationProperties.sslSubjectAlternativeNameDomains(),
                ConfigurationProperties.sslSubjectAlternativeNameIps()
            );
            String randomUUID = UUID.randomUUID().toString();
            mockServerCertificatePEMFile = saveCertificateAsPEMFile(mockServerCert, "MockServerCertificate" + randomUUID + ".pem", true);
            mockServerPublicKeyPEMFile = saveCertificateAsPEMFile(mockServerPublicKey, "MockServerPublicKey" + randomUUID + ".pem", true);
            mockServerPrivateKeyPEMFile = saveCertificateAsPEMFile(mockServerPrivateKey, "MockServerPrivateKey" + randomUUID + ".pem", true);
        } catch (Exception e) {
            MOCK_SERVER_LOGGER.error("Error while refreshing certificates", e);
        }
        return this;
    }
synchronized KeyAndCertificateFactory buildAndSaveCertificates ( ) { try { KeyPair keyPair = generateKeyPair ( FAKE_KEYSIZE ) ; PrivateKey mockServerPrivateKey = keyPair . getPrivate ( ) ; PublicKey mockServerPublicKey = keyPair . getPublic ( ) ; PrivateKey caPrivateKey = loadPrivateKeyFromPEMFile ( "org/mockserver/socket/CertificateAuthorityPrivateKey.pem" ) ; X509Certificate caCert = loadX509FromPEMFile ( "org/mockserver/socket/CertificateAuthorityCertificate.pem" ) ; X509Certificate mockServerCert = createCASignedCert ( mockServerPublicKey , caCert , caPrivateKey , caCert . getPublicKey ( ) , ConfigurationProperties . sslCertificateDomainName ( ) , ConfigurationProperties . sslSubjectAlternativeNameDomains ( ) , ConfigurationProperties . sslSubjectAlternativeNameIps ( ) ) ; String randomUUID = UUID . randomUUID ( ) . toString ( ) ; mockServerCertificatePEMFile = saveCertificateAsPEMFile ( mockServerCert , "MockServerCertificate" + randomUUID + ".pem" , true ) ; mockServerPublicKeyPEMFile = saveCertificateAsPEMFile ( mockServerPublicKey , "MockServerPublicKey" + randomUUID + ".pem" , true ) ; mockServerPrivateKeyPEMFile = saveCertificateAsPEMFile ( mockServerPrivateKey , "MockServerPrivateKey" + randomUUID + ".pem" , true ) ; } catch ( Exception e ) { MOCK_SERVER_LOGGER . error ( "Error while refreshing certificates" , e ) ; } return this ; }
Create a KeyStore with a server certificate for the given domain and subject alternative names.