private SSLContextAndOptions createSSLContextAndOptions() throws SSLContextException { /* * Since Configuration initializes the key store and trust store related * configuration from system property. Reading property from * configuration will be same reading from system property */ return createSSLContextAndOptions(zkConfig == null ? new ZKConfig() : zkConfig); }
/** * Tells the background thread to start. Does not wait for it to be running. * Calling this method more than once has no effect. */ public void start() { if (!compareAndSetState(State.NEW, State.STARTING)) { // If previous state was not NEW, start() has already been called. return; } this.watcherThread.start(); }
/** * Tells the background thread to stop. Does not wait for it to exit. */ public void stop() { if (compareAndSetState( new State[]{State.RUNNING, State.STARTING}, State.STOPPING)) { watcherThread.interrupt(); } }
@Test(expected = IOException.class) public void testLoadKeyStoreWithWrongFilePath() throws Exception { String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS) .getAbsolutePath(); new JKSFileLoader.Builder() .setKeyStorePath(path + ".does_not_exist") .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); }
@Test(expected = IOException.class) public void testLoadTrustStoreWithWrongFilePath() throws Exception { String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS) .getAbsolutePath(); new JKSFileLoader.Builder() .setTrustStorePath(path + ".does_not_exist") .setTrustStorePassword(x509TestContext.getTrustStorePassword()) .build() .loadTrustStore(); }
@Test(expected = IOException.class) public void testLoadKeyStoreWithWrongFilePath() throws Exception { String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM) .getAbsolutePath(); new PEMFileLoader.Builder() .setKeyStorePath(path + ".does_not_exist") .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); }
@Test(expected = IOException.class) public void testLoadTrustStoreWithWrongFilePath() throws Exception { String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM) .getAbsolutePath(); new PEMFileLoader.Builder() .setTrustStorePath(path + ".does_not_exist") .setTrustStorePassword(x509TestContext.getTrustStorePassword()) .build() .loadTrustStore(); }
@Test(expected = NullPointerException.class) public void testLoadKeyStoreWithNullFilePath() throws Exception { new JKSFileLoader.Builder() .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); }
@Test(expected = NullPointerException.class) public void testLoadKeyStoreWithNullFilePath() throws Exception { new PEMFileLoader.Builder() .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); }
@Test(expected = NullPointerException.class) public void testLoadTrustStoreWithNullFilePath() throws Exception { new PEMFileLoader.Builder() .setTrustStorePassword(x509TestContext.getTrustStorePassword()) .build() .loadTrustStore(); }
@Test(expected = NullPointerException.class) public void testLoadTrustStoreWithNullFilePath() throws Exception { new JKSFileLoader.Builder() .setTrustStorePassword(x509TestContext.getTrustStorePassword()) .build() .loadTrustStore(); }
private X509Util.ClientAuth getClientAuth(final ZKConfig config) { return X509Util.ClientAuth.fromPropertyValue(config.getProperty(x509Util.getSslClientAuthProperty())); }
public SSLContext createSSLContext(ZKConfig config) throws SSLContextException { return createSSLContextAndOptions(config).getSSLContext(); }
public SSLSocket createSSLSocket(Socket socket, byte[] pushbackBytes) throws X509Exception, IOException { return getDefaultSSLContextAndOptions().createSSLSocket(socket, pushbackBytes); }
public SSLServerSocket createSSLServerSocket(int port) throws X509Exception, IOException { return getDefaultSSLContextAndOptions().createSSLServerSocket(port); }
@Test(expected = IOException.class) public void testLoadKeyStoreWithWrongFileType() throws Exception { // Trying to load a PEM file with JKS loader should fail String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM) .getAbsolutePath(); new JKSFileLoader.Builder() .setKeyStorePath(path) .setKeyStorePassword(x509TestContext.getKeyStorePassword()) .build() .loadKeyStore(); }
@Test(expected = IOException.class) public void testLoadTrustStoreWithWrongFileType() throws Exception { // Trying to load a PEM file with JKS loader should fail String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.PEM) .getAbsolutePath(); new JKSFileLoader.Builder() .setTrustStorePath(path) .setTrustStorePassword(x509TestContext.getTrustStorePassword()) .build() .loadTrustStore(); } }
@Test(expected = Exception.class) public void testLoadKeyStoreWithWrongPassword() throws Exception { String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.PEM) .getAbsolutePath(); new PEMFileLoader.Builder() .setKeyStorePath(path) .setKeyStorePassword("wrong password") .build() .loadKeyStore(); }
@Test(expected = Exception.class) public void testLoadKeyStoreWithWrongPassword() throws Exception { String path = x509TestContext.getKeyStoreFile(KeyStoreFileType.JKS) .getAbsolutePath(); new JKSFileLoader.Builder() .setKeyStorePath(path) .setKeyStorePassword("wrong password") .build() .loadKeyStore(); }
@Test(expected = Exception.class) public void testLoadTrustStoreWithWrongPassword() throws Exception { String path = x509TestContext.getTrustStoreFile(KeyStoreFileType.JKS) .getAbsolutePath(); new JKSFileLoader.Builder() .setTrustStorePath(path) .setTrustStorePassword("wrong password") .build() .loadTrustStore(); }