Skip to content

Commit

Permalink
feat(PYTHON3.12): ✨ new python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
tyki6 committed Jul 10, 2024
1 parent 73c4d58 commit 0544d0a
Show file tree
Hide file tree
Showing 29 changed files with 1,369 additions and 1,312 deletions.
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

9 changes: 5 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ on:
jobs:
lint:
runs-on: "ubuntu-latest"
name: "Run pre-commit"
name: "Run ruff"
steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v2"
with:
python-version: "3.11"
- name: "Install dependencies"
run: |
pip install pre-commit
- name: "Run pre-commit"
mypy --install-types --non-interactive
poetry install
- name: "Run ruff"
run: "make lint"
hadolint:
runs-on: "ubuntu-latest"
Expand All @@ -39,5 +40,5 @@ jobs:
- name: "Install dependencies"
run: |
pip install docstr-coverage
- name: "Run pre-commit"
- name: "Run docstr"
run: "make docstr"
2 changes: 1 addition & 1 deletion .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: "actions/checkout@v2"
Expand Down
44 changes: 0 additions & 44 deletions .pre-commit-config.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions .pyup.yml

This file was deleted.

8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

## [2.0.0] - 10-07-2024
### Added
- python 3.12 compliance
- ruff linter
- adding mypy for typing
- poetry update
- fix pypi authentification
## [1.6.1] - 10-03-2022
### Added
- python 3.11 compliance
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM bitnami/python:3.11 as base
FROM bitnami/python:3.12 as base
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
WORKDIR /app

Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ install:
install-docs:
cd docs && pip install -r requirements.txt && cd ..
lint:
pre-commit run --all-files
poetry run ruff check --fix . && poetry run ruff format .
type:
poetry run mypy .
tox:
pip install tox tox-gh-actions
tox
Expand Down Expand Up @@ -45,6 +47,7 @@ help:
@echo "make install Install requirements."
@echo "make install-docs Install docs requirements."
@echo "make lint Run Lint."
@echo "make type Run mypy."
@echo "make docstr Run docstr report."
@echo "make tox Run Unit test tox."
@echo "make test Run Unit test."
Expand Down
7 changes: 7 additions & 0 deletions docs/source/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.
## [2.0.0] - 10-07-2024
### Added
- python 3.12 compliance
- ruff linter
- adding mypy for typing
- poetry update
- fix pypi authentification

## [1.6.1] - 10-03-2022
### Added
Expand Down
6 changes: 4 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------

from typing import Any

project = "myjwt"
copyright = "2020, matthieu Bouamama"
author = "matthieu Bouamama"

# The full version, including alpha/beta/rc tags
release = "1.2.0"
release = "2.0.0"


