NanoHttpd / nanohttpd

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

Https in Server #535

Open sumit-vuliv opened 5 years ago

sumit-vuliv commented 5 years ago

Hi All, We need to start working on HTTPS implementation in Nanohttpd server.as per sample we have ,it is giving error while loading jks file.If someone has implemented HTTPS protocol .please share the sample code.

JiashuGuo commented 5 years ago

I tried .jks in Android it failed because Android doen't support .jks. What I did is convert .jks to .bks-V1 in Keystore Explore and then put it under assets folder. Below is code I am use: KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); InputStream keystoreStream = MyApplication.getContext().getAssets().open("keystore.bks"); if (keystoreStream == null) { throw new IOException("Unable to load keystore from classpath: " + "keystore.bks"); } keystore.load(keystoreStream, "password".toCharArray()); KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); keyManagerFactory.init(keystore, "password".toCharArray()); server.makeSecure(NanoHTTPD.makeSSLSocketFactory(keystore, keyManagerFactory), null); server.start();

LordFokas commented 5 years ago

I don't understand the SSL code in NanoHTTPD very well, but whoever did it doesn't seem to have done a very good job. This being said you can always create your own secure server socket and roll from there.

stefan-reich commented 5 years ago

I have HTTPS working fine with a fork of NanoHTTPD, certificates, SNI and all. Examples: https://botcompany.de | https://agi.blue - This is just NanoHTTPD, no proxies, no nothing.

You can see the full code e.g. in here: http://botcompany.de:8081/ssl-bugreport.tgz

Or ask me if you have any questions.

JiashuGuo commented 5 years ago

Thank you so much for sharing, I got the NanoHttpd finally works in our project. Your applications are very helpful for future use.

On Fri, Aug 2, 2019 at 6:40 AM Stefan Reich notifications@github.com wrote:

I have HTTPS working fine with a fork of NanoHTTPD, certificates and all. Examples: https://botcompany.de | https://agi.blue - This is just NanoHTTPD, no proxies, no nothing.

You can see the full code e.g. in here: http://botcompany.de:8081/ssl-bugreport.tgz

Or ask me if you have any questions.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/NanoHttpd/nanohttpd/issues/535?email_source=notifications&email_token=AF72A23XK2XIAO6FTNZRE2DQCQ2M7A5CNFSM4HB7UU62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3NYX2I#issuecomment-517704681, or mute the thread https://github.com/notifications/unsubscribe-auth/AF72A2ZTKSSDJJ42ZZVBDBDQCQ2M7ANCNFSM4HB7UU6Q .

wasimshariff11 commented 3 years ago

I created https server by generating .bks file, but when I hit request form web application I get handshake failed, web application doesn't have client certificate as it is one way authentication. How can we achieve https with only server side certificate.