From fe180a5845f21f3b5d6319806a903c4237b50ab2 Mon Sep 17 00:00:00 2001 From: Andrey Kislyuk Date: Tue, 8 Oct 2024 05:55:47 -0700 Subject: [PATCH] WIP --- http_message_signatures/resolvers.py | 2 +- http_message_signatures/signatures.py | 18 +++++++----------- setup.py | 4 ++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/http_message_signatures/resolvers.py b/http_message_signatures/resolvers.py index 16cba59..55de8aa 100644 --- a/http_message_signatures/resolvers.py +++ b/http_message_signatures/resolvers.py @@ -1,6 +1,6 @@ import urllib.parse -import http_sfv +import http_sf from .exceptions import HTTPMessageSignaturesException from .structures import CaseInsensitiveDict diff --git a/http_message_signatures/signatures.py b/http_message_signatures/signatures.py index 1e5510c..c3898d6 100644 --- a/http_message_signatures/signatures.py +++ b/http_message_signatures/signatures.py @@ -3,7 +3,7 @@ import logging from typing import Any, Dict, List, Optional, Sequence, Tuple, Type -import http_sfv +import http_sf from .algorithms import HTTPSignatureAlgorithm, signature_algorithms from .exceptions import HTTPMessageSignaturesException, InvalidSignature @@ -36,7 +36,7 @@ def _build_signature_base( sig_elements = collections.OrderedDict() component_resolver = self.component_resolver_class(message) for component_id in covered_component_ids: - component_key = str(http_sfv.List([component_id])) + component_key = http_sf.ser([component_id]) # TODO: model situations when header occurs multiple times component_value = component_resolver.resolve(component_id) if str(component_id.value).lower() != str(component_id.value): @@ -49,9 +49,8 @@ def _build_signature_base( f'Component ID "{component_key}" appeared multiple times in ' "signature input" ) sig_elements[component_key] = component_value - sig_params_node = http_sfv.InnerList(covered_component_ids) - sig_params_node.params.update(signature_params) - sig_elements['"@signature-params"'] = str(sig_params_node) + sig_params_node = [(list(covered_component_ids), signature_params)] + sig_elements['"@signature-params"'] = http_sf.ser(sig_params_node) sig_base = "\n".join(f"{k}: {v}" for k, v in sig_elements.items()) return sig_base, sig_params_node, sig_elements @@ -104,10 +103,8 @@ def sign( sig_label = self.DEFAULT_SIGNATURE_LABEL if label is not None: sig_label = label - sig_input_node = http_sfv.Dictionary({sig_label: sig_params_node}) - message.headers["Signature-Input"] = str(sig_input_node) - sig_node = http_sfv.Dictionary({sig_label: signature}) - message.headers["Signature"] = str(sig_node) + message.headers["Signature-Input"] = http_sf.ser({sig_label: sig_params_node}) + message.headers["Signature"] = http_sf.ser({sig_label: signature}) class HTTPMessageVerifier(HTTPSignatureHandler): @@ -118,8 +115,7 @@ def _parse_dict_header(self, header_name, headers): if header_name not in headers: raise InvalidSignature(f'Expected "{header_name}" header field to be present') try: - dict_header_node = http_sfv.Dictionary() - dict_header_node.parse(headers[header_name].encode()) + dict_header_node = http_sf.parse(headers[header_name].encode(), tltype="dictionary") except Exception as e: raise InvalidSignature(f'Malformed structured header field "{header_name}"') from e return dict_header_node diff --git a/setup.py b/setup.py index 7b5b745..d050708 100755 --- a/setup.py +++ b/setup.py @@ -8,13 +8,13 @@ license="Apache Software License", author="Andrey Kislyuk", author_email="kislyuk@gmail.com", - description="An implementation of the IETF HTTP Message Signatures draft standard", + description="An implementation of RFC 9421, the IETF HTTP Message Signatures standard", long_description=open("README.rst").read(), use_scm_version={ "write_to": "http_message_signatures/version.py", }, setup_requires=["setuptools_scm >= 3.4.3"], - install_requires=["http-sfv >= 0.9.3", "cryptography >= 36.0.2"], + install_requires=["http-sf >= 1.0.1", "cryptography >= 36.0.2"], extras_require={ "tests": [ "flake8",