List of usage examples for io.netty.handler.ssl SslHandler engine
SSLEngine engine
To view the source code for io.netty.handler.ssl SslHandler engine.
Click Source Link
From source file:org.apache.cxf.transport.http.netty.server.servlet.NettyHttpServletRequest.java
License:Apache License
public NettyHttpServletRequest(HttpRequest request, String contextPath, ChannelHandlerContext ctx) { this.originalRequest = request; this.contextPath = contextPath; this.uriParser = new URIParser(contextPath); uriParser.parse(request.getUri());/*from w w w .ja va2 s .c om*/ this.inputStream = new NettyServletInputStream((HttpContent) request); this.reader = new BufferedReader(new InputStreamReader(inputStream)); this.queryStringDecoder = new QueryStringDecoder(request.getUri()); // setup the SSL security attributes this.channelHandlerContext = ctx; SslHandler sslHandler = channelHandlerContext.pipeline().get(SslHandler.class); if (sslHandler != null) { SSLSession session = sslHandler.engine().getSession(); if (session != null) { attributes.put(SSL_CIPHER_SUITE_ATTRIBUTE, session.getCipherSuite()); try { attributes.put(SSL_PEER_CERT_CHAIN_ATTRIBUTE, session.getPeerCertificates()); } catch (SSLPeerUnverifiedException ex) { // do nothing here } } } }
From source file:org.apache.qpid.jms.transports.netty.NettyOpenSslTransportTest.java
License:Apache License
private void assertOpenSSL(String message, boolean expected, Transport transport) throws Exception { Field channel = null;/*from w ww . j a v a2 s . c o m*/ Class<?> transportType = transport.getClass(); while (transportType != null && channel == null) { try { channel = transportType.getDeclaredField("channel"); } catch (NoSuchFieldException error) { transportType = transportType.getSuperclass(); if (Object.class.equals(transportType)) { transportType = null; } } } assertNotNull("Transport implementation unknown", channel); channel.setAccessible(true); Channel activeChannel = (Channel) channel.get(transport); ChannelHandler handler = activeChannel.pipeline().get("ssl"); assertNotNull("Channel should have an SSL Handler registered"); assertTrue(handler instanceof SslHandler); SslHandler sslHandler = (SslHandler) handler; if (expected) { assertTrue(message, sslHandler.engine() instanceof OpenSslEngine); } else { assertFalse(message, sslHandler.engine() instanceof OpenSslEngine); } }
From source file:org.apache.qpid.jms.transports.netty.NettySslTransport.java
License:Apache License
@Override public Principal getLocalPrincipal() { SslHandler sslHandler = channel.pipeline().get(SslHandler.class); return sslHandler.engine().getSession().getLocalPrincipal(); }
From source file:org.apache.qpid.jms.transports.netty.NettyTcpTransport.java
License:Apache License
@Override public Principal getLocalPrincipal() { Principal result = null;//from w ww.j av a2 s .c o m if (isSecure()) { SslHandler sslHandler = channel.pipeline().get(SslHandler.class); result = sslHandler.engine().getSession().getLocalPrincipal(); } return result; }
From source file:org.apache.qpid.jms.transports.TransportSupportTest.java
License:Apache License
@Test(timeout = 100000) public void testCreateSslHandlerJDK() throws Exception { assumeTrue(OpenSsl.isAvailable());// ww w. j a v a 2 s .co m assumeTrue(OpenSsl.supportsKeyManagerFactory()); TransportOptions options = new TransportOptions(); options.setUseOpenSSL(false); SslHandler handler = TransportSupport.createSslHandler(null, null, options); assertNotNull(handler); assertFalse(handler.engine() instanceof OpenSslEngine); }
From source file:org.apache.qpid.jms.transports.TransportSupportTest.java
License:Apache License
@Test(timeout = 100000) public void testCreateSslHandlerOpenSSL() throws Exception { assumeTrue(OpenSsl.isAvailable());/*from ww w . j a va2 s.c o m*/ assumeTrue(OpenSsl.supportsKeyManagerFactory()); TransportOptions options = new TransportOptions(); options.setUseOpenSSL(true); SslHandler handler = TransportSupport.createSslHandler(PooledByteBufAllocator.DEFAULT, null, options); assertNotNull(handler); assertTrue(handler.engine() instanceof OpenSslEngine); }
From source file:org.asterisque.netty.WireConnect.java
License:Apache License
/** * ???????????//from ww w . j av a 2 s. c o m * SSL ?????? * @param ctx */ @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { trace("channelActive(" + ctx.name() + ")"); assert (!wire.isPresent()); // SSLHandler ???????? SSLSession ? CompletableFuture<Optional<SSLSession>> future = new CompletableFuture<>(); if (sslHandler.isPresent()) { SslHandler h = sslHandler.get(); h.handshakeFuture().addListener(f -> { SSLSession session = h.engine().getSession(); if (session.isValid()) { // SSL ? future.complete(Optional.of(session)); debug("tls handshake success"); } else { // SSL ? future.completeExceptionally(new IOException("tls handshake failure: invalid session")); debug("tls handshake failure: invalid session"); } Debug.dumpSSLSession(logger, sym + "[" + id + "]", session); }); } else { // SSL ?? future.complete(Optional.empty()); } // Wire NettyWire w = new NettyWire(node, local, remote, isServer, future, ctx); wire = Optional.of(w); super.channelActive(ctx); // onWireCreate.accept(w); }
From source file:org.asynchttpclient.providers.netty.request.NettyConnectListener.java
License:Apache License
public void onFutureSuccess(final Channel channel) throws ConnectException { Channels.setDefaultAttribute(channel, future); final HostnameVerifier hostnameVerifier = config.getHostnameVerifier(); final SslHandler sslHandler = Channels.getSslHandler(channel); if (hostnameVerifier != null && sslHandler != null) { final String host = future.getURI().getHost(); sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<? super Channel>>() { @Override/*w ww .j a v a 2s.c o m*/ public void operationComplete(Future<? super Channel> handshakeFuture) throws Exception { if (handshakeFuture.isSuccess()) { Channel channel = (Channel) handshakeFuture.getNow(); SSLEngine engine = sslHandler.engine(); SSLSession session = engine.getSession(); LOGGER.debug("onFutureSuccess: session = {}, id = {}, isValid = {}, host = {}", session.toString(), Base64.encode(session.getId()), session.isValid(), host); if (!hostnameVerifier.verify(host, session)) { ConnectException exception = new ConnectException("HostnameVerifier exception"); future.abort(exception); throw exception; } else { requestSender.writeRequest(future, channel); } } } }); } else { requestSender.writeRequest(future, channel); } }
From source file:org.asynchttpclient.providers.netty4.NettyConnectListener.java
License:Apache License
private void onFutureSuccess(final Channel channel) throws Exception { Channels.setDefaultAttribute(channel, future); SslHandler sslHandler = Channels.getSslHandler(channel); if (sslHandler != null) { // FIXME done on connect or on every request? HostnameVerifier v = config.getHostnameVerifier(); if (!v.verify(future.getURI().getHost(), sslHandler.engine().getSession())) { ConnectException exception = new ConnectException("HostnameVerifier exception."); future.abort(exception);/*www .j a v a2s .co m*/ throw exception; } } requestSender.writeRequest(channel, config, future); }
From source file:org.asynchttpclient.providers.netty4.request.NettyConnectListener.java
License:Open Source License
private void onFutureSuccess(final Channel channel) throws ConnectException { Channels.setAttribute(channel, future); final HostnameVerifier hostnameVerifier = config.getHostnameVerifier(); final SslHandler sslHandler = ChannelManager.getSslHandler(channel.pipeline()); if (hostnameVerifier != null && sslHandler != null) { final String host = future.getUri().getHost(); sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<? super Channel>>() { @Override// w w w .ja va 2 s . com public void operationComplete(Future<? super Channel> handshakeFuture) throws Exception { if (handshakeFuture.isSuccess()) { Channel channel = (Channel) handshakeFuture.getNow(); SSLEngine engine = sslHandler.engine(); SSLSession session = engine.getSession(); LOGGER.debug("onFutureSuccess: session = {}, id = {}, isValid = {}, host = {}", session.toString(), Base64.encode(session.getId()), session.isValid(), host); if (hostnameVerifier.verify(host, session)) { final AsyncHandler<T> asyncHandler = future.getAsyncHandler(); if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onSslHandshakeCompleted(); writeRequest(channel); } else { onFutureFailure(channel, new ConnectException("HostnameVerifier exception")); } } else { onFutureFailure(channel, handshakeFuture.cause()); } } }); } else { writeRequest(channel); } }