I am doing an assignment where I have a CA (server) and a client that requests a certificate from the CA, this function works. The certificate is sent via tcp as bytes. The idea is that clients will share a session key, but before they do they need to verify each others certificates. I do not have two clients set up so I decided to verify the clients own certificate using the function I created, yet it somehow says the certificate is invalid even though I am verifying a certificate I just got from the CA:
Here is my function:
def verifyCert(certificate):
certificatetoRead = x509.load_pem_x509_certificate(certificate, default_backend())
public_key = certificatetoRead.public_key()
try:
public_key.verify(
certificatetoRead.signature,
certificatetoRead.tbs_certificate_bytes,
padding.PKCS1v15(),
certificatetoRead.signature_hash_algorithm,
)
print("Certificate signature verified. It's legitimate.")
except Exception:
print("Certificate signature verification failed. It may be tampered or invalid.")
When the CA sends me the certificate I pass it to this verifyCert function, and becuase I’ve not done anything I’m expecting it to verify it and say it is legitimate but it says its tampered.
Could I please get help as to what I may be doing wrong.
Reabetsoe Mpapa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.