Skip to content

Commit b829715

Browse files
committed
fix: warning about draft-ietf-jose-deprecate-none-rsa15-02
1 parent fba3066 commit b829715

8 files changed

Lines changed: 32 additions & 8 deletions

File tree

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ line-length = 120
7777
[tool.pytest.ini_options]
7878
pythonpath = ["src", "."]
7979
testpaths = ["tests"]
80-
filterwarnings = ["error"]
80+
filterwarnings = [
81+
"error::DeprecationWarning",
82+
"ignore::UserWarning",
83+
]
8184

8285
[tool.coverage.run]
8386
branch = true

src/joserfc/_rfc7515/model.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
from typing import Any, ClassVar
2+
from typing import Any, ClassVar, Literal
33
from abc import ABCMeta, abstractmethod
44
from .types import SegmentsDict, JSONSignatureDict
55
from ..errors import InvalidKeyTypeError
@@ -107,8 +107,10 @@ class JWSAlgModel(object, metaclass=ABCMeta):
107107
name: str
108108
description: str
109109
recommended: bool = False
110+
security_warning: str | None = None
111+
110112
key_type = "oct"
111-
algorithm_type = "JWS"
113+
algorithm_type: Literal["JWS"] = "JWS"
112114
algorithm_location = "sig"
113115

114116
def check_key_type(self, key: Any) -> None:

src/joserfc/_rfc7515/registry.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
2+
import warnings
23
from typing import Dict
34
from .model import JWSAlgModel
4-
from ..errors import UnsupportedAlgorithmError
5+
from ..errors import UnsupportedAlgorithmError, SecurityWarning
56
from ..registry import (
67
JWS_HEADER_REGISTRY,
78
Header,
@@ -66,7 +67,11 @@ def get_alg(self, name: str) -> JWSAlgModel:
6667
else:
6768
if name not in self.recommended:
6869
raise UnsupportedAlgorithmError(f"Algorithm of '{name}' is not recommended")
69-
return self.algorithms[name]
70+
71+
alg = self.algorithms[name]
72+
if alg.security_warning:
73+
warnings.warn(alg.security_warning, SecurityWarning)
74+
return alg
7075

7176
def check_header(self, header: Header) -> None:
7277
"""Check and validate the fields in header part of a JWS object."""

src/joserfc/_rfc7516/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ class KeyManagement:
229229
name: str
230230
description: str
231231
recommended: bool = False
232-
key_size: t.Optional[int] = None
232+
key_size: int | None = None
233233
key_types: t.List[str]
234+
security_warning: str | None = None
235+
234236
algorithm_type: t.Literal["JWE"] = "JWE"
235237
algorithm_location: t.Literal["alg"] = "alg"
236238
more_header_registry: HeaderRegistryDict = {}

src/joserfc/_rfc7516/registry.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
2+
import warnings
23
import typing as t
34
from .models import JWEAlgModel, JWEEncModel, JWEZipModel
4-
from ..errors import UnsupportedAlgorithmError
5+
from ..errors import UnsupportedAlgorithmError, SecurityWarning
56
from ..registry import (
67
Header,
78
HeaderRegistryDict,
@@ -91,7 +92,10 @@ def get_alg(self, name: str) -> JWEAlgModel:
9192
"""
9293
registry = self.algorithms["alg"]
9394
self._check_algorithm(name, registry)
94-
return registry[name]
95+
alg: JWEAlgModel = registry[name]
96+
if alg.security_warning:
97+
warnings.warn(alg.security_warning, SecurityWarning)
98+
return alg
9599

96100
def get_enc(self, name: str) -> JWEEncModel:
97101
"""Get the allowed ("enc") algorithm instance of the given name.

src/joserfc/_rfc7518/jwe_algs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def __init__(self, name: str, description: str, pad_fn: padding.AsymmetricPaddin
6060
self.description = description
6161
self.padding = pad_fn
6262
self.recommended = recommended
63+
if name == "RSA1_5":
64+
self.security_warning = 'JWE algorithm "RSA1_5" is deprecated, via draft-ietf-jose-deprecate-none-rsa15-02'
6365

6466
def encrypt_cek(self, cek: bytes, recipient: Recipient[RSAKey]) -> bytes:
6567
key = recipient.recipient_key

src/joserfc/_rfc7518/jws_algs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
class NoneAlgModel(JWSAlgModel):
3131
name = "none"
3232
description = "No digital signature or MAC performed"
33+
security_warning = 'JWS algorithm "none" is deprecated, via draft-ietf-jose-deprecate-none-rsa15-02'
3334

3435
def sign(self, msg: bytes, key: t.Any) -> bytes:
3536
return b""

src/joserfc/errors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from __future__ import annotations
22

33

4+
class SecurityWarning(UserWarning):
5+
"""Base class for warnings of security issues."""
6+
pass
7+
8+
49
class JoseError(Exception):
510
"""Base Exception for all errors in joserfc."""
611

0 commit comments

Comments
 (0)