Search code examples
androidhttpswebservernanohttpd

nanohttpd https server in android , android and ios browser connect fail


I try establish a https server in android for other phones to connect,but only iphone6 sometimes can connected , ipod ,android browser all failed to get the webserver content. (the browser message is fail to establish safe connect) I use nanohttpd's simpleServer Class to establish it.

my CA is here

http://www.mediafire.com/download/53f6e9uveb47kqv/ca.cer // for client to download

http://www.mediafire.com/download/v9i58n38yb85co5/server.p12 //for server to load keystore

CA password both are singuler .

Here is my sslServerSocket Code

    char[]kspass = KEYSTOREPASS.toCharArray();
    char[]ctpass = KEYSTOREPASS.toCharArray();
    try {


        KeyStore ks = KeyStore.getInstance("PKCS12");
        //ks.load(new FileInputStream("file:///android_asset/singuler.keystore"),kspass);
        ks.load(getResources().getAssets().open("server.p12"),kspass);

        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        kmf.init(ks, ctpass);
        TrustManagerFactory tmFactory = TrustManagerFactory.getInstance("X509");
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(kmf.getKeyManagers(), null, null);

        //webServer.makeSecure(NanoHTTPD.makeSSLSocketFactory(ks, kmf.getKeyManagers()));
        webServerSSL.makeSecure(sc.getServerSocketFactory());

    } catch (Exception e) {
        // TODO: handle exceptionser
        Log.i("test", e.toString());
    }



    try {
        webServer.start(15);
        webServerSSL.start(15);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        webServer = null;
        webServerSSL=null;
        Log.i("test", e.toString());
    }

Can any one help me ? Thank you.


Solution

  • I found the answer Whe start nanohttpd server , need set the timeout millonseconds for every connect socket,especial for https request.