Add startup password, configurable server address, and image transfer#2
Add startup password, configurable server address, and image transfer#2
Conversation
There was a problem hiding this comment.
Codex Review: Here are some suggestions.
Reply with @codex fix comments to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
| def send_large_file(sock, path, tag, session_cipher, local_cipher, chunk_size=32768): | ||
| """Send large files (videos or generic files) in chunks.""" | ||
| filename = os.path.basename(path) | ||
| size = os.path.getsize(path) | ||
| send_encrypted(sock, f"{tag}START|{filename}|{size}", session_cipher, local_cipher) | ||
| with open(path, "rb") as f: | ||
| while True: | ||
| chunk = f.read(chunk_size) | ||
| if not chunk: | ||
| break | ||
| b64 = base64.b64encode(chunk).decode() | ||
| send_encrypted(sock, f"{tag}CHUNK|{filename}|{b64}", session_cipher, local_cipher) | ||
| send_encrypted(sock, f"{tag}END|{filename}", session_cipher, local_cipher) | ||
|
|
||
|
|
||
| def receive_messages(sock, session_cipher, local_cipher): | ||
| """Continuously receive and process messages from the server.""" | ||
| ongoing = {} | ||
| try: | ||
| while True: | ||
| encrypted = sock.recv(65536) | ||
| if not encrypted: | ||
| break | ||
| locally_encrypted = session_cipher.decrypt(encrypted) | ||
| message = local_cipher.decrypt(locally_encrypted).decode() |
There was a problem hiding this comment.
[P1] Limit encrypted chunk size before reading with fixed buffer
File/video transfer encrypts each 32 KB chunk twice (send_large_file → send_encrypted), which base64-expands the payload to roughly 77 KB. Both the client receiver and the server call recv(65536) and immediately decrypt the returned bytes as a complete Fernet token. When a chunk exceeds the 64 KB buffer the socket can split the token across multiple reads, and decryption will raise InvalidToken, terminating the transfer. Any file larger than ~26 KB (after base64 + double encryption) will consistently fail. Consider reducing the chunk size or framing the messages so the receiver reads until an entire token has been collected before decrypting.
Useful? React with 👍 / 👎.
Summary
Testing
python -m py_compile encrypted_chat/*.pyhttps://chatgpt.com/codex/tasks/task_e_68ba7a272ecc832b95275853cb750de6