diff options
author | Michał Górny <mgorny@gentoo.org> | 2017-10-26 22:44:33 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2017-10-26 22:44:33 +0200 |
commit | ea4d757852786ea334a034c30b4cd4cd34b76a21 (patch) | |
tree | 196078382605cc405d54403eefb5bae694c693dd | |
parent | 32a985784b9d5a9abe6dd14cd43048d3da0753b5 (diff) | |
download | gemato-ea4d757852786ea334a034c30b4cd4cd34b76a21.tar.gz |
manifest: Test for incomplete OpenPGP message
-rw-r--r-- | gemato/manifest.py | 10 | ||||
-rw-r--r-- | tests/test_openpgp.py | 18 |
2 files changed, 28 insertions, 0 deletions
diff --git a/gemato/manifest.py b/gemato/manifest.py index 0fae91f..e6c9837 100644 --- a/gemato/manifest.py +++ b/gemato/manifest.py @@ -349,6 +349,16 @@ class ManifestFile(object): tag = sl[0] self.entries.append(MANIFEST_TAG_MAPPING[tag].from_list(sl)) + if state == ManifestState.SIGNED_PREAMBLE: + raise gemato.exceptions.ManifestSyntaxError( + "Manifest terminated early, in OpenPGP headers") + elif state == ManifestState.SIGNED_DATA: + raise gemato.exceptions.ManifestSyntaxError( + "Manifest terminated early, before signature") + elif state == ManifestState.SIGNATURE: + raise gemato.exceptions.ManifestSyntaxError( + "Manifest terminated early, inside signature") + def dump(self, f): """ Dump data into file @f. The file should be open for writing diff --git a/tests/test_openpgp.py b/tests/test_openpgp.py index 3771bed..32028f0 100644 --- a/tests/test_openpgp.py +++ b/tests/test_openpgp.py @@ -171,6 +171,24 @@ class SignedManifestTest(unittest.TestCase): self.assertRaises(gemato.exceptions.ManifestUnsignedData, m.load, f) + def test_signed_manifest_terminated_before_data(self): + m = gemato.manifest.ManifestFile() + with io.StringIO('\n'.join(SIGNED_MANIFEST.splitlines()[:3])) as f: + self.assertRaises(gemato.exceptions.ManifestSyntaxError, + m.load, f) + + def test_signed_manifest_terminated_before_signature(self): + m = gemato.manifest.ManifestFile() + with io.StringIO('\n'.join(SIGNED_MANIFEST.splitlines()[:7])) as f: + self.assertRaises(gemato.exceptions.ManifestSyntaxError, + m.load, f) + + def test_signed_manifest_terminated_before_end(self): + m = gemato.manifest.ManifestFile() + with io.StringIO('\n'.join(SIGNED_MANIFEST.splitlines()[:15])) as f: + self.assertRaises(gemato.exceptions.ManifestSyntaxError, + m.load, f) + class OpenPGPCorrectKeyTest(unittest.TestCase): """ |