Solution 1 :
Since JEP-229, which shipped with Java 8, the default keystore type of the Java runtime is PKCS12.
I guess it would make sense if the secure(...)
method of Spark also accepted a parameter for the type of keystore. Maybe you should check in their issue tracker if they’d be interested in a contribution for this.
Problem :
I am trying to run a Spark (sparkjava.com) server application that runs on Android. This server requires support for HTTPS. I am using Spark 2.9.2.
Here is the secure call to support HTTPS in Spark.
secure(“/sdcard/oursecurity/keystore.bks”, “mypassword”, null, null);
When the application is started, it crashes with a java.security.KeyStoreException: JKS not found.
I have seen in various posts that Android does not support the JKS keystore type.
While debugging, I noticed that the Jetty server has a setKeyStoreType call that allows the user to change the keystore type from Jetty’s default of JKS to some other type.
My plan is to do the following:
- Download the Spark 2.9.2 source code.
- In the createSecureSocketConnector method of the Spark file /src/main/java/spark/embeddedserver/jetty/SocketConnectorFactory.java, call sslContextFactory.setKeyStoreType(AndroidSupportKeystoreType) to switch the keystore type to a keystore type supported by Android.
- Rebuild the class and create a new modified Spark jar.
- Rebuild my application with this new modified Spark jar.
I am thinking of using BKS or PKCS12 as the keystore type.
Has anyone else run the Spark server successfully on Android with support for HTTPS requests? If so, any suggestions would be appreciated.
Comments
Comment posted by this question
Did you see
Comment posted by paul
@mthmulders No, I had not seen that question. Thanks for pointing it out. Unfortunately, my issue is different. I am able to run Spark in Android successfully. However, I am not able to run Spark in Android when supporting the “secure” call which is needed to support HTTPS requests. Hopefully I can help the other person with their question.
Comment posted by paul
Thanks for the info on the default keystore type and the issue tracker. I can take a look at the tracker.