restlet / restlet-framework-java

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

HTTPS server in android stalls or goes into infinite loop #1212

Open mrducky4 opened 8 years ago

mrducky4 commented 8 years ago

I am using restlet 2.2.3 for android, on android 4.2.2. Trying to use org.restlet.ext.nio.HttpsServerHelper. To simplify the test, I'm just using a browser to get a static HTML file, then refreshing the page to get the same thing again. The first time it works, then it fails, with the browser waiting for a response. If I close the browser, then the server looks like it goes into infinite loop.

This sounds same or very similar to https://github.com/restlet/restlet-framework-java/issues/702, the issue from lhanusiak not the original issue from waywaaard.

Here is my server startup code:

Engine.getInstance().getRegisteredServers().add(new HttpsServerHelper(null));
mComponent = new Component();
Server server = new Server(Protocol.HTTPS, 443);
mComponent.getServers().add(server);
mComponent.getClients().add(Protocol.FILE);
application.getConnectorService().getClientProtocols().add(Protocol.FILE);

// This overrides the restlet default algorithm "SunX509" with "X509". The Sun version is not available on android.
System.setProperty("ssl.KeyManagerFactory.algorithm",javax.net.ssl.KeyManagerFactory.getDefaultAlgorithm());

Series<Parameter> parameters = server.getContext().getParameters();
parameters.add("keyStorePath", "keyfile");
parameters.add("keyStorePassword", "xxx");
parameters.add("keyPassword", "xxx");
parameters.add("keyStoreType", "pkcs12");

mComponent.getDefaultHost().attach(application);

java.util.logging.Logger logger = mComponent.getLogger();
logger.setLevel(Level.FINE);
logger = logger.getParent().getParent();
logger.setLevel(Level.FINEST);
logger.getHandlers()[0].setLevel(Level.FINEST);

mComponent.start();

lhanusiak commented about workaround using the JSE distribution of org.restlet.ext.simple (for the HttpsServerHelper I assume) and running it on android. Is this a valid thing to do?

mrducky4 commented 8 years ago

I am having mostly success with using org.restlet.ext.simple.HttpsServerHelper on android. Except for big problem that the android 4.2.2 web browser and webview can't connect to it. Still working on that. Android 4.4.2 browser works ok, and chrome on Windows works fine too.

Why isn't org.restlet.ext.simple package included with the android distribution? Is there some fundamental reason why it is not supposed to work?

thboileau commented 8 years ago

Hi @mrducky4 , I think that there may be some issues in the past with the Simple extension, mainly because the Android SDK is a subpart of the Java SDK. But if you tell me that the extension works also in Android, that's a good news!!

mrducky4 commented 8 years ago

Yes I have good results with org.restlet.ext.simple.HttpsServerHelper. But one downside is it uses SSLEngine rather than SSLServerSocket for TLS handshake, so in Android 4.2 it does not support TLSv1.1 and TLSv1.2. I think nio.HttpsServerHelper uses SSLServerSocket. I still would like to use the nio version, if it worked.

If I can create a small Android Studio project that shows the problem with org.restlet.ext.nio.HttpsServerHelper, would that help?