Skip to content

Commit ae5155c

Browse files
committed
chore: Update to SignXML 4.0.3 version
- Updated error messages and expected exception in tests. - Updated `add_pem_cert_header_footer` and now `signxml.util.add_pem_header` returns a byte object. - Removed use of `crypto_utils._X509CertOpenSsl` in `verify_xml_signature` as SignXML has deprecated PyOpenSSL. Ref: https://app.shortcut.com/cordada/story/11838/ [sc-11838]
1 parent 1b9d20d commit ae5155c

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

src/cl_sii/libs/crypto_utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ def add_pem_cert_header_footer(pem_cert: bytes) -> bytes:
157157
"""
158158
pem_value_str = pem_cert.decode('ascii')
159159
# note: it would be great if 'add_pem_header' did not forcefully convert bytes to str.
160-
mod_pem_value_str = signxml.util.add_pem_header(pem_value_str)
161-
mod_pem_value: bytes = mod_pem_value_str.encode('ascii')
160+
mod_pem_value: bytes = signxml.util.add_pem_header(pem_value_str)
162161
return mod_pem_value
163162

164163

src/cl_sii/libs/xml_utils.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,8 @@ def verify_xml_signature(
440440
)
441441

442442
if isinstance(trusted_x509_cert, crypto_utils._X509CertOpenSsl):
443-
trusted_x509_cert_open_ssl = trusted_x509_cert
444-
elif isinstance(trusted_x509_cert, crypto_utils.X509Cert):
445-
trusted_x509_cert_open_ssl = crypto_utils._X509CertOpenSsl.from_cryptography(
446-
trusted_x509_cert
447-
)
448-
elif trusted_x509_cert is None:
449-
trusted_x509_cert_open_ssl = None
450-
else:
443+
trusted_x509_cert = trusted_x509_cert.to_cryptography()
444+
elif not isinstance(trusted_x509_cert, (crypto_utils.X509Cert, type(None))):
451445
# A 'crypto_utils._X509CertOpenSsl' is ok but we prefer 'crypto_utils.X509Cert'.
452446
raise TypeError("'trusted_x509_cert' must be a 'crypto_utils.X509Cert' instance, or None.")
453447

@@ -482,7 +476,7 @@ def verify_xml_signature(
482476
result = xml_verifier.verify(
483477
data=tmp_bytes,
484478
require_x509=True,
485-
x509_cert=trusted_x509_cert_open_ssl,
479+
x509_cert=trusted_x509_cert,
486480
ignore_ambiguous_key_info=True,
487481
expect_config=signxml.verifier.SignatureConfiguration(
488482
signature_methods=frozenset([signxml.algorithms.SignatureMethod.RSA_SHA1]),

src/tests/test_libs_xml_utils.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def test_fail_verify_with_other_cert(self) -> None:
221221
verify_xml_signature(xml_doc, trusted_x509_cert=cert)
222222
self.assertEqual(
223223
cm.exception.args,
224-
("Signature verification failed: wrong signature length",),
224+
("Signature verification failed: ",),
225225
)
226226

227227
def test_bad_cert_included(self) -> None:
@@ -247,11 +247,14 @@ def test_fail_replaced_cert(self) -> None:
247247
xml_doc = parse_untrusted_xml(self.with_replaced_cert)
248248
cert = load_pem_x509_cert(self.any_x509_cert_pem_file)
249249

250-
with self.assertRaises(XmlSignatureInvalid) as cm:
250+
with self.assertRaises(ValueError) as cm:
251251
verify_xml_signature(xml_doc, trusted_x509_cert=cert)
252252
self.assertEqual(
253253
cm.exception.args,
254-
("Signature verification failed: []",),
254+
(
255+
'Invalid input.',
256+
'DER encoded key value does not match specified signature algorithm',
257+
),
255258
)
256259

257260
def test_fail_included_cert_not_from_a_known_ca(self) -> None:
@@ -262,7 +265,7 @@ def test_fail_included_cert_not_from_a_known_ca(self) -> None:
262265
verify_xml_signature(xml_doc, trusted_x509_cert=None)
263266
self.assertEqual(
264267
cm.exception.args,
265-
('unable to get local issuer certificate',),
268+
('validation failed: cert is not valid at validation time',),
266269
)
267270

268271
def test_fail_signed_data_modified(self) -> None:

0 commit comments

Comments
 (0)