Correctly handle & warn about key-less devices

This commit is contained in:
miruka 2020-06-25 16:10:44 -04:00
parent a15a101ce0
commit d35173adc3
4 changed files with 49 additions and 10 deletions

View File

@ -1,5 +1,6 @@
# TODO
- verify & delete devices
- sessions page size
- flickshortcuts
- avatar upload/change component

View File

@ -9,6 +9,7 @@ import logging as log
import platform
import re
import sys
import textwrap
import traceback
from contextlib import suppress
from copy import deepcopy
@ -1261,17 +1262,28 @@ class MatrixClient(nio.AsyncClient):
"""Get sorted list of devices and their info for our user."""
def get_type(device_id: str) -> str:
# Return "current", "verified", "blacklisted", "ignored" or "unset"
# Return "current", "no_keys", "verified", "blacklisted",
# "ignored" or "unset"
if device_id == self.device_id:
return "current"
if device_id not in self.olm.device_store[self.user_id]:
return "unset"
return "no_keys"
trust = self.olm.device_store[self.user_id][device_id].trust_state
return trust.name
def get_ed25519(device_id: str) -> str:
key = ""
if device_id == self.device_id:
key = self.olm.account.identity_keys["ed25519"]
elif device_id in self.olm.device_store[self.user_id]:
key = self.olm.device_store[self.user_id][device_id].ed25519
return " ".join(textwrap.wrap(key, 4))
devices = [
{
"id": device.id,
@ -1280,14 +1292,16 @@ class MatrixClient(nio.AsyncClient):
"last_seen_date": device.last_seen_date or ZeroDate,
"last_seen_country": "",
"type": get_type(device.id),
"ed25519_key": get_ed25519(device.id),
}
for device in (await self.devices()).devices
]
# Reversed due to sorted(reverse=True) call below
types_order = {
"current": 4,
"unset": 3,
"current": 5,
"unset": 4,
"no_keys": 3,
"verified": 2,
"ignored": 1,
"blacklisted": 0,

View File

@ -103,6 +103,27 @@ HTile {
HMenuSeparator {}
HLabel {
id: noKeysLabel
visible: model.type === "no_keys"
width: parent.width
height: visible ? implicitHeight : 0 // avoid empty space
wrapMode: HLabel.Wrap
horizontalAlignment: Qt.AlignHCenter
textFormat: HLabel.RichText
color: theme.colors.warningText
text: qsTr(
"This session doesn't support encryption or " +
"failed to upload a verification key"
)
}
HMenuSeparator {
visible: noKeysLabel.visible
height: visible ? implicitHeight : 0
}
HLabeledItem {
width: parent.width
label.text: qsTr("Actions:")
@ -112,8 +133,10 @@ HTile {
width: parent.width
ApplyButton {
enabled:
model.type !== "current" && model.type !== "verified"
enabled: [
"unset", "ignored", "blacklisted",
].includes(model.type)
text: qsTr("Verify")
icon.name: "device-verify"
}

View File

@ -22,10 +22,11 @@ HRowLayout {
text:
section === "current" ? qsTr("Current session") :
section === "unset" ? qsTr("Unverified") :
section === "no_keys" ? qsTr("Unverifiable") :
section === "verified" ? qsTr("Verified") :
section === "ignored" ? qsTr("Ignored") :
section === "blacklisted" ? qsTr("Blacklisted") :
qsTr("Unverified")
qsTr("Blacklisted")
tristate: true
@ -67,10 +68,10 @@ HRowLayout {
verticalAlignment: Qt.AlignVCenter
color:
section === "current" || section === "verified" ?
["current", "verified"].includes(section) ?
theme.colors.positiveText :
section === "unset" || section === "ignored" ?
["unset", "ignored", "no_keys"].includes(section) ?
theme.colors.warningText :
theme.colors.errorText