/usr/lib/python2.7/dist-packages/otrapps/gnupg.py is in keysync 0.2.1.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import pgpdump
class GnuPGProperties():
path = os.path.expanduser('~/.gnupg')
secring = 'secring.gpg'
pubring = 'pubring.gpg'
files = (secring, pubring)
@staticmethod
def parse(settingsdir=None):
if settingsdir == None:
settingsdir = GnuPGProperties.path
secring_file = os.path.join(settingsdir, GnuPGProperties.secring)
if not os.path.exists(secring_file):
return dict()
rawdata = GnuPGProperties.load_data(secring_file)
try:
data = pgpdump.BinaryData(rawdata)
except pgpdump.utils.PgpdumpException, e:
print("gnupg: %s" % (e))
return dict()
packets = list(data.packets())
names = []
keydict = dict()
for packet in packets:
values = dict()
if isinstance(packet, pgpdump.packet.SecretSubkeyPacket):
if packet.pub_algorithm_type == "dsa":
values['p'] = packet.prime
values['q'] = packet.group_order
values['g'] = packet.group_gen
values['y'] = packet.key_value
values['x'] = packet.exponent_x
# the data comes directly from secret key, mark verified
values['verification'] = 'verified'
values['fingerprint'] = packet.fingerprint
elif isinstance(packet, pgpdump.packet.UserIDPacket):
names.append(str(packet.user_email)) # everything is str, not unicode
if 'fingerprint' in values.keys():
for name in names:
keydict[name] = values
keydict[name]['name'] = name
keydict[name]['protocol'] = 'prpl-jabber' # assume XMPP for now
return keydict
@staticmethod
def write(keys, savedir):
print('Writing GnuPG output files is not yet supported!')
@staticmethod
def load_data(filename):
with open(filename, 'rb') as fileobj:
data = fileobj.read()
return data
if __name__ == '__main__':
import pprint
print('GnuPG stores its files in ' + GnuPGProperties.path)
if len(sys.argv) == 2:
settingsdir = sys.argv[1]
else:
settingsdir = '../tests/gnupg'
l = GnuPGProperties.parse(settingsdir)
pprint.pprint(l)
|