verifykey.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import OpenPGP
  2. import OpenPGP.Crypto
  3. key_and_sigs = OpenPGP.Message.parse(open('key').read())
  4. key = key_and_sigs[0]
  5. print "Verifying self-signatures on top-level key: " + key.fingerprint()
  6. print "If no valid signatures are printed, the key's integrity is in question"
  7. # Run verification in the presence of only the key itself,
  8. # so all verified signatures will be self-sigs
  9. verify = OpenPGP.Crypto.Wrapper(key)
  10. verified_signatures = verify.verify(key_and_sigs)
  11. for sig_chunk in verified_signatures:
  12. if sig_chunk[0] != key:
  13. continue # Not a signature bound to the key in question at all
  14. # Direct signature on the top-level key, pretty rare
  15. # If there is one of these, you can be sure of they key's integrity
  16. if len(sig_chunk) == 2:
  17. for sig in sig_chunk[1]:
  18. print "Valid self-sig on top-level key"
  19. # Signature to bind a UserID to the top-level key
  20. # This signature proves the top-level claims the UserID
  21. # If there is one of these, you can be sure of they key's integrity
  22. elif isinstance(sig_chunk[1], OpenPGP.UserIDPacket):
  23. for sig in sig_chunk[2]:
  24. print "Top level key claims UserID: " + str(sig_chunk[1])
  25. # Signature to bind a subkey to the top-level key
  26. # This signature proves the top-level claims the subkey
  27. # This is not usually interpreted to mean anything about key integrity
  28. elif isinstance(sig_chunk[1], OpenPGP.PublicSubkeyPacket):
  29. for sig in sig_chunk[2]:
  30. print "Top level key claims subkey: " + sig_chunk[1].fingerprint()