separate code for ssl session management, and add test mocks