1
# This program is free software; you can redistribute it and/or modify
 
 
2
# it under the terms of the GNU General Public License as published by
 
 
3
# the Free Software Foundation; either version 2 of the License, or
 
 
4
# (at your option) any later version.
 
 
6
# This program is distributed in the hope that it will be useful,
 
 
7
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 
8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 
9
# GNU General Public License for more details.
 
 
11
# You should have received a copy of the GNU General Public License
 
 
12
# along with this program; if not, write to the Free Software
 
 
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
15
__copyright__ = 'Copyright (C) 2008 Daniel Schierbeck'
 
 
16
__author__ = 'Daniel Schierbeck <daniel.schierbeck@gmail.com>'
 
 
20
BUS_NAME = 'org.gnome.seahorse'
 
 
22
CRYPTO_INTERFACE = 'org.gnome.seahorse.CryptoService'
 
 
23
CRYPTO_PATH = '/org/gnome/seahorse/crypto'
 
 
25
OPENPGP_INTERFACE = 'org.gnome.seahorse.Keys'
 
 
26
OPENPGP_PATH = '/org/gnome/seahorse/keys/openpgp'
 
 
28
KEY_TYPE_OPENPGP = 'openpgp'
 
 
31
bus = dbus.SessionBus()
 
 
33
if hasattr(bus, 'list_activatable_names'):
 
 
34
    bus_names = bus.list_activatable_names()
 
 
36
    bus_object = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
 
 
37
    bus_names = bus_object.ListNames(dbus_interface='org.freedesktop.DBus')
 
 
39
if BUS_NAME not in bus_names:
 
 
42
crypto = dbus.Interface(bus.get_object(BUS_NAME, CRYPTO_PATH), 
 
 
44
openpgp = dbus.Interface(bus.get_object(BUS_NAME, OPENPGP_PATH),
 
 
48
FLAG_CAN_ENCRYPT = 0x0002
 
 
49
FLAG_CAN_SIGN = 0x0004
 
 
52
FLAG_DISABLED = 0x0400
 
 
62
LOCATION_SEARCHING = 20
 
 
68
def verify(crypttext):
 
 
69
    (cleartext, key) = crypto.VerifyText(KEY_TYPE_OPENPGP, 1, crypttext)
 
 
73
            keyset[key] = Key(key)
 
 
79
    def __init__(self, key):
 
 
82
        (keys, unmatched) = openpgp.MatchKeys([self.get_id()], 0x00000010)
 
 
83
        self.available = (key in keys)
 
 
86
            fields = openpgp.GetKeyFields(key, ['fingerprint', 'trust', 'flags', 'display-name', 'location'])
 
 
90
        self.fingerprint = fields.get('fingerprint', 'N/A')
 
 
91
        self.trust = fields.get('trust', TRUST_UNKNOWN)
 
 
92
        self.flags = fields.get('flags', 0)
 
 
93
        self.display_name = fields.get('display-name', '')
 
 
94
        self.location = fields.get('location', LOCATION_MISSING)
 
 
99
    def get_display_name(self):
 
 
100
        return self.display_name
 
 
103
        return self.key.split(':')[1][8:]
 
 
105
    def get_fingerprint(self):
 
 
106
        return self.fingerprint
 
 
111
    def get_location(self):
 
 
114
    def is_available(self):
 
 
115
        return self.available
 
 
117
    def is_trusted(self):
 
 
118
        return self.flags & FLAG_TRUSTED != 0