123
116
return (count, result, all_verifiable)
125
118
def valid_commits_message(self, count):
126
return i18n.gettext(u"{0} commits with valid signatures").format(
127
count[SIGNATURE_VALID])
119
return gettext(u"{0} commits with valid signatures").format(
120
count[SIGNATURE_VALID])
129
122
def unknown_key_message(self, count):
130
return i18n.ngettext(u"{0} commit with unknown key",
123
return ngettext(u"{0} commit with unknown key",
131
124
u"{0} commits with unknown keys",
132
125
count[SIGNATURE_KEY_MISSING]).format(
133
126
count[SIGNATURE_KEY_MISSING])
135
128
def commit_not_valid_message(self, count):
136
return i18n.ngettext(u"{0} commit not valid",
129
return ngettext(u"{0} commit not valid",
137
130
u"{0} commits not valid",
138
131
count[SIGNATURE_NOT_VALID]).format(
139
132
count[SIGNATURE_NOT_VALID])
141
134
def commit_not_signed_message(self, count):
142
return i18n.ngettext(u"{0} commit not signed",
135
return ngettext(u"{0} commit not signed",
143
136
u"{0} commits not signed",
144
137
count[SIGNATURE_NOT_SIGNED]).format(
145
138
count[SIGNATURE_NOT_SIGNED])
147
140
def expired_commit_message(self, count):
148
return i18n.ngettext(u"{0} commit with key now expired",
149
u"{0} commits with key now expired",
150
count[SIGNATURE_EXPIRED]).format(
141
return ngettext(u"{0} commit with key now expired",
142
u"{0} commits with key now expired",
143
count[SIGNATURE_EXPIRED]).format(
151
144
count[SIGNATURE_EXPIRED])
185
186
def _command_line(self):
187
return [self._config.gpg_signing_command(), '--clearsign', '-u',
188
self._config.gpg_signing_key()]
190
def __init__(self, config):
191
self._config = config
194
self.context = gpgme.Context()
195
except ImportError, error:
196
pass # can't use verify()
187
key = self._config_stack.get('gpg_signing_key')
188
if key is None or key == 'default':
189
# 'default' or not setting gpg_signing_key at all means we should
190
# use the user email address
191
key = config.extract_email_address(self._config_stack.get('email'))
192
return [self._config_stack.get('gpg_signing_command'), '--clearsign',
198
195
def sign(self, content):
199
196
if isinstance(content, unicode):
256
252
# test_verify_invalid()
257
253
if len(result) == 0:
258
254
return SIGNATURE_NOT_VALID, None
259
# User has specified a list of acceptable keys, check our result is in it.
260
# test_verify_unacceptable_key()
255
# User has specified a list of acceptable keys, check our result is in
256
# it. test_verify_unacceptable_key()
261
257
fingerprint = result[0].fpr
262
258
if self.acceptable_keys is not None:
263
if not fingerprint in self.acceptable_keys:
259
if not fingerprint in self.acceptable_keys:
264
260
return SIGNATURE_KEY_MISSING, fingerprint[-8:]
265
261
# Check the signature actually matches the testament.
266
262
# test_verify_bad_testament()
267
263
if testament != plain_output.getvalue():
268
return SIGNATURE_NOT_VALID, None
264
return SIGNATURE_NOT_VALID, None
269
265
# Yay gpgme set the valid bit.
270
266
# Can't write a test for this one as you can't set a key to be
271
267
# trusted using gpgme.
282
278
# test_verify_unknown_key()
283
279
if result[0].summary & gpgme.SIGSUM_KEY_MISSING:
284
280
return SIGNATURE_KEY_MISSING, fingerprint[-8:]
285
# Summary isn't set if sig is valid but key is untrusted
286
# but if user has explicity set the key as acceptable we can validate it.
281
# Summary isn't set if sig is valid but key is untrusted but if user
282
# has explicity set the key as acceptable we can validate it.
287
283
if result[0].summary == 0 and self.acceptable_keys is not None:
288
284
if fingerprint in self.acceptable_keys:
289
285
# test_verify_untrusted_but_accepted()
290
return SIGNATURE_VALID, None
286
return SIGNATURE_VALID, None
291
287
# test_verify_valid_but_untrusted()
292
288
if result[0].summary == 0 and self.acceptable_keys is None:
293
289
return SIGNATURE_NOT_VALID, None
311
307
"verification result")
313
309
def set_acceptable_keys(self, command_line_input):
314
"""sets the acceptable keys for verifying with this GPGStrategy
310
"""Set the acceptable keys for verifying with this GPGStrategy.
316
312
:param command_line_input: comma separated list of patterns from
320
316
key_patterns = None
321
acceptable_keys_config = self._config.acceptable_keys()
317
acceptable_keys_config = self._config_stack.get('acceptable_keys')
323
319
if isinstance(acceptable_keys_config, unicode):
324
320
acceptable_keys_config = str(acceptable_keys_config)
325
321
except UnicodeEncodeError:
326
#gpg Context.keylist(pattern) does not like unicode
327
raise errors.BzrCommandError('Only ASCII permitted in option names')
322
# gpg Context.keylist(pattern) does not like unicode
323
raise errors.BzrCommandError(
324
gettext('Only ASCII permitted in option names'))
329
326
if acceptable_keys_config is not None:
330
327
key_patterns = acceptable_keys_config
331
if command_line_input is not None: #command line overrides config
328
if command_line_input is not None: # command line overrides config
332
329
key_patterns = command_line_input
333
330
if key_patterns is not None:
334
331
patterns = key_patterns.split(",")
451
448
fingerprint_to_authors[fingerprint] = authors
453
450
for fingerprint, number in signers.items():
454
result.append( i18n.ngettext(u"{0} commit by author {1} with "\
455
"key {2} now expired",
456
u"{0} commits by author {1} with key {2} now "\
458
number).format(number,
459
fingerprint_to_authors[fingerprint], fingerprint) )
452
ngettext(u"{0} commit by author {1} with key {2} now expired",
453
u"{0} commits by author {1} with key {2} now expired",
455
number, fingerprint_to_authors[fingerprint], fingerprint) )
462
458
def valid_commits_message(self, count):
463
459
"""returns message for number of commits"""
464
return i18n.gettext(u"{0} commits with valid signatures").format(
460
return gettext(u"{0} commits with valid signatures").format(
465
461
count[SIGNATURE_VALID])
467
463
def unknown_key_message(self, count):
468
464
"""returns message for number of commits"""
469
return i18n.ngettext(u"{0} commit with unknown key",
470
u"{0} commits with unknown keys",
471
count[SIGNATURE_KEY_MISSING]).format(
465
return ngettext(u"{0} commit with unknown key",
466
u"{0} commits with unknown keys",
467
count[SIGNATURE_KEY_MISSING]).format(
472
468
count[SIGNATURE_KEY_MISSING])
474
470
def commit_not_valid_message(self, count):
475
471
"""returns message for number of commits"""
476
return i18n.ngettext(u"{0} commit not valid",
477
u"{0} commits not valid",
478
count[SIGNATURE_NOT_VALID]).format(
472
return ngettext(u"{0} commit not valid",
473
u"{0} commits not valid",
474
count[SIGNATURE_NOT_VALID]).format(
479
475
count[SIGNATURE_NOT_VALID])
481
477
def commit_not_signed_message(self, count):
482
478
"""returns message for number of commits"""
483
return i18n.ngettext(u"{0} commit not signed",
484
u"{0} commits not signed",
485
count[SIGNATURE_NOT_SIGNED]).format(
479
return ngettext(u"{0} commit not signed",
480
u"{0} commits not signed",
481
count[SIGNATURE_NOT_SIGNED]).format(
486
482
count[SIGNATURE_NOT_SIGNED])
488
484
def expired_commit_message(self, count):
489
485
"""returns message for number of commits"""
490
return i18n.ngettext(u"{0} commit with key now expired",
491
u"{0} commits with key now expired",
492
count[SIGNATURE_EXPIRED]).format(
493
count[SIGNATURE_EXPIRED])
486
return ngettext(u"{0} commit with key now expired",
487
u"{0} commits with key now expired",
488
count[SIGNATURE_EXPIRED]).format(
489
count[SIGNATURE_EXPIRED])