Skip to content

Commit ab4232c

Browse files
committed
XAdES fixes
1 parent f5ee30f commit ab4232c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

signxml/xades/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ def __init__(
7777
signature_policy: Optional[Dict] = None,
7878
claimed_roles: Optional[List] = None,
7979
data_object_format: Dict = default_data_object_format,
80+
**kwargs,
8081
) -> None:
81-
super().__init__()
82+
super().__init__(**kwargs)
8283
if self.sign_alg.startswith("hmac-"):
8384
raise Exception("HMAC signatures are not supported by XAdES")
8485
self.signature_annotators.append(self._build_xades_ds_object)
@@ -96,6 +97,7 @@ def __init__(
9697
self.signature_policy = signature_policy
9798
self.claimed_roles = claimed_roles
9899
self.data_object_format = data_object_format
100+
self.namespaces.update(xades=namespaces.xades)
99101

100102
def sign(self, data, always_add_key_value=True, **kwargs):
101103
return super().sign(data=data, always_add_key_value=always_add_key_value, **kwargs)
@@ -153,7 +155,8 @@ def _add_reference_to_signed_info(self, sig_root, node_to_reference):
153155
def add_signing_time(self, signed_signature_properties, sig_root, signing_settings: SigningSettings):
154156
signing_time = SubElement(signed_signature_properties, xades_tag("SigningTime"), nsmap=self.namespaces)
155157
# TODO: make configurable
156-
signing_time.text = datetime.datetime.utcnow().isoformat()
158+
utc_iso_ts = datetime.datetime.utcnow().isoformat(timespec="seconds")
159+
signing_time.text = f"{utc_iso_ts}+00:00"
157160

158161
def add_signing_certificate(self, signed_signature_properties, sig_root, signing_settings: SigningSettings):
159162
# TODO: check if we need to support SigningCertificate
@@ -193,10 +196,10 @@ def add_signature_policy_identifier(self, signed_signature_properties, sig_root,
193196
description = SubElement(sig_policy_id, xades_tag("Description"), nsmap=self.namespaces)
194197
description.text = self.signature_policy["Description"]
195198
sig_policy_hash = SubElement(signature_policy_id, xades_tag("SigPolicyHash"), nsmap=self.namespaces)
196-
digest_alg = self.known_digest_tags[self.digest_alg]
199+
digest_alg = self.known_digest_tags[self.signature_policy["DigestMethod"]]
197200
SubElement(sig_policy_hash, ds_tag("DigestMethod"), nsmap=self.namespaces, Algorithm=digest_alg)
198201
digest_value_node = SubElement(sig_policy_hash, ds_tag("DigestValue"), nsmap=self.namespaces)
199-
digest_value_node.text = b64encode(b"FIXME").decode()
202+
digest_value_node.text = b64encode(self.signature_policy["DigestValue"]).decode()
200203

201204
def add_signature_production_place(self, signed_signature_properties, sig_root, signing_settings: SigningSettings):
202205
# SignatureProductionPlace or SignatureProductionPlaceV2

test/test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,10 @@ class TestXAdES(unittest.TestCase, LoadExampleKeys):
569569
"nonconformant-dss1770.xml": 3,
570570
}
571571
signature_policy = {
572-
"Identifier": "Hello",
573-
"Description": "XAdES",
572+
"Identifier": "http://www.facturae.es/politica_de_firma_formato_facturae/politica_de_firma_formato_facturae_v3_1.pdf",
573+
"Description": "Política de Firma FacturaE v3.1",
574+
"DigestMethod": "sha1",
575+
"DigestValue": b":\x18\xb1\x97\xab\xa9\x0f\xa6\xaf\xf0\xde\xe9\x12\xf0\xc0\x06\x11\x0b\xea\x13",
574576
}
575577
claimed_roles = ["signer"]
576578
data_object_format = {"Description": "Important Document", "MimeType": "text/xml"}

0 commit comments

Comments
 (0)