improve support for ssl
handle wrong handshake correctly