ssl: improve error handling