Skip to content

Commit 9df3da9

Browse files
Release updates (#138)
* Bad password notification * Check is file is not password protected
1 parent 7593941 commit 9df3da9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

api/transfer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ async def post(self, request) -> PlainTextResponse:
7676
enums.NotificationType.BAD_PASSWORD_DURING_IMPORT,
7777
print_traceback=False,
7878
)
79+
notification.send_organization_update(
80+
project_id, f"bad_password:{project_id}", True
81+
)
7982
except Exception:
8083
file_import_error_handling(task, project_id, is_global_update)
8184
notification.send_organization_update(

util/file.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
def zip_to_json(local_file_name: str, key: Optional[str] = None) -> Dict[str, Any]:
1111
zip_file = ZipFile(local_file_name)
1212
file_name = zip_file.namelist()[0]
13+
if key and not is_zip_password_protected(local_file_name):
14+
raise BadPasswordError
1315
if key:
1416
key = key.encode()
1517
zip_file.setpassword(key)
@@ -22,6 +24,15 @@ def zip_to_json(local_file_name: str, key: Optional[str] = None) -> Dict[str, An
2224
raise BadPasswordError
2325

2426

27+
def is_zip_password_protected(file_name: str) -> bool:
28+
zf = ZipFile(file_name)
29+
for zinfo in zf.infolist():
30+
is_encrypted = zinfo.flag_bits & 0x1
31+
if is_encrypted:
32+
return True
33+
return False
34+
35+
2536
def zip_to_json_file(zip_file_path: str, key: Optional[str] = None) -> str:
2637
json_data = zip_to_json(zip_file_path, key)
2738
file_name = __get_free_file_path(f"{zip_file_path}.json")

0 commit comments

Comments
 (0)