@Test public void testListenerConfigOverride() throws Exception { String node = "0"; ListenerName clientListenerName = new ListenerName("client"); sslServerConfigs.put(SslConfigs.SSL_CLIENT_AUTH_CONFIG, "required"); sslServerConfigs.put(clientListenerName.configPrefix() + SslConfigs.SSL_CLIENT_AUTH_CONFIG, "none"); server = createEchoServer(SecurityProtocol.SSL); InetSocketAddress addr = new InetSocketAddress("localhost", server.port()); createSelector(sslClientConfigs); selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE); NetworkTestUtils.checkClientConnection(selector, node, 100, 10); selector.close(); sslClientConfigs.remove(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG); sslClientConfigs.remove(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG); sslClientConfigs.remove(SslConfigs.SSL_KEY_PASSWORD_CONFIG); createSelector(sslClientConfigs); selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE); NetworkTestUtils.waitForChannelClose(selector, node, ChannelState.AUTHENTICATE); selector.close(); server.close(); server = createEchoServer(clientListenerName, SecurityProtocol.SSL); addr = new InetSocketAddress("localhost", server.port()); createSelector(sslClientConfigs); selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE); NetworkTestUtils.checkClientConnection(selector, node, 100, 10); }
@Override public void close() throws IOException { if (closing) return; closing = true; sslEngine.closeOutbound(); try { if (isConnected()) { if (!flush(netWriteBuffer)) { throw new IOException("Remaining data in the network buffer, can't send SSL close message."); } netWriteBuffer.clear(); SSLEngineResult wrapResult = sslEngine.wrap(emptyBuf, netWriteBuffer); if (wrapResult.getStatus() != SSLEngineResult.Status.CLOSED) { throw new IOException("Unexpected status returned by SSLEngine.wrap, expected CLOSED, received " + wrapResult.getStatus() + ". Will not send close message to peer."); } netWriteBuffer.flip(); flush(netWriteBuffer); } } catch (IOException ie) { log.warn("Failed to send SSL Close message ", ie); } finally { try { socketChannel.socket().close(); socketChannel.close(); } finally { key.attach(null); key.cancel(); } } }
SslTransportLayer implements TransportLayer { @Override public void close() throws IOException { if (closing) return; closing = true; sslEngine.closeOutbound(); try { if (isConnected()) { if (!flush(netWriteBuffer)) { throw new IOException("Remaining data in the network buffer, can't send SSL close message."); } netWriteBuffer.clear(); SSLEngineResult wrapResult = sslEngine.wrap(emptyBuf, netWriteBuffer); if (wrapResult.getStatus() != SSLEngineResult.Status.CLOSED) { throw new IOException("Unexpected status returned by SSLEngine.wrap, expected CLOSED, received " + wrapResult.getStatus() + ". Will not send close message to peer."); } netWriteBuffer.flip(); flush(netWriteBuffer); } } catch (IOException ie) { log.warn("Failed to send SSL Close message ", ie); } finally { try { socketChannel.socket().close(); socketChannel.close(); } finally { key.attach(null); key.cancel(); } } } }
SslTransportLayer implements TransportLayer { @Override public void close() throws IOException { if (closing) return; closing = true; sslEngine.closeOutbound(); try { if (isConnected()) { if (!flush(netWriteBuffer)) { throw new IOException("Remaining data in the network buffer, can't send SSL close message."); } netWriteBuffer.clear(); SSLEngineResult wrapResult = sslEngine.wrap(emptyBuf, netWriteBuffer); if (wrapResult.getStatus() != SSLEngineResult.Status.CLOSED) { throw new IOException("Unexpected status returned by SSLEngine.wrap, expected CLOSED, received " + wrapResult.getStatus() + ". Will not send close message to peer."); } netWriteBuffer.flip(); flush(netWriteBuffer); } } catch (IOException ie) { log.warn("Failed to send SSL Close message ", ie); } finally { try { socketChannel.socket().close(); socketChannel.close(); } finally { key.attach(null); key.cancel(); } } } SslTransportLayer(String channelId, SelectionKey key, SSLEngine sslEngine, boolean enableRenegotiation); }
SslTransportLayer implements TransportLayer { @Override public void close() throws IOException { if (closing) return; closing = true; sslEngine.closeOutbound(); try { if (isConnected()) { if (!flush(netWriteBuffer)) { throw new IOException("Remaining data in the network buffer, can't send SSL close message."); } netWriteBuffer.clear(); SSLEngineResult wrapResult = sslEngine.wrap(emptyBuf, netWriteBuffer); if (wrapResult.getStatus() != SSLEngineResult.Status.CLOSED) { throw new IOException("Unexpected status returned by SSLEngine.wrap, expected CLOSED, received " + wrapResult.getStatus() + ". Will not send close message to peer."); } netWriteBuffer.flip(); flush(netWriteBuffer); } } catch (IOException ie) { log.warn("Failed to send SSL Close message ", ie); } finally { try { socketChannel.socket().close(); socketChannel.close(); } finally { key.attach(null); key.cancel(); } } } SslTransportLayer(String channelId, SelectionKey key, SSLEngine sslEngine, boolean enableRenegotiation); static SslTransportLayer create(String channelId, SelectionKey key, SSLEngine sslEngine); @Override boolean ready(); @Override boolean finishConnect(); @Override void disconnect(); @Override SocketChannel socketChannel(); @Override boolean isOpen(); @Override boolean isConnected(); @Override void close(); @Override boolean hasPendingWrites(); @Override void handshake(); @Override int read(ByteBuffer dst); @Override long read(ByteBuffer[] dsts); @Override long read(ByteBuffer[] dsts, int offset, int length); @Override int write(ByteBuffer src); @Override long write(ByteBuffer[] srcs, int offset, int length); @Override long write(ByteBuffer[] srcs); Principal peerPrincipal(); SSLSession sslSession(); @Override void addInterestOps(int ops); @Override void removeInterestOps(int ops); @Override boolean isMute(); @Override long transferFrom(FileChannel fileChannel, long position, long count); }
SslTransportLayer implements TransportLayer { @Override public void close() throws IOException { if (closing) return; closing = true; sslEngine.closeOutbound(); try { if (isConnected()) { if (!flush(netWriteBuffer)) { throw new IOException("Remaining data in the network buffer, can't send SSL close message."); } netWriteBuffer.clear(); SSLEngineResult wrapResult = sslEngine.wrap(emptyBuf, netWriteBuffer); if (wrapResult.getStatus() != SSLEngineResult.Status.CLOSED) { throw new IOException("Unexpected status returned by SSLEngine.wrap, expected CLOSED, received " + wrapResult.getStatus() + ". Will not send close message to peer."); } netWriteBuffer.flip(); flush(netWriteBuffer); } } catch (IOException ie) { log.warn("Failed to send SSL Close message ", ie); } finally { try { socketChannel.socket().close(); socketChannel.close(); } finally { key.attach(null); key.cancel(); } } } SslTransportLayer(String channelId, SelectionKey key, SSLEngine sslEngine, boolean enableRenegotiation); static SslTransportLayer create(String channelId, SelectionKey key, SSLEngine sslEngine); @Override boolean ready(); @Override boolean finishConnect(); @Override void disconnect(); @Override SocketChannel socketChannel(); @Override boolean isOpen(); @Override boolean isConnected(); @Override void close(); @Override boolean hasPendingWrites(); @Override void handshake(); @Override int read(ByteBuffer dst); @Override long read(ByteBuffer[] dsts); @Override long read(ByteBuffer[] dsts, int offset, int length); @Override int write(ByteBuffer src); @Override long write(ByteBuffer[] srcs, int offset, int length); @Override long write(ByteBuffer[] srcs); Principal peerPrincipal(); SSLSession sslSession(); @Override void addInterestOps(int ops); @Override void removeInterestOps(int ops); @Override boolean isMute(); @Override long transferFrom(FileChannel fileChannel, long position, long count);  }