Transmit hashed password

This commit is contained in:
Kovid Goyal 2021-09-13 12:00:38 +05:30
parent 78fd05c1c6
commit 38a5e38f88
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 16 additions and 7 deletions

View File

@ -18,7 +18,7 @@ from kitty.cli_stub import TransferCLIOptions
from kitty.fast_data_types import FILE_TRANSFER_CODE from kitty.fast_data_types import FILE_TRANSFER_CODE
from kitty.file_transmission import ( from kitty.file_transmission import (
Action, Compression, FileTransmissionCommand, FileType, NameReprEnum, Action, Compression, FileTransmissionCommand, FileType, NameReprEnum,
TransmissionType TransmissionType, encode_password
) )
from kitty.types import run_once from kitty.types import run_once
from kitty.typing import KeyEventType from kitty.typing import KeyEventType
@ -295,7 +295,7 @@ class SendManager:
def __init__(self, request_id: str, files: Tuple[File, ...], pw: Optional[str] = None): def __init__(self, request_id: str, files: Tuple[File, ...], pw: Optional[str] = None):
self.files = files self.files = files
self.password = pw or '' self.password = encode_password(request_id, pw) if pw else ''
self.fid_map = {f.file_id: f for f in self.files} self.fid_map = {f.file_id: f for f in self.files}
self.request_id = request_id self.request_id = request_id
self.state = SendState.waiting_for_permission self.state = SendState.waiting_for_permission

View File

@ -26,6 +26,12 @@ EXPIRE_TIME = 10 # minutes
MAX_ACTIVE_RECEIVES = 10 MAX_ACTIVE_RECEIVES = 10
def encode_password(request_id: str, pw: str) -> str:
import hashlib
q = request_id + ';' + pw
return 'sha256:' + hashlib.sha256(q.encode('utf-8', 'replace')).hexdigest()
class NameReprEnum(Enum): class NameReprEnum(Enum):
def __repr__(self) -> str: def __repr__(self) -> str:
@ -335,9 +341,12 @@ class ActiveReceive:
files: Dict[str, DestFile] files: Dict[str, DestFile]
accepted: bool = False accepted: bool = False
def __init__(self, id: str, quiet: int, password: str) -> None: def __init__(self, request_id: str, quiet: int, password: str) -> None:
self.id = id self.id = request_id
self.password = password self.password_ok: Optional[bool] = None
pw = get_options().file_transfer_password
if pw and password:
self.password_ok = encode_password(request_id, pw) == password
self.files = {} self.files = {}
self.last_activity_at = monotonic() self.last_activity_at = monotonic()
self.send_acknowledgements = quiet < 1 self.send_acknowledgements = quiet < 1
@ -559,8 +568,8 @@ class FileTransmission:
def start_receive(self, ar_id: str) -> None: def start_receive(self, ar_id: str) -> None:
ar = self.active_receives[ar_id] ar = self.active_receives[ar_id]
if ar.password: if ar.password_ok is not None:
self.handle_send_confirmation(ar_id, {'response': 'y' if ar.password == get_options().file_transfer_password else 'n'}) self.handle_send_confirmation(ar_id, {'response': 'y' if ar.password_ok else 'n'})
return return
boss = get_boss() boss = get_boss()
window = boss.window_id_map.get(self.window_id) window = boss.window_id_map.get(self.window_id)