All the SSL session logic, preliminary commit