New release.
[zeroinstall.git] / trust_box.py
blob0842965f93017b83ca6558c57bf93989bcba9b22
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 model = None
24 tree_view = None
26 interface = None
27 sigs = None
28 iface_xml = None
30 def __init__(self, interface, sigs, iface_xml):
31 dialog.Dialog.__init__(self)
32 self.connect('destroy', lambda a: _pop_queue())
34 self.interface = interface
35 self.sigs = sigs
36 self.iface_xml = iface_xml
38 self.set_title('Confirm trust')
40 label = gtk.Label('Please confirm that you trust '
41 'these keys to sign software updates:')
42 label.set_padding(8, 8)
43 self.vbox.pack_start(label, False, True, 0)
45 swin = gtk.ScrolledWindow()
46 self.vbox.pack_start(swin, True, True, 0)
47 swin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
48 swin.set_shadow_type(gtk.SHADOW_IN)
49 swin.set_border_width(8)
51 self.model = gtk.ListStore(str, object)
52 self.tree_view = gtk.TreeView(self.model)
53 self.tree_view.get_selection().set_mode(gtk.SELECTION_NONE)
54 swin.add(self.tree_view)
56 self.tree_view.set_size_request(-1, 100)
58 text = gtk.CellRendererText()
60 for column in [gtk.TreeViewColumn('Key fingerprint', text, text = 0)]:
61 self.tree_view.append_column(column)
63 self.vbox.show_all()
65 self.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
66 self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
67 self.add_button(gtk.STOCK_ADD, gtk.RESPONSE_OK)
68 self.set_default_response(gtk.RESPONSE_OK)
70 def response(box, resp):
71 if resp == gtk.RESPONSE_HELP:
72 trust_help.display()
73 return
74 if resp == gtk.RESPONSE_OK:
75 self.trust_keys()
76 self.destroy()
77 self.connect('response', response)
79 valid_sigs = [s for s in sigs if isinstance(s, gpg.ValidSig)]
80 if not valid_sigs:
81 raise SafeException('No valid signatures found')
83 for sig in sigs:
84 titer = self.model.append()
85 self.model[titer][0] = pretty_fp(fingerprint(sig))
86 self.model[titer][1] = sig
88 self.tree_view.expand_all()
89 self.present()
91 def trust_keys(self):
92 for row in self.model:
93 sig = row[1]
94 trust.trust_db.trust_key(fingerprint(sig))
96 if not iface_cache.update_interface_if_trusted(self.interface, self.sigs,
97 self.iface_xml):
98 raise Exception('Bug: still not trusted!!')
100 _queue = []
101 def _pop_queue():
102 if _queue:
103 a = _queue.pop()
104 a.show()
106 def confirm_trust(interface, sigs, iface_xml):
107 _queue.append(TrustBox(interface, sigs, iface_xml))
108 if len(_queue) == 1:
109 _pop_queue()
111 trust_help = help_box.HelpBox("Trust Help",
112 ('Overview', """
113 When you run a program, it typically has access to all your files and can generally do \
114 anything that you're allowed to do (delete files, send emails, etc). So it's important \
115 to make sure that you don't run anything malicious."""),
117 ('Digital signatures', """
118 Each software author creates a 'key-pair'; a 'public key' and a 'private key'. Without going \
119 into the maths, only something encrypted with the private key will decrypt with the public key.
121 So, when a programmer releases some software, they encrypt it with their private key (which no-one \
122 else has). When you download it, the injector checks that it decrypts using their public key, thus \
123 proving that it came from them and hasn't been tampered with."""),
125 ('Trust', """
126 After the injector has checked that the software hasn't been modified since it was signed with \
127 the private key, you still have the following problems:
129 1. Does the public key you have really belong to the author?
130 2. Even if the software really did come from that person, do you trust them?"""),
132 ('Key fingerprints', """
133 To confirm (1), you should compare the public key you have with the genuine one. To make this \
134 easier, the injector displays a 'fingerprint' for the key. Look in mailing list postings or some \
135 other source to check that the fingerprint is right (a different key will have a different \
136 fingerprint).
138 You're trying to protect against the situation where an attacker breaks into a web site \
139 and puts up malicious software, signed with the attacker's private key, and puts up the \
140 attacker's public key too. If you've downloaded this software before, you \
141 should be suspicious that you're being asked to confirm another key!"""),
143 ('Reputation', """
144 In general, most problems seem to come from malicous and otherwise-unknown people \
145 replacing software with modified versions, or creating new programs intended only to \
146 cause damage. So, check your programs are signed by a key with a good reputation!"""))