NanoHttpd / nanohttpd

Tiny, easily embeddable HTTP server in Java.

Home Page:http://nanohttpd.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

https connection

Rezasahebi76 opened this issue · comments

Hi
I try to create https web sever in android app.
I found below code for makeSecure connection but it doesn't work.
val keystore =KeyStore.getInstance(KeyStore.getDefaultType()) val keystoreStream: InputStream = assets.open("keySSS.jks") if (keystoreStream == null) { throw IOException("Unable to load keystore from classpath: " + "keystore.bks") } keystore.load(keystoreStream, "password".toCharArray()) val keyManagerFactory:KeyManagerFactory =KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()) keyManagerFactory.init(keystore, "password".toCharArray()) val server = AndroidWebServer(this) server.makeSecure(NanoHTTPD.makeSSLSocketFactory(keystore, keyManagerFactory), null) server.start(6000)
I generate sign key by below command:
keytool -genkey -keyalg RSA -alias selfsigned -keystore keySSS.jks -storepass password -validity 9999 -keysize 2048 -ext SAN=DNS:localhost,IP:127.0.0.1 -validity 9999
And convert it to bks format with KeyStore Explorer Sofware.
But when i open the IP in browser, browser show below warning:
Your connection to this site is not secure
can anyone say me what's wrong?

The reason you are seeing that error message is because you are using a self-signed certificate. If you want that error message to go away, you need to use a certificate from a certificate authority like Lets Encrypt.