/** * Constuctor. * * @param sslc * @throws SSLException */ public SslHandler(SslFilter parent, SSLContext sslContext, IoSession session) throws SSLException { this.parent = parent; this.session = session; this.sslContext = sslContext; init(); }
/** * Executed just before the filter is added into the chain, we do : * <ul> * <li>check that we don't have a SSL filter already present * <li>we update the next filter * <li>we create the SSL handler helper class * <li>and we store it into the session's Attributes * </ul> */ @Override public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws SSLException { // Check that we don't have a SSL filter already present in the chain if (parent.contains(SslFilter.class)) { String msg = "Only one SSL filter is permitted in a chain."; LOGGER.error(msg); throw new IllegalStateException(msg); } LOGGER.debug("Adding the SSL Filter {} to the chain", name); IoSession session = parent.getSession(); session.setAttribute(NEXT_FILTER, nextFilter); // Create a SSL handler and start handshake. SslHandler sslHandler = new SslHandler(this, session); // Adding the supported ciphers in the SSLHandler if ((enabledCipherSuites == null) || (enabledCipherSuites.length == 0)) { enabledCipherSuites = sslContext.getServerSocketFactory().getSupportedCipherSuites(); } sslHandler.init(); session.setAttribute(SSL_HANDLER, sslHandler); }
/** * Executed just before the filter is added into the chain, we do : * <ul> * <li>check that we don't have a SSL filter already present * <li>we update the next filter * <li>we create the SSL handler helper class * <li>and we store it into the session's Attributes * </ul> */ @Override public void onPreAdd(IoFilterChain parent, String name, NextFilter nextFilter) throws SSLException { // Check that we don't have a SSL filter already present in the chain if (parent.contains(SslFilter.class)) { String msg = "Only one SSL filter is permitted in a chain."; LOGGER.error(msg); throw new IllegalStateException(msg); } LOGGER.debug("Adding the SSL Filter {} to the chain", name); IoSession session = parent.getSession(); session.setAttribute(NEXT_FILTER, nextFilter); // Create a SSL handler and start handshake. SslHandler sslHandler = new SslHandler(this, session); // Adding the supported ciphers in the SSLHandler if ((enabledCipherSuites == null) || (enabledCipherSuites.length == 0)) { enabledCipherSuites = sslContext.getServerSocketFactory().getSupportedCipherSuites(); } sslHandler.init(); session.setAttribute(SSL_HANDLER, sslHandler); }
/** * (Re)starts SSL session for the specified <tt>session</tt> if not started yet. * Please note that SSL session is automatically started by default, and therefore * you don't need to call this method unless you've used TLS closure. * * @return <tt>true</tt> if the SSL session has been started, <tt>false</tt> if already started. * @throws SSLException if failed to start the SSL session */ public boolean startSsl(IoSession session) throws SSLException { SslHandler handler = getSslSessionHandler(session); boolean started; synchronized (handler) { if (handler.isOutboundDone()) { NextFilter nextFilter = (NextFilter) session .getAttribute(NEXT_FILTER); handler.destroy(); handler.init(); handler.handshake(nextFilter); started = true; } else { started = false; } } handler.flushScheduledEvents(); return started; }
NextFilter nextFilter = (NextFilter) session.getAttribute(NEXT_FILTER); sslHandler.destroy(); sslHandler.init(); sslHandler.handshake(nextFilter); started = true;
NextFilter nextFilter = (NextFilter) session.getAttribute(NEXT_FILTER); sslHandler.destroy(); sslHandler.init(); sslHandler.handshake(nextFilter); started = true;