Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kislyuk committed Oct 8, 2024
1 parent 5a59f52 commit fe180a5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion http_message_signatures/resolvers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import urllib.parse

import http_sfv
import http_sf

from .exceptions import HTTPMessageSignaturesException
from .structures import CaseInsensitiveDict
Expand Down
18 changes: 7 additions & 11 deletions http_message_signatures/signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit fe180a5

Please sign in to comment.