Updates for injector 0.17:
[zeroinstall.git] / trust_box.py
blob1ceabd3e5e64c28c921091685fc5fcb9323544c6
1 import gtk
2 from zeroinstall.injector.model import SafeException
3 from zeroinstall.injector import gpg, trust
4 from zeroinstall.injector.iface_cache import iface_cache
6 import gui
7 import dialog, help_box
9 def fingerprint(sig):
10 try:
11 return sig.fingerprint
12 except:
13 # Work around a bug in injector-0.9
14 return sig.status[sig.FINGERPRINT]
16 def pretty_fp(fp):
17 s = fp[0:4]
18 for x in range(4, len(fp), 4):
19 s += ' ' + fp[x:x + 4]
20 return s
22 class TrustBox(dialog.Dialog):
23 interface = None
24 sigs = None
25 iface_xml = None
27 def __init__(self, interface, sigs, iface_xml):
28 dialog.Dialog.__init__(self)
29 self.connect('destroy', lambda a: _pop_queue())
31 def left(text):
32 label = gtk.Label(text)
33 label.set_alignment(0, 0.5)
34 label.set_selectable(True)
35 return label
37 self.interface = interface
38 self.sigs = sigs
39 self.iface_xml = iface_xml
41 self.set_title('Confirm trust')
43 vbox = gtk.VBox(False, 4)
44 vbox.set_border_width(4)
45 self.vbox.pack_start(vbox, True, True, 0)
47 label = left('Checking: ' + interface.uri + '\n\n'
48 'Please confirm that you trust '
49 'these keys to sign software updates:')
50 vbox.pack_start(label, False, True, 0)
52 notebook = gtk.Notebook()
53 vbox.pack_start(notebook, True, True, 0)
55 self.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
56 self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
57 self.add_button(gtk.STOCK_ADD, gtk.RESPONSE_OK)
58 self.set_default_response(gtk.RESPONSE_OK)
60 valid_sigs = [s for s in sigs if isinstance(s, gpg.ValidSig)]
61 if not valid_sigs:
62 raise SafeException('No valid signatures found')
64 trust = {} # Sig -> CheckButton
65 def ok_sensitive():
66 trust_any = False
67 for toggle in trust.values():
68 if toggle.get_active():
69 trust_any = True
70 break
71 self.set_response_sensitive(gtk.RESPONSE_OK, trust_any)
72 for sig in sigs:
73 if hasattr(sig, 'get_details'):
74 name = '<unknown>'
75 details = sig.get_details()
76 for item in details:
77 if item[0] in ('pub', 'uid'):
78 name = item[9]
79 break
80 else:
81 name = None
82 page = gtk.VBox(False, 4)
83 page.set_border_width(8)
84 page.pack_start(left('Fingerprint: ' + pretty_fp(fingerprint(sig))), False, True, 0)
85 if name is not None:
86 page.pack_start(left('Claimed identity: ' + name), False, True, 0)
88 frame = gtk.Frame('Unreliable hints database says')
89 frame.set_border_width(4)
90 hint = left(hints.get(fingerprint(sig), 'Warning: Nothing known about this key!'))
91 hint.set_line_wrap(True)
92 hint.set_padding(4, 4)
93 frame.add(hint)
94 page.pack_start(frame, True, True, 0)
96 trust[sig] = gtk.CheckButton('Trust this key')
97 page.pack_start(trust[sig], False, True, 0)
98 trust[sig].connect('toggled', lambda t: ok_sensitive())
100 notebook.append_page(page, gtk.Label(name or 'Signature'))
102 ok_sensitive()
103 self.vbox.show_all()
105 def response(box, resp):
106 if resp == gtk.RESPONSE_HELP:
107 trust_help.display()
108 return
109 if resp == gtk.RESPONSE_OK:
110 self.trust_keys([sig for sig in trust if trust[sig].get_active()])
111 self.destroy()
112 self.connect('response', response)
114 self.present()
116 def trust_keys(self, sigs):
117 try:
118 for sig in sigs:
119 trust.trust_db.trust_key(fingerprint(sig))
121 if not iface_cache.update_interface_if_trusted(self.interface, self.sigs,
122 self.iface_xml):
123 raise Exception('Bug: still not trusted!!')
124 except Exception, ex:
125 dialog.alert(None, ex)
127 _queue = []
128 def _pop_queue():
129 if _queue:
130 a = _queue.pop()
131 a.show()
133 def confirm_trust(interface, sigs, iface_xml):
134 _queue.append(TrustBox(interface, sigs, iface_xml))
135 if len(_queue) == 1:
136 _pop_queue()
138 trust_help = help_box.HelpBox("Trust Help",
139 ('Overview', """
140 When you run a program, it typically has access to all your files and can generally do \
141 anything that you're allowed to do (delete files, send emails, etc). So it's important \
142 to make sure that you don't run anything malicious."""),
144 ('Digital signatures', """
145 Each software author creates a 'key-pair'; a 'public key' and a 'private key'. Without going \
146 into the maths, only something encrypted with the private key will decrypt with the public key.
148 So, when a programmer releases some software, they encrypt it with their private key (which no-one \
149 else has). When you download it, the injector checks that it decrypts using their public key, thus \
150 proving that it came from them and hasn't been tampered with."""),
152 ('Trust', """
153 After the injector has checked that the software hasn't been modified since it was signed with \
154 the private key, you still have the following problems:
156 1. Does the public key you have really belong to the author?
157 2. Even if the software really did come from that person, do you trust them?"""),
159 ('Key fingerprints', """
160 To confirm (1), you should compare the public key you have with the genuine one. To make this \
161 easier, the injector displays a 'fingerprint' for the key. Look in mailing list postings or some \
162 other source to check that the fingerprint is right (a different key will have a different \
163 fingerprint).
165 You're trying to protect against the situation where an attacker breaks into a web site \
166 and puts up malicious software, signed with the attacker's private key, and puts up the \
167 attacker's public key too. If you've downloaded this software before, you \
168 should be suspicious that you're being asked to confirm another key!"""),
170 ('Reputation', """
171 In general, most problems seem to come from malicous and otherwise-unknown people \
172 replacing software with modified versions, or creating new programs intended only to \
173 cause damage. So, check your programs are signed by a key with a good reputation!"""))
175 hints = {
176 '1DC295D11A3F910DA49D3839AA1A7812B40B0B6E' :
177 'Ken Hayber has been writing ROX applications since 2003. This key '
178 'was announced on the rox-users list on 5 Jun 2005.',
180 '4338D5420E0BAEB6B2E73530B66A4F24AB8B4B65' :
181 'Thomas Formella is experimenting with packaging programs for 0launch. This key '
182 'was announced on 11 Sep 2005 on the zero-install mailing list.',
184 '92429807C9853C0744A68B9AAE07828059A53CC1' :
185 'Thomas Leonard created Zero Install and ROX. This key is normally trusted by default.',
187 '0597A2AFB6B372ACB97AC6E433B938C2E9D8826D' :
188 'Stephen Watson is a project admin for the ROX desktop, and has been involved with the '
189 'project since 2000. This key has been used for signing software since the 23 Jul 2005 '
190 'announcement on the zero-install mailing list.',
192 'F0A0CA2A8D8FCC123F5EC04CD8D59DC384AE988E' :
193 'Piero Ottuzzi is experimenting with packaging programs for 0launch. This key has been '
194 'known since a 16 Mar 2005 post to the zero-install mailing list. It was first used to '
195 'sign software in an announcement posted on 9 Aug 2005.',