Implement key sharing

This commit is contained in:
Christian Pauly 2020-02-22 08:27:08 +01:00
parent 708eae34a3
commit 8cf52ca4fa
12 changed files with 199 additions and 7 deletions

View file

@ -70,6 +70,7 @@ class SimpleDialogs {
Future<bool> askConfirmation({
String titleText,
String contentText,
String confirmText,
String cancelText,
}) async {
@ -78,6 +79,7 @@ class SimpleDialogs {
context: context,
builder: (c) => AlertDialog(
title: Text(titleText ?? I18n.of(context).areYouSure),
content: contentText != null ? Text(contentText) : null,
actions: <Widget>[
FlatButton(
child: Text(

View file

@ -125,6 +125,14 @@ class Message extends StatelessWidget {
event,
textColor: textColor,
),
if (event.type == EventTypes.Encrypted &&
event.messageType == MessageTypes.BadEncrypted &&
event.content["body"] == DecryptError.UNKNOWN_SESSION)
RaisedButton(
child: Text(I18n.of(context).requestPermission),
onPressed: () => Matrix.of(context)
.tryRequestWithLoadingDialog(event.requestKey()),
),
],
),
),

View file

@ -4,6 +4,7 @@ import 'dart:io';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
@ -13,6 +14,7 @@ import 'package:toast/toast.dart';
import '../i18n/i18n.dart';
import '../utils/app_route.dart';
import '../utils/beautify_string_extension.dart';
import '../utils/event_extension.dart';
import '../utils/famedlysdk_store.dart';
import '../utils/room_extension.dart';
@ -327,11 +329,27 @@ class MatrixState extends State<Matrix> {
"session": session,
};
StreamSubscription onRoomKeyRequestSub;
@override
void initState() {
if (widget.client == null) {
debugPrint("[Matrix] Init matrix client");
client = Client(widget.clientName, debug: false);
onRoomKeyRequestSub ??=
client.onRoomKeyRequest.stream.listen((RoomKeyRequest request) async {
final Room room = request.room;
final User sender = room.getUserByMXIDSync(request.sender);
if (await SimpleDialogs(context).askConfirmation(
titleText: I18n.of(context).requestToReadOlderMessages,
contentText:
"${sender.id}\n\n${I18n.of(context).device}:\n${request.requestingDevice.deviceId}\n\n${I18n.of(context).identity}:\n${request.requestingDevice.curve25519Key.beautified}",
confirmText: I18n.of(context).verify,
cancelText: I18n.of(context).deny,
)) {
await request.forwardKey();
}
});
_initWithStore();
} else {
client = widget.client;
@ -341,6 +359,7 @@ class MatrixState extends State<Matrix> {
@override
void dispose() {
onRoomKeyRequestSub?.cancel();
super.dispose();
}

View file

@ -188,6 +188,9 @@ class I18n {
String get changeTheNameOfTheGroup =>
Intl.message("Change the name of the group");
String get channelCorruptedDecryptError =>
Intl.message("The encryption has been corrupted");
String get chatDetails => Intl.message('Chat details');
String get chooseAUsername => Intl.message("Choose a username");
@ -256,6 +259,10 @@ class I18n {
String get deleteMessage => Intl.message("Delete message");
String get deny => Intl.message("Deny");
String get device => Intl.message("Device");
String get devices => Intl.message("Devices");
String get discardPicture => Intl.message("Discard picture");
@ -278,6 +285,8 @@ class I18n {
String get encryptionAlgorithm => Intl.message("Encryption algorithm");
String get encryptionNotEnabled => Intl.message("Encryption is not enabled");
String get end2endEncryptionSettings =>
Intl.message("End-to-end encryption settings");
@ -328,6 +337,8 @@ class I18n {
String get id => Intl.message("ID");
String get identity => Intl.message("Identity");
String get inviteContact => Intl.message("Invite contact");
String inviteContactToGroup(String groupName) => Intl.message(
@ -429,6 +440,8 @@ class I18n {
String get none => Intl.message("None");
String get noPermission => Intl.message("No permission");
String get noRoomsFound => Intl.message("No rooms found...");
String get notSupportedInWeb => Intl.message("Not supported in web");
@ -499,6 +512,11 @@ class I18n {
String get reply => Intl.message('Reply');
String get requestPermission => Intl.message('Request permission');
String get requestToReadOlderMessages =>
Intl.message("Request to read older messages");
String get saturday => Intl.message("Saturday");
String get share => Intl.message("Share");
@ -633,6 +651,9 @@ class I18n {
String get unknownDevice => Intl.message("Unknown device");
String get unknownEncryptionAlgorithm =>
Intl.message("Unknown encryption algorithm");
String unknownEvent(String type) => Intl.message(
"Unknown event '$type'",
name: "unknownEvent",
@ -679,6 +700,8 @@ class I18n {
args: [username, type],
);
String get verify => Intl.message("Verify");
String get visibleForAllParticipants =>
Intl.message("Visible for all participants");

View file

@ -216,6 +216,11 @@
"type": "text",
"placeholders": {}
},
"The encryption has been corrupted": "Die Verschlüsselung wurde korrumpiert",
"@The encryption has been corrupted": {
"type": "text",
"placeholders": {}
},
"Chat details": "Gruppeninfo",
"@Chat details": {
"type": "text",
@ -340,6 +345,16 @@
"type": "text",
"placeholders": {}
},
"Deny": "Ablehnen",
"@Deny": {
"type": "text",
"placeholders": {}
},
"Device": "Gerät",
"@Device": {
"type": "text",
"placeholders": {}
},
"Devices": "Geräte",
"@Devices": {
"type": "text",
@ -382,6 +397,11 @@
"type": "text",
"placeholders": {}
},
"Encryption is not enabled": "Verschlüsselung ist nicht aktiviert",
"@Encryption is not enabled": {
"type": "text",
"placeholders": {}
},
"End-to-end encryption settings": "Ende-zu-Ende-Verschlüsselung",
"@End-to-end encryption settings": {
"type": "text",
@ -482,6 +502,11 @@
"type": "text",
"placeholders": {}
},
"Identity": "Identität",
"@Identity": {
"type": "text",
"placeholders": {}
},
"Invite contact": "Kontakt einladen",
"@Invite contact": {
"type": "text",
@ -662,6 +687,11 @@
"type": "text",
"placeholders": {}
},
"No permission": "Keine Berechtigung",
"@No permission": {
"type": "text",
"placeholders": {}
},
"No rooms found...": "Keine Räume gefunden ...",
"@No rooms found...": {
"type": "text",
@ -792,6 +822,16 @@
"type": "text",
"placeholders": {}
},
"Request permission": "Berechtigung anfragen",
"@Request permission": {
"type": "text",
"placeholders": {}
},
"Request to read older messages": "Anfrage um ältere Nachrichten zu lesen",
"@Request to read older messages": {
"type": "text",
"placeholders": {}
},
"Saturday": "Samstag",
"@Saturday": {
"type": "text",
@ -1021,6 +1061,11 @@
"type": "text",
"placeholders": {}
},
"Unknown encryption algorithm": "Unbekannter Verschlüsselungsalgorithmus",
"@Unknown encryption algorithm": {
"type": "text",
"placeholders": {}
},
"unknownEvent": "Unbekanntes Event '{type}'",
"@unknownEvent": {
"type": "text",
@ -1079,6 +1124,11 @@
"type": {}
}
},
"Verify": "Bestätigen",
"@Verify": {
"type": "text",
"placeholders": {}
},
"Visible for all participants": "Sichtbar für alle Teilnehmer",
"@Visible for all participants": {
"type": "text",

View file

@ -1,5 +1,5 @@
{
"@@last_modified": "2020-02-19T16:20:13.752724",
"@@last_modified": "2020-02-22T08:18:47.225173",
"About": "About",
"@About": {
"type": "text",
@ -216,6 +216,11 @@
"type": "text",
"placeholders": {}
},
"The encryption has been corrupted": "The encryption has been corrupted",
"@The encryption has been corrupted": {
"type": "text",
"placeholders": {}
},
"Chat details": "Chat details",
"@Chat details": {
"type": "text",
@ -340,6 +345,16 @@
"type": "text",
"placeholders": {}
},
"Deny": "Deny",
"@Deny": {
"type": "text",
"placeholders": {}
},
"Device": "Device",
"@Device": {
"type": "text",
"placeholders": {}
},
"Devices": "Devices",
"@Devices": {
"type": "text",
@ -382,6 +397,11 @@
"type": "text",
"placeholders": {}
},
"Encryption is not enabled": "Encryption is not enabled",
"@Encryption is not enabled": {
"type": "text",
"placeholders": {}
},
"End-to-end encryption settings": "End-to-end encryption settings",
"@End-to-end encryption settings": {
"type": "text",
@ -482,6 +502,11 @@
"type": "text",
"placeholders": {}
},
"Identity": "Identity",
"@Identity": {
"type": "text",
"placeholders": {}
},
"Invite contact": "Invite contact",
"@Invite contact": {
"type": "text",
@ -662,6 +687,11 @@
"type": "text",
"placeholders": {}
},
"No permission": "No permission",
"@No permission": {
"type": "text",
"placeholders": {}
},
"No rooms found...": "No rooms found...",
"@No rooms found...": {
"type": "text",
@ -792,6 +822,16 @@
"type": "text",
"placeholders": {}
},
"Request permission": "Request permission",
"@Request permission": {
"type": "text",
"placeholders": {}
},
"Request to read older messages": "Request to read older messages",
"@Request to read older messages": {
"type": "text",
"placeholders": {}
},
"Saturday": "Saturday",
"@Saturday": {
"type": "text",
@ -1021,6 +1061,11 @@
"type": "text",
"placeholders": {}
},
"Unknown encryption algorithm": "Unknown encryption algorithm",
"@Unknown encryption algorithm": {
"type": "text",
"placeholders": {}
},
"unknownEvent": "Unknown event '{type}'",
"@unknownEvent": {
"type": "text",
@ -1079,6 +1124,11 @@
"type": {}
}
},
"Verify": "Verify",
"@Verify": {
"type": "text",
"placeholders": {}
},
"Visible for all participants": "Visible for all participants",
"@Visible for all participants": {
"type": "text",

View file

@ -170,6 +170,8 @@ class MessageLookup extends MessageLookupByLibrary {
"Dark" : MessageLookupByLibrary.simpleMessage("Dunkel"),
"Delete" : MessageLookupByLibrary.simpleMessage("Löschen"),
"Delete message" : MessageLookupByLibrary.simpleMessage("Nachricht löschen"),
"Deny" : MessageLookupByLibrary.simpleMessage("Ablehnen"),
"Device" : MessageLookupByLibrary.simpleMessage("Gerät"),
"Devices" : MessageLookupByLibrary.simpleMessage("Geräte"),
"Discard picture" : MessageLookupByLibrary.simpleMessage("Bild verwerfen"),
"Displayname has been changed" : MessageLookupByLibrary.simpleMessage("Anzeigename wurde geändert"),
@ -177,6 +179,7 @@ class MessageLookup extends MessageLookupByLibrary {
"Edit displayname" : MessageLookupByLibrary.simpleMessage("Anzeigename ändern"),
"Empty chat" : MessageLookupByLibrary.simpleMessage("Leerer Chat"),
"Encryption algorithm" : MessageLookupByLibrary.simpleMessage("Verschlüsselungsalgorithmus"),
"Encryption is not enabled" : MessageLookupByLibrary.simpleMessage("Verschlüsselung ist nicht aktiviert"),
"End to end encryption is currently in Beta! Use at your own risk!" : MessageLookupByLibrary.simpleMessage("Ende-zu-Ende-Verschlüsselung ist im Beta-Status. Benutzung auf eigene Gefahr!"),
"End-to-end encryption settings" : MessageLookupByLibrary.simpleMessage("Ende-zu-Ende-Verschlüsselung"),
"Enter a group name" : MessageLookupByLibrary.simpleMessage("Gib einen Gruppennamen ein"),
@ -195,6 +198,7 @@ class MessageLookup extends MessageLookupByLibrary {
"Help" : MessageLookupByLibrary.simpleMessage("Hilfe"),
"Homeserver is not compatible" : MessageLookupByLibrary.simpleMessage("Homeserver ist nicht kompatibel"),
"ID" : MessageLookupByLibrary.simpleMessage("ID"),
"Identity" : MessageLookupByLibrary.simpleMessage("Identität"),
"Invite contact" : MessageLookupByLibrary.simpleMessage("Kontakt einladen"),
"Invited" : MessageLookupByLibrary.simpleMessage("Eingeladen"),
"Invited users only" : MessageLookupByLibrary.simpleMessage("Nur eingeladene Benutzer"),
@ -217,6 +221,7 @@ class MessageLookup extends MessageLookupByLibrary {
"Mute chat" : MessageLookupByLibrary.simpleMessage("Stummschalten"),
"New message in FluffyChat" : MessageLookupByLibrary.simpleMessage("Neue Nachricht in FluffyChat"),
"New private chat" : MessageLookupByLibrary.simpleMessage("Neuer privater Chat"),
"No permission" : MessageLookupByLibrary.simpleMessage("Keine Berechtigung"),
"No rooms found..." : MessageLookupByLibrary.simpleMessage("Keine Räume gefunden ..."),
"None" : MessageLookupByLibrary.simpleMessage("Keiner"),
"Not supported in web" : MessageLookupByLibrary.simpleMessage("Wird in der Web-Version nicht unterstützt"),
@ -236,6 +241,8 @@ class MessageLookup extends MessageLookupByLibrary {
"Remove exile" : MessageLookupByLibrary.simpleMessage("Verbannung aufheben"),
"Remove message" : MessageLookupByLibrary.simpleMessage("Nachricht entfernen"),
"Reply" : MessageLookupByLibrary.simpleMessage("Antworten"),
"Request permission" : MessageLookupByLibrary.simpleMessage("Berechtigung anfragen"),
"Request to read older messages" : MessageLookupByLibrary.simpleMessage("Anfrage um ältere Nachrichten zu lesen"),
"Revoke all permissions" : MessageLookupByLibrary.simpleMessage("Alle Berechtigungen zurücknehmen"),
"Saturday" : MessageLookupByLibrary.simpleMessage("Samstag"),
"Search for a chat" : MessageLookupByLibrary.simpleMessage("Durchsuche die Chats"),
@ -254,14 +261,17 @@ class MessageLookup extends MessageLookupByLibrary {
"Sunday" : MessageLookupByLibrary.simpleMessage("Sonntag"),
"System" : MessageLookupByLibrary.simpleMessage("System"),
"Tap to show menu" : MessageLookupByLibrary.simpleMessage("Tippen, um das Menü anzuzeigen"),
"The encryption has been corrupted" : MessageLookupByLibrary.simpleMessage("Die Verschlüsselung wurde korrumpiert"),
"This room has been archived." : MessageLookupByLibrary.simpleMessage("Dieser Raum wurde archiviert."),
"Thursday" : MessageLookupByLibrary.simpleMessage("Donnerstag"),
"Try to send again" : MessageLookupByLibrary.simpleMessage("Nochmal versuchen zu senden"),
"Tuesday" : MessageLookupByLibrary.simpleMessage("Tuesday"),
"Unknown device" : MessageLookupByLibrary.simpleMessage("Unbekanntes Gerät"),
"Unknown encryption algorithm" : MessageLookupByLibrary.simpleMessage("Unbekannter Verschlüsselungsalgorithmus"),
"Unmute chat" : MessageLookupByLibrary.simpleMessage("Stumm aus"),
"Use Amoled compatible colors?" : MessageLookupByLibrary.simpleMessage("Amoled optimierte Farben verwenden?"),
"Username" : MessageLookupByLibrary.simpleMessage("Benutzername"),
"Verify" : MessageLookupByLibrary.simpleMessage("Bestätigen"),
"Visibility of the chat history" : MessageLookupByLibrary.simpleMessage("Sichtbarkeit des Chat-Verlaufs"),
"Visible for all participants" : MessageLookupByLibrary.simpleMessage("Sichtbar für alle Teilnehmer"),
"Visible for everyone" : MessageLookupByLibrary.simpleMessage("Für jeden sichtbar"),

View file

@ -170,6 +170,8 @@ class MessageLookup extends MessageLookupByLibrary {
"Dark" : MessageLookupByLibrary.simpleMessage("Dark"),
"Delete" : MessageLookupByLibrary.simpleMessage("Delete"),
"Delete message" : MessageLookupByLibrary.simpleMessage("Delete message"),
"Deny" : MessageLookupByLibrary.simpleMessage("Deny"),
"Device" : MessageLookupByLibrary.simpleMessage("Device"),
"Devices" : MessageLookupByLibrary.simpleMessage("Devices"),
"Discard picture" : MessageLookupByLibrary.simpleMessage("Discard picture"),
"Displayname has been changed" : MessageLookupByLibrary.simpleMessage("Displayname has been changed"),
@ -177,6 +179,7 @@ class MessageLookup extends MessageLookupByLibrary {
"Edit displayname" : MessageLookupByLibrary.simpleMessage("Edit displayname"),
"Empty chat" : MessageLookupByLibrary.simpleMessage("Empty chat"),
"Encryption algorithm" : MessageLookupByLibrary.simpleMessage("Encryption algorithm"),
"Encryption is not enabled" : MessageLookupByLibrary.simpleMessage("Encryption is not enabled"),
"End to end encryption is currently in Beta! Use at your own risk!" : MessageLookupByLibrary.simpleMessage("End to end encryption is currently in Beta! Use at your own risk!"),
"End-to-end encryption settings" : MessageLookupByLibrary.simpleMessage("End-to-end encryption settings"),
"Enter a group name" : MessageLookupByLibrary.simpleMessage("Enter a group name"),
@ -195,6 +198,7 @@ class MessageLookup extends MessageLookupByLibrary {
"Help" : MessageLookupByLibrary.simpleMessage("Help"),
"Homeserver is not compatible" : MessageLookupByLibrary.simpleMessage("Homeserver is not compatible"),
"ID" : MessageLookupByLibrary.simpleMessage("ID"),
"Identity" : MessageLookupByLibrary.simpleMessage("Identity"),
"Invite contact" : MessageLookupByLibrary.simpleMessage("Invite contact"),
"Invited" : MessageLookupByLibrary.simpleMessage("Invited"),
"Invited users only" : MessageLookupByLibrary.simpleMessage("Invited users only"),
@ -217,6 +221,7 @@ class MessageLookup extends MessageLookupByLibrary {
"Mute chat" : MessageLookupByLibrary.simpleMessage("Mute chat"),
"New message in FluffyChat" : MessageLookupByLibrary.simpleMessage("New message in FluffyChat"),
"New private chat" : MessageLookupByLibrary.simpleMessage("New private chat"),
"No permission" : MessageLookupByLibrary.simpleMessage("No permission"),
"No rooms found..." : MessageLookupByLibrary.simpleMessage("No rooms found..."),
"None" : MessageLookupByLibrary.simpleMessage("None"),
"Not supported in web" : MessageLookupByLibrary.simpleMessage("Not supported in web"),
@ -236,6 +241,8 @@ class MessageLookup extends MessageLookupByLibrary {
"Remove exile" : MessageLookupByLibrary.simpleMessage("Remove exile"),
"Remove message" : MessageLookupByLibrary.simpleMessage("Remove message"),
"Reply" : MessageLookupByLibrary.simpleMessage("Reply"),
"Request permission" : MessageLookupByLibrary.simpleMessage("Request permission"),
"Request to read older messages" : MessageLookupByLibrary.simpleMessage("Request to read older messages"),
"Revoke all permissions" : MessageLookupByLibrary.simpleMessage("Revoke all permissions"),
"Saturday" : MessageLookupByLibrary.simpleMessage("Saturday"),
"Search for a chat" : MessageLookupByLibrary.simpleMessage("Search for a chat"),
@ -254,14 +261,17 @@ class MessageLookup extends MessageLookupByLibrary {
"Sunday" : MessageLookupByLibrary.simpleMessage("Sunday"),
"System" : MessageLookupByLibrary.simpleMessage("System"),
"Tap to show menu" : MessageLookupByLibrary.simpleMessage("Tap to show menu"),
"The encryption has been corrupted" : MessageLookupByLibrary.simpleMessage("The encryption has been corrupted"),
"This room has been archived." : MessageLookupByLibrary.simpleMessage("This room has been archived."),
"Thursday" : MessageLookupByLibrary.simpleMessage("Thursday"),
"Try to send again" : MessageLookupByLibrary.simpleMessage("Try to send again"),
"Tuesday" : MessageLookupByLibrary.simpleMessage("Tuesday"),
"Unknown device" : MessageLookupByLibrary.simpleMessage("Unknown device"),
"Unknown encryption algorithm" : MessageLookupByLibrary.simpleMessage("Unknown encryption algorithm"),
"Unmute chat" : MessageLookupByLibrary.simpleMessage("Unmute chat"),
"Use Amoled compatible colors?" : MessageLookupByLibrary.simpleMessage("Use Amoled compatible colors?"),
"Username" : MessageLookupByLibrary.simpleMessage("Username"),
"Verify" : MessageLookupByLibrary.simpleMessage("Verify"),
"Visibility of the chat history" : MessageLookupByLibrary.simpleMessage("Visibility of the chat history"),
"Visible for all participants" : MessageLookupByLibrary.simpleMessage("Visible for all participants"),
"Visible for everyone" : MessageLookupByLibrary.simpleMessage("Visible for everyone"),

View file

@ -192,8 +192,28 @@ extension LocalizedBody on Event {
localizedBody = "* $body";
break;
case MessageTypes.BadEncrypted:
localizedBody =
"🔒 " + I18n.of(context).couldNotDecryptMessage + ": " + body;
String errorText;
switch (body) {
case DecryptError.CHANNEL_CORRUPTED:
errorText = I18n.of(context).channelCorruptedDecryptError + ".";
break;
case DecryptError.NOT_ENABLED:
errorText = I18n.of(context).encryptionNotEnabled + ".";
break;
case DecryptError.UNKNOWN_ALGORITHM:
errorText = I18n.of(context).unknownEncryptionAlgorithm + ".";
break;
case DecryptError.UNKNOWN_SESSION:
errorText = I18n.of(context).noPermission + ".";
break;
default:
errorText = body;
break;
}
localizedBody = "🔒 " +
I18n.of(context).couldNotDecryptMessage +
": " +
errorText;
break;
case MessageTypes.Text:
case MessageTypes.Notice:

View file

@ -155,7 +155,7 @@ class _ChatState extends State<_Chat> {
@override
void dispose() {
timeline?.sub?.cancel();
timeline?.cancelSubscriptions();
timeline = null;
matrix.activeRoomId = "";
super.dispose();

View file

@ -124,8 +124,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: f6379597ed403f340601a27a3ef6b2b971ac1c27
resolved-ref: f6379597ed403f340601a27a3ef6b2b971ac1c27
ref: "8a3547a1ee0464ef54a212046f742891dd586724"
resolved-ref: "8a3547a1ee0464ef54a212046f742891dd586724"
url: "https://gitlab.com/famedly/famedlysdk.git"
source: git
version: "0.0.1"

View file

@ -27,7 +27,7 @@ dependencies:
famedlysdk:
git:
url: https://gitlab.com/famedly/famedlysdk.git
ref: 664f97b251ba67a163a5ba37c9344c5011275b54
ref: 8a3547a1ee0464ef54a212046f742891dd586724
localstorage: ^3.0.1+4
bubble: ^1.1.9+1