abstract connection code into SecureConnection