/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to brzlib/gpg.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""GPG signing and checking logic."""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
import os
 
23
import sys
 
24
from StringIO import StringIO
21
25
 
22
 
from breezy.lazy_import import lazy_import
 
26
from brzlib.lazy_import import lazy_import
23
27
lazy_import(globals(), """
24
 
from breezy import (
 
28
import errno
 
29
import subprocess
 
30
 
 
31
from brzlib import (
25
32
    config,
 
33
    errors,
26
34
    trace,
27
35
    ui,
28
36
    )
29
 
from breezy.i18n import (
30
 
    gettext,
 
37
from brzlib.i18n import (
 
38
    gettext, 
31
39
    ngettext,
32
40
    )
33
41
""")
34
42
 
35
 
from . import (
36
 
    errors,
 
43
from brzlib.symbol_versioning import (
 
44
    deprecated_in,
 
45
    deprecated_method,
37
46
    )
38
47
 
39
 
# verification results
 
48
#verification results
40
49
SIGNATURE_VALID = 0
41
50
SIGNATURE_KEY_MISSING = 1
42
51
SIGNATURE_NOT_VALID = 2
43
52
SIGNATURE_NOT_SIGNED = 3
44
53
SIGNATURE_EXPIRED = 4
45
54
 
46
 
MODE_NORMAL = 0
47
 
MODE_DETACH = 1
48
 
MODE_CLEAR = 2
49
 
 
50
 
 
51
 
class GpgNotInstalled(errors.DependencyNotPresent):
52
 
 
53
 
    _fmt = ('python-gpg is not installed, it is needed to create or '
54
 
            'verify signatures. %(error)s')
55
 
 
56
 
    def __init__(self, error):
57
 
        errors.DependencyNotPresent.__init__(self, 'gpg', error)
58
 
 
59
 
 
60
 
class SigningFailed(errors.BzrError):
61
 
 
62
 
    _fmt = 'Failed to GPG sign data: "%(error)s"'
63
 
 
64
 
    def __init__(self, error):
65
 
        errors.BzrError.__init__(self, error=error)
66
 
 
67
 
 
68
 
class SignatureVerificationFailed(errors.BzrError):
69
 
 
70
 
    _fmt = 'Failed to verify GPG signature data with error "%(error)s"'
71
 
 
72
 
    def __init__(self, error):
73
 
        errors.BzrError.__init__(self, error=error)
74
 
 
75
55
 
76
56
def bulk_verify_signatures(repository, revids, strategy,
77
 
                           process_events_callback=None):
 
57
        process_events_callback=None):
78
58
    """Do verifications on a set of revisions
79
59
 
80
60
    :param repository: repository object
95
75
    result = []
96
76
    all_verifiable = True
97
77
    total = len(revids)
98
 
    with ui.ui_factory.nested_progress_bar() as pb:
 
78
    pb = ui.ui_factory.nested_progress_bar()
 
79
    try:
99
80
        for i, (rev_id, verification_result, uid) in enumerate(
100
81
                repository.verify_revision_signatures(
101
82
                    revids, strategy)):
106
87
                all_verifiable = False
107
88
            if process_events_callback is not None:
108
89
                process_events_callback()
 
90
    finally:
 
91
        pb.finished()
109
92
    return (count, result, all_verifiable)
110
93
 
111
94
 
119
102
    def __init__(self, ignored):
120
103
        """Real strategies take a configuration."""
121
104
 
122
 
    def sign(self, content, mode):
123
 
        raise SigningFailed('Signing is disabled.')
 
105
    def sign(self, content):
 
106
        raise errors.SigningFailed('Signing is disabled.')
124
107
 
125
 
    def verify(self, signed_data, signature=None):
126
 
        raise SignatureVerificationFailed('Signature verification is \
 
108
    def verify(self, content, testament):
 
109
        raise errors.SignatureVerificationFailed('Signature verification is \
127
110
disabled.')
128
111
 
129
112
    def set_acceptable_keys(self, command_line_input):
142
125
    def __init__(self, ignored):
143
126
        """Real strategies take a configuration."""
144
127
 
145
 
    def sign(self, content, mode):
146
 
        return (b"-----BEGIN PSEUDO-SIGNED CONTENT-----\n" + content
147
 
                + b"-----END PSEUDO-SIGNED CONTENT-----\n")
 
128
    def sign(self, content):
 
129
        return ("-----BEGIN PSEUDO-SIGNED CONTENT-----\n" + content +
 
130
                "-----END PSEUDO-SIGNED CONTENT-----\n")
148
131
 
149
 
    def verify(self, signed_data, signature=None):
150
 
        plain_text = signed_data.replace(
151
 
            b"-----BEGIN PSEUDO-SIGNED CONTENT-----\n", b"")
152
 
        plain_text = plain_text.replace(
153
 
            b"-----END PSEUDO-SIGNED CONTENT-----\n", b"")
154
 
        return SIGNATURE_VALID, None, plain_text
 
132
    def verify(self, content, testament):
 
133
        return SIGNATURE_VALID, None
155
134
 
156
135
    def set_acceptable_keys(self, command_line_input):
157
136
        if command_line_input is not None:
163
142
                else:
164
143
                    self.acceptable_keys.append(pattern)
165
144
 
 
145
    @deprecated_method(deprecated_in((2, 6, 0)))
 
146
    def do_verifications(self, revisions, repository):
 
147
        return bulk_verify_signatures(repository, revisions, self)
 
148
 
 
149
    @deprecated_method(deprecated_in((2, 6, 0)))
 
150
    def valid_commits_message(self, count):
 
151
        return valid_commits_message(count)
 
152
 
 
153
    @deprecated_method(deprecated_in((2, 6, 0)))
 
154
    def unknown_key_message(self, count):
 
155
        return unknown_key_message(count)
 
156
 
 
157
    @deprecated_method(deprecated_in((2, 6, 0)))
 
158
    def commit_not_valid_message(self, count):
 
159
        return commit_not_valid_message(count)
 
160
 
 
161
    @deprecated_method(deprecated_in((2, 6, 0)))
 
162
    def commit_not_signed_message(self, count):
 
163
        return commit_not_signed_message(count)
 
164
 
 
165
    @deprecated_method(deprecated_in((2, 6, 0)))
 
166
    def expired_commit_message(self, count):
 
167
        return expired_commit_message(count)
 
168
 
166
169
 
167
170
def _set_gpg_tty():
168
171
    tty = os.environ.get('TTY')
172
175
    else:
173
176
        # This is not quite worthy of a warning, because some people
174
177
        # don't need GPG_TTY to be set. But it is worthy of a big mark
175
 
        # in brz.log, so that people can debug it if it happens to them
 
178
        # in ~/.bzr.log, so that people can debug it if it happens to them
176
179
        trace.mutter('** Env var TTY empty, cannot set GPG_TTY.'
177
180
                     '  Is TTY exported?')
178
181
 
185
188
    def __init__(self, config_stack):
186
189
        self._config_stack = config_stack
187
190
        try:
188
 
            import gpg
189
 
            self.context = gpg.Context()
190
 
            self.context.armor = True
191
 
            self.context.signers = self._get_signing_keys()
192
 
        except ImportError:
193
 
            pass  # can't use verify()
194
 
 
195
 
    def _get_signing_keys(self):
196
 
        import gpg
197
 
        keyname = self._config_stack.get('gpg_signing_key')
198
 
        if keyname == 'default':
199
 
            # Leave things to gpg
200
 
            return []
201
 
 
202
 
        if keyname:
203
 
            try:
204
 
                return [self.context.get_key(keyname)]
205
 
            except gpg.errors.KeyNotFound:
206
 
                pass
207
 
 
208
 
        if keyname is None:
209
 
            # not setting gpg_signing_key at all means we should
210
 
            # use the user email address
211
 
            keyname = config.extract_email_address(
212
 
                self._config_stack.get('email'))
213
 
        if keyname == 'default':
214
 
            return []
215
 
        possible_keys = self.context.keylist(keyname, secret=True)
216
 
        try:
217
 
            return [next(possible_keys)]
218
 
        except StopIteration:
219
 
            return []
 
191
            import gpgme
 
192
            self.context = gpgme.Context()
 
193
        except ImportError, error:
 
194
            pass # can't use verify()
220
195
 
221
196
    @staticmethod
222
197
    def verify_signatures_available():
226
201
        :return: boolean if this strategy can verify signatures
227
202
        """
228
203
        try:
229
 
            import gpg  # noqa: F401
 
204
            import gpgme
230
205
            return True
231
 
        except ImportError:
 
206
        except ImportError, error:
232
207
            return False
233
208
 
234
 
    def sign(self, content, mode):
235
 
        try:
236
 
            import gpg
237
 
        except ImportError as error:
238
 
            raise GpgNotInstalled(
239
 
                'Set create_signatures=no to disable creating signatures.')
 
209
    def _command_line(self):
 
210
        key = self._config_stack.get('gpg_signing_key')
 
211
        if key is None or key == 'default':
 
212
            # 'default' or not setting gpg_signing_key at all means we should
 
213
            # use the user email address
 
214
            key = config.extract_email_address(self._config_stack.get('email'))
 
215
        return [self._config_stack.get('gpg_signing_command'), '--clearsign',
 
216
                '-u', key]
240
217
 
241
 
        if isinstance(content, str):
 
218
    def sign(self, content):
 
219
        if isinstance(content, unicode):
242
220
            raise errors.BzrBadParameterUnicode('content')
 
221
        ui.ui_factory.clear_term()
243
222
 
244
 
        plain_text = gpg.Data(content)
 
223
        preexec_fn = _set_gpg_tty
 
224
        if sys.platform == 'win32':
 
225
            # Win32 doesn't support preexec_fn, but wouldn't support TTY anyway.
 
226
            preexec_fn = None
245
227
        try:
246
 
            output, result = self.context.sign(
247
 
                plain_text, mode={
248
 
                    MODE_DETACH: gpg.constants.sig.mode.DETACH,
249
 
                    MODE_CLEAR: gpg.constants.sig.mode.CLEAR,
250
 
                    MODE_NORMAL: gpg.constants.sig.mode.NORMAL,
251
 
                    }[mode])
252
 
        except gpg.errors.GPGMEError as error:
253
 
            raise SigningFailed(str(error))
254
 
 
255
 
        return output
256
 
 
257
 
    def verify(self, signed_data, signature=None):
 
228
            process = subprocess.Popen(self._command_line(),
 
229
                                       stdin=subprocess.PIPE,
 
230
                                       stdout=subprocess.PIPE,
 
231
                                       preexec_fn=preexec_fn)
 
232
            try:
 
233
                result = process.communicate(content)[0]
 
234
                if process.returncode is None:
 
235
                    process.wait()
 
236
                if process.returncode != 0:
 
237
                    raise errors.SigningFailed(self._command_line())
 
238
                return result
 
239
            except OSError, e:
 
240
                if e.errno == errno.EPIPE:
 
241
                    raise errors.SigningFailed(self._command_line())
 
242
                else:
 
243
                    raise
 
244
        except ValueError:
 
245
            # bad subprocess parameters, should never happen.
 
246
            raise
 
247
        except OSError, e:
 
248
            if e.errno == errno.ENOENT:
 
249
                # gpg is not installed
 
250
                raise errors.SigningFailed(self._command_line())
 
251
            else:
 
252
                raise
 
253
 
 
254
    def verify(self, content, testament):
258
255
        """Check content has a valid signature.
259
256
 
260
 
        :param signed_data; Signed data
261
 
        :param signature: optional signature (if detached)
 
257
        :param content: the commit signature
 
258
        :param testament: the valid testament string for the commit
262
259
 
263
 
        :return: SIGNATURE_VALID or a failed SIGNATURE_ value, key uid if valid, plain text
 
260
        :return: SIGNATURE_VALID or a failed SIGNATURE_ value, key uid if valid
264
261
        """
265
262
        try:
266
 
            import gpg
267
 
        except ImportError as error:
268
 
            raise GpgNotInstalled(
269
 
                'Set check_signatures=ignore to disable verifying signatures.')
 
263
            import gpgme
 
264
        except ImportError, error:
 
265
            raise errors.GpgmeNotInstalled(error)
270
266
 
271
 
        signed_data = gpg.Data(signed_data)
272
 
        if signature:
273
 
            signature = gpg.Data(signature)
 
267
        signature = StringIO(content)
 
268
        plain_output = StringIO()
274
269
        try:
275
 
            plain_output, result = self.context.verify(signed_data, signature)
276
 
        except gpg.errors.BadSignatures as error:
277
 
            fingerprint = error.result.signatures[0].fpr
278
 
            if error.result.signatures[0].summary & gpg.constants.SIGSUM_KEY_EXPIRED:
279
 
                expires = self.context.get_key(
280
 
                    error.result.signatures[0].fpr).subkeys[0].expires
281
 
                if expires > error.result.signatures[0].timestamp:
282
 
                    # The expired key was not expired at time of signing.
283
 
                    # test_verify_expired_but_valid()
284
 
                    return SIGNATURE_EXPIRED, fingerprint[-8:], None
285
 
                else:
286
 
                    # I can't work out how to create a test where the signature
287
 
                    # was expired at the time of signing.
288
 
                    return SIGNATURE_NOT_VALID, None, None
289
 
 
290
 
            # GPG does not know this key.
291
 
            # test_verify_unknown_key()
292
 
            if (error.result.signatures[0].summary &
293
 
                    gpg.constants.SIGSUM_KEY_MISSING):
294
 
                return SIGNATURE_KEY_MISSING, fingerprint[-8:], None
295
 
 
296
 
            return SIGNATURE_NOT_VALID, None, None
297
 
        except gpg.errors.GPGMEError as error:
298
 
            raise SignatureVerificationFailed(error)
 
270
            result = self.context.verify(signature, None, plain_output)
 
271
        except gpgme.GpgmeError,error:
 
272
            raise errors.SignatureVerificationFailed(error[2])
299
273
 
300
274
        # No result if input is invalid.
301
275
        # test_verify_invalid()
302
 
        if len(result.signatures) == 0:
303
 
            return SIGNATURE_NOT_VALID, None, plain_output
304
 
 
 
276
        if len(result) == 0:
 
277
            return SIGNATURE_NOT_VALID, None
305
278
        # User has specified a list of acceptable keys, check our result is in
306
279
        # it.  test_verify_unacceptable_key()
307
 
        fingerprint = result.signatures[0].fpr
 
280
        fingerprint = result[0].fpr
308
281
        if self.acceptable_keys is not None:
309
 
            if fingerprint not in self.acceptable_keys:
310
 
                return SIGNATURE_KEY_MISSING, fingerprint[-8:], plain_output
311
 
        # Yay gpg set the valid bit.
 
282
            if not fingerprint in self.acceptable_keys:
 
283
                return SIGNATURE_KEY_MISSING, fingerprint[-8:]
 
284
        # Check the signature actually matches the testament.
 
285
        # test_verify_bad_testament()
 
286
        if testament != plain_output.getvalue():
 
287
            return SIGNATURE_NOT_VALID, None
 
288
        # Yay gpgme set the valid bit.
312
289
        # Can't write a test for this one as you can't set a key to be
313
 
        # trusted using gpg.
314
 
        if result.signatures[0].summary & gpg.constants.SIGSUM_VALID:
 
290
        # trusted using gpgme.
 
291
        if result[0].summary & gpgme.SIGSUM_VALID:
315
292
            key = self.context.get_key(fingerprint)
316
293
            name = key.uids[0].name
317
 
            if isinstance(name, bytes):
318
 
                name = name.decode('utf-8')
319
294
            email = key.uids[0].email
320
 
            if isinstance(email, bytes):
321
 
                email = email.decode('utf-8')
322
 
            return (SIGNATURE_VALID, name + u" <" + email + u">", plain_output)
 
295
            return SIGNATURE_VALID, name + " <" + email + ">"
323
296
        # Sigsum_red indicates a problem, unfortunatly I have not been able
324
297
        # to write any tests which actually set this.
325
 
        if result.signatures[0].summary & gpg.constants.SIGSUM_RED:
326
 
            return SIGNATURE_NOT_VALID, None, plain_output
 
298
        if result[0].summary & gpgme.SIGSUM_RED:
 
299
            return SIGNATURE_NOT_VALID, None
 
300
        # GPG does not know this key.
 
301
        # test_verify_unknown_key()
 
302
        if result[0].summary & gpgme.SIGSUM_KEY_MISSING:
 
303
            return SIGNATURE_KEY_MISSING, fingerprint[-8:]
327
304
        # Summary isn't set if sig is valid but key is untrusted but if user
328
305
        # has explicity set the key as acceptable we can validate it.
329
 
        if (result.signatures[0].summary == 0 and
330
 
                self.acceptable_keys is not None):
 
306
        if result[0].summary == 0 and self.acceptable_keys is not None:
331
307
            if fingerprint in self.acceptable_keys:
332
308
                # test_verify_untrusted_but_accepted()
333
 
                return SIGNATURE_VALID, None, plain_output
 
309
                return SIGNATURE_VALID, None
334
310
        # test_verify_valid_but_untrusted()
335
 
        if result.signatures[0].summary == 0 and self.acceptable_keys is None:
336
 
            return SIGNATURE_NOT_VALID, None, plain_output
 
311
        if result[0].summary == 0 and self.acceptable_keys is None:
 
312
            return SIGNATURE_NOT_VALID, None
 
313
        if result[0].summary & gpgme.SIGSUM_KEY_EXPIRED:
 
314
            expires = self.context.get_key(result[0].fpr).subkeys[0].expires
 
315
            if expires > result[0].timestamp:
 
316
                # The expired key was not expired at time of signing.
 
317
                # test_verify_expired_but_valid()
 
318
                return SIGNATURE_EXPIRED, fingerprint[-8:]
 
319
            else:
 
320
                # I can't work out how to create a test where the signature
 
321
                # was expired at the time of signing.
 
322
                return SIGNATURE_NOT_VALID, None
 
323
        # A signature from a revoked key gets this.
 
324
        # test_verify_revoked_signature()
 
325
        if ((result[0].summary & gpgme.SIGSUM_SYS_ERROR
 
326
             or result[0].status.strerror == 'Certificate revoked')):
 
327
            return SIGNATURE_NOT_VALID, None
337
328
        # Other error types such as revoked keys should (I think) be caught by
338
329
        # SIGSUM_RED so anything else means something is buggy.
339
 
        raise SignatureVerificationFailed(
 
330
        raise errors.SignatureVerificationFailed(
340
331
            "Unknown GnuPG key verification result")
341
332
 
342
333
    def set_acceptable_keys(self, command_line_input):
350
341
        acceptable_keys_config = self._config_stack.get('acceptable_keys')
351
342
        if acceptable_keys_config is not None:
352
343
            patterns = acceptable_keys_config
353
 
        if command_line_input is not None:  # command line overrides config
 
344
        if command_line_input is not None: # command line overrides config
354
345
            patterns = command_line_input.split(',')
355
346
 
356
347
        if patterns:
364
355
                    trace.mutter("Added acceptable key: " + key.subkeys[0].fpr)
365
356
                if not found_key:
366
357
                    trace.note(gettext(
367
 
                        "No GnuPG key results for pattern: {0}"
368
 
                        ).format(pattern))
 
358
                            "No GnuPG key results for pattern: {0}"
 
359
                                ).format(pattern))
 
360
 
 
361
    @deprecated_method(deprecated_in((2, 6, 0)))
 
362
    def do_verifications(self, revisions, repository,
 
363
                            process_events_callback=None):
 
364
        """do verifications on a set of revisions
 
365
 
 
366
        :param revisions: list of revision ids to verify
 
367
        :param repository: repository object
 
368
        :param process_events_callback: method to call for GUI frontends that
 
369
            want to keep their UI refreshed
 
370
 
 
371
        :return: count dictionary of results of each type,
 
372
                 result list for each revision,
 
373
                 boolean True if all results are verified successfully
 
374
        """
 
375
        return bulk_verify_signatures(repository, revisions, self,
 
376
            process_events_callback)
 
377
 
 
378
    @deprecated_method(deprecated_in((2, 6, 0)))
 
379
    def verbose_valid_message(self, result):
 
380
        """takes a verify result and returns list of signed commits strings"""
 
381
        return verbose_valid_message(result)
 
382
 
 
383
    @deprecated_method(deprecated_in((2, 6, 0)))
 
384
    def verbose_not_valid_message(self, result, repo):
 
385
        """takes a verify result and returns list of not valid commit info"""
 
386
        return verbose_not_valid_message(result, repo)
 
387
 
 
388
    @deprecated_method(deprecated_in((2, 6, 0)))
 
389
    def verbose_not_signed_message(self, result, repo):
 
390
        """takes a verify result and returns list of not signed commit info"""
 
391
        return verbose_not_valid_message(result, repo)
 
392
 
 
393
    @deprecated_method(deprecated_in((2, 6, 0)))
 
394
    def verbose_missing_key_message(self, result):
 
395
        """takes a verify result and returns list of missing key info"""
 
396
        return verbose_missing_key_message(result)
 
397
 
 
398
    @deprecated_method(deprecated_in((2, 6, 0)))
 
399
    def verbose_expired_key_message(self, result, repo):
 
400
        """takes a verify result and returns list of expired key info"""
 
401
        return verbose_expired_key_message(result, repo)
 
402
 
 
403
    @deprecated_method(deprecated_in((2, 6, 0)))
 
404
    def valid_commits_message(self, count):
 
405
        """returns message for number of commits"""
 
406
        return valid_commits_message(count)
 
407
 
 
408
    @deprecated_method(deprecated_in((2, 6, 0)))
 
409
    def unknown_key_message(self, count):
 
410
        """returns message for number of commits"""
 
411
        return unknown_key_message(count)
 
412
 
 
413
    @deprecated_method(deprecated_in((2, 6, 0)))
 
414
    def commit_not_valid_message(self, count):
 
415
        """returns message for number of commits"""
 
416
        return commit_not_valid_message(count)
 
417
 
 
418
    @deprecated_method(deprecated_in((2, 6, 0)))
 
419
    def commit_not_signed_message(self, count):
 
420
        """returns message for number of commits"""
 
421
        return commit_not_signed_message(count)
 
422
 
 
423
    @deprecated_method(deprecated_in((2, 6, 0)))
 
424
    def expired_commit_message(self, count):
 
425
        """returns message for number of commits"""
 
426
        return expired_commit_message(count)
369
427
 
370
428
 
371
429
def valid_commits_message(count):
372
430
    """returns message for number of commits"""
373
431
    return gettext(u"{0} commits with valid signatures").format(
374
 
        count[SIGNATURE_VALID])
 
432
                                    count[SIGNATURE_VALID])
375
433
 
376
434
 
377
435
def unknown_key_message(count):
379
437
    return ngettext(u"{0} commit with unknown key",
380
438
                    u"{0} commits with unknown keys",
381
439
                    count[SIGNATURE_KEY_MISSING]).format(
382
 
        count[SIGNATURE_KEY_MISSING])
 
440
                                    count[SIGNATURE_KEY_MISSING])
383
441
 
384
442
 
385
443
def commit_not_valid_message(count):
387
445
    return ngettext(u"{0} commit not valid",
388
446
                    u"{0} commits not valid",
389
447
                    count[SIGNATURE_NOT_VALID]).format(
390
 
        count[SIGNATURE_NOT_VALID])
 
448
                                        count[SIGNATURE_NOT_VALID])
391
449
 
392
450
 
393
451
def commit_not_signed_message(count):
395
453
    return ngettext(u"{0} commit not signed",
396
454
                    u"{0} commits not signed",
397
455
                    count[SIGNATURE_NOT_SIGNED]).format(
398
 
        count[SIGNATURE_NOT_SIGNED])
 
456
                                    count[SIGNATURE_NOT_SIGNED])
399
457
 
400
458
 
401
459
def expired_commit_message(count):
403
461
    return ngettext(u"{0} commit with key now expired",
404
462
                    u"{0} commits with key now expired",
405
463
                    count[SIGNATURE_EXPIRED]).format(
406
 
        count[SIGNATURE_EXPIRED])
 
464
                                count[SIGNATURE_EXPIRED])
407
465
 
408
466
 
409
467
def verbose_expired_key_message(result, repo):
436
494
            signers[uid] += 1
437
495
    result = []
438
496
    for uid, number in signers.items():
439
 
        result.append(ngettext(u"{0} signed {1} commit",
440
 
                               u"{0} signed {1} commits",
441
 
                               number).format(uid, number))
 
497
         result.append(ngettext(u"{0} signed {1} commit",
 
498
                                u"{0} signed {1} commits",
 
499
                                number).format(uid, number))
442
500
    return result
443
501
 
444
502
 
484
542
            signers.setdefault(fingerprint, 0)
485
543
            signers[fingerprint] += 1
486
544
    result = []
487
 
    for fingerprint, number in list(signers.items()):
 
545
    for fingerprint, number in signers.items():
488
546
        result.append(ngettext(u"Unknown key {0} signed {1} commit",
489
547
                               u"Unknown key {0} signed {1} commits",
490
548
                               number).format(fingerprint, number))