Fix the certificate validity check