Merge branch 'client-enhance-enable-file-encryption' into 'master'
[Client] Enable file encryption See merge request famedly/famedlysdk!241
This commit is contained in:
commit
f7ef64f5eb
|
@ -135,7 +135,7 @@ class Client {
|
||||||
bool get encryptionEnabled => _olmAccount != null;
|
bool get encryptionEnabled => _olmAccount != null;
|
||||||
|
|
||||||
/// Whether this client is able to encrypt and decrypt files.
|
/// Whether this client is able to encrypt and decrypt files.
|
||||||
bool get fileEncryptionEnabled => false;
|
bool get fileEncryptionEnabled => true;
|
||||||
|
|
||||||
/// Warning! This endpoint is for testing only!
|
/// Warning! This endpoint is for testing only!
|
||||||
set rooms(List<Room> newList) {
|
set rooms(List<Room> newList) {
|
||||||
|
@ -877,15 +877,15 @@ class Client {
|
||||||
|
|
||||||
/// Uploads a file with the name [fileName] as base64 encoded to the server
|
/// Uploads a file with the name [fileName] as base64 encoded to the server
|
||||||
/// and returns the mxc url as a string.
|
/// and returns the mxc url as a string.
|
||||||
Future<String> upload(MatrixFile file) async {
|
Future<String> upload(MatrixFile file, {String contentType}) async {
|
||||||
// For testing
|
// For testing
|
||||||
if (this.homeserver.toLowerCase() == "https://fakeserver.notexisting") {
|
if (this.homeserver.toLowerCase() == "https://fakeserver.notexisting") {
|
||||||
return "mxc://example.com/AQwafuaFswefuhsfAFAgsw";
|
return "mxc://example.com/AQwafuaFswefuhsfAFAgsw";
|
||||||
}
|
}
|
||||||
Map<String, String> headers = {};
|
Map<String, String> headers = {};
|
||||||
headers["Authorization"] = "Bearer $accessToken";
|
headers["Authorization"] = "Bearer $accessToken";
|
||||||
headers["Content-Type"] = mime(file.path);
|
headers["Content-Type"] = contentType ?? mime(file.path);
|
||||||
String fileName = file.path.split("/").last.toLowerCase();
|
String fileName = Uri.encodeFull(file.path.split("/").last.toLowerCase());
|
||||||
final url = "$homeserver/_matrix/media/r0/upload?filename=$fileName";
|
final url = "$homeserver/_matrix/media/r0/upload?filename=$fileName";
|
||||||
final streamedRequest = http.StreamedRequest('POST', Uri.parse(url))
|
final streamedRequest = http.StreamedRequest('POST', Uri.parse(url))
|
||||||
..headers.addAll(headers);
|
..headers.addAll(headers);
|
||||||
|
@ -897,6 +897,10 @@ class Client {
|
||||||
Map<String, dynamic> jsonResponse = json.decode(
|
Map<String, dynamic> jsonResponse = json.decode(
|
||||||
String.fromCharCodes(await streamedResponse.stream.first),
|
String.fromCharCodes(await streamedResponse.stream.first),
|
||||||
);
|
);
|
||||||
|
if (!(jsonResponse["content_uri"] is String &&
|
||||||
|
jsonResponse["content_uri"].isNotEmpty)) {
|
||||||
|
throw ("Missing json key: 'content_uri' ${jsonResponse.toString()}");
|
||||||
|
}
|
||||||
return jsonResponse["content_uri"];
|
return jsonResponse["content_uri"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -481,7 +481,10 @@ class Room {
|
||||||
if (sendEncrypted) {
|
if (sendEncrypted) {
|
||||||
encryptedFile = await file.encrypt();
|
encryptedFile = await file.encrypt();
|
||||||
}
|
}
|
||||||
final String uploadResp = await client.upload(file);
|
final String uploadResp = await client.upload(
|
||||||
|
file,
|
||||||
|
contentType: sendEncrypted ? "application/octet-stream" : null,
|
||||||
|
);
|
||||||
|
|
||||||
// Send event
|
// Send event
|
||||||
Map<String, dynamic> content = {
|
Map<String, dynamic> content = {
|
||||||
|
|
|
@ -8,10 +8,10 @@ class MatrixFile {
|
||||||
Uint8List bytes;
|
Uint8List bytes;
|
||||||
String path;
|
String path;
|
||||||
|
|
||||||
|
/// Encrypts this file, changes the [bytes] and returns the
|
||||||
|
/// encryption information as an [EncryptedFile].
|
||||||
Future<EncryptedFile> encrypt() async {
|
Future<EncryptedFile> encrypt() async {
|
||||||
print("[Matrix] Encrypt file with a size of ${bytes.length} bytes");
|
|
||||||
final EncryptedFile encryptedFile = await encryptFile(bytes);
|
final EncryptedFile encryptedFile = await encryptFile(bytes);
|
||||||
print("[Matrix] File encryption successfull");
|
|
||||||
this.bytes = encryptedFile.data;
|
this.bytes = encryptedFile.data;
|
||||||
return encryptedFile;
|
return encryptedFile;
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,7 +257,7 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: "1.x.y"
|
ref: HEAD
|
||||||
resolved-ref: b043fcc29031979dc65e5b08e10ebb9b8d2fae30
|
resolved-ref: b043fcc29031979dc65e5b08e10ebb9b8d2fae30
|
||||||
url: "https://gitlab.com/famedly/libraries/matrix_file_e2ee.git"
|
url: "https://gitlab.com/famedly/libraries/matrix_file_e2ee.git"
|
||||||
source: git
|
source: git
|
||||||
|
|
|
@ -20,7 +20,7 @@ dependencies:
|
||||||
matrix_file_e2ee:
|
matrix_file_e2ee:
|
||||||
git:
|
git:
|
||||||
url: https://gitlab.com/famedly/libraries/matrix_file_e2ee.git
|
url: https://gitlab.com/famedly/libraries/matrix_file_e2ee.git
|
||||||
ref: 1.x.y
|
#ref: 1.x.y
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
test: ^1.0.0
|
test: ^1.0.0
|
||||||
|
|
Loading…
Reference in a new issue