Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace http-sfv with http-sf #14

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="[email protected]",
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
Loading