fix: fresh node_uid on re-registration, remove duplicate ensure_registered call

This commit is contained in:
2026-06-07 11:50:40 +02:00
parent 6ed94916e9
commit b6bad09a2b
2 changed files with 67 additions and 18 deletions

View File

@@ -163,9 +163,11 @@ class IdentityIoT:
return f.read().strip()
except OSError:
pass
raw_uid = machine.unique_id()
h = uhashlib.sha256(raw_uid)
uid_hex = ubinascii.hexlify(h.digest()).decode()
# Fresh UID — hardware ID + random entropy so each new registration is unique
raw_uid = machine.unique_id()
entropy = bytes([urandom.getrandbits(8) for _ in range(16)])
h = uhashlib.sha256(raw_uid + entropy)
uid_hex = ubinascii.hexlify(h.digest()).decode()
with open(self._F_NODEID, 'w') as f:
f.write(uid_hex)
return uid_hex
@@ -294,4 +296,4 @@ def _normalize_b64(s: str) -> str:
class StateError(Exception):
pass
pass