NanoHttpd / nanohttpd

Tiny, easily embeddable HTTP server in Java.
http://nanohttpd.org
BSD 3-Clause "New" or "Revised" License
6.9k stars 1.69k forks source link

https connection #572

Open Rezasahebi76 opened 4 years ago

Rezasahebi76 commented 4 years ago

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?

MarcWoodyard commented 4 years ago

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.