Files
sepot/app/lib/models/contact.dart
T
Julius Joska 717aeed4ff 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.
2026-10-23 10:50:42 +02:00

97 lines
3.2 KiB
Dart

import 'package:sepot/models/avatar_ref.dart';
import 'package:sepot/models/identity.dart';
/// Kontakt — osoba, se kterou můžeme chatovat
///
/// Odpovídá Rust: Contact
class Contact {
String displayName;
final PublicIdentity publicIdentity;
final DateTime addedAt;
bool verified;
String? notes;
/// Blokovaný kontakt: příchozí zprávy se zahodí (ACKnou, ale neuloží ani
/// nezobrazí) a odesílání je v UI zablokované.
bool blocked;
/// 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,
required this.addedAt,
this.verified = false,
this.notes,
this.blocked = false,
this.avatar,
this.accepted = true,
});
/// ID kontaktu = fingerprint identity klíče (identita = klíč).
///
/// Dřív náhodné UUID — vznikly tím DVĚ klíčové soustavy (konverzace se
/// ukládaly pod UUID, UI ale routovalo fingerprintem), takže konverzace
/// otevřená z kontaktů neuměla odeslat zprávu a chat list nenašel jméno.
/// Bez datové migrace (žádná produkční data; testovací zařízení se
/// re-párují — stejný precedens jako S9).
String get id => publicIdentity.id;
/// Vytvoř nový kontakt z veřejné identity
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,
);
}
/// Šepot ID kontaktu
String get sepotId => publicIdentity.sepotId;
/// Otisk kontaktu (plné Crockford base32 zobrazení)
String get fingerprint => publicIdentity.fingerprint.display;
Map<String, dynamic> toJson() => {
'displayName': displayName,
'publicIdentity': publicIdentity.toJson(),
'addedAt': addedAt.toIso8601String(),
'verified': verified,
'notes': notes,
'blocked': blocked,
'avatar': avatar?.toJson(),
'accepted': accepted,
};
factory Contact.fromJson(Map<String, dynamic> json) {
return Contact(
displayName: json['displayName'] as String,
publicIdentity: PublicIdentity.fromJson(
json['publicIdentity'] as Map<String, dynamic>,
),
addedAt: DateTime.parse(json['addedAt'] as String),
verified: json['verified'] as bool? ?? false,
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,
);
}
}