Detect invalid X509 certificates.
Refactor X509 certificate validation and debugging.