Skip to content

Add startup password, configurable server address, and image transfer#2

Open
dxy0218 wants to merge 1 commit intomainfrom
codex/fix-code-errors-ytj61h
Open

Add startup password, configurable server address, and image transfer#2
dxy0218 wants to merge 1 commit intomainfrom
codex/fix-code-errors-ytj61h

Conversation

@dxy0218
Copy link
Copy Markdown
Owner

@dxy0218 dxy0218 commented Sep 5, 2025

Summary

  • allow connecting to a specified IP address via command-line argument
  • require a password before enabling chat features
  • reuse standard 2048-bit Diffie-Hellman parameters to avoid regeneration
  • support sending and receiving images, videos, and arbitrary files via chunked base64 encoding

Testing

  • python -m py_compile encrypted_chat/*.py

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

Copy link
Copy Markdown

@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 +74 to +98
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()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P1] Limit encrypted chunk size before reading with fixed buffer

File/video transfer encrypts each 32 KB chunk twice (send_large_filesend_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 👍 / 👎.

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.

1 participant