UPDATE (This Question Have been Solved): I have updated the code in this question to contain the now working code, feel free to use it in your own works (Code samples have been mode to pastbins for simplicity)
Good afternoon StackOverflow,
So for the past day or to I have been working on a server software that has a web interface and I have been trying to setup handling for HTTPS connections. I got it to work fine and every thing but now I am trying to handle both HTTP and HTTPS connections on the one TCP port.
I have code that can detect a SSL/TLS ClientHello message, the problem is trying to convert the pain text socket to a SSLSocket once the message has been detected, bellow in the code I am using.
WebServer.java
-> http://pastebin.com/JSjNpC2Y
SecurityTools.java
-> http://pastebin.com/Q8yVLNp7
BufferedSocket.java
-> http://pastebin.com/SuWB8P7r
BufferedSocketServer.java
-> http://pastebin.com/Nr7MrhEH
When I connect with HTTP nothing at all happens, not even a error or exception is throw and when I connect with HTTPS I get the following set of exceptions (I am linking to a paste bin to save space in this post)
Any and all help and suggestions are welcome.
Thanks for any help!
Resetting your own input stream has no effect on the underlying socket. You need to create your own wrapper for the Socket class, that returns a markable input stream. Then you need to reset that stream if it's SSL and pass your wrapper to the SSLSocketFactory. Otherwise it won't see the client hello that you saw.