195
187
-----END PGP PRIVATE KEY BLOCK-----
198
revoked_key = StringIO("""-----BEGIN PGP PUBLIC KEY BLOCK-----
199
Version: GnuPG v1.4.11 (GNU/Linux)
201
mI0ETjlW5gEEAOb/6P+TVM59E897wRtatxys2BhsHCXM4T7xjIiANfDwejDdifqh
202
tluTfSJLLxPembtrrEjux1C0AJgc+f0MIfsc3Pr3eFJzKB2ot/1IVG1/1KnA0zt3
203
W2xPT3lRib27WJ9Fag+dMtQaIzgJ7/n2DFxsFZ33FD2kxrEXB2exGg6FABEBAAGI
204
pgQgAQIAEAUCTjlXkAkdAHJldm9rZWQACgkQjs6dvEpb0cQPHAP/Wi9rbx0e+1Sf
205
ziGgyVdr3m3A6uvze5oXKVgFRbGRUYSH4/I8GW0W9x4TcRg9h+YaQ8NUdADr9kNE
206
tKAljLqYA5qdqSfYuaij1M++Xj+KUZ359R74sHuQqwnRy1XXQNfRs/QpXA7vLdds
207
rjg+pbWuXO92TZJUdnqtWW+VEyZBsPy0G3Rlc3Qga2V5IDx0ZXN0QGV4YW1wbGUu
208
Y29tPoi4BBMBAgAiBQJOOVbmAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAK
209
CRCOzp28SlvRxNWzA/42WVmI0b+6mF/imEOlY1TiyvrcpK250rkSDsCtL4lOwy7G
210
antZhpgNfnXRd/ySfsS3EB6dpOWgOSxGRvWQhA+vxBT9BYNk49qd3JIrSaSWpR12
211
rET8qO1rEQQFWsw03CxTGujxGlmEO+a1yguRXp2UWaY7FngcQmD+8q7BUIVm7riN
212
BE45VuYBBADTEH2jHTjNCc5CMOhea6EJTrkx3upcEqB2oyhWeSWJiBGOxlcddsjo
213
3J3/EmBB8kK1hM9TidD3SG64x1N287lg8ELJBlKv+pQVyxohGJ1u/THgpTDMMQcL
214
luG5rAHQGSfyzKTiOnaTyBYg3M/nzgUOU9dKEFB0EA3tjUXFOT+r3wARAQABiJ8E
215
GAECAAkFAk45VuYCGwwACgkQjs6dvEpb0cRSLQP/fzCWX2lXwlwWiVF8BOPF7o9z
216
icHErc7/X17RGb4qj1kVf+UkRdUWJrbEVh4h6MncBIuA70WsYogiw+Kz/0LCtQAR
217
YUJsPy/EL++OKPH1aFasOdTxwkTka85+RdYqhP1+z/aYLFMWq6mRFI+o6x2k5mGi
220
-----END PGP PUBLIC KEY BLOCK-----
223
expired_key = StringIO("""-----BEGIN PGP PUBLIC KEY BLOCK-----
224
Version: GnuPG v1.4.11 (GNU/Linux)
226
mI0ETjZ6PAEEALkR4GcFQidCCxV7pgQwQd5MZua0YO2l92fVqHX+PhnZ6egCLKdD
227
2bWlMUd6MLPF3FlRL7BBAxvW/DazkBOp7ljsnpMpptEzY49Uem1irYLYiVb9zK96
228
0sQZzFxFkfEYetQEXC68mIck8tbySOX5NAOw++3jFm3J7dsU1R3XtYzRABEBAAG0
229
G3Rlc3Qga2V5IDx0ZXN0QGV4YW1wbGUuY29tPoi+BBMBAgAoBQJONno8AhsDBQkA
230
AVGABgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRAc4m97T40VEz+DA/9PBphG
231
Yp9cHVaHSfTUKGTGgIbvRe60sFNpDCYZeAGDrygOMuI8MNzbVpwefRBFHVPx7jWd
232
rrYMsLkcsNUS9D0baU+0D/qp7JVg7ZSQtG0O6IG4eTZhibteY1fu0+unlXmg9NHx
233
5VvhwzBiJDYji00M2p/CZEMiYFUuy76CsxUpN7iNBE42ejwBBACkv2/mX7IPQg0C
234
A3KSrJsJv+sdvKm4b4xuI4OwagwTIVz4KlTqV4IBrVjSBfwyMXucXz0bTW85qjgA
235
+n67td8vyjYYZUEz1uY9lSquQQDnAN0txL3cLHZXWiWOkmzZVddQtlflK2a/J9o0
236
QkHPVUm+hc4l64dIzStrNl2S66fAvQARAQABiKUEGAECAA8FAk42ejwCGwwFCQAB
237
UYAACgkQHOJve0+NFROEYQP/epg+o8iBs31hkSERyZjrRR66LpywezWj30Rn/3mX
238
Fzi9HkF4xLemWOzdNt9C5PYrOep85PQg8haEjknxVjZFS0ikT1h3OWk/TF1ZrLVm
239
WzyX8DaHQEjKpLJJjXcAbTiZBNMk0QaVC9RvIeHpCf3n3DC49DdjsPJRMKOn8KDi
242
-----END PGP PUBLIC KEY BLOCK-----
244
190
context.import_(key)
245
191
context.import_(secret_key)
246
context.import_(revoked_key)
247
context.import_(expired_key)
249
def test_verify_untrusted_but_accepted(self):
250
#untrusted by gpg but listed as acceptable_keys by user
193
def test_verify_valid(self):
251
194
self.requireFeature(features.gpgme)
252
195
self.import_keys()
278
221
self.assertEqual((gpg.SIGNATURE_VALID, None), my_gpg.verify(content,
281
def test_verify_unacceptable_key(self):
282
self.requireFeature(features.gpgme)
285
content = """-----BEGIN PGP SIGNED MESSAGE-----
288
bazaar-ng testament short form 1
289
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
290
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
291
-----BEGIN PGP SIGNATURE-----
292
Version: GnuPG v1.4.11 (GNU/Linux)
294
iQEcBAEBAgAGBQJN+ekFAAoJEIdoGx7jCA5FGtEH/i+XxJRvqU6wdBtLVrGBMAGk
295
FZ5VP+KyXYtymSbgSstj/vM12NeMIeFs3xGnNnYuX1MIcY6We5TKtCH0epY6ym5+
296
6g2Q2QpQ5/sT2d0mWzR0K4uVngmxVQaXTdk5PdZ40O7ULeDLW6CxzxMHyUL1rsIx
297
7UBUTBh1O/1n3ZfD99hUkm3hVcnsN90uTKH59zV9NWwArU0cug60+5eDKJhSJDbG
298
rIwlqbFAjDZ7L/48e+IaYIJwBZFzMBpJKdCxzALLtauMf+KK8hGiL2hrRbWm7ty6
299
NgxfkMYOB4rDPdSstT35N+5uBG3n/UzjxHssi0svMfVETYYX40y57dm2eZQXFp8=
301
-----END PGP SIGNATURE-----
303
plain = """bazaar-ng testament short form 1
304
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
305
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
307
my_gpg = gpg.GPGStrategy(FakeConfig())
308
my_gpg.set_acceptable_keys("foo@example.com")
309
self.assertEqual((gpg.SIGNATURE_KEY_MISSING, u'E3080E45'),
310
my_gpg.verify(content, plain))
312
def test_verify_valid_but_untrusted(self):
313
self.requireFeature(features.gpgme)
316
content = """-----BEGIN PGP SIGNED MESSAGE-----
319
bazaar-ng testament short form 1
320
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
321
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
322
-----BEGIN PGP SIGNATURE-----
323
Version: GnuPG v1.4.11 (GNU/Linux)
325
iQEcBAEBAgAGBQJN+ekFAAoJEIdoGx7jCA5FGtEH/i+XxJRvqU6wdBtLVrGBMAGk
326
FZ5VP+KyXYtymSbgSstj/vM12NeMIeFs3xGnNnYuX1MIcY6We5TKtCH0epY6ym5+
327
6g2Q2QpQ5/sT2d0mWzR0K4uVngmxVQaXTdk5PdZ40O7ULeDLW6CxzxMHyUL1rsIx
328
7UBUTBh1O/1n3ZfD99hUkm3hVcnsN90uTKH59zV9NWwArU0cug60+5eDKJhSJDbG
329
rIwlqbFAjDZ7L/48e+IaYIJwBZFzMBpJKdCxzALLtauMf+KK8hGiL2hrRbWm7ty6
330
NgxfkMYOB4rDPdSstT35N+5uBG3n/UzjxHssi0svMfVETYYX40y57dm2eZQXFp8=
332
-----END PGP SIGNATURE-----
334
plain = """bazaar-ng testament short form 1
335
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
336
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
338
my_gpg = gpg.GPGStrategy(FakeConfig())
339
self.assertEqual((gpg.SIGNATURE_NOT_VALID, None), my_gpg.verify(content,
342
224
def test_verify_bad_testament(self):
343
225
self.requireFeature(features.gpgme)
344
226
self.import_keys()
370
252
self.assertEqual((gpg.SIGNATURE_NOT_VALID, None), my_gpg.verify(content,
374
def test_verify_revoked_signature(self):
375
self.requireFeature(features.gpgme)
378
content = """-----BEGIN PGP SIGNED MESSAGE-----
382
-----BEGIN PGP SIGNATURE-----
383
Version: GnuPG v1.4.11 (GNU/Linux)
385
iJwEAQECAAYFAk45V18ACgkQjs6dvEpb0cSIZQP/eOGTXGPlrNwvDkcX2d8O///I
386
ecB4sUIUEpv1XAk1MkNu58lsjjK72lRaLusEGqd7HwrFmpxVeVs0oWLg23PNPCFs
387
yJBID9ma+VxFVPtkEFnrc1R72sBJLfBcTxMkwVTC8eeznjdtn+cg+aLkxbPdrGnr
390
-----END PGP SIGNATURE-----
393
my_gpg = gpg.GPGStrategy(FakeConfig())
394
my_gpg.set_acceptable_keys("test@example.com")
395
self.assertEqual((gpg.SIGNATURE_NOT_VALID, None), my_gpg.verify(content,
398
255
def test_verify_invalid(self):
399
256
self.requireFeature(features.gpgme)
401
257
content = """-----BEGIN PGP SIGNED MESSAGE-----
420
276
self.assertEqual((gpg.SIGNATURE_NOT_VALID, None),
421
277
my_gpg.verify(content, plain))
423
def test_verify_expired_but_valid(self):
424
self.requireFeature(features.gpgme)
426
content = """-----BEGIN PGP SIGNED MESSAGE-----
429
bazaar-ng testament short form 1
430
revision-id: test@example.com-20110801100657-f1dr1nompeex723z
431
sha1: 59ab434be4c2d5d646dee84f514aa09e1b72feeb
432
-----BEGIN PGP SIGNATURE-----
433
Version: GnuPG v1.4.10 (GNU/Linux)
435
iJwEAQECAAYFAk42esUACgkQHOJve0+NFRPc5wP7BoZkzBU8JaHMLv/LmqLr0sUz
436
zuE51ofZZ19L7KVtQWsOi4jFy0fi4A5TFwO8u9SOfoREGvkw292Uty9subSouK5/
437
mFmDOYPQ+O83zWgYZsBmMJWYDZ+X9I6XXZSbPtV/7XyTjaxtl5uRnDVJjg+AzKvD
440
-----END PGP SIGNATURE-----
442
plain = """bazaar-ng testament short form 1
443
revision-id: test@example.com-20110801100657-f1dr1nompeex723z
444
sha1: 59ab434be4c2d5d646dee84f514aa09e1b72feeb
446
my_gpg = gpg.GPGStrategy(FakeConfig())
447
self.assertEqual((gpg.SIGNATURE_EXPIRED, u'4F8D1513'),
448
my_gpg.verify(content, plain))
450
def test_verify_unknown_key(self):
451
self.requireFeature(features.gpgme)
453
content = """-----BEGIN PGP SIGNED MESSAGE-----
457
-----BEGIN PGP SIGNATURE-----
458
Version: GnuPG v1.4.11 (GNU/Linux)
460
iQEcBAEBAgAGBQJOORKwAAoJENf6AkFdUeVvJDYH/1Cz+AJn1Jvy5n64o+0fZ5Ow
461
Y7UQb4QQTIOV7jI7n4hv/yBzuHrtImFzYvQl/o2Ezzi8B8L5gZtQy+xCUF+Q8iWs
462
gytZ5JUtSze7hDZo1NUl4etjoRGYqRfrUcvE2LkVH2dFbDGyyQfVmoeSHa5akuuP
463
QZmyg2F983rACVIpGvsqTH6RcBdvE9vx68lugeKQA8ArDn39/74FBFipFzrXSPij
464
eKFpl+yZmIb3g6HkPIC8o4j/tMvc37xF1OG5sBu8FT0+FC+VgY7vAblneDftAbyP
465
sIODx4WcfJtjLG/qkRYqJ4gDHo0eMpTJSk2CWebajdm4b+JBrM1F9mgKuZFLruE=
467
-----END PGP SIGNATURE-----
470
my_gpg = gpg.GPGStrategy(FakeConfig())
471
self.assertEqual((gpg.SIGNATURE_KEY_MISSING, u'5D51E56F'),
472
my_gpg.verify(content, plain))
474
279
def test_set_acceptable_keys(self):
475
280
self.requireFeature(features.gpgme)
476
281
self.import_keys()
482
287
def test_set_acceptable_keys_unknown(self):
483
288
self.requireFeature(features.gpgme)
484
289
my_gpg = gpg.GPGStrategy(FakeConfig())
487
self.notes.append(args[0] % args[1:])
488
self.overrideAttr(trace, 'note', note)
489
290
my_gpg.set_acceptable_keys("unknown")
490
291
self.assertEqual(my_gpg.acceptable_keys, [])
491
self.assertEqual(self.notes,
492
['No GnuPG key results for pattern: unknown'])
495
294
class TestDisabled(TestCase):