0

I created a NanoHTTPD Server on Android. I was able to create an https server on my previous work, but it's not secure. I want it to have added security like the one with the green padlock because I'm having problems connecting to the server on iOS so I did some research and modified my old code and did this but the browser shows "This site can't provide a secure connection". What do I do to fix this?

 try {
                if (!isServerConnected) {
                    KeyStore keyStore = KeyStore.getInstance("BKS");
                    keyStore.load(Objects.requireNonNull(getClass().getClassLoader()).getResourceAsStream("newselfsigned.bks"), "mypassword".toCharArray());

                    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
                    trustManagerFactory.init(keyStore);

                    SSLContext sslctx = SSLContext.getInstance("TLS");
                    sslctx.init(null, trustManagerFactory.getTrustManagers(), new SecureRandom());

                    SSLServerSocketFactory factory = sslctx.getServerSocketFactory();

                    server.makeSecure(factory, new String [] { "TLSv1", "TLSv1.1","SSLv3"});
                    server.start(10000);

                    WifiManager wifiManager = (WifiManager) v.getContext().getApplicationContext().getSystemService(WIFI_SERVICE);

                    int ipAddress = wifiManager.getConnectionInfo().getIpAddress();
                    @SuppressLint("DefaultLocale") final String formatedIpAddress = String.format("%d.%d.%d.%d", (ipAddress & 0xff), (ipAddress >> 8 & 0xff),
                            +(ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff));

                    isServerConnected = true;

                    Toast.makeText(v.getContext(), "Connected : " + "Please access! https://" + formatedIpAddress + ":" + server.getListeningPort() + " From a web browser", Toast.LENGTH_SHORT).show();

                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://" + formatedIpAddress + ":" + server.getListeningPort()));
                    startActivity(browserIntent);

                }
            } catch (IOException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException | CertificateException e) {
                Toast.makeText(v.getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
user8248810
  • 36
  • 1
  • 3
  • 11
  • Is your server using an SSL certificate that is signed by a recognized root CA? – Stephen C Sep 21 '19 at 07:19
  • @StephenC Not sure I generated a .jks file from keytool then I converted it to .bks using Keystore Explorer and that's what I used. – user8248810 Sep 21 '19 at 08:23
  • I'm confused. Is this client code or server code? If it is client code, then ... you have missed the point of my question. I am asking about the SSL cert used in your HTTPS server. – Stephen C Sep 21 '19 at 09:56

0 Answers0