mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 10:38:41 +00:00
rename files
This commit is contained in:
parent
c94ed3b088
commit
78ca650166
6 changed files with 93 additions and 84 deletions
|
|
@ -10,9 +10,9 @@ import 'package:twonly/src/services/api.service.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:twonly/src/providers/connection.provider.dart';
|
import 'package:twonly/src/providers/connection.provider.dart';
|
||||||
import 'package:twonly/src/providers/settings.provider.dart';
|
import 'package:twonly/src/providers/settings.provider.dart';
|
||||||
import 'package:twonly/src/services/twonly_safe.service.dart';
|
|
||||||
import 'package:twonly/src/services/fcm.service.dart';
|
import 'package:twonly/src/services/fcm.service.dart';
|
||||||
import 'package:twonly/src/services/notification.service.dart';
|
import 'package:twonly/src/services/notification.service.dart';
|
||||||
|
import 'package:twonly/src/services/twonly_safe/create_backup.service.dart';
|
||||||
import 'package:twonly/src/utils/log.dart';
|
import 'package:twonly/src/utils/log.dart';
|
||||||
import 'package:twonly/src/utils/storage.dart';
|
import 'package:twonly/src/utils/storage.dart';
|
||||||
import 'app.dart';
|
import 'app.dart';
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@ import 'package:twonly/src/model/json/message.dart';
|
||||||
import 'package:twonly/src/model/protobuf/api/http/http_requests.pb.dart';
|
import 'package:twonly/src/model/protobuf/api/http/http_requests.pb.dart';
|
||||||
import 'package:twonly/src/model/protobuf/api/websocket/error.pb.dart';
|
import 'package:twonly/src/model/protobuf/api/websocket/error.pb.dart';
|
||||||
import 'package:twonly/src/services/api/media_download.dart';
|
import 'package:twonly/src/services/api/media_download.dart';
|
||||||
import 'package:twonly/src/services/twonly_safe.service.dart';
|
|
||||||
import 'package:twonly/src/services/notification.service.dart';
|
import 'package:twonly/src/services/notification.service.dart';
|
||||||
import 'package:twonly/src/services/signal/encryption.signal.dart';
|
import 'package:twonly/src/services/signal/encryption.signal.dart';
|
||||||
|
import 'package:twonly/src/services/twonly_safe/create_backup.service.dart';
|
||||||
import 'package:twonly/src/utils/log.dart';
|
import 'package:twonly/src/utils/log.dart';
|
||||||
import 'package:twonly/src/utils/misc.dart';
|
import 'package:twonly/src/utils/misc.dart';
|
||||||
import 'package:twonly/src/utils/storage.dart';
|
import 'package:twonly/src/utils/storage.dart';
|
||||||
|
|
|
||||||
87
lib/src/services/twonly_safe/common.service.dart
Normal file
87
lib/src/services/twonly_safe/common.service.dart
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'package:drift/drift.dart';
|
||||||
|
import 'package:hashlib/hashlib.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:twonly/src/model/json/userdata.dart';
|
||||||
|
import 'package:twonly/src/services/api/media_upload.dart';
|
||||||
|
import 'package:twonly/src/services/twonly_safe/create_backup.service.dart';
|
||||||
|
import 'package:twonly/src/utils/log.dart';
|
||||||
|
import 'package:twonly/src/utils/storage.dart';
|
||||||
|
|
||||||
|
Future<String?> getTwonlySafeBackupUrl() async {
|
||||||
|
final user = await getUser();
|
||||||
|
if (user == null || user.twonlySafeBackup == null) return null;
|
||||||
|
|
||||||
|
String backupServerUrl = "https://safe.twonly.eu/";
|
||||||
|
|
||||||
|
if (user.backupServer != null) {
|
||||||
|
backupServerUrl = user.backupServer!.serverUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
String backupId =
|
||||||
|
uint8ListToHex(user.twonlySafeBackup!.backupId).toLowerCase();
|
||||||
|
|
||||||
|
return "${backupServerUrl}backups/$backupId";
|
||||||
|
}
|
||||||
|
|
||||||
|
Future enableTwonlySafe(String password) async {
|
||||||
|
final user = await getUser();
|
||||||
|
if (user == null) return;
|
||||||
|
|
||||||
|
final (backupId, encryptionKey) = await getMasterKey(password, user.username);
|
||||||
|
|
||||||
|
await updateUserdata((user) {
|
||||||
|
user.twonlySafeBackup = TwonlySafeBackup(
|
||||||
|
encryptionKey: encryptionKey,
|
||||||
|
backupId: backupId,
|
||||||
|
);
|
||||||
|
return user;
|
||||||
|
});
|
||||||
|
performTwonlySafeBackup(force: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future disableTwonlySafe() async {
|
||||||
|
final serverUrl = await getTwonlySafeBackupUrl();
|
||||||
|
if (serverUrl != null) {
|
||||||
|
try {
|
||||||
|
final response = await http.delete(
|
||||||
|
Uri.parse(serverUrl),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json', // Set the content type if needed
|
||||||
|
// Add any other headers if required
|
||||||
|
},
|
||||||
|
);
|
||||||
|
Log.info("Download deleted with: ${response.statusCode}");
|
||||||
|
} catch (e) {
|
||||||
|
Log.error("Could not connect to the server.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await updateUserdata((user) {
|
||||||
|
user.twonlySafeBackup = null;
|
||||||
|
return user;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<(Uint8List, Uint8List)> getMasterKey(
|
||||||
|
String password,
|
||||||
|
String username,
|
||||||
|
) async {
|
||||||
|
List<int> passwordBytes = utf8.encode(password);
|
||||||
|
List<int> saltBytes = utf8.encode(username);
|
||||||
|
|
||||||
|
// Parameters for scrypt
|
||||||
|
|
||||||
|
// Create an instance of Scrypt
|
||||||
|
final scrypt = Scrypt(
|
||||||
|
cost: 65536,
|
||||||
|
blockSize: 8,
|
||||||
|
parallelism: 1,
|
||||||
|
derivedKeyLength: 64,
|
||||||
|
salt: saltBytes,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Derive the key
|
||||||
|
// final key = (await compute(scrypt.convert, passwordBytes)).bytes;
|
||||||
|
final key = (scrypt.convert(passwordBytes)).bytes;
|
||||||
|
return (key.sublist(0, 32), key.sublist(32, 64));
|
||||||
|
}
|
||||||
|
|
@ -5,8 +5,6 @@ import 'package:cryptography_plus/cryptography_plus.dart';
|
||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
import 'package:drift_flutter/drift_flutter.dart';
|
import 'package:drift_flutter/drift_flutter.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:hashlib/hashlib.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
import 'package:path/path.dart';
|
import 'package:path/path.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:twonly/src/constants/secure_storage_keys.dart';
|
import 'package:twonly/src/constants/secure_storage_keys.dart';
|
||||||
|
|
@ -14,26 +12,11 @@ import 'package:twonly/src/database/twonly_database.dart';
|
||||||
import 'package:twonly/src/model/json/userdata.dart';
|
import 'package:twonly/src/model/json/userdata.dart';
|
||||||
import 'package:twonly/src/model/protobuf/backup/backup.pb.dart';
|
import 'package:twonly/src/model/protobuf/backup/backup.pb.dart';
|
||||||
import 'package:twonly/src/services/api/media_upload.dart';
|
import 'package:twonly/src/services/api/media_upload.dart';
|
||||||
|
import 'package:twonly/src/services/twonly_safe/common.service.dart';
|
||||||
import 'package:twonly/src/utils/log.dart';
|
import 'package:twonly/src/utils/log.dart';
|
||||||
import 'package:twonly/src/utils/storage.dart';
|
import 'package:twonly/src/utils/storage.dart';
|
||||||
import 'package:twonly/src/views/settings/backup/backup.view.dart';
|
import 'package:twonly/src/views/settings/backup/backup.view.dart';
|
||||||
|
|
||||||
Future<String?> getTwonlySafeBackupUrl() async {
|
|
||||||
final user = await getUser();
|
|
||||||
if (user == null || user.twonlySafeBackup == null) return null;
|
|
||||||
|
|
||||||
String backupServerUrl = "https://safe.twonly.eu/";
|
|
||||||
|
|
||||||
if (user.backupServer != null) {
|
|
||||||
backupServerUrl = user.backupServer!.serverUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
String backupId =
|
|
||||||
uint8ListToHex(user.twonlySafeBackup!.backupId).toLowerCase();
|
|
||||||
|
|
||||||
return "${backupServerUrl}backups/$backupId";
|
|
||||||
}
|
|
||||||
|
|
||||||
Future performTwonlySafeBackup({bool force = false}) async {
|
Future performTwonlySafeBackup({bool force = false}) async {
|
||||||
final user = await getUser();
|
final user = await getUser();
|
||||||
|
|
||||||
|
|
@ -227,65 +210,3 @@ Future handleBackupStatusUpdate(TaskStatusUpdate update) async {
|
||||||
}
|
}
|
||||||
gUpdateBackupView();
|
gUpdateBackupView();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future enableTwonlySafe(String password) async {
|
|
||||||
final user = await getUser();
|
|
||||||
if (user == null) return;
|
|
||||||
|
|
||||||
final (backupId, encryptionKey) = await getMasterKey(password, user.username);
|
|
||||||
|
|
||||||
await updateUserdata((user) {
|
|
||||||
user.twonlySafeBackup = TwonlySafeBackup(
|
|
||||||
encryptionKey: encryptionKey,
|
|
||||||
backupId: backupId,
|
|
||||||
);
|
|
||||||
return user;
|
|
||||||
});
|
|
||||||
performTwonlySafeBackup(force: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future disableTwonlySafe() async {
|
|
||||||
final serverUrl = await getTwonlySafeBackupUrl();
|
|
||||||
if (serverUrl != null) {
|
|
||||||
try {
|
|
||||||
final response = await http.delete(
|
|
||||||
Uri.parse(serverUrl),
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json', // Set the content type if needed
|
|
||||||
// Add any other headers if required
|
|
||||||
},
|
|
||||||
);
|
|
||||||
Log.info("Download deleted with: ${response.statusCode}");
|
|
||||||
} catch (e) {
|
|
||||||
Log.error("Could not connect to the server.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await updateUserdata((user) {
|
|
||||||
user.twonlySafeBackup = null;
|
|
||||||
return user;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<(Uint8List, Uint8List)> getMasterKey(
|
|
||||||
String password,
|
|
||||||
String username,
|
|
||||||
) async {
|
|
||||||
List<int> passwordBytes = utf8.encode(password);
|
|
||||||
List<int> saltBytes = utf8.encode(username);
|
|
||||||
|
|
||||||
// Parameters for scrypt
|
|
||||||
|
|
||||||
// Create an instance of Scrypt
|
|
||||||
final scrypt = Scrypt(
|
|
||||||
cost: 65536,
|
|
||||||
blockSize: 8,
|
|
||||||
parallelism: 1,
|
|
||||||
derivedKeyLength: 64,
|
|
||||||
salt: saltBytes,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Derive the key
|
|
||||||
// final key = (await compute(scrypt.convert, passwordBytes)).bytes;
|
|
||||||
final key = (scrypt.convert(passwordBytes)).bytes;
|
|
||||||
return (key.sublist(0, 32), key.sublist(32, 64));
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:twonly/src/model/json/userdata.dart';
|
import 'package:twonly/src/model/json/userdata.dart';
|
||||||
import 'package:twonly/src/services/twonly_safe.service.dart';
|
import 'package:twonly/src/services/twonly_safe/common.service.dart';
|
||||||
|
import 'package:twonly/src/services/twonly_safe/create_backup.service.dart';
|
||||||
import 'package:twonly/src/utils/misc.dart';
|
import 'package:twonly/src/utils/misc.dart';
|
||||||
import 'package:twonly/src/utils/storage.dart';
|
import 'package:twonly/src/utils/storage.dart';
|
||||||
import 'package:twonly/src/views/components/alert_dialog.dart';
|
import 'package:twonly/src/views/components/alert_dialog.dart';
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import 'package:flutter/services.dart' show rootBundle;
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:twonly/src/services/twonly_safe.service.dart';
|
import 'package:twonly/src/services/twonly_safe/common.service.dart';
|
||||||
import 'package:twonly/src/utils/misc.dart';
|
import 'package:twonly/src/utils/misc.dart';
|
||||||
import 'package:twonly/src/views/components/alert_dialog.dart';
|
import 'package:twonly/src/views/components/alert_dialog.dart';
|
||||||
import 'package:twonly/src/views/settings/backup/twonly_safe_server.view.dart';
|
import 'package:twonly/src/views/settings/backup/twonly_safe_server.view.dart';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue