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 cryptography with hashlib #278

Merged
merged 2 commits into from
Aug 27, 2023
Merged
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ classifiers = [
"Programming Language :: Python :: 3",
]
dependencies = [
"cryptography>=40.0.0",
"pyzipper>=0.3.6",
]
description = "A library to gather information from ETS project files used for KNX"
Expand Down
1 change: 0 additions & 1 deletion requirements_production.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
cryptography==41.0.3
pyzipper==0.3.6
13 changes: 7 additions & 6 deletions xknxproject/zip/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import base64
from collections.abc import Iterator
from contextlib import contextmanager
import hashlib
import logging
from pathlib import Path
import re
from typing import IO
from zipfile import Path as ZipPath, ZipFile, ZipInfo

from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
import pyzipper

from xknxproject.const import ETS_4_2_SCHEMA_VERSION, ETS_6_SCHEMA_VERSION
Expand Down Expand Up @@ -173,11 +172,13 @@ def _get_schema_version(namespace: str) -> int:

def _generate_ets6_zip_password(password: str) -> bytes:
"""Generate ZIP archive password."""

return base64.b64encode(
PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
hashlib.pbkdf2_hmac(
hash_name="sha256",
password=password.encode("utf-16-le"),
salt=b"21.project.ets.knx.org",
iterations=65536,
).derive(password.encode("utf-16-le"))
dklen=32,
)
)