AthenzJettyContainer { SslContextFactory.Server createSSLContextObject(boolean needClientAuth) { final String keyStorePath = System.getProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PATH); final String keyStorePasswordAppName = System.getProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PASSWORD_APPNAME); final String keyStorePassword = System.getProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PASSWORD); final String keyStoreType = System.getProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_TYPE, "PKCS12"); final String keyManagerPassword = System.getProperty(AthenzConsts.ATHENZ_PROP_KEYMANAGER_PASSWORD); final String keyManagerPasswordAppName = System.getProperty(AthenzConsts.ATHENZ_PROP_KEYMANAGER_PASSWORD_APPNAME); final String trustStorePath = System.getProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PATH); final String trustStorePassword = System.getProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PASSWORD); final String trustStorePasswordAppName = System.getProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PASSWORD_APPNAME); final String trustStoreType = System.getProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_TYPE, "PKCS12"); final String includedCipherSuites = System.getProperty(AthenzConsts.ATHENZ_PROP_INCLUDED_CIPHER_SUITES); final String excludedCipherSuites = System.getProperty(AthenzConsts.ATHENZ_PROP_EXCLUDED_CIPHER_SUITES); final String excludedProtocols = System.getProperty(AthenzConsts.ATHENZ_PROP_EXCLUDED_PROTOCOLS, ATHENZ_DEFAULT_EXCLUDED_PROTOCOLS); boolean enableOCSP = Boolean.parseBoolean(System.getProperty(AthenzConsts.ATHENZ_PROP_ENABLE_OCSP, "false")); boolean renegotiationAllowed = Boolean.parseBoolean(System.getProperty(AthenzConsts.ATHENZ_PROP_RENEGOTIATION_ALLOWED, "true")); SslContextFactory.Server sslContextFactory = new SslContextFactory.Server(); sslContextFactory.setEndpointIdentificationAlgorithm(null); if (keyStorePath != null) { LOG.info("Using SSL KeyStore path: {}", keyStorePath); sslContextFactory.setKeyStorePath(keyStorePath); } if (keyStorePassword != null) { sslContextFactory.setKeyStorePassword(this.privateKeyStore.getApplicationSecret(keyStorePasswordAppName, keyStorePassword)); } sslContextFactory.setKeyStoreType(keyStoreType); if (keyManagerPassword != null) { sslContextFactory.setKeyManagerPassword(this.privateKeyStore.getApplicationSecret(keyManagerPasswordAppName, keyManagerPassword)); } if (trustStorePath != null) { LOG.info("Using SSL TrustStore path: {}", trustStorePath); sslContextFactory.setTrustStorePath(trustStorePath); } if (trustStorePassword != null) { sslContextFactory.setTrustStorePassword(this.privateKeyStore.getApplicationSecret(trustStorePasswordAppName, trustStorePassword)); } sslContextFactory.setTrustStoreType(trustStoreType); if (includedCipherSuites != null && !includedCipherSuites.isEmpty()) { sslContextFactory.setIncludeCipherSuites(includedCipherSuites.split(",")); } if (excludedCipherSuites != null && !excludedCipherSuites.isEmpty()) { sslContextFactory.setExcludeCipherSuites(excludedCipherSuites.split(",")); } if (!excludedProtocols.isEmpty()) { sslContextFactory.setExcludeProtocols(excludedProtocols.split(",")); } if (needClientAuth) { sslContextFactory.setNeedClientAuth(true); } else { sslContextFactory.setWantClientAuth(true); } sslContextFactory.setEnableOCSP(enableOCSP); sslContextFactory.setRenegotiationAllowed(renegotiationAllowed); return sslContextFactory; } AthenzJettyContainer(); static String getRootDir(); void addRequestLogHandler(); void addServletHandlers(String serverHostName); HttpConfiguration newHttpConfiguration(); void addHTTPConnectors(HttpConfiguration httpConfig, int httpPort, int httpsPort,
            int statusPort); void setBanner(String banner); void createServer(int maxThreads); static AthenzJettyContainer createJettyContainer(); void run(); void stop(); static void main(String [] args);  }
@Test public void testCreateSSLContextObject() { AthenzJettyContainer container = new AthenzJettyContainer(); System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PATH, "file: System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_TYPE, "PKCS12"); System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PASSWORD, "pass123"); System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PATH, "file: System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_TYPE, "PKCS12"); System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PASSWORD, "pass123"); System.setProperty(AthenzConsts.ATHENZ_PROP_KEYMANAGER_PASSWORD, "pass123"); System.setProperty(AthenzConsts.ATHENZ_PROP_EXCLUDED_CIPHER_SUITES, DEFAULT_EXCLUDED_CIPHERS); System.setProperty(AthenzConsts.ATHENZ_PROP_INCLUDED_CIPHER_SUITES, DEFAULT_INCLUDED_CIPHERS); System.setProperty(AthenzConsts.ATHENZ_PROP_EXCLUDED_PROTOCOLS, AthenzJettyContainer.ATHENZ_DEFAULT_EXCLUDED_PROTOCOLS); SslContextFactory.Server sslContextFactory = container.createSSLContextObject(true); assertNotNull(sslContextFactory); assertEquals(sslContextFactory.getKeyStorePath(), "file: assertEquals(sslContextFactory.getKeyStoreType(), "PKCS12"); assertEquals(sslContextFactory.getTrustStoreResource().toString(), "file: assertEquals(sslContextFactory.getTrustStoreType(), "PKCS12"); assertEquals(sslContextFactory.getExcludeCipherSuites(), DEFAULT_EXCLUDED_CIPHERS.split(",")); assertEquals(sslContextFactory.getIncludeCipherSuites(), DEFAULT_INCLUDED_CIPHERS.split(",")); assertEquals(sslContextFactory.getExcludeProtocols(), AthenzJettyContainer.ATHENZ_DEFAULT_EXCLUDED_PROTOCOLS.split(",")); assertTrue(sslContextFactory.getNeedClientAuth()); }
@Test public void testCreateSSLContextObjectNoValues() { AthenzJettyContainer container = new AthenzJettyContainer(); SslContextFactory.Server sslContextFactory = container.createSSLContextObject(false); assertNotNull(sslContextFactory); assertNull(sslContextFactory.getKeyStoreResource()); assertEquals(sslContextFactory.getKeyStoreType(), "PKCS12"); assertNull(sslContextFactory.getTrustStoreResource()); assertEquals(sslContextFactory.getTrustStoreType(), "PKCS12"); assertTrue(sslContextFactory.getWantClientAuth()); assertFalse(sslContextFactory.getNeedClientAuth()); }
@Test public void testCreateSSLContextObjectNoKeyStore() { AthenzJettyContainer container = new AthenzJettyContainer(); System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PATH, "file: System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_TYPE, "PKCS12"); System.setProperty(AthenzConsts.ATHENZ_PROP_TRUSTSTORE_PASSWORD, "pass123"); System.setProperty(AthenzConsts.ATHENZ_PROP_KEYMANAGER_PASSWORD, "pass123"); System.setProperty(AthenzConsts.ATHENZ_PROP_EXCLUDED_CIPHER_SUITES, DEFAULT_EXCLUDED_CIPHERS); System.setProperty(AthenzConsts.ATHENZ_PROP_INCLUDED_CIPHER_SUITES, DEFAULT_INCLUDED_CIPHERS); System.setProperty(AthenzConsts.ATHENZ_PROP_EXCLUDED_PROTOCOLS, AthenzJettyContainer.ATHENZ_DEFAULT_EXCLUDED_PROTOCOLS); SslContextFactory.Server sslContextFactory = container.createSSLContextObject(true); assertNotNull(sslContextFactory); assertNull(sslContextFactory.getKeyStoreResource()); assertEquals(sslContextFactory.getKeyStoreType(), "PKCS12"); assertEquals(sslContextFactory.getTrustStoreResource().toString(), "file: assertEquals(sslContextFactory.getTrustStoreType(), "PKCS12"); assertEquals(sslContextFactory.getExcludeCipherSuites(), DEFAULT_EXCLUDED_CIPHERS.split(",")); assertEquals(sslContextFactory.getIncludeCipherSuites(), DEFAULT_INCLUDED_CIPHERS.split(",")); assertEquals(sslContextFactory.getExcludeProtocols(), AthenzJettyContainer.ATHENZ_DEFAULT_EXCLUDED_PROTOCOLS.split(",")); }
@Test public void testCreateSSLContextObjectNoTrustStore() { AthenzJettyContainer container = new AthenzJettyContainer(); System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PATH, "file: System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_TYPE, "PKCS12"); System.setProperty(AthenzConsts.ATHENZ_PROP_KEYSTORE_PASSWORD, "pass123"); System.setProperty(AthenzConsts.ATHENZ_PROP_EXCLUDED_CIPHER_SUITES, DEFAULT_EXCLUDED_CIPHERS); System.setProperty(AthenzConsts.ATHENZ_PROP_INCLUDED_CIPHER_SUITES, DEFAULT_INCLUDED_CIPHERS); System.setProperty(AthenzConsts.ATHENZ_PROP_EXCLUDED_PROTOCOLS, AthenzJettyContainer.ATHENZ_DEFAULT_EXCLUDED_PROTOCOLS); SslContextFactory.Server sslContextFactory = container.createSSLContextObject(false); assertNotNull(sslContextFactory); assertEquals(sslContextFactory.getKeyStorePath(), "file: assertEquals(sslContextFactory.getKeyStoreType(), "PKCS12"); assertNull(sslContextFactory.getTrustStore()); assertEquals(sslContextFactory.getTrustStoreType(), "PKCS12"); assertEquals(sslContextFactory.getExcludeCipherSuites(), DEFAULT_EXCLUDED_CIPHERS.split(",")); assertEquals(sslContextFactory.getIncludeCipherSuites(), DEFAULT_INCLUDED_CIPHERS.split(",")); assertEquals(sslContextFactory.getExcludeProtocols(), AthenzJettyContainer.ATHENZ_DEFAULT_EXCLUDED_PROTOCOLS.split(",")); }