Skip to content

feat: Add Protocol 3.4 Session Key Negotiation #284

@damacus

Description

@damacus

feat: Add Protocol 3.4 Session Key Negotiation

Summary

Protocol 3.4 devices require a 3-way session key negotiation before encrypted
communication can begin. This is required for some newer Eufy vacuum models.

Technical Details

Based on tinytuya protocol notes:

Session Key Negotiation Flow

  1. Client → Device: Send 16-byte nonce
  2. Device → Client: Respond with 16-byte device nonce + 32-byte HMAC-SHA256
    of client nonce
  3. Client → Device: Send 32-byte HMAC-SHA256 of device nonce

Session Key Calculation

tmp_key = bytes([a^b for (a,b) in zip(device_nonce, client_nonce)])
cipher = AESCipher(real_key)
session_key = cipher.encrypt(tmp_key, use_base64=False, pad=False, iv=client_nonce[:12])[12:28]

Known quirk: If the first byte of the resulting session key is 0x00, the
device considers it invalid and negotiation must restart.

Current State

  • ✅ Protocol 3.4 HMAC-SHA256 checksum support added
  • ❌ Session key negotiation not implemented

Affected Models (Suspected)

Models that may require session key negotiation:

Implementation Notes

  • Session keys are per-connection and must be renegotiated on reconnect
  • The existing TuyaCipher class will need modification to support session keys
  • Connection flow in TuyaDevice needs to include negotiation step

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions