Merge remote-tracking branch 'origin/dkg/fix-T4276'

This commit is contained in:
Andre Heinecke 2019-05-06 08:10:03 +02:00
commit f303806a11
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C
7 changed files with 64 additions and 14 deletions

View File

@ -342,10 +342,12 @@ class Context(GpgmeWrapper):
Decrypt the given ciphertext and verify any signatures. If Decrypt the given ciphertext and verify any signatures. If
VERIFY is an iterable of keys, the ciphertext must be signed VERIFY is an iterable of keys, the ciphertext must be signed
by all those keys, otherwise an error is raised. Note: if by all those keys, otherwise a MissingSignatures error is
VERIFY is an empty iterable, that is treated the same as raised. Note: if VERIFY is an empty iterable, that is treated
passing verify=True (that is, do verify signatures, but no the same as passing verify=True (that is, verify signatures
specific keys are required). and return data about any valid signatures found, but no
signatures are required and no MissingSignatures error will be
raised).
If the ciphertext is symmetrically encrypted using a If the ciphertext is symmetrically encrypted using a
passphrase, that passphrase can be given as parameter, using a passphrase, that passphrase can be given as parameter, using a
@ -361,11 +363,10 @@ class Context(GpgmeWrapper):
Returns: Returns:
plaintext -- the decrypted data (or None if sink is given) plaintext -- the decrypted data (or None if sink is given)
result -- additional information about the decryption result -- additional information about the decryption
verify_result -- additional information about the signature(s) verify_result -- additional information about the valid signature(s) found
Raises: Raises:
UnsupportedAlgorithm -- if an unsupported algorithm was used UnsupportedAlgorithm -- if an unsupported algorithm was used
BadSignatures -- if a bad signature is encountered
MissingSignatures -- if expected signatures are missing or bad MissingSignatures -- if expected signatures are missing or bad
GPGMEError -- as signaled by the underlying library GPGMEError -- as signaled by the underlying library
@ -430,13 +431,8 @@ class Context(GpgmeWrapper):
results=results) results=results)
if do_sig_verification: if do_sig_verification:
# FIXME: should we really throw BadSignature, even if # filter out all invalid signatures
# we've encountered some good signatures? as above, once verify_result.signatures = list(filter(lambda s: s.status == errors.NO_ERROR, verify_result.signatures))
# we hit this error, there is no way to accept it and
# continue to process the remaining signatures.
if any(s.status != errors.NO_ERROR
for s in verify_result.signatures):
raise errors.BadSignatures(verify_result, results=results)
if required_keys is not None: if required_keys is not None:
missing = [] missing = []
for key in required_keys: for key in required_keys:

View File

@ -28,7 +28,7 @@ TESTS_ENVIRONMENT = GNUPGHOME=$(GNUPGHOME) \
srcdir=$(srcdir) \ srcdir=$(srcdir) \
LD_LIBRARY_PATH="../../../src/.libs:$(LD_LIBRARY_PATH)" LD_LIBRARY_PATH="../../../src/.libs:$(LD_LIBRARY_PATH)"
py_tests = t-wrapper.py \ py_tests ?= t-wrapper.py \
t-callbacks.py \ t-callbacks.py \
t-data.py \ t-data.py \
t-encrypt.py \ t-encrypt.py \

View File

@ -75,3 +75,15 @@ with gpg.Context() as c:
assert e.missing[0] == bob assert e.missing[0] == bob
else: else:
assert False, "Expected an error, got none" assert False, "Expected an error, got none"
plaintext, _, verify_result = c.decrypt(open(support.make_filename("cipher-no-sig.asc")))
assert len(plaintext) > 0
assert len(verify_result.signatures) == 0
assert plaintext.find(b'Viscosity Dispersal Thimble Saturday Flaxseed Deflected') >= 0, \
'unsigned Plaintext was not found'
plaintext, _, verify_result = c.decrypt(open(support.make_filename("cipher-3.asc")))
assert len(plaintext) > 0
assert len(verify_result.signatures) == 1
assert plaintext.find(b'Reenact Studied Thermos Bonehead Unclasp Opposing') >= 0, \
'second Plaintext not found'

View File

@ -42,3 +42,13 @@ with gpg.Context() as c:
assert len(plaintext) > 0 assert len(plaintext) > 0
assert plaintext.find(b'Wenn Sie dies lesen k') >= 0, \ assert plaintext.find(b'Wenn Sie dies lesen k') >= 0, \
'Plaintext not found' 'Plaintext not found'
plaintext, _, _ = c.decrypt(open(support.make_filename("cipher-3.asc")), verify=False)
assert len(plaintext) > 0
assert plaintext.find(b'Reenact Studied Thermos Bonehead Unclasp Opposing') >= 0, \
'second Plaintext not found'
plaintext, _, _ = c.decrypt(open(support.make_filename("cipher-no-sig.asc")), verify=False)
assert len(plaintext) > 0
assert plaintext.find(b'Viscosity Dispersal Thimble Saturday Flaxseed Deflected') >= 0, \
'third Plaintext was not found'

View File

@ -59,6 +59,7 @@ private_keys = \
EXTRA_DIST = initial.test final.test \ EXTRA_DIST = initial.test final.test \
pubdemo.asc secdemo.asc cipher-1.asc cipher-2.asc \ pubdemo.asc secdemo.asc cipher-1.asc cipher-2.asc \
cipher-3.asc cipher-no-sig.asc \
geheim.txt pubkey-1.asc seckey-1.asc pinentry $(private_keys) geheim.txt pubkey-1.asc seckey-1.asc pinentry $(private_keys)
BUILT_SOURCES = gpg.conf gpg-agent.conf pubring-stamp \ BUILT_SOURCES = gpg.conf gpg-agent.conf pubring-stamp \

18
tests/gpg/cipher-3.asc Normal file
View File

@ -0,0 +1,18 @@
-----BEGIN PGP MESSAGE-----
hQEOA++dwnahcsiBEAQApowkbz0idxMfLIT/a1G4QbZy77cWyaYOM/qh4lH4h7ra
f19MZzbRViZYBtJeITszTFmulp31qrF++6gBy8tU7l8VfVfOtvwn1WlRvn2+bsns
SicJAXtUiwIF8fbapSrkN6qpg2l+Fnx3SYV7+lh/7Fbf93DquwVEn+GwvgkyCQkD
/j5UVU6PJ+k5E5JG7CMzLZHnpW1MtKUqKRG9sTW83SvvI5Wl9VMgjmdO6bZRPKPY
Fr5udYJ1v4CIpVTb0O/TgAaiw7/Ak4SOg6jK0H0l1vuPPRjyzx43G4Y4lZ/EoCzT
gU+0kiDD+O7xLDml5jPWTYov7LkhRMKI4Ugp37FzbF9p0sClAR1mY4WlAN23ku0W
3bw54zSi7S6sh+i/uOmjZ+ziXr/S1pHFN2TNAkpH42o6VDhJ4vYk5KIB/mn/IoP1
G57JUhLqpSHO7LF8X45eBLT3tKC3rIaILHXcXE5PeyMiOrl1snIClrpX+Qn6dRPX
cYssX/0OQwE77bAla5QpZEy6YLOC4Ej4oTX5QU1rHNyLfvIDhwtphKMvbbssmsVI
tAMvrGQudEwLSlvNlnJsI79jqmbi5W8PYr+ssvOvrd5hWoKti7EdglWddFNVVjZl
ooJgztXUnPcufhaimQtNvX0Tj2hI8QwTxGPNO3aesPCQI0GbSUSqpvu6mlaQY2Q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