ZTSUtils { public static SslContextFactory createSSLContextObject(String[] clientProtocols) { return createSSLContextObject(clientProtocols, null); }  static SslContextFactory createSSLContextObject(String[] clientProtocols); static SslContextFactory createSSLContextObject(final String[] clientProtocols,
            final PrivateKeyStore privateKeyStore); static boolean emitMonmetricError(int errorCode, String caller,
            String requestDomain, String principalDomain, Metric metric); static boolean verifyCertificateRequest(PKCS10CertificationRequest certReq,
            final String domain, final String service, X509CertRecord certRecord); static boolean validateCertReqCommonName(PKCS10CertificationRequest certReq, String cn); static String extractCertReqInstanceId(PKCS10CertificationRequest certReq); static Identity generateIdentity(InstanceCertManager certManager, final String csr,
            final String cn, final String certUsage, int expiryTime); static SSLContext createServerClientSSLContext(PrivateKeyStore privateKeyStore); static int parseInt(final String value, int defaultValue); static boolean parseBoolean(final String value, boolean defaultValue); static final String ZTS_CERT_DNS_SUFFIX; }
@Test public void testCreateSSLContextObject() { System.setProperty(ZTSConsts.ZTS_PROP_KEYSTORE_PATH, "file: System.setProperty(ZTSConsts.ZTS_PROP_KEYSTORE_TYPE, "PKCS12"); System.setProperty(ZTSConsts.ZTS_PROP_KEYSTORE_PASSWORD, "pass123"); System.setProperty(ZTSConsts.ZTS_PROP_TRUSTSTORE_PATH, "file: System.setProperty(ZTSConsts.ZTS_PROP_TRUSTSTORE_TYPE, "PKCS12"); System.setProperty(ZTSConsts.ZTS_PROP_TRUSTSTORE_PASSWORD, "pass123"); System.setProperty(ZTSConsts.ZTS_PROP_KEYMANAGER_PASSWORD, "pass123"); System.setProperty(ZTSConsts.ZTS_PROP_EXCLUDED_CIPHER_SUITES, ZTSUtils.ZTS_DEFAULT_EXCLUDED_CIPHER_SUITES); System.setProperty(ZTSConsts.ZTS_PROP_EXCLUDED_PROTOCOLS, ZTSUtils.ZTS_DEFAULT_EXCLUDED_PROTOCOLS); System.setProperty(ZTSConsts.ZTS_PROP_WANT_CLIENT_CERT, "true"); SslContextFactory sslContextFactory = ZTSUtils.createSSLContextObject(null); assertNotNull(sslContextFactory); assertEquals(sslContextFactory.getKeyStorePath(), "file: assertEquals(sslContextFactory.getKeyStoreType(), "PKCS12"); assertEquals(sslContextFactory.getTrustStoreResource().toString(), "file: assertEquals(sslContextFactory.getTrustStoreType(), "PKCS12"); assertEquals(sslContextFactory.getExcludeCipherSuites(), ZTSUtils.ZTS_DEFAULT_EXCLUDED_CIPHER_SUITES.split(",")); assertEquals(sslContextFactory.getExcludeProtocols(), ZTSUtils.ZTS_DEFAULT_EXCLUDED_PROTOCOLS.split(",")); assertTrue(sslContextFactory.getWantClientAuth()); }
@Test public void testCreateSSLContextObjectNoValues() { SslContextFactory sslContextFactory = ZTSUtils.createSSLContextObject(null); assertNotNull(sslContextFactory); assertFalse(sslContextFactory.getWantClientAuth()); assertNull(sslContextFactory.getKeyStoreResource()); assertEquals(sslContextFactory.getKeyStoreType(), "PKCS12"); assertNull(sslContextFactory.getTrustStore()); assertEquals(sslContextFactory.getTrustStoreType(), "PKCS12"); }
@Test public void testCreateSSLContextObjectNoKeyStore() { System.setProperty(ZTSConsts.ZTS_PROP_TRUSTSTORE_PATH, "file: System.setProperty(ZTSConsts.ZTS_PROP_TRUSTSTORE_TYPE, "PKCS12"); System.setProperty(ZTSConsts.ZTS_PROP_TRUSTSTORE_PASSWORD, "pass123"); System.setProperty(ZTSConsts.ZTS_PROP_KEYMANAGER_PASSWORD, "pass123"); SslContextFactory sslContextFactory = ZTSUtils.createSSLContextObject(null); assertNotNull(sslContextFactory); assertFalse(sslContextFactory.getWantClientAuth()); assertNull(sslContextFactory.getKeyStoreResource()); assertEquals(sslContextFactory.getKeyStoreType(), "PKCS12"); assertEquals(sslContextFactory.getTrustStoreResource().toString(), "file: assertEquals(sslContextFactory.getTrustStoreType(), "PKCS12"); }
@Test public void testCreateSSLContextObjectNoTrustStore() { System.setProperty(ZTSConsts.ZTS_PROP_KEYSTORE_PATH, "file: System.setProperty(ZTSConsts.ZTS_PROP_KEYSTORE_TYPE, "PKCS12"); System.setProperty(ZTSConsts.ZTS_PROP_KEYSTORE_PASSWORD, "pass123"); System.setProperty(ZTSConsts.ZTS_PROP_EXCLUDED_CIPHER_SUITES, ZTSUtils.ZTS_DEFAULT_EXCLUDED_CIPHER_SUITES); System.setProperty(ZTSConsts.ZTS_PROP_EXCLUDED_PROTOCOLS, ZTSUtils.ZTS_DEFAULT_EXCLUDED_PROTOCOLS); System.setProperty(ZTSConsts.ZTS_PROP_WANT_CLIENT_CERT, "true"); SslContextFactory sslContextFactory = ZTSUtils.createSSLContextObject(null); assertNotNull(sslContextFactory); assertTrue(sslContextFactory.getWantClientAuth()); assertEquals(sslContextFactory.getKeyStorePath(), "file: assertEquals(sslContextFactory.getKeyStoreType(), "PKCS12"); assertNull(sslContextFactory.getTrustStoreResource()); assertEquals(sslContextFactory.getTrustStoreType(), "PKCS12"); assertEquals(sslContextFactory.getExcludeCipherSuites(), ZTSUtils.ZTS_DEFAULT_EXCLUDED_CIPHER_SUITES.split(",")); assertEquals(sslContextFactory.getExcludeProtocols(), ZTSUtils.ZTS_DEFAULT_EXCLUDED_PROTOCOLS.split(",")); }