def test_verify(self): p7m = P7M("tests/data/test.txt.p7m") if p7m.is_expired(): self.skipTest( "test signature has expired and needs to be regenerated") with self.capath() as capath: p7m.verify_signature(capath)
def test_verify_corrupted_random(self): p7m = P7M("tests/data/test.txt.p7m") data_mid = len(p7m.data) // 2 p7m.data = p7m.data[:data_mid] + bytes([p7m.data[data_mid] + 1]) + p7m.data[data_mid + 1:] with self.capath() as capath: with self.assertRaises(InvalidSignatureError): p7m.verify_signature(capath)
def test_load(self): p7m = P7M("tests/data/test.txt.p7m") data = p7m.get_payload() self.assertEqual( data, "This is only a test payload.\n" "\n" "Questo è solo un payload di test.\n".encode("utf8"))
def test_verify_noca(self): p7m = P7M("tests/data/test.txt.p7m") if p7m.is_expired(): self.skipTest("test signature has expired and needs to be regenerated") with tempfile.TemporaryDirectory() as capath: with self.assertRaisesRegexp(InvalidSignatureError, r"Verify error:unable to get local issuer certificate"): p7m.verify_signature(capath)
def load_fattura(self, pathname): if pathname.endswith(".p7m"): from a38.crypto import P7M p7m = P7M(pathname) return p7m.get_fattura() else: tree = ET.parse(pathname) return a38.auto_from_etree(tree.getroot())
def test_verify_corrupted_payload(self): p7m = P7M("tests/data/test.txt.p7m") signed_data = p7m.get_signed_data() encap_content_info = signed_data["encap_content_info"] encap_content_info["content"] = b"All your base are belong to us" p7m.data = p7m.content_info.dump() with self.capath() as capath: with self.assertRaisesRegexp(InvalidSignatureError, r"routines:CMS_verify:content verify error"): p7m.verify_signature(capath)
def test_verify_corrupted_random(self): p7m = P7M("tests/data/test.txt.p7m") if p7m.is_expired(): self.skipTest("test signature has expired and needs to be regenerated") data_mid = len(p7m.data) // 2 p7m.data = p7m.data[:data_mid] + bytes([p7m.data[data_mid] + 1]) + p7m.data[data_mid + 1:] with self.capath() as capath: with self.assertRaises(InvalidSignatureError): p7m.verify_signature(capath)
def test_verify_noca(self): p7m = P7M("tests/data/test.txt.p7m") with tempfile.TemporaryDirectory() as capath: with self.assertRaisesRegexp(InvalidSignatureError, r"Verify error:unable to get local issuer certificate"): p7m.verify_signature(capath)
def test_verify(self): p7m = P7M("tests/data/test.txt.p7m") with self.capath() as capath: p7m.verify_signature(capath)