def show_simple_packet(p): p_string = ['%s:' % TXT.pkt_msg(p.tag.type)] if p.tag.type in [ PKT_PUBLICKEY, PKT_PRIVATEKEY, PKT_PUBLICSUBKEY, PKT_PRIVATESUBKEY ]: p_string.append(p.body.id) p_string.append(TXT.alg_pubkey_msg(p.body.alg)) elif PKT_USERID == p.tag.type: p_string.append(p.body.value) elif PKT_SIGNATURE == p.tag.type: p_string.append(TXT.sig_msg(p.body.type)) p_string.append("from %s" % p.body.keyid) elif PKT_PUBKEYSESKEY == p.tag.type: p_string.append(TXT.alg_pubkey_msg(p.body.alg_pubkey)) p_string.append(p.body.keyid) elif PKT_LITERAL == p.tag.type: p_string.append(' '.join( [p.body.filename, p.body.format, "%s bytes" % len(p.body.data)])) return ' '.join(p_string)
def show_simple_packet(p): p_string = ['%s:' % TXT.pkt_msg(p.tag.type)] if p.tag.type in [PKT_PUBLICKEY, PKT_PRIVATEKEY, PKT_PUBLICSUBKEY, PKT_PRIVATESUBKEY]: p_string.append(p.body.id) p_string.append(TXT.alg_pubkey_msg(p.body.alg)) elif PKT_USERID == p.tag.type: p_string.append(p.body.value) elif PKT_SIGNATURE == p.tag.type: p_string.append(TXT.sig_msg(p.body.type)) p_string.append("from %s" % p.body.keyid) elif PKT_PUBKEYSESKEY == p.tag.type: p_string.append(TXT.alg_pubkey_msg(p.body.alg_pubkey)) p_string.append(p.body.keyid) elif PKT_LITERAL == p.tag.type: p_string.append(' '.join([p.body.filename, p.body.format, "%s bytes" % len(p.body.data)])) return ' '.join(p_string)
def report_body(pkt): """Return a list of reports on a packet body. :Parameters: - `pkt`: instance of a `OpenPGP.packet.Packet` subclass :Returns: string reporting something about the packet body """ report = [] body = pkt.body if PKT_PUBKEYSESKEY == pkt.tag.type: report.append(" version: %s" % body.version) report.append(" key id: %s" % body.keyid) report.append(" key algorithm: %s (%s)" % (body.alg_pubkey, TXT.alg_pubkey_msg(body.alg_pubkey))) if body.alg_pubkey in [ASYM_RSA_EOS, ASYM_RSA_E]: report.append(" RSA 'me mod n' bit count: %s" % body.RSA_me_modn.bit_length) elif body.alg_pubkey in [ASYM_ELGAMAL_EOS, ASYM_ELGAMAL_E]: report.append(" ElGamal 'gk mod p' bit count: %s" % body.ELGAMAL_gk_modp.bit_length) report.append(" ElGamal 'myk mod p' bit count: %s" % body.ELGAMAL_myk_modp.bit_length) elif PKT_SIGNATURE == pkt.tag.type: report.append(" version: %s type: %s %s" % (body.version, body.type, TXT.sig_msg(body.type))) report.append(" signer: %s" % body.keyid) report.append(" created: %s" % body.created) report.append(" hash: %s (%s)" % (body.alg_hash, TXT.alg_hash_msg(body.alg_hash))) report.append(" public key algorithm: %s (%s)" % (body.alg_pubkey, TXT.alg_pubkey_msg(body.alg_pubkey))) if 4 == body.version: report.append(" unhashed data:") for s in body.unhashed_subpkts: report.append( " %s (%s/%s): %s" % (TXT.sigsub_msg(s.type), s.type, hex(s.type), s.value)) report.append(" hashed data:") for s in body.hashed_subpkts: report.append( " %s (%s/%s): %s" % (TXT.sigsub_msg(s.type), s.type, hex(s.type), s.value)) if body.alg_pubkey in [ASYM_RSA_EOS, ASYM_RSA_S]: report.append(" RSA value bit count: %s" % body.RSA.bit_length) elif ASYM_DSA == body.alg_pubkey: report.append(" DSA 'r' bit count: %s" % body.DSA_r.bit_length) report.append(" DSA 's' bit count: %s" % body.DSA_s.bit_length) report.append(" hash fragment: %s" % [hex(ord(x)) for x in body.hash_frag]) elif PKT_SYMKEYSESKEY == pkt.tag.type: report.append(" version: %s" % body.version) report.append(" algorithm: %s (%s)" % (body.alg, TXT.alg_symkey_msg(body.alg))) if 's2k' in body.__dict__: report.append(" S2K type: %s" % body.s2k.type) if 'alg_hash' in body.s2k.__dict__: report.append( " S2K hash: %s (%s)" % (body.s2k.alg_hash, TXT.alg_hash_msg(body.s2k.alg_hash))) if 'salt' in body.s2k.__dict__: report.append(" S2K salt: %s" % [hex(ord(x)) for x in body.s2k.salt]) if 'count_code' in body.s2k.__dict__: report.append(" S2K count code: %s" % body.s2k.count_code) if 'count' in body.s2k.__dict__: report.append(" S2K count: %s" % body.s2k.count) elif PKT_ONEPASS == pkt.tag.type: report.append(" version: %s" % body.version) report.append(" signature type: %s (%s)" % (body.type, TXT.sig_msg(body.type))) report.append(" key id: %s" % body.keyid) report.append(" hash: %s (%s)" % (body.alg_hash, TXT.alg_hash_msg(body.alg_hash))) report.append(" key algorithm: %s (%s)" % (body.alg_pubkey, TXT.alg_pubkey_msg(body.alg_pubkey))) report.append(" nested: %s" % body.nest) elif pkt.tag.type in [ PKT_PUBLICKEY, PKT_PUBLICSUBKEY, PKT_PRIVATEKEY, PKT_PRIVATESUBKEY ]: report.append(" version: %s created: %s" % (body.version, body.created)) report.append(" algorithm: %s (%s)" % (body.alg, TXT.alg_pubkey_msg(body.alg))) report.append(" fingerprint: %s ID: %s" % (body.fingerprint, body.id)) if body.alg in [ASYM_RSA_EOS, ASYM_RSA_S]: report.append(" RSA 'n' bit count: %s" % body.RSA_n.bit_length) report.append(" RSA 'n' value: %s" % body.RSA_n.value) report.append(" RSA 'e' bit count: %s" % body.RSA_e.bit_length) report.append(" RSA 'e' value: %s" % body.RSA_e.value) elif ASYM_DSA == body.alg: report.append(" DSA 'p' bit count: %s" % body.DSA_p.bit_length) report.append(" DSA 'p' value: %s" % body.DSA_p.value) report.append(" DSA 'q' bit count: %s" % body.DSA_q.bit_length) report.append(" DSA 'q' value: %s" % body.DSA_q.value) report.append(" DSA 'g' bit count: %s" % body.DSA_g.bit_length) report.append(" DSA 'g' value: %s" % body.DSA_g.value) report.append(" DSA 'y' bit count: %s" % body.DSA_y.bit_length) report.append(" DSA 'y' value: %s" % body.DSA_y.value) elif body.alg in [ASYM_ELGAMAL_EOS, ASYM_ELGAMAL_E]: report.append(" ElGamal 'p' bit count: %s" % body.ELGAMAL_p.bit_length) report.append(" ElGamal 'p' value: %s" % body.ELGAMAL_p.value) report.append(" ElGamal 'g' bit count: %s" % body.ELGAMAL_g.bit_length) report.append(" ElGamal 'g' value: %s" % body.ELGAMAL_g.value) report.append(" ElGamal 'y' bit count: %s" % body.ELGAMAL_y.bit_length) report.append(" ElGamal 'y' value: %s" % body.ELGAMAL_y.value) if hasattr(body, 'expires'): report.append(" expires: %s" % body.expires) if hasattr(body, 'expires'): report.append(" expires: %s" % body.expires) if pkt.tag.type in [PKT_PRIVATEKEY, PKT_PRIVATESUBKEY]: if hasattr(body, 'alg_sym'): report.append(" encrypted with algorithm: %s %s" % (body.alg_sym, TXT.alg_symkey_msg(body.alg_sym))) if hasattr(body, 's2k_usg'): report.append(" S2K usage: %s" % body.s2k_usg) if hasattr(body, 'iv'): report.append(" IV: %s" % [hex(ord(x)) for x in body.iv]) if hasattr(body, 's2k'): report.append(" S2K type: %s" % body.s2k.type) if hasattr(body.s2k, 'alg_hash'): report.append(" S2K hash: %s (%s)" % (body.s2k.alg_hash, TXT.alg_hash_msg(body.s2k.alg_hash))) if hasattr(body.s2k, 'salt'): report.append(" S2K salt: %s" % ''.join([ '\\x%s' % hex(ord(c))[2:].zfill(2) for c in body.s2k.salt ])) if hasattr(body.s2k, 'count_code'): report.append(" S2K count code: %s" % body.s2k.count_code) if hasattr(body.s2k, 'count'): report.append(" S2K count: %s" % body.s2k.count) if hasattr(body, '_enc_d'): report.append(" encrypted data: %s octets" % len(body._enc_d)) #report.append(" encrypted data: %s" % [hex(ord(x)) for x in body._enc_d]) report.append(" encrypted data: %s" % ''.join( ['\\x%s' % hex(ord(c))[2:].zfill(2) for c in body._enc_d])) else: if body.alg in [ASYM_RSA_EOS, ASYM_RSA_S]: report.append(" Secret RSA 'd' bit count: %s" % body.RSA_d.bit_length) report.append(" Secret RSA 'd' value: %s" % body.RSA_d.value) report.append(" Secret RSA 'p' bit count: %s" % body.RSA_p.bit_length) report.append(" Secret RSA 'p' value: %s" % body.RSA_p.value) report.append(" Secret RSA 'q' bit count: %s" % body.RSA_q.bit_length) report.append(" Secret RSA 'q' value: %s" % body.RSA_q.value) report.append(" Secret RSA 'u' bit count: %s" % body.RSA_u.bit_length) report.append(" Secret RSA 'u' value: %s" % body.RSA_u.value) elif ASYM_DSA == body.alg: report.append(" Secret DSA 'x' bit count: %s" % body.DSA_x.bit_length) report.append(" Secret DSA 'x' value: %s" % body.DSA_x.value) elif body.alg in [ASYM_ELGAMAL_EOS, ASYM_ELGAMAL_E]: report.append(" Secret ElGamal 'x' bit count: %s" % body.ELGAMAL_x.bit_length) report.append(" Secret ElGamal 'x' value: %s" % body.ELGAMAL_x.value) if hasattr(body, 'chksum') and body.chksum: # for chksum == None?? report.append(" checksum: %s" % [hex(ord(x)) for x in body.chksum]) elif PKT_COMPRESSED == pkt.tag.type: report.append(" compression type %s (%s)" % (pkt.body.alg, TXT.alg_comp_msg(pkt.body.alg))) elif PKT_SYMENCDATA == pkt.tag.type: report.append(" encrypted data: %s octets" % len(body.data)) elif PKT_MARKER == pkt.tag.type: report.append(" left a mark: %s" % pkt.body.value) elif PKT_LITERAL == pkt.tag.type: report.append(" format: %s" % pkt.body.format) report.append(" modified: %s" % pkt.body.modified) report.append(" filename: %s" % pkt.body.filename) report.append(" data length: %s" % len(pkt.body.data)) elif PKT_TRUST == pkt.tag.type: pass elif PKT_USERID == pkt.tag.type: report.append(" ID: %s" % body.value) elif PKT_USERATTR == pkt.tag.type: pass elif PKT_SYMENCINTDATA == pkt.tag.type: report.append(" version: %s" % body.version) # suspect exception report.append(" encrypted data: %s octets" % len(body.data)) # suspect exception elif PKT_MODDETECT == pkt.tag.type: # will this ever be shown? report.append(" detection hash: %s" % [hex(ord(x)) for x in body.hash]) # suspect exception else: pass return linesep.join(report)
def report_body(pkt): """Return a list of reports on a packet body. :Parameters: - `pkt`: instance of a `OpenPGP.packet.Packet` subclass :Returns: string reporting something about the packet body """ report = [] body = pkt.body if PKT_PUBKEYSESKEY == pkt.tag.type: report.append(" version: %s" % body.version) report.append(" key id: %s" % body.keyid) report.append(" key algorithm: %s (%s)" % (body.alg_pubkey, TXT.alg_pubkey_msg(body.alg_pubkey))) if body.alg_pubkey in [ASYM_RSA_EOS, ASYM_RSA_E]: report.append(" RSA 'me mod n' bit count: %s" % body.RSA_me_modn.bit_length) elif body.alg_pubkey in [ASYM_ELGAMAL_EOS, ASYM_ELGAMAL_E]: report.append(" ElGamal 'gk mod p' bit count: %s" % body.ELGAMAL_gk_modp.bit_length) report.append(" ElGamal 'myk mod p' bit count: %s" % body.ELGAMAL_myk_modp.bit_length) elif PKT_SIGNATURE == pkt.tag.type: report.append(" version: %s type: %s %s" % (body.version, body.type, TXT.sig_msg(body.type))) report.append(" signer: %s" % body.keyid) report.append(" created: %s" % body.created) report.append(" hash: %s (%s)" % (body.alg_hash, TXT.alg_hash_msg(body.alg_hash))) report.append(" public key algorithm: %s (%s)" % (body.alg_pubkey, TXT.alg_pubkey_msg(body.alg_pubkey))) if 4 == body.version: report.append(" unhashed data:") for s in body.unhashed_subpkts: report.append(" %s (%s/%s): %s" % (TXT.sigsub_msg(s.type), s.type, hex(s.type), s.value)) report.append(" hashed data:") for s in body.hashed_subpkts: report.append(" %s (%s/%s): %s" % (TXT.sigsub_msg(s.type), s.type, hex(s.type), s.value)) if body.alg_pubkey in [ASYM_RSA_EOS, ASYM_RSA_S]: report.append(" RSA value bit count: %s" % body.RSA.bit_length) elif ASYM_DSA == body.alg_pubkey: report.append(" DSA 'r' bit count: %s" % body.DSA_r.bit_length) report.append(" DSA 's' bit count: %s" % body.DSA_s.bit_length) report.append(" hash fragment: %s" % [hex(ord(x)) for x in body.hash_frag]) elif PKT_SYMKEYSESKEY == pkt.tag.type: report.append(" version: %s" % body.version) report.append(" algorithm: %s (%s)" % (body.alg, TXT.alg_symkey_msg(body.alg))) if 's2k' in body.__dict__: report.append(" S2K type: %s" % body.s2k.type) if 'alg_hash' in body.s2k.__dict__: report.append(" S2K hash: %s (%s)" % (body.s2k.alg_hash, TXT.alg_hash_msg(body.s2k.alg_hash))) if 'salt' in body.s2k.__dict__: report.append(" S2K salt: %s" % [hex(ord(x)) for x in body.s2k.salt]) if 'count_code' in body.s2k.__dict__: report.append(" S2K count code: %s" % body.s2k.count_code) if 'count' in body.s2k.__dict__: report.append(" S2K count: %s" % body.s2k.count) elif PKT_ONEPASS == pkt.tag.type: report.append(" version: %s" % body.version) report.append(" signature type: %s (%s)" % (body.type, TXT.sig_msg(body.type))) report.append(" key id: %s" % body.keyid) report.append(" hash: %s (%s)" % (body.alg_hash, TXT.alg_hash_msg(body.alg_hash))) report.append(" key algorithm: %s (%s)" % (body.alg_pubkey, TXT.alg_pubkey_msg(body.alg_pubkey))) report.append(" nested: %s" % body.nest) elif pkt.tag.type in [PKT_PUBLICKEY, PKT_PUBLICSUBKEY, PKT_PRIVATEKEY, PKT_PRIVATESUBKEY]: report.append(" version: %s created: %s" % (body.version, body.created)) report.append(" algorithm: %s (%s)" % (body.alg, TXT.alg_pubkey_msg(body.alg))) report.append(" fingerprint: %s ID: %s" % (body.fingerprint, body.id)) if body.alg in [ASYM_RSA_EOS, ASYM_RSA_S]: report.append(" RSA 'n' bit count: %s" % body.RSA_n.bit_length) report.append(" RSA 'n' value: %s" % body.RSA_n.value) report.append(" RSA 'e' bit count: %s" % body.RSA_e.bit_length) report.append(" RSA 'e' value: %s" % body.RSA_e.value) elif ASYM_DSA == body.alg: report.append(" DSA 'p' bit count: %s" % body.DSA_p.bit_length) report.append(" DSA 'p' value: %s" % body.DSA_p.value) report.append(" DSA 'q' bit count: %s" % body.DSA_q.bit_length) report.append(" DSA 'q' value: %s" % body.DSA_q.value) report.append(" DSA 'g' bit count: %s" % body.DSA_g.bit_length) report.append(" DSA 'g' value: %s" % body.DSA_g.value) report.append(" DSA 'y' bit count: %s" % body.DSA_y.bit_length) report.append(" DSA 'y' value: %s" % body.DSA_y.value) elif body.alg in [ASYM_ELGAMAL_EOS, ASYM_ELGAMAL_E]: report.append(" ElGamal 'p' bit count: %s" % body.ELGAMAL_p.bit_length) report.append(" ElGamal 'p' value: %s" % body.ELGAMAL_p.value) report.append(" ElGamal 'g' bit count: %s" % body.ELGAMAL_g.bit_length) report.append(" ElGamal 'g' value: %s" % body.ELGAMAL_g.value) report.append(" ElGamal 'y' bit count: %s" % body.ELGAMAL_y.bit_length) report.append(" ElGamal 'y' value: %s" % body.ELGAMAL_y.value) if hasattr(body, 'expires'): report.append(" expires: %s" % body.expires) if hasattr(body, 'expires'): report.append(" expires: %s" % body.expires) if pkt.tag.type in [PKT_PRIVATEKEY, PKT_PRIVATESUBKEY]: if hasattr(body, 'alg_sym'): report.append(" encrypted with algorithm: %s %s" % (body.alg_sym, TXT.alg_symkey_msg(body.alg_sym))) if hasattr(body, 's2k_usg'): report.append(" S2K usage: %s" % body.s2k_usg) if hasattr(body, 'iv'): report.append(" IV: %s" % [hex(ord(x)) for x in body.iv]) if hasattr(body, 's2k'): report.append(" S2K type: %s" % body.s2k.type) if hasattr(body.s2k, 'alg_hash'): report.append(" S2K hash: %s (%s)" % (body.s2k.alg_hash, TXT.alg_hash_msg(body.s2k.alg_hash))) if hasattr(body.s2k, 'salt'): report.append(" S2K salt: %s" % ''.join(['\\x%s' % hex(ord(c))[2:].zfill(2) for c in body.s2k.salt])) if hasattr(body.s2k, 'count_code'): report.append(" S2K count code: %s" % body.s2k.count_code) if hasattr(body.s2k, 'count'): report.append(" S2K count: %s" % body.s2k.count) if hasattr(body, '_enc_d'): report.append(" encrypted data: %s octets" % len(body._enc_d)) #report.append(" encrypted data: %s" % [hex(ord(x)) for x in body._enc_d]) report.append(" encrypted data: %s" % ''.join(['\\x%s' % hex(ord(c))[2:].zfill(2) for c in body._enc_d])) else: if body.alg in [ASYM_RSA_EOS, ASYM_RSA_S]: report.append(" Secret RSA 'd' bit count: %s" % body.RSA_d.bit_length) report.append(" Secret RSA 'd' value: %s" % body.RSA_d.value) report.append(" Secret RSA 'p' bit count: %s" % body.RSA_p.bit_length) report.append(" Secret RSA 'p' value: %s" % body.RSA_p.value) report.append(" Secret RSA 'q' bit count: %s" % body.RSA_q.bit_length) report.append(" Secret RSA 'q' value: %s" % body.RSA_q.value) report.append(" Secret RSA 'u' bit count: %s" % body.RSA_u.bit_length) report.append(" Secret RSA 'u' value: %s" % body.RSA_u.value) elif ASYM_DSA == body.alg: report.append(" Secret DSA 'x' bit count: %s" % body.DSA_x.bit_length) report.append(" Secret DSA 'x' value: %s" % body.DSA_x.value) elif body.alg in [ASYM_ELGAMAL_EOS, ASYM_ELGAMAL_E]: report.append(" Secret ElGamal 'x' bit count: %s" % body.ELGAMAL_x.bit_length) report.append(" Secret ElGamal 'x' value: %s" % body.ELGAMAL_x.value) if hasattr(body, 'chksum') and body.chksum: # for chksum == None?? report.append(" checksum: %s" % [hex(ord(x)) for x in body.chksum]) elif PKT_COMPRESSED == pkt.tag.type: report.append(" compression type %s (%s)" % (pkt.body.alg, TXT.alg_comp_msg(pkt.body.alg))) elif PKT_SYMENCDATA == pkt.tag.type: report.append(" encrypted data: %s octets" % len(body.data)) elif PKT_MARKER == pkt.tag.type: report.append(" left a mark: %s" % pkt.body.value) elif PKT_LITERAL == pkt.tag.type: report.append(" format: %s" % pkt.body.format) report.append(" modified: %s" % pkt.body.modified) report.append(" filename: %s" % pkt.body.filename) report.append(" data length: %s" % len(pkt.body.data)) elif PKT_TRUST == pkt.tag.type: pass elif PKT_USERID == pkt.tag.type: report.append(" ID: %s" % body.value) elif PKT_USERATTR == pkt.tag.type: pass elif PKT_SYMENCINTDATA == pkt.tag.type: report.append(" version: %s" % body.version) # suspect exception report.append(" encrypted data: %s octets" % len(body.data)) # suspect exception elif PKT_MODDETECT == pkt.tag.type: # will this ever be shown? report.append(" detection hash: %s" % [hex(ord(x)) for x in body.hash]) # suspect exception else: pass return linesep.join(report)