refactor ssl handshake + auth into their own functions