Skip to content

Commit

Permalink
Fix issue with latest version of cffi (#56)
Browse files Browse the repository at this point in the history
* Fix the version in the changelog
* Freeze the version of pyflakes to resolve klen/pylama#224
* Update the versions of oscrypt and asn1crypto
* Use SMIMECapabilites from asn1crypto instead of the custom class
  • Loading branch information
abhishek-ram authored Dec 11, 2022
1 parent 7f11cb4 commit 7cadd1a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- "master"
jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10"]
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release History

## 1.4.0 - 2022-02-06
## 1.4.1 - 2022-02-06

* fix: freezing pylama version to avoid breaking changes
* feat: option to pass custom domain for AS2 message-id generation
Expand Down
96 changes: 30 additions & 66 deletions pyas2lib/cms.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""Define functions related to the CMS operations such as encrypting, signature, etc."""
import hashlib
import zlib
from collections import OrderedDict
from datetime import datetime, timezone

from asn1crypto import cms, core, algos
from asn1crypto.cms import SMIMECapabilityIdentifier
from oscrypto import asymmetric, symmetric, util

from pyas2lib.constants import DIGEST_ALGORITHMS
from pyas2lib.exceptions import (
AS2Exception,
DecompressionError,
DecryptionError,
IntegrityError,
)
from pyas2lib.constants import DIGEST_ALGORITHMS
from pyas2lib.utils import normalize_digest_alg


Expand Down Expand Up @@ -277,68 +277,6 @@ def sign_message(
digest_func.update(data_to_sign)
message_digest = digest_func.digest()

class SmimeCapability(core.Sequence):
"""Define the possible list of Smime Capability."""

_fields = [
("0", core.Any, {"optional": True}),
("1", core.Any, {"optional": True}),
("2", core.Any, {"optional": True}),
("3", core.Any, {"optional": True}),
("4", core.Any, {"optional": True}),
]

class SmimeCapabilities(core.Sequence):
"""Define the Smime Capabilities supported by pyas2."""

_fields = [
("0", SmimeCapability),
("1", SmimeCapability, {"optional": True}),
("2", SmimeCapability, {"optional": True}),
("3", SmimeCapability, {"optional": True}),
("4", SmimeCapability, {"optional": True}),
("5", SmimeCapability, {"optional": True}),
]

smime_cap = OrderedDict(
[
(
"0",
OrderedDict(
[("0", core.ObjectIdentifier("2.16.840.1.101.3.4.1.42"))]
),
),
(
"1",
OrderedDict(
[("0", core.ObjectIdentifier("2.16.840.1.101.3.4.1.2"))]
),
),
(
"2",
OrderedDict([("0", core.ObjectIdentifier("1.2.840.113549.3.7"))]),
),
(
"3",
OrderedDict(
[
("0", core.ObjectIdentifier("1.2.840.113549.3.2")),
("1", core.Integer(128)),
]
),
),
(
"4",
OrderedDict(
[
("0", core.ObjectIdentifier("1.2.840.113549.3.4")),
("1", core.Integer(128)),
]
),
),
]
)

signed_attributes = cms.CMSAttributes(
[
cms.CMSAttribute(
Expand Down Expand Up @@ -376,8 +314,34 @@ class SmimeCapabilities(core.Sequence):
cms.CMSAttribute(
{
"type": cms.CMSAttributeType("1.2.840.113549.1.9.15"),
"values": cms.SetOfAny(
[core.Any(SmimeCapabilities(smime_cap))]
"values": cms.SetOfSMIMECapabilites(
[
cms.SMIMECapabilites(
[
SMIMECapabilityIdentifier(
{"capability_id": "2.16.840.1.101.3.4.1.42"}
),
SMIMECapabilityIdentifier(
{"capability_id": "2.16.840.1.101.3.4.1.2"}
),
SMIMECapabilityIdentifier(
{"capability_id": "1.2.840.113549.3.7"}
),
SMIMECapabilityIdentifier(
{
"capability_id": "1.2.840.113549.3.2",
"parameters": core.Integer(128),
}
),
SMIMECapabilityIdentifier(
{
"capability_id": "1.2.840.113549.3.4",
"parameters": core.Integer(128),
}
),
]
)
]
),
}
),
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from setuptools import setup, find_packages

install_requires = [
"asn1crypto==1.4.0",
"oscrypto==1.2.1",
"asn1crypto==1.5.1",
"oscrypto==1.3.0",
"pyOpenSSL==21.0.0",
]

Expand All @@ -16,6 +16,7 @@
"pylama-pylint==3.1.1",
"black==22.6.0",
"pytest-black==0.3.12",
"pyflakes==2.4.0",
]

setup(
Expand Down

0 comments on commit 7cadd1a

Please sign in to comment.