fix(security): treat a new identity key as a message request, never as a known contact
A stranger could pick the display name of an existing contact ("Mom")
and appear as that contact. Messages from a key that is not in the
contact list now open a message request labelled "(unknown)": no
replies, read receipts, typing indicators, calls or name in
notifications until the user accepts it and names the contact
themselves. Names that look like an existing contact (case, diacritics,
Cyrillic/Greek homoglyphs, invisible characters) also show a warning in
the real contact's chat.
When the relay account of a known contact shows up with a different
key, the chat shows "safety number changed", verification is cleared
and the session that now belongs to the other key is dropped before
sending, so a reply never goes to the new key.
This commit is contained in:
@@ -18,6 +18,13 @@ class Contact {
|
||||
/// Profilová fotka, kterou kontakt sdílí (null = iniciály).
|
||||
AvatarRef? avatar;
|
||||
|
||||
/// Přijatý kontakt. False = žádost o zprávu: napsal mi někdo, koho jsem
|
||||
/// si sám nepřidal (nebo jsem ho potkal jen ve skupině), takže jméno
|
||||
/// i fotku si zvolil on. Dokud ho nepřijmu, appka ho značí jako
|
||||
/// neznámého, neukazuje jeho fotku, nezvoní jeho hovory a nedává mu
|
||||
/// vědět, že čtu nebo píšu.
|
||||
bool accepted;
|
||||
|
||||
Contact({
|
||||
required this.displayName,
|
||||
required this.publicIdentity,
|
||||
@@ -26,6 +33,7 @@ class Contact {
|
||||
this.notes,
|
||||
this.blocked = false,
|
||||
this.avatar,
|
||||
this.accepted = true,
|
||||
});
|
||||
|
||||
/// ID kontaktu = fingerprint identity klíče (identita = klíč).
|
||||
@@ -41,12 +49,14 @@ class Contact {
|
||||
factory Contact.fromPublicIdentity(
|
||||
PublicIdentity identity, {
|
||||
bool verified = false,
|
||||
bool accepted = true,
|
||||
}) {
|
||||
return Contact(
|
||||
displayName: identity.displayName,
|
||||
publicIdentity: identity,
|
||||
addedAt: DateTime.now(),
|
||||
verified: verified,
|
||||
accepted: accepted,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,6 +74,7 @@ class Contact {
|
||||
'notes': notes,
|
||||
'blocked': blocked,
|
||||
'avatar': avatar?.toJson(),
|
||||
'accepted': accepted,
|
||||
};
|
||||
|
||||
factory Contact.fromJson(Map<String, dynamic> json) {
|
||||
@@ -77,6 +88,9 @@ class Contact {
|
||||
notes: json['notes'] as String?,
|
||||
blocked: json['blocked'] as bool? ?? false,
|
||||
avatar: AvatarRef.fromJson(json['avatar']),
|
||||
// Kontakty z doby před žádostmi o zprávu uživatel už léta používá —
|
||||
// zpětně je vydávat za neznámé by jen naučilo varování odklikávat.
|
||||
accepted: json['accepted'] as bool? ?? true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,18 @@ import 'package:sepot/models/group.dart';
|
||||
import 'package:sepot/models/poll.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
/// Bezpečnostní upozornění, které appka sama vloží do konverzace.
|
||||
/// Nikdy nejde po drátě — protistrana ho podvrhnout nemůže.
|
||||
enum MessageNotice {
|
||||
/// Pod adresou tohohle kontaktu se ozval jiný identity klíč (relay
|
||||
/// hlásí jiný klíč, nebo relace patří cizímu klíči). Ověření se ruší.
|
||||
identityChanged,
|
||||
|
||||
/// Neznámý odesílatel si zvolil jméno, které se plete s tímhle
|
||||
/// kontaktem. [Message.content] nese jméno, které si zvolil.
|
||||
lookalikeRequest,
|
||||
}
|
||||
|
||||
/// Typy zpráv — odpovídá Rust: MessageType
|
||||
enum MessageType {
|
||||
text,
|
||||
@@ -62,6 +74,9 @@ class Message {
|
||||
/// Lokální záznam hovoru — taková zpráva nemá text ani přílohu.
|
||||
final CallLog? callLog;
|
||||
|
||||
/// Bezpečnostní upozornění appky (není to zpráva od nikoho).
|
||||
final MessageNotice? notice;
|
||||
|
||||
const Message({
|
||||
required this.id,
|
||||
required this.senderId,
|
||||
@@ -85,8 +100,30 @@ class Message {
|
||||
this.poll,
|
||||
this.mentions = const [],
|
||||
this.callLog,
|
||||
this.notice,
|
||||
});
|
||||
|
||||
/// Upozornění appky v konverzaci [contactId]. Odesílatel = kontakt, aby
|
||||
/// se konverzace v seznamu ukázala jako nepřečtená a upozornění si
|
||||
/// uživatel nepřehlédl.
|
||||
factory Message.notice({
|
||||
required String contactId,
|
||||
required String myId,
|
||||
required MessageNotice notice,
|
||||
String? content,
|
||||
}) {
|
||||
return Message(
|
||||
id: const Uuid().v4(),
|
||||
senderId: contactId,
|
||||
recipientId: myId,
|
||||
type: MessageType.text,
|
||||
content: content,
|
||||
timestamp: DateTime.now(),
|
||||
isDelivered: true,
|
||||
notice: notice,
|
||||
);
|
||||
}
|
||||
|
||||
/// Vytvoř textovou zprávu
|
||||
factory Message.text({
|
||||
required String senderId,
|
||||
@@ -191,6 +228,7 @@ class Message {
|
||||
poll: poll ?? this.poll,
|
||||
mentions: mentions,
|
||||
callLog: callLog,
|
||||
notice: notice,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -231,6 +269,7 @@ class Message {
|
||||
'poll': poll?.toJson(),
|
||||
if (mentions.isNotEmpty) 'mentions': mentions,
|
||||
if (callLog != null) 'call': callLog!.toJson(),
|
||||
if (notice != null) 'notice': notice!.name,
|
||||
};
|
||||
|
||||
static Map<String, int> _timesToJson(Map<String, DateTime> times) =>
|
||||
@@ -282,6 +321,7 @@ class Message {
|
||||
poll: Poll.fromJson(json['poll']),
|
||||
mentions: mentionsFromWire(json['mentions']),
|
||||
callLog: CallLog.fromJson(json['call']),
|
||||
notice: MessageNotice.values.asNameMap()[json['notice']],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user