restlet / restlet-framework-java

The first REST API framework for Java
https://restlet.talend.com
648 stars 284 forks source link

https server on android L leading to exception #1076

Open skrishnaprasad opened 9 years ago

skrishnaprasad commented 9 years ago

When I try to run an https server connection using nio https helper I run in to execeptions when ever I try to make a connection.

5-23 14:57:22.970: W/System.err(13593): NIO controller selected 1 key(s) ! 05-23 14:57:23.005: W/System.err(13593): Unexpected error while controlling connector 05-23 14:57:23.005: W/System.err(13593): java.lang.IllegalStateException: Handshake has already been started 05-23 14:57:23.005: W/System.err(13593): at com.android.org.conscrypt.OpenSSLEngineImpl.beginHandshake(OpenSSLEngineImpl.java:139) 05-23 14:57:23.005: W/System.err(13593): at org.restlet.ext.nio.internal.connection.SslConnection.initSslEngine(SslConnection.java:381) 05-23 14:57:23.005: W/System.err(13593): at org.restlet.ext.nio.internal.connection.SslConnection.reuse(SslConnection.java:486) 05-23 14:57:23.005: W/System.err(13593): at org.restlet.ext.nio.ConnectionHelper.checkout(ConnectionHelper.java:245) 05-23 14:57:23.005: W/System.err(13593): at org.restlet.ext.nio.internal.controller.ServerConnectionController.onSelected(ServerConnectionController.java:117) 05-23 14:57:23.005: W/System.err(13593): at org.restlet.ext.nio.internal.controller.ConnectionController.selectKeys(ConnectionController.java:311) 05-23 14:57:23.005: W/System.err(13593): at org.restlet.ext.nio.internal.controller.ConnectionController.doRun(ConnectionController.java:174) 05-23 14:57:23.005: W/System.err(13593): at org.restlet.ext.nio.internal.controller.Controller.run(Controller.java:161) 05-23 14:57:23.010: W/System.err(13593): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 05-23 14:57:23.010: W/System.err(13593): at java.util.concurrent.FutureTask.run(FutureTask.java:237) 05-23 14:57:23.010: W/System.err(13593): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 05-23 14:57:23.010: W/System.err(13593): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 05-23 14:57:23.010: W/System.err(13593): at java.lang.Thread.run(Thread.java:818) 05-23 14:57:23.010: W/System.err(13593): NIO controller woke up

Restlet Configuration for HTTPS/SSL

parameters.add("sslContextFactory","org.restlet.ext.ssl.SslContextFactory");
server.getContext().getParameters().add("sslContextFactory","org.restlet.engine.ssl.DefaultSslContextFactory");
server.getContext().getParameters().add("keyStorePath", "/mnt/extSdCard/xtv_app.bks");
//server.getContext().getParameters().add("keyStorePath", "/storage/sdcard0/test.bks" );

server.getContext().getParameters().add("keyStorePassword", "yGNmnDr6xmmM7R9vAQ6KC2GArRWMNmjwMpU3z6CP33YsWLV7Rb8NcY6qcDDmZT6AcKjF5QHCAQE5AhaGCcaACfkuYf9FqEF8KAF4x5mSHevE4zLc4uQpbwTeJ27CHCSCJYH7CqRfhKjNtR3ey3AwpRqL7j6LACNCMAWf8x3MpmdTsLLj98Um7eK8knGbdmjBcuW6BP7Mv44uhhC4G4GBtATh8fZBbHK6GdGV3a43XMbEtTz7uAwHth3Gj94syxXz");
server.getContext().getParameters().add("keyPassword", "xCHCMVUSxVCVnRF2HFkLXRcztdU8f3gdsKb9TGjkM8GWcatrpmZF5SBEkeZVWJ5dfyNQWqJjFqeU7tFUJAb6QcMEet58AEHqkcsLK46ACRkDL6mwXEfVWAeNPATAJbdxyTdk26DUSmYAsZPEWxHaVxMd6Cht3PTsyf7ZjWfQxQCMRpjtVd5bk3Xq47CkP6FkVVkcFceKPQ5B7NwN54L5Gmpam7sgV6QnTDsgQjjRGffkJGexyjkmVWBsqrEWrzBA");
server.getContext().getParameters().add("disabledProtocols", "SSL");
server.getContext().getParameters().add("enabledProtocols", "TLS");
server.getContext().getParameters().add("protocol", "TLS");
//server.getContext().getParameters().add("disabledCipherSuites", "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA");
//server.getContext().getParameters().add("enabledCipherSuites", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
server.getContext().getParameters().add("trustManagerAlgorithm", "X509");
server.getContext().getParameters().add("keyManagerAlgorithm", "X509");
server.getContext().getParameters().add("trustStorePath", "/mnt/extSdCard/test.bks");
thboileau commented 9 years ago

