Skip to content

Instantly share code, notes, and snippets.

@ediskandarov
Created April 9, 2023 17:43
Show Gist options
  • Save ediskandarov/cc38683a720cad080ba89493ea47fe9e to your computer and use it in GitHub Desktop.
Save ediskandarov/cc38683a720cad080ba89493ea47fe9e to your computer and use it in GitHub Desktop.
pycades script example that verifies attached signature
import pycades
signed_data = pycades.SignedData()
with open('message.txt') as f:
msg = f.read()
signed_data.Content = msg
with open('message.txt.sig') as f:
signature_raw = f.read()
# Success if does not raise an exception
# False positive if root CA cert is not installed (test CA requires a dedicated installation)
signed_data.VerifyCades(signature_raw, pycades.CADESCOM_CADES_X_LONG_TYPE_1)
print('verified')
print('Content', signed_data.Content)
print('Number of signers', signed_data.Signers.Count)
for i in range(signed_data.Signers.Count):
signer = signed_data.Signers.Item(i + 1) # 1-indexed array
signer_cert = signer.Certificate
print('signer', signer_cert.SubjectName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment