from M2Crypto import X509, SSL
ca = X509.load_cert('/path/to/ca_cert.pem')
cert = X509.load_cert('certificate_to_validate.pem')
print('Verification results:', cert.verify(ca.get_pubkey()))
ctx = SSL.Context()
ctx.load_verify_locations(cafile='/path/to/ca_cert.pem')
ctx.load_verify_locations(capath='/path/to/ca/dir')
Verifying peer in SSL using python