def verify_signed_message(given_message,given_encoded_sig,given_cert):
'''Given strings for the message, its signature, and a certificate object,
verify the message. Returns true or false.'''
# Decode given signature (expected base64 encoding):
try:
decoded_sig = base64.b64decode(given_encoded_sig)
except:
common.logging_error("Could not interpret encoded signature.")
return False
# Verify the signature:
try:
# OpenSSL is funny. A successful crypto.verify() returns a None object!
crypto.verify(given_cert,decoded_sig,given_message,config_client_pki.CSR_SIGNING_HASH_ALGORITHM)
return True
except crypto.Error:
common.logging_error("Message fails verification.")
return False
评论列表
文章目录