Search in sources :

Example 1 with ClientX509Util

use of org.apache.zookeeper.common.ClientX509Util in project zookeeper by apache.

the class SaslKerberosAuthOverSSLTest method setUpSSLWithNoAuth.

public ClientX509Util setUpSSLWithNoAuth() {
    String testDataPath = System.getProperty("test.data.dir", "src/test/resources/data");
    System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
    System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
    System.setProperty(ZKClientConfig.SECURE_CLIENT, "true");
    System.setProperty("zookeeper.ssl.clientAuth", "none");
    System.setProperty("zookeeper.ssl.quorum.clientAuth", "none");
    ClientX509Util x509Util = new ClientX509Util();
    System.setProperty(x509Util.getSslTruststoreLocationProperty(), testDataPath + "/ssl/testTrustStore.jks");
    System.setProperty(x509Util.getSslTruststorePasswdProperty(), "testpass");
    System.setProperty(x509Util.getSslKeystoreLocationProperty(), testDataPath + "/ssl/testKeyStore.jks");
    System.setProperty(x509Util.getSslKeystorePasswdProperty(), "testpass");
    return x509Util;
}
Also used : ClientX509Util(org.apache.zookeeper.common.ClientX509Util)

Example 2 with ClientX509Util

use of org.apache.zookeeper.common.ClientX509Util in project zookeeper by apache.

the class SSLAuthTest method setUpSecure.

public static ClientX509Util setUpSecure() throws Exception {
    ClientX509Util x509Util = new ClientX509Util();
    String testDataPath = System.getProperty("test.data.dir", "src/test/resources/data");
    System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
    System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
    System.setProperty(ZKClientConfig.SECURE_CLIENT, "true");
    System.setProperty(x509Util.getSslAuthProviderProperty(), "x509");
    System.setProperty(x509Util.getSslKeystoreLocationProperty(), testDataPath + "/ssl/testKeyStore.jks");
    System.setProperty(x509Util.getSslKeystorePasswdProperty(), "testpass");
    System.setProperty(x509Util.getSslTruststoreLocationProperty(), testDataPath + "/ssl/testTrustStore.jks");
    System.setProperty(x509Util.getSslTruststorePasswdProperty(), "testpass");
    System.setProperty("javax.net.debug", "ssl");
    System.setProperty("zookeeper.authProvider.x509", "org.apache.zookeeper.server.auth.X509AuthenticationProvider");
    return x509Util;
}
Also used : ClientX509Util(org.apache.zookeeper.common.ClientX509Util)

Example 3 with ClientX509Util

use of org.apache.zookeeper.common.ClientX509Util in project zookeeper by apache.

the class UnifiedServerSocketModeDetectionTest method init.

public void init(boolean useSecureClient) throws Exception {
    x509Util = new ClientX509Util();
    x509TestContext.setSystemProperties(x509Util, KeyStoreFileType.JKS, KeyStoreFileType.JKS);
    System.setProperty(x509Util.getSslHandshakeDetectionTimeoutMillisProperty(), "100");
    workerPool = Executors.newCachedThreadPool();
    port = PortAssignment.unique();
    localServerAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), port);
    listeningSocket = new UnifiedServerSocket(x509Util, true);
    listeningSocket.bind(localServerAddress);
    Future<UnifiedServerSocket.UnifiedSocket> acceptFuture;
    acceptFuture = workerPool.submit(new Callable<UnifiedServerSocket.UnifiedSocket>() {

        @Override
        public UnifiedServerSocket.UnifiedSocket call() throws Exception {
            try {
                return (UnifiedServerSocket.UnifiedSocket) listeningSocket.accept();
            } catch (IOException e) {
                LOG.error("Error in accept()", e);
                throw e;
            }
        }
    });
    if (useSecureClient) {
        clientSocket = x509Util.createSSLSocket();
        clientSocket.connect(localServerAddress);
    } else {
        clientSocket = new Socket();
        clientSocket.connect(localServerAddress);
        clientSocket.getOutputStream().write(new byte[] { 1, 2, 3, 4, 5 });
    }
    serverSideSocket = acceptFuture.get();
}
Also used : ClientX509Util(org.apache.zookeeper.common.ClientX509Util) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket)

Example 4 with ClientX509Util

use of org.apache.zookeeper.common.ClientX509Util in project zookeeper by apache.

the class UnifiedServerSocketTest method setUp.

public void setUp() throws Exception {
    localServerAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), PortAssignment.unique());
    x509Util = new ClientX509Util();
    x509TestContext.setSystemProperties(x509Util, KeyStoreFileType.JKS, KeyStoreFileType.JKS);
}
Also used : ClientX509Util(org.apache.zookeeper.common.ClientX509Util) InetSocketAddress(java.net.InetSocketAddress)

Example 5 with ClientX509Util

use of org.apache.zookeeper.common.ClientX509Util in project zookeeper by apache.

the class QuorumPeerConfigTest method testCustomSSLAuth.

/**
 * https://issues.apache.org/jira/browse/ZOOKEEPER-2297
 */
@Test
public void testCustomSSLAuth() throws IOException {
    try (ClientX509Util x509Util = new ClientX509Util()) {
        System.setProperty(x509Util.getSslAuthProviderProperty(), "y509");
        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        try {
            Properties zkProp = getDefaultZKProperties();
            zkProp.setProperty("secureClientPort", "12345");
            quorumPeerConfig.parseProperties(zkProp);
            fail("ConfigException is expected");
        } catch (ConfigException e) {
            assertNotNull(e.getMessage());
        }
    }
}
Also used : ClientX509Util(org.apache.zookeeper.common.ClientX509Util) ConfigException(org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Aggregations

ClientX509Util (org.apache.zookeeper.common.ClientX509Util)12 InetSocketAddress (java.net.InetSocketAddress)4 IOException (java.io.IOException)2 Socket (java.net.Socket)2 ZooKeeper (org.apache.zookeeper.ZooKeeper)2 X509Util (org.apache.zookeeper.common.X509Util)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 ServerSocket (java.net.ServerSocket)1 SocketTimeoutException (java.net.SocketTimeoutException)1 Properties (java.util.Properties)1 Random (java.util.Random)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 SSLContext (javax.net.ssl.SSLContext)1 SSLSocket (javax.net.ssl.SSLSocket)1