Created
April 9, 2023 17:43
-
-
Save ediskandarov/cc38683a720cad080ba89493ea47fe9e to your computer and use it in GitHub Desktop.
pycades script example that verifies attached signature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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