Skip to content

Conversation

@dxy0218
Copy link
Owner

@dxy0218 dxy0218 commented Sep 5, 2025

Summary

  • manage and send emojis with /emoji commands
  • support timed self-destructing messages and hiding/unhiding contacts
  • archive or favorite messages and export/import encrypted chat histories
  • centralize message ID handling and fix timestamp logging during media sends
  • track nicknames with join/leave notifications and allow changing them via /nick
  • add PyInstaller build script to produce a standalone Windows executable
  • rename startup banner, CLI, and build output to 隧道聊天
  • enable direct peer-to-peer chats by listening for incoming connections and performing a bidirectional Diffie-Hellman handshake
  • ensure full socket transfers and clean up temporary file handles after large-file receives

Testing

  • python -m py_compile encrypted_chat/*.py build_exe.py

https://chatgpt.com/codex/tasks/task_e_68ba7a272ecc832b95275853cb750de6

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Comment on lines +170 to +174
def send_encrypted(sock, payload, session_cipher, local_cipher):
"""Encrypt payload with local and session keys then send."""
locally_encrypted = local_cipher.encrypt(payload.encode())
session_encrypted = session_cipher.encrypt(locally_encrypted)
sock.sendall(session_encrypted)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P0] Avoid encrypting payloads with unshared local key

Messages are encrypted twice in send_encrypted: first with a locally generated Fernet key and then with the Diffie‑Hellman session key. The receiver reverses this in receive_messages, but load_or_create_key produces a random key.key on each host and there is no step that exchanges or synchronises that key with peers. As soon as two different machines connect, local_cipher.decrypt(...) raises InvalidToken and the receive loop exits, making chat sessions unusable unless users manually copy the same key.key between devices. If the intent is that the DH handshake secures the wire, the local cipher should only be used for at‑rest storage, not for network payloads.

Useful? React with 👍 / 👎.

Comment on lines +193 to +197
while True:
encrypted = sock.recv(65536)
if not encrypted:
break
locally_encrypted = session_cipher.decrypt(encrypted)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Buffer complete Fernet tokens before decrypting

The receive loop calls sock.recv(65536) once per iteration and immediately decrypts the result (receive_messages). TCP does not preserve message boundaries, so a single sendall of an encrypted chunk can be split across multiple recv calls or coalesced with adjacent messages. When this happens—especially for 32 KB file chunks whose encrypted tokens are ~44 KB—session_cipher.decrypt or local_cipher.decrypt will fail and the thread prints “Receive error” then stops processing further messages. A framing protocol or length-prefixed reads are needed here (and similarly in the server’s handle_client).

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants