Details
Description
I'm developing an Android app using Apache Mina for network IO. Non-SSL connections (reading, writing) work fine, but as soon as I add an SSL filter things stop working. I also tried pure SSL sockets and they work fine.
This is my Mina connection code (in a separate networking thread):
IoConnector connector = new NioSocketConnector();
connector.getSessionConfig().setReadBufferSize(2048);
SocketSessionConfig cfg = (SocketSessionConfig)connector.getSessionConfig();
cfg.setTcpNoDelay(true);
SslContextFactory f = new SslContextFactory();
f.setTrustManagerFactory(new BogusTrustManagerFactory());
f.setProtocol("SSL");
try
{ filter = new SslFilter(f.newInstance(), true); }catch (Exception e)
{ Log.d(TAG, "Exception: ", e); return; }filter.setUseClientMode(true);
connector.getFilterChain().addLast("sslFilter", filter);
connector.getFilterChain().addLast("logger", new LoggingFilter());
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("ASCII"))));
connector.setHandler(new MinaClientHandler());
ConnectFuture future = connector.connect(new InetSocketAddress("10.0.1.9", 7072));
future.awaitUninterruptibly();
if (!future.isConnected())
{ Log.d(TAG, "not connected, return"); return; } IoSession session = future.getSession();
session.getConfig().setUseReadOperation(true);
session.getCloseFuture().awaitUninterruptibly();
//System.out.println(session.read().getMessage());
Log.d(TAG, "after writting");
connector.dispose();
Not my actual code, but it reproduces the problem.
On the server side I see that the connection is accepted an the handshake succeeds. But on the client side nothing is sent over the socket. I have tried the same code in a desktop Java application and it also works.
Also if I move the write call just after
future.awaitUninterruptibly(); and program is not continue.
server log:
DEBUG 2014-12-02 20:05:34,413 [org.apache.mina.filter.ssl.SslFilter] - Adding the SSL Filter sslFilter to the chain
DEBUG 2014-12-02 20:05:34,417 [org.apache.mina.filter.ssl.SslHandler] - Session Server[1](no sslEngine) Initializing the SSL Handler
DEBUG 2014-12-02 20:05:34,440 [org.apache.mina.filter.ssl.SslHandler] - Session Server[1](no sslEngine) SSL Handler Initialization done.
DEBUG 2014-12-02 20:05:34,441 [org.apache.mina.filter.ssl.SslFilter] - Session Server[1](ssl...) : Starting the first handshake
DEBUG 2014-12-02 20:05:34,441 [org.apache.mina.filter.ssl.SslHandler] - Session Server[1](ssl...) processing the NEED_UNWRAP state
INFO 2014-12-02 20:05:34,443 [org.apache.mina.filter.logging.LoggingFilter] - CREATED
DEBUG 2014-12-02 20:05:34,443 [zycj.ktc.server.ThunderMinaIOHandler] - SessionCreated, client = 192.168.1.112/null
INFO 2014-12-02 20:05:34,443 [org.apache.mina.filter.logging.LoggingFilter] - OPENED
DEBUG 2014-12-02 20:05:34,445 [org.apache.mina.core.filterchain.IoFilterEvent] - Firing a SESSION_OPENED event for session 1
DEBUG 2014-12-02 20:05:34,446 [zycj.ktc.server.ThunderMinaIOHandler] - SessionOpened, client = 192.168.1.112/null
DEBUG 2014-12-02 20:05:34,446 [org.apache.mina.core.filterchain.IoFilterEvent] - Event SESSION_OPENED has been fired for session 1
android log:
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): Unexpected exception.
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): org.apache.mina.core.filterchain.IoFilterLifeCycleException: onPreAdd(): SSL:SslFilter in (0x00000001: nio socket, client, 192.168.1.112/192.168.1.112:41921 => 192.168.1.100/192.168.1.100:8900)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at org.apache.mina.core.filterchain.DefaultIoFilterChain.register(DefaultIoFilterChain.java:383)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at org.apache.mina.core.filterchain.DefaultIoFilterChain.addLast(DefaultIoFilterChain.java:189)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder.buildFilterChain(DefaultIoFilterChainBuilder.java:436)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at org.apache.mina.core.polling.AbstractPollingIoProcessor.addNow(AbstractPollingIoProcessor.java:532)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at org.apache.mina.core.polling.AbstractPollingIoProcessor.handleNewSessions(AbstractPollingIoProcessor.java:505)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$400(AbstractPollingIoProcessor.java:67)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1113)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at java.lang.Thread.run(Thread.java:1019)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): Caused by: java.lang.IllegalArgumentException: Log tag "org.apache.mina.filter.ssl.SslHandler" exceeds limit of 23 characters
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at android.util.Log.isLoggable(Native Method)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at org.slf4j.impl.AndroidLogger.isDebugEnabled(AndroidLogger.java:109)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at org.apache.mina.filter.ssl.SslHandler.init(SslHandler.java:193)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at org.apache.mina.filter.ssl.SslFilter.onPreAdd(SslFilter.java:426)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): at org.apache.mina.core.filterchain.DefaultIoFilterChain.register(DefaultIoFilterChain.java:381)
12-02 19:55:40.156: W/org.apache.mina.util.DefaultExceptionMonitor(16032): ... 10 more