@Test void buildTlsConfig_shouldUseUserSuppliedCertificateWhenDefined() throws Exception { Config defaultConfig = ConfigFactory.parseResources(XConfigTest.class, "xrpc.conf").getConfig("tls"); Config configWithCertPaths = ConfigFactory.parseMap( ImmutableMap.of( "privateKeyPath", getResourceAbsolutePath("testing-purposes-only-key.pem"), "x509CertPath", getResourceAbsolutePath("testing-purposes-only-certificate.crt"))); TlsConfig tlsConfig = XConfig.buildTlsConfig(configWithCertPaths.withFallback(defaultConfig)); String privateKey = getFileContent("testing-purposes-only-key.pem"); String certificate = getFileContent("testing-purposes-only-certificate.crt"); assertThat(tlsConfig.getPrivateKey(), is(parsePrivateKeyFromPem(privateKey))); assertThat(tlsConfig.getCertificateAndChain().length, is(1)); assertThat(tlsConfig.getCertificateAndChain()[0], is(parseX509CertificateFromPem(certificate))); }
@VisibleForTesting static TlsConfig buildTlsConfig(Config config) { TlsConfig.Builder configBuilder = TlsConfig.builderFrom(config); if (!config.hasPath("privateKeyPath") || !config.hasPath("x509CertPath")) { log.info( "Private key path or x509 certificate path not defined. " + "Generating self signed certificate."); SelfSignedCertificate selfSignedCert; try { selfSignedCert = new SelfSignedCertificate("localhost"); } catch (CertificateException ce) { throw new IllegalStateException("Error creating a self-signed cert", ce); } configBuilder.privateKey(selfSignedCert.key()).certificate(selfSignedCert.cert()); } return configBuilder.build(); }
XConfig { @VisibleForTesting static TlsConfig buildTlsConfig(Config config) { TlsConfig.Builder configBuilder = TlsConfig.builderFrom(config); if (!config.hasPath("privateKeyPath") || !config.hasPath("x509CertPath")) { log.info( "Private key path or x509 certificate path not defined. " + "Generating self signed certificate."); SelfSignedCertificate selfSignedCert; try { selfSignedCert = new SelfSignedCertificate("localhost"); } catch (CertificateException ce) { throw new IllegalStateException("Error creating a self-signed cert", ce); } configBuilder.privateKey(selfSignedCert.key()).certificate(selfSignedCert.cert()); } return configBuilder.build(); } }
XConfig { @VisibleForTesting static TlsConfig buildTlsConfig(Config config) { TlsConfig.Builder configBuilder = TlsConfig.builderFrom(config); if (!config.hasPath("privateKeyPath") || !config.hasPath("x509CertPath")) { log.info( "Private key path or x509 certificate path not defined. " + "Generating self signed certificate."); SelfSignedCertificate selfSignedCert; try { selfSignedCert = new SelfSignedCertificate("localhost"); } catch (CertificateException ce) { throw new IllegalStateException("Error creating a self-signed cert", ce); } configBuilder.privateKey(selfSignedCert.key()).certificate(selfSignedCert.cert()); } return configBuilder.build(); } XConfig();  XConfig(Config configOverrides); }
XConfig { @VisibleForTesting static TlsConfig buildTlsConfig(Config config) { TlsConfig.Builder configBuilder = TlsConfig.builderFrom(config); if (!config.hasPath("privateKeyPath") || !config.hasPath("x509CertPath")) { log.info( "Private key path or x509 certificate path not defined. " + "Generating self signed certificate."); SelfSignedCertificate selfSignedCert; try { selfSignedCert = new SelfSignedCertificate("localhost"); } catch (CertificateException ce) { throw new IllegalStateException("Error creating a self-signed cert", ce); } configBuilder.privateKey(selfSignedCert.key()).certificate(selfSignedCert.cert()); } return configBuilder.build(); } XConfig();  XConfig(Config configOverrides); Map<String, List<Double>> getClientRateLimitOverride(); }
XConfig { @VisibleForTesting static TlsConfig buildTlsConfig(Config config) { TlsConfig.Builder configBuilder = TlsConfig.builderFrom(config); if (!config.hasPath("privateKeyPath") || !config.hasPath("x509CertPath")) { log.info( "Private key path or x509 certificate path not defined. " + "Generating self signed certificate."); SelfSignedCertificate selfSignedCert; try { selfSignedCert = new SelfSignedCertificate("localhost"); } catch (CertificateException ce) { throw new IllegalStateException("Error creating a self-signed cert", ce); } configBuilder.privateKey(selfSignedCert.key()).certificate(selfSignedCert.cert()); } return configBuilder.build(); } XConfig();  XConfig(Config configOverrides); Map<String, List<Double>> getClientRateLimitOverride();  }