X509 tests and fixes