I have to write a Node.JS application that connects to a remote server. The remote server has a login manager that authenticates my session then spawns a separate process to handle the rest of my session. The way that works is that I have to make a non-SSL network connection to the login manager and do an initial unprotected handshake. The lets the client and server negotiate if they will be doing SSL or plain text communications. If SSL then I need to elevate my socket to an SSL socket, send my login and password along with some other initial information, then get a success of failure message back from the login manager. If success then I know the login manager is starting a new process and handing off my open socket connection to that new process. Since the server can't pass the SSL context it de-elevates the SSL connection and runs a program passing it the non-SSL open socket. Then the new program creates it's own SSL context on the open socket. So in my Node.JS code I need to close the SSL socket but leave the raw socket open. The new program will send me a success message when it is up and running at which time I need to re-elevate my open socket to SSL again.
My question is how can I close an SSL socket leaving the raw socket open so I can continue to use the raw socket and then re-elevate it to SSL again?