Hi @skrishnaprasad could you precise the version of RF, the kind of RF extensions you are using?

amitchaturvedi commented 9 years ago

Hi thboileau,

I am also facing the same issue. Android Restlet library does not work for Android L. I have tried to resolve the issue by putting multiple if/else in SSLConnection.java file like this :+1: : public void initSslEngine() throws SSLException { if(getSslHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING && isHandshaking != true && getSslHandshakeStatus() != HandshakeStatus.NEED_UNWRAP){

    getLogger().log(Level.INFO,"Amit:Handshake status is " +getSslHandshakeStatus());
    getSslEngine().setUseClientMode(isClientSide());
    getSslEngine().beginHandshake();
    }else {
        getLogger().log(Level.INFO,"Amit:Handshake is already going on so don't begin it again");

    }
}

HTTPS works for sometime but again stopped with a lot exceptions :+1:

/System.err( 4235): Amit:Handshake Exception and isHandshaking variable value isfalse W/System.err( 4235): java.lang.IllegalStateException: Handshake has already been started W/System.err( 4235): at com.android.org.conscrypt.OpenSSLEngineImpl.beginHandshake(OpenSSLEngineImpl.java:139) W/System.err( 4235): at org.restlet.ext.nio.internal.connection.SslConnection.initSslEngine(SslConnection.java:400) W/System.err( 4235): at org.restlet.ext.nio.internal.connection.SslConnection.reuse(SslConnection.java:526) W/System.err( 4235): at org.restlet.ext.nio.ConnectionHelper.checkout(ConnectionHelper.java:236) W/System.err( 4235): at org.restlet.ext.nio.internal.controller.ServerConnectionController.onSelected(ServerConnectionController.java:125) W/System.err( 4235): at org.restlet.ext.nio.internal.controller.ConnectionController.selectKeys(ConnectionController.java:302) W/System.err( 4235): at org.restlet.ext.nio.internal.controller.ConnectionController.doRun(ConnectionController.java:165) W/System.err( 4235): at org.restlet.ext.nio.internal.controller.Controller.run(Controller.java:152) W/System.err( 4235): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) W/System.err( 4235): at java.util.concurrent.FutureTask.run(FutureTask.java:237) W/System.err( 4235): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) W/System.err( 4235): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) W/System.err( 4235): at java.lang.Thread.run(Thread.java:818) W/System.err( 4235): Amit:Last Handshake status is NEED_UNWRAP

Could you please fix it ASAP. i am using latest version of Restlet Android libraries.

jlouvel commented 9 years ago

The NIO extension is considered a dev preview and has some known stability issues. We actually don't plan to keep it moving forward (v3).

As an alternative, I would suggest looking at: https://github.com/jetty-project/i-jetty

We will look into integrating i-Jety with Restlet Framework like we do with regular Jetty. Contributions welcome on this front!

amitchaturvedi commented 9 years ago

NIO HTTPS extension not at all working with Android 5.
You mean you will not support NIO extension from the next version of Restlet releases. Please let me know so that I can plan accordingly,

In case , I am not using NIO extensions provided by Restlet Framework then I will not be able to use Restlet Framework? Is this correct?

jlouvel commented 9 years ago

@amitchaturvedi This is correct, we won't be supporting the NIO extension moving forward, focusing on integration with Jetty (i-Jetty integration would be nice as well for the Android edition) and with Netty (new connector in the works). Sorry about the inconvenience.

@thboileau Could we make the NIO extension as deprecated in the Javadocs and related Java code in branch 2.3 to prevent any confusion? Other extensions we plan to drop in v3.0 seem properly marked.