Java Code Examples for org.apache.mina.filter.ssl.SslFilter#setUseClientMode()
The following examples show how to use
org.apache.mina.filter.ssl.SslFilter#setUseClientMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EncryptionArtifactFactory.java From Openfire with Apache License 2.0 | 6 votes |
/** * A utility method that implements the shared functionality of getServerModeSslFilter and getClientModeSslFilter. * * This method is used to initialize and configure an instance of SslFilter for a particular pre-configured * SSLContext and SSLEngine. In most cases, developers will want to use getServerModeSslFilter or * getClientModeSslFilter instead of this method. * * @param sslContext a pre-configured SSL Context instance (cannot be null). * @param sslEngine a pre-configured SSL Engine instance (cannot be null). * @return A SslFilter instance (never null). */ private static SslFilter createSslFilter( SSLContext sslContext, SSLEngine sslEngine ) { final SslFilter filter = new SslFilter( sslContext ); // Copy configuration from the SSL Engine into the filter. filter.setUseClientMode( sslEngine.getUseClientMode() ); filter.setEnabledProtocols( sslEngine.getEnabledProtocols() ); filter.setEnabledCipherSuites( sslEngine.getEnabledCipherSuites() ); // Note that the setters for 'need' and 'want' influence each-other. Invoke only one of them! if ( sslEngine.getNeedClientAuth() ) { filter.setNeedClientAuth( true ); } else if ( sslEngine.getWantClientAuth() ) { filter.setWantClientAuth( true ); } return filter; }
Example 2
Source File: ConnectorTest.java From game-server with MIT License | 5 votes |
@Before public void setUp() throws Exception { super.setUp(); handler = new EchoConnectorHandler(); connectorSSLFilter = new SslFilter(GateSslContextFactory .getInstance(false)); connectorSSLFilter.setUseClientMode(true); // set client mode }
Example 3
Source File: ChainConfigurator.java From neoscada with Eclipse Public License 1.0 | 5 votes |
public void startSsl ( final boolean startInactive, final boolean clientMode ) throws Exception { logger.info ( "Starting SSL (startInactive: {})", startInactive ); final ProtocolConfiguration configuration = ProtocolConfiguration.fromSession ( this.session ); final SslContextFactory sslFactory = configuration.getSslContextFactory (); final SSLContext sslContext = sslFactory.newInstance (); if ( startInactive ) { this.session.setAttribute ( SslFilter.DISABLE_ENCRYPTION_ONCE, Boolean.TRUE ); } final SslFilter filter = new SslFilter ( sslContext ); filter.setUseClientMode ( clientMode ); filter.setWantClientAuth ( false ); filter.setNeedClientAuth ( false ); if ( logger.isDebugEnabled () ) { logger.debug ( "Enabled protocols:" ); for ( final String protocol : sslContext.getDefaultSSLParameters ().getProtocols () ) { logger.debug ( "\t" + protocol ); } logger.debug ( "Enabled ciphers:" ); for ( final String cipher : sslContext.getDefaultSSLParameters ().getCipherSuites () ) { logger.debug ( "\t" + cipher ); } } replaceMarker ( "ssl", filter ); }
Example 4
Source File: TestHttpServer.java From jane with GNU Lesser General Public License v3.0 | 5 votes |
public TestHttpServer(String key_file, String key_pw) throws Exception { if (key_file != null && key_pw != null) { SslFilter sf = HttpCodec.getSslFilter(key_file, key_pw); sf.setUseClientMode(false); getAcceptor().getDefaultIoFilterChainBuilder().addFirst("ssl", sf); } setCodecFactory(HttpCodec::new); }
Example 5
Source File: RTMPSClient.java From red5-client with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void sessionOpened(IoSession session) throws Exception { // START OF NATIVE SSL STUFF SSLContext sslContext = BogusSslContextFactory.getInstance(false); SslFilter sslFilter = new SslFilter(sslContext); sslFilter.setUseClientMode(true); if (sslFilter != null) { session.getFilterChain().addFirst("sslFilter", sslFilter); } // END OF NATIVE SSL STUFF super.sessionOpened(session); }
Example 6
Source File: PressureClientTool.java From game-server with MIT License | 4 votes |
public PressureClientTool(int clientNum, String userNamePrefix, String password, String clusterIp,JTextArea logTextArea) { this.clientNum = clientNum; this.clusterIp = clusterIp; this.userNamePrefix = userNamePrefix; initConfigPath(); ScriptManager.getInstance().init(null); //循环初始化客户端 try { for (int i = 0; i < clientNum; i++) { PressureClientHandler pressureClientHandler = new PressureClientHandler(); MinaClientConfig minaClientConfig = getMinaClientConfig(); String userName = userNamePrefix + userNameNo.incrementAndGet(); // TCP // 添加ssl Map<String, IoFilter> filters = new HashMap<>(); SslFilter sslFilter = new SslFilter(ClientSslContextFactory.getInstance(false)); sslFilter.setUseClientMode(true); // filters.put("ssl", sslFilter); SingleMinaTcpClientService service = new SingleMinaTcpClientService(minaClientConfig, new ClientProtocolCodecFactory(), pressureClientHandler, filters); pressureClientHandler.setService(service); new Thread(service).start(); // UDP MinaClientConfig minaClientConfig2 = new MinaClientConfig(); MinaClienConnToConfig connTo = new MinaClienConnToConfig(); connTo.setHost(minaClientConfig.getConnTo().getHost()); connTo.setPort(8004); minaClientConfig2.setConnTo(connTo); MinaUdpClient udpClient = new MinaUdpClient(minaClientConfig2, pressureClientHandler, new ClientProtocolCodecFactory()); new Thread(udpClient).start(); while (udpClient.getSession() == null) { Thread.sleep(MathUtil.random(500, 3000)); } Player player = new Player(); player.setUserName(userName); player.setPassword(password); player.setUdpSession(udpClient.getSession()); player.setTcpSession(service.getMostIdleIoSession()); player.setLogTextArea(logTextArea); if(player.getTcpSession()==null||player.getUdpSession()==null){ LOGGER.warn("用户{}连接服务器失败",userName); logTextArea.append(String.format("用户%s连接服务器失败\n",userName)); continue; } player.loginInit(); players.put(userName, player); new PressureServiceThread(player).start(); } } catch (Exception e) { LOGGER.error("PressureClientTool", e); } }
Example 7
Source File: LdapNetworkConnection.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Adds {@link SslFilter} to the IOConnector or IOSession's filter chain * * @throws LdapException If the SSL filter addition failed */ private void addSslFilter() throws LdapException { try { SSLContext sslContext = SSLContext.getInstance( config.getSslProtocol() ); sslContext.init( config.getKeyManagers(), config.getTrustManagers(), config.getSecureRandom() ); SslFilter sslFilter = new SslFilter( sslContext ); sslFilter.setUseClientMode( true ); // Configure the enabled cipher lists String[] enabledCipherSuite = config.getEnabledCipherSuites(); if ( ( enabledCipherSuite != null ) && ( enabledCipherSuite.length != 0 ) ) { sslFilter.setEnabledCipherSuites( enabledCipherSuite ); } // Be sure we disable SSLV3 String[] enabledProtocols = config.getEnabledProtocols(); if ( ( enabledProtocols != null ) && ( enabledProtocols.length != 0 ) ) { sslFilter.setEnabledProtocols( enabledProtocols ); } else { // Default to TLS sslFilter.setEnabledProtocols( new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" } ); } // for LDAPS/TLS handshakeFuture = new HandshakeFuture(); if ( ( ioSession == null ) || !isConnected() ) { connector.getFilterChain().addFirst( SSL_FILTER_KEY, sslFilter ); } else // for StartTLS { ioSession.getFilterChain().addFirst( SSL_FILTER_KEY, sslFilter ); boolean isSecured = handshakeFuture.get( timeout, TimeUnit.MILLISECONDS ); if ( !isSecured ) { Throwable cause = ( Throwable ) ioSession.getAttribute( EXCEPTION_KEY ); throw new LdapTlsHandshakeException( I18n.err( I18n.ERR_04120_TLS_HANDSHAKE_ERROR ), cause ); } } } catch ( Exception e ) { if ( e instanceof LdapException ) { throw ( LdapException ) e; } String msg = I18n.err( I18n.ERR_04122_SSL_CONTEXT_INIT_FAILURE ); LOG.error( msg, e ); throw new LdapException( msg, e ); } }