# -- General configuration ---------------------------------------------------
Expand Down Expand Up @@ -90,7 +92,7 @@
##################################################
# Options for LaTeX Output
##################################################
latex_elements = {
latex_elements: Any = {
# 'papersize': 'letterpaper', # The paper size ('letterpaper' or 'a4paper')
# 'pointsize': '10pt', # The font size ('10pt', '11pt' or '12pt')
# 'preamble': '', # Additional stuff for the LaTeX preamble
Expand Down
8 changes: 2 additions & 6 deletions examples/01-modify-jwt/modify-jwt.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from myjwt.modify_jwt import add_header
from myjwt.modify_jwt import add_payload
from myjwt.modify_jwt import change_payload
from myjwt.utils import encode_jwt
from myjwt.utils import jwt_to_json
from myjwt.utils import SIGNATURE
from myjwt.modify_jwt import add_header, add_payload, change_payload
from myjwt.utils import SIGNATURE, encode_jwt, jwt_to_json

jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjpudWxsfQ.Tr0VvdP6rVBGBGuI_luxGCOaz6BbhC6IxRTlKOW8UjM"
# header {"typ": "JWT", "alg": "HS256"}
Expand Down
4 changes: 1 addition & 3 deletions examples/02-none-vulnerability/none-vulnerability.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from myjwt.modify_jwt import change_payload
from myjwt.utils import encode_jwt
from myjwt.utils import jwt_to_json
from myjwt.utils import SIGNATURE
from myjwt.utils import SIGNATURE, encode_jwt, jwt_to_json
from myjwt.vulnerabilities import none_vulnerability

jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjpudWxsfQ.Tr0VvdP6rVBGBGuI_luxGCOaz6BbhC6IxRTlKOW8UjM"
Expand Down
10 changes: 3 additions & 7 deletions examples/03-sign-key/sign-key.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from myjwt.modify_jwt import change_payload
from myjwt.modify_jwt import signature
from myjwt.modify_jwt import change_payload, signature
from myjwt.utils import jwt_to_json
from myjwt.variables import INVALID_SIGNATURE
from myjwt.variables import VALID_SIGNATURE
from myjwt.variables import INVALID_SIGNATURE, VALID_SIGNATURE

jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjpudWxsfQ.Tr0VvdP6rVBGBGuI_luxGCOaz6BbhC6IxRTlKOW8UjM"
key = "pentesterlab"
Expand All @@ -19,7 +17,5 @@

# verify your jwt
print(
VALID_SIGNATURE
if new_jwt.split(".")[2] == jwt.split(".")[2]
else INVALID_SIGNATURE,
VALID_SIGNATURE if new_jwt.split(".")[2] == jwt.split(".")[2] else INVALID_SIGNATURE,
)
8 changes: 4 additions & 4 deletions myjwt/Exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InvalidJWT(Exception):
Invalid JWT
"""

def __init__(self, message):
def __init__(self, message: str):
self.message = message


Expand All @@ -17,7 +17,7 @@ class InvalidJwtJson(Exception):
Invalid InvalidJwtJson
"""

def __init__(self, message):
def __init__(self, message: str):
self.message = message


Expand All @@ -26,7 +26,7 @@ class InvalidParam(Exception):
Invalid Param
"""

def __init__(self, message):
def __init__(self, message: str):
self.message = message


Expand All @@ -35,5 +35,5 @@ class UnknownAlg(Exception):
UnknownAlg
"""

def __init__(self, message):
def __init__(self, message: str):
self.message = message
1 change: 1 addition & 0 deletions myjwt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""autogenerated"""

__version__ = "1.6.1"
__commit__ = "34a82dc12b295caaec3b5803ff553713c44765e0"
34 changes: 12 additions & 22 deletions myjwt/modify_jwt.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
"""
Package for modify your jwt(header, payload, signature)
"""

import base64
import hashlib
import hmac
from typing import Dict
from typing import Any

from myjwt.Exception import InvalidJwtJson
from myjwt.Exception import InvalidParam
from myjwt.Exception import UnknownAlg
from myjwt.utils import encode_jwt
from myjwt.utils import HEADER
from myjwt.utils import is_valid_jwt_json
from myjwt.utils import PAYLOAD
from myjwt.Exception import InvalidJwtJson, InvalidParam, UnknownAlg
from myjwt.utils import HEADER, PAYLOAD, encode_jwt, is_valid_jwt_json


def add_payload(jwt_json: Dict, payload) -> Dict:
def add_payload(jwt_json: dict[str, Any], payload: dict[str, Any]) -> dict[str, Any]:
"""
Add new key:value to jwt's payload.
Expand Down Expand Up @@ -50,7 +46,7 @@ def add_payload(jwt_json: Dict, payload) -> Dict:
return jwt_json


def add_header(jwt_json: Dict, header: Dict) -> Dict:
def add_header(jwt_json: dict[str, Any], header: dict[str, Any]) -> dict[str, Any]:
"""
Add new key:value to jwt's header.
Expand Down Expand Up @@ -85,7 +81,7 @@ def add_header(jwt_json: Dict, header: Dict) -> Dict:
return jwt_json


def change_alg(jwt_json: Dict, algo: str) -> Dict:
def change_alg(jwt_json: dict[str, Any], algo: str) -> dict[str, Any]:
"""
Change alg of your jwt.
Expand Down Expand Up @@ -113,7 +109,7 @@ def change_alg(jwt_json: Dict, algo: str) -> Dict:
return jwt_json


def change_payload(jwt_json: Dict, payload: Dict) -> Dict:
def change_payload(jwt_json: dict[str, Any], payload: dict[str, Any]) -> dict[str, Any]:
"""
Change the current payload to your jwt_json for the new payload given.
Expand All @@ -140,7 +136,7 @@ def change_payload(jwt_json: Dict, payload: Dict) -> Dict:
return jwt_json


def signature(jwt_json: Dict, key: str) -> str:
def signature(jwt_json: dict[str, Any], key: str) -> str:
"""
Sign your jwt.
Expand Down Expand Up @@ -176,9 +172,7 @@ def signature(jwt_json: Dict, key: str) -> str:
jwt.encode(),
hashlib.sha256,
).digest()
new_signature = (
base64.urlsafe_b64encode(signature_hmac).decode("UTF-8").strip("=")
)
new_signature = base64.urlsafe_b64encode(signature_hmac).decode("UTF-8").strip("=")
return jwt + "." + new_signature
elif jwt_json[HEADER]["alg"] == "HS384":
jwt = encode_jwt(jwt_json)
Expand All @@ -187,9 +181,7 @@ def signature(jwt_json: Dict, key: str) -> str:
jwt.encode(),
hashlib.sha384,
).digest()
new_signature = (
base64.urlsafe_b64encode(signature_hmac).decode("UTF-8").strip("=")
)
new_signature = base64.urlsafe_b64encode(signature_hmac).decode("UTF-8").strip("=")
return jwt + "." + new_signature
elif jwt_json[HEADER]["alg"] == "HS512":
jwt = encode_jwt(jwt_json)
Expand All @@ -198,9 +190,7 @@ def signature(jwt_json: Dict, key: str) -> str:
jwt.encode(),
hashlib.sha512,
).digest()
new_signature = (
base64.urlsafe_b64encode(signature_hmac).decode("UTF-8").strip("=")
)
new_signature = base64.urlsafe_b64encode(signature_hmac).decode("UTF-8").strip("=")
return jwt + "." + new_signature

raise UnknownAlg(
Expand Down
Loading

0 comments on commit 0544d0a

Please sign in to comment.