/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to seahorse.py

Merged Seahorse integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
5
 
 
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.
 
10
 
 
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
 
14
 
 
15
__copyright__ = 'Copyright (C) 2008 Daniel Schierbeck'
 
16
__author__ = 'Daniel Schierbeck <daniel.schierbeck@gmail.com>'
 
17
 
 
18
import dbus
 
19
 
 
20
BUS_NAME = 'org.gnome.seahorse'
 
21
 
 
22
CRYPTO_INTERFACE = 'org.gnome.seahorse.CryptoService'
 
23
CRYPTO_PATH = '/org/gnome/seahorse/crypto'
 
24
 
 
25
OPENPGP_INTERFACE = 'org.gnome.seahorse.Keys'
 
26
OPENPGP_PATH = '/org/gnome/seahorse/keys/openpgp'
 
27
 
 
28
KEY_TYPE_OPENPGP = 'openpgp'
 
29
KEY_TYPE_SSH = 'ssh'
 
30
 
 
31
bus = dbus.SessionBus()
 
32
 
 
33
if not bus.name_has_owner(BUS_NAME):
 
34
    raise ImportError
 
35
 
 
36
crypto = dbus.Interface(bus.get_object(BUS_NAME, CRYPTO_PATH), 
 
37
                        CRYPTO_INTERFACE)
 
38
openpgp = dbus.Interface(bus.get_object(BUS_NAME, OPENPGP_PATH),
 
39
                         OPENPGP_INTERFACE)
 
40
 
 
41
FLAG_VALID = 0x0001
 
42
FLAG_CAN_ENCRYPT = 0x0002
 
43
FLAG_CAN_SIGN = 0x0004
 
44
FLAG_EXPIRED = 0x0100
 
45
FLAG_REVOKED = 0x0200
 
46
FLAG_DISABLED = 0x0400
 
47
FLAG_TRUSTED = 0x1000
 
48
 
 
49
TRUST_NEVER = -1
 
50
TRUST_UNKNOWN = 0
 
51
TRUST_MARGINAL = 1
 
52
TRUST_FULL = 5
 
53
TRUST_ULTIMATE = 10
 
54
 
 
55
LOCATION_MISSING = 10
 
56
LOCATION_SEARCHING = 20
 
57
LOCATION_REMOTE = 50
 
58
LOCATION_LOCAL = 100
 
59
 
 
60
def discover(*key_ids):
 
61
    return openpgp.DiscoverKeys(key_ids, 0)
 
62
 
 
63
def verify(crypttext):
 
64
    (cleartext, key) = crypto.VerifyText(KEY_TYPE_OPENPGP, 1, crypttext)
 
65
 
 
66
    return Key(key)
 
67
 
 
68
class Key:
 
69
 
 
70
    def __init__(self, key):
 
71
        self.key = key
 
72
        self.fingerprint = None
 
73
        self.trust = None
 
74
        self.flags = None
 
75
        self.display_name = None
 
76
        self.location = None
 
77
 
 
78
        discover(key)
 
79
 
 
80
    def get_field(self, field, default=None):
 
81
        (valid, value) = openpgp.GetKeyField(self.key, field)
 
82
 
 
83
        if valid:
 
84
            return value
 
85
        else:
 
86
            return default
 
87
    
 
88
    def get_flags(self):
 
89
        if self.flags is None:
 
90
            self.flags = self.get_field('flags', 0)
 
91
 
 
92
        return self.flags
 
93
 
 
94
    def get_display_name(self):
 
95
        if self.display_name is None:
 
96
            self.display_name = self.get_field('display-name')
 
97
 
 
98
        return self.display_name
 
99
 
 
100
    def get_id(self):
 
101
        return self.key.split(':')[1][8:]
 
102
 
 
103
    def get_fingerprint(self):
 
104
        if self.fingerprint is None:
 
105
            self.fingerprint = self.get_field('fingerprint')
 
106
 
 
107
        return self.fingerprint
 
108
 
 
109
    def get_trust(self):
 
110
        if self.trust is None:
 
111
            self.trust = self.get_field('trust', TRUST_UNKNOWN)
 
112
 
 
113
        return self.trust
 
114
 
 
115
    def get_location(self):
 
116
        if self.location is None:
 
117
            self.location = self.get_field('location', LOCATION_MISSING)
 
118
 
 
119
        return self.location
 
120
 
 
121
    def is_available(self):
 
122
        return self.key != ""
 
123
 
 
124
    def is_trusted(self):
 
125
        return self.get_flags() & FLAG_TRUSTED