121
113
return (count, result, all_verifiable)
123
115
def valid_commits_message(self, count):
124
return i18n.gettext(u"{0} commits with valid signatures").format(
116
return gettext(u"{0} commits with valid signatures").format(
125
117
count[SIGNATURE_VALID])
127
119
def unknown_key_message(self, count):
128
return i18n.ngettext(u"{0} commit with unknown key",
120
return ngettext(u"{0} commit with unknown key",
129
121
u"{0} commits with unknown keys",
130
122
count[SIGNATURE_KEY_MISSING]).format(
131
123
count[SIGNATURE_KEY_MISSING])
133
125
def commit_not_valid_message(self, count):
134
return i18n.ngettext(u"{0} commit not valid",
126
return ngettext(u"{0} commit not valid",
135
127
u"{0} commits not valid",
136
128
count[SIGNATURE_NOT_VALID]).format(
137
129
count[SIGNATURE_NOT_VALID])
139
131
def commit_not_signed_message(self, count):
140
return i18n.ngettext(u"{0} commit not signed",
132
return ngettext(u"{0} commit not signed",
141
133
u"{0} commits not signed",
142
134
count[SIGNATURE_NOT_SIGNED]).format(
143
135
count[SIGNATURE_NOT_SIGNED])
137
def expired_commit_message(self, count):
138
return ngettext(u"{0} commit with key now expired",
139
u"{0} commits with key now expired",
140
count[SIGNATURE_EXPIRED]).format(
141
count[SIGNATURE_EXPIRED])
146
144
def _set_gpg_tty():
147
145
tty = os.environ.get('TTY')
242
242
except gpgme.GpgmeError,error:
243
243
raise errors.SignatureVerificationFailed(error[2])
245
# No result if input is invalid.
246
# test_verify_invalid()
245
247
if len(result) == 0:
246
248
return SIGNATURE_NOT_VALID, None
249
# User has specified a list of acceptable keys, check our result is in it.
250
# test_verify_unacceptable_key()
247
251
fingerprint = result[0].fpr
248
252
if self.acceptable_keys is not None:
249
if not fingerprint in self.acceptable_keys:
253
if not fingerprint in self.acceptable_keys:
250
254
return SIGNATURE_KEY_MISSING, fingerprint[-8:]
255
# Check the signature actually matches the testament.
256
# test_verify_bad_testament()
251
257
if testament != plain_output.getvalue():
252
return SIGNATURE_NOT_VALID, None
258
return SIGNATURE_NOT_VALID, None
259
# Yay gpgme set the valid bit.
260
# Can't write a test for this one as you can't set a key to be
261
# trusted using gpgme.
253
262
if result[0].summary & gpgme.SIGSUM_VALID:
254
263
key = self.context.get_key(fingerprint)
255
264
name = key.uids[0].name
256
265
email = key.uids[0].email
257
266
return SIGNATURE_VALID, name + " <" + email + ">"
267
# Sigsum_red indicates a problem, unfortunatly I have not been able
268
# to write any tests which actually set this.
258
269
if result[0].summary & gpgme.SIGSUM_RED:
259
270
return SIGNATURE_NOT_VALID, None
271
# GPG does not know this key.
272
# test_verify_unknown_key()
260
273
if result[0].summary & gpgme.SIGSUM_KEY_MISSING:
261
274
return SIGNATURE_KEY_MISSING, fingerprint[-8:]
262
#summary isn't set if sig is valid but key is untrusted
275
# Summary isn't set if sig is valid but key is untrusted
276
# but if user has explicity set the key as acceptable we can validate it.
263
277
if result[0].summary == 0 and self.acceptable_keys is not None:
264
278
if fingerprint in self.acceptable_keys:
265
return SIGNATURE_VALID, None
267
return SIGNATURE_KEY_MISSING, None
279
# test_verify_untrusted_but_accepted()
280
return SIGNATURE_VALID, None
281
# test_verify_valid_but_untrusted()
282
if result[0].summary == 0 and self.acceptable_keys is None:
283
return SIGNATURE_NOT_VALID, None
284
if result[0].summary & gpgme.SIGSUM_KEY_EXPIRED:
285
expires = self.context.get_key(result[0].fpr).subkeys[0].expires
286
if expires > result[0].timestamp:
287
# The expired key was not expired at time of signing.
288
# test_verify_expired_but_valid()
289
return SIGNATURE_EXPIRED, fingerprint[-8:]
291
# I can't work out how to create a test where the signature
292
# was expired at the time of signing.
293
return SIGNATURE_NOT_VALID, None
294
# A signature from a revoked key gets this.
295
# test_verify_revoked_signature()
296
if result[0].summary & gpgme.SIGSUM_SYS_ERROR:
297
return SIGNATURE_NOT_VALID, None
298
# Other error types such as revoked keys should (I think) be caught by
299
# SIGSUM_RED so anything else means something is buggy.
268
300
raise errors.SignatureVerificationFailed("Unknown GnuPG key "\
269
301
"verification result")
390
423
signers[fingerprint] += 1
392
425
for fingerprint, number in signers.items():
393
result.append( i18n.ngettext(u"Unknown key {0} signed {1} commit",
426
result.append( ngettext(u"Unknown key {0} signed {1} commit",
394
427
u"Unknown key {0} signed {1} commits",
395
428
number).format(fingerprint, number) )
431
def verbose_expired_key_message(self, result, repo):
432
"""takes a verify result and returns list of expired key info"""
434
fingerprint_to_authors = {}
435
for rev_id, validity, fingerprint in result:
436
if validity == SIGNATURE_EXPIRED:
437
revision = repo.get_revision(rev_id)
438
authors = ', '.join(revision.get_apparent_authors())
439
signers.setdefault(fingerprint, 0)
440
signers[fingerprint] += 1
441
fingerprint_to_authors[fingerprint] = authors
443
for fingerprint, number in signers.items():
444
result.append(ngettext(u"{0} commit by author {1} with "\
445
"key {2} now expired",
446
u"{0} commits by author {1} with key {2} now "\
448
number).format(number,
449
fingerprint_to_authors[fingerprint], fingerprint) )
398
452
def valid_commits_message(self, count):
399
453
"""returns message for number of commits"""
400
return i18n.gettext(u"{0} commits with valid signatures").format(
454
return gettext(u"{0} commits with valid signatures").format(
401
455
count[SIGNATURE_VALID])
403
457
def unknown_key_message(self, count):
404
458
"""returns message for number of commits"""
405
return i18n.ngettext(u"{0} commit with unknown key",
406
u"{0} commits with unknown keys",
407
count[SIGNATURE_KEY_MISSING]).format(
459
return ngettext(u"{0} commit with unknown key",
460
u"{0} commits with unknown keys",
461
count[SIGNATURE_KEY_MISSING]).format(
408
462
count[SIGNATURE_KEY_MISSING])
410
464
def commit_not_valid_message(self, count):
411
465
"""returns message for number of commits"""
412
return i18n.ngettext(u"{0} commit not valid",
413
u"{0} commits not valid",
414
count[SIGNATURE_NOT_VALID]).format(
466
return ngettext(u"{0} commit not valid",
467
u"{0} commits not valid",
468
count[SIGNATURE_NOT_VALID]).format(
415
469
count[SIGNATURE_NOT_VALID])
417
471
def commit_not_signed_message(self, count):
418
472
"""returns message for number of commits"""
419
return i18n.ngettext(u"{0} commit not signed",
420
u"{0} commits not signed",
421
count[SIGNATURE_NOT_SIGNED]).format(
473
return ngettext(u"{0} commit not signed",
474
u"{0} commits not signed",
475
count[SIGNATURE_NOT_SIGNED]).format(
422
476
count[SIGNATURE_NOT_SIGNED])
478
def expired_commit_message(self, count):
479
"""returns message for number of commits"""
480
return ngettext(u"{0} commit with key now expired",
481
u"{0} commits with key now expired",
482
count[SIGNATURE_EXPIRED]).format(
483
count[SIGNATURE_EXPIRED])