Skip to content

Add Device Identity and Registration System Using Ed25519 and TCP with Persistent Device Identity Support#2

Open
ShigrafS wants to merge 3 commits intomainfrom
feat/iden
Open

Add Device Identity and Registration System Using Ed25519 and TCP with Persistent Device Identity Support#2
ShigrafS wants to merge 3 commits intomainfrom
feat/iden

Conversation

@ShigrafS
Copy link
Owner

🧾 Summary

This PR introduces a new device registration system by replacing the existing tcp_server.py implementation with a modular architecture consisting of:

  • identity.py: Generates and persists a unique device identity and public key.
  • register_client.py: Handles client-side registration to the central registry server.
  • registry_server.py: Central registry server to assign unique 3-digit IDs and store device metadata.

The change adds 133 lines of new code and removes 126 lines by removing the monolithic tcp_server.py.


📂 Changes Overview

✅ Added:

  1. identity.py

    • Generates Ed25519 key pairs for the device.
    • Persists private keys in device_key.pem.
    • Returns a unique device_id (first 20 chars of SHA-256 hash of the public key) and the PEM-encoded public key.
  2. register_client.py

    • Calls get_device_id_and_key() from identity.py.
    • Sends device info (device_id, public key, IP, port) to a registry server over TCP.
    • Displays the server's response after registration.
  3. registry_server.py

    • Listens on port 9000 for incoming client registrations.
    • Assigns a unique 3-digit number (starting from 100) to each device.
    • Stores device data (ID, public key, IP, port) in a local JSON file db.json.
    • Returns a JSON response to the client with registration status and number.

❌ Removed:

  • tcp_server.py

    • Removed in favor of the new, modular, and more maintainable system.

🎯 Motivation

The previous tcp_server.py lacked modularity, device identity persistence, and proper state tracking for registered clients.

This PR addresses those issues by:

  • Separating concerns (identity generation, client logic, server logic).
  • Introducing persistent identities and registry.
  • Improving maintainability, extensibility, and clarity of the registration process.

⚠️ Potential Issues / Considerations

  • Key Persistence: Currently stores private key in plain PEM format — consider encrypting it for production.
  • Concurrency: registry_server.py uses basic threads; future improvements might involve async I/O or thread pooling for scalability.
  • Security: Registration over raw TCP lacks authentication and encryption — may need TLS and device signature verification.

🧪 How to Test

  1. Run the registry server:

    python registry_server.py
  2. Register a client device:

    python register_client.py
  3. Expected Behavior:

    • Client prints registration response with assigned number.
    • Server updates db.json with new device metadata.
    • device_key.pem is created on first run and reused thereafter.

📌 Related Tickets / References

  • Replaces outdated tcp_server.py
  • Lays groundwork for future features like secure communication and authentication.

ShigrafS and others added 3 commits August 19, 2025 22:59
Signed-off-by: ShigrafS <shigrafsalik@proton.me>
Signed-off-by: ShigrafS <shigrafsalik@proton.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants