Bug fix for mac verification step
This commit is contained in:
parent
5dc3fe4023
commit
f7db8f7fd9
1 changed files with 19 additions and 8 deletions
|
|
@ -188,13 +188,21 @@ async def on_to_device(client: AsyncClient, event):
|
||||||
print(f"Failed to confirm SAS: {resp}")
|
print(f"Failed to confirm SAS: {resp}")
|
||||||
|
|
||||||
elif isinstance(event, KeyVerificationMac):
|
elif isinstance(event, KeyVerificationMac):
|
||||||
print(f"Key verification MAC received from {event.sender} ({event.from_device}). Finalizing verification...")
|
# Extract device_id safely from the raw event payload
|
||||||
|
content = event.source.get("content", {})
|
||||||
|
from_device = (
|
||||||
|
content.get("from_device")
|
||||||
|
or event.source.get("sender_device")
|
||||||
|
or "*"
|
||||||
|
)
|
||||||
|
|
||||||
# 1. Send m.key.verification.done to complete the SAS protocol in Element Web
|
print(f"Key verification MAC received from {event.sender} ({from_device}). Finalizing verification...")
|
||||||
|
|
||||||
|
# 1. Send m.key.verification.done to complete the SAS exchange
|
||||||
done_msg = ToDeviceMessage(
|
done_msg = ToDeviceMessage(
|
||||||
"m.key.verification.done",
|
"m.key.verification.done",
|
||||||
event.sender,
|
event.sender,
|
||||||
event.from_device,
|
from_device,
|
||||||
{"transaction_id": event.transaction_id},
|
{"transaction_id": event.transaction_id},
|
||||||
)
|
)
|
||||||
resp = await client.to_device(done_msg)
|
resp = await client.to_device(done_msg)
|
||||||
|
|
@ -203,11 +211,14 @@ async def on_to_device(client: AsyncClient, event):
|
||||||
else:
|
else:
|
||||||
print(f"Sent m.key.verification.done for {event.transaction_id}.")
|
print(f"Sent m.key.verification.done for {event.transaction_id}.")
|
||||||
|
|
||||||
# 2. Mark the device as verified in matrix-nio's device store
|
# 2. Mark the sender's device as verified in nio's local device store
|
||||||
if event.sender in client.device_store and event.from_device in client.device_store[event.sender]:
|
if from_device != "*":
|
||||||
device = client.device_store[event.sender][event.from_device]
|
device = client.device_store.get(event.sender, {}).get(from_device)
|
||||||
|
if device:
|
||||||
client.verify_device(device)
|
client.verify_device(device)
|
||||||
print(f"✅ Device {event.from_device} for {event.sender} is now verified and trusted!")
|
print(f"✅ Device {from_device} for {event.sender} is now verified and trusted!")
|
||||||
|
else:
|
||||||
|
print(f"⚠️ Device {from_device} not found in store, but verification completed.")
|
||||||
|
|
||||||
elif isinstance(event, KeyVerificationCancel):
|
elif isinstance(event, KeyVerificationCancel):
|
||||||
print(f"Key verification cancelled by {event.sender}: {getattr(event, 'reason', 'No reason given')}")
|
print(f"Key verification cancelled by {event.sender}: {getattr(event, 'reason', 'No reason given')}")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue