/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

  • Committer: Jasper Groenewegen
  • Date: 2008-07-27 12:01:40 UTC
  • mfrom: (576.3.2 improve-merge)
  • mto: This revision was merged to the branch mainline in revision 579.
  • Revision ID: colbrac@xs4all.nl-20080727120140-1agdlzkc9fumjk5f
Merge merge dialog improvements

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
try:
 
32
    bus = dbus.SessionBus()
 
33
    crypto = dbus.Interface(bus.get_object(BUS_NAME, CRYPTO_PATH), 
 
34
                            CRYPTO_INTERFACE)
 
35
    openpgp = dbus.Interface(bus.get_object(BUS_NAME, OPENPGP_PATH),
 
36
                             OPENPGP_INTERFACE)
 
37
except dbus.exceptions.DBusException, e:
 
38
    get_name = getattr(e, 'get_dbus_name', None)
 
39
    if get_name is not None:
 
40
        name = get_name()
 
41
    else:
 
42
        name = getattr(e, '_dbus_error_name', None)
 
43
    # DBus sometimes fails like this, just treat it as if seahorse is not
 
44
    # available rather than crashing.
 
45
    if name in ("org.freedesktop.DBus.Error.Spawn.ExecFailed", 
 
46
                "org.freedesktop.DBus.Error.ServiceUnknown"):
 
47
        raise ImportError
 
48
    else:
 
49
        raise
 
50
 
 
51
FLAG_VALID = 0x0001
 
52
FLAG_CAN_ENCRYPT = 0x0002
 
53
FLAG_CAN_SIGN = 0x0004
 
54
FLAG_EXPIRED = 0x0100
 
55
FLAG_REVOKED = 0x0200
 
56
FLAG_DISABLED = 0x0400
 
57
FLAG_TRUSTED = 0x1000
 
58
 
 
59
TRUST_NEVER = -1
 
60
TRUST_UNKNOWN = 0
 
61
TRUST_MARGINAL = 1
 
62
TRUST_FULL = 5
 
63
TRUST_ULTIMATE = 10
 
64
 
 
65
LOCATION_MISSING = 10
 
66
LOCATION_SEARCHING = 20
 
67
LOCATION_REMOTE = 50
 
68
LOCATION_LOCAL = 100
 
69
 
 
70
keyset = dict()
 
71
 
 
72
def verify(crypttext):
 
73
    (cleartext, key) = crypto.VerifyText(KEY_TYPE_OPENPGP, 1, crypttext)
 
74
 
 
75
    if key != "":
 
76
        if key not in keyset:
 
77
            keyset[key] = Key(key)
 
78
 
 
79
        return (cleartext, keyset[key])
 
80
 
 
81
    return (cleartext, None)
 
82
 
 
83
 
 
84
class Key:
 
85
 
 
86
    def __init__(self, key):
 
87
        self.key = key
 
88
 
 
89
        (keys, unmatched) = openpgp.MatchKeys([self.get_id()], 0x00000010)
 
90
        self.available = (key in keys)
 
91
 
 
92
        if self.available:
 
93
            fields = openpgp.GetKeyFields(key, ['fingerprint', 'trust', 'flags', 'display-name', 'location'])
 
94
        else:
 
95
            fields = dict()
 
96
 
 
97
        self.fingerprint = fields.get('fingerprint', 'N/A')
 
98
        self.trust = fields.get('trust', TRUST_UNKNOWN)
 
99
        self.flags = fields.get('flags', 0)
 
100
        self.display_name = fields.get('display-name', '')
 
101
        self.location = fields.get('location', LOCATION_MISSING)
 
102
    
 
103
    def get_flags(self):
 
104
        return self.flags
 
105
 
 
106
    def get_display_name(self):
 
107
        return self.display_name
 
108
 
 
109
    def get_id(self):
 
110
        return self.key.split(':')[1][8:]
 
111
 
 
112
    def get_fingerprint(self):
 
113
        return self.fingerprint
 
114
 
 
115
    def get_trust(self):
 
116
        return self.trust
 
117
 
 
118
    def get_location(self):
 
119
        return self.location
 
120
 
 
121
    def is_available(self):
 
122
        return self.available
 
123
 
 
124
    def is_trusted(self):
 
125
        return self.flags & FLAG_TRUSTED != 0