Improve support for self-signed certificates