Encrypt file key with the collection key
This commit is contained in:
parent
6f2f95b038
commit
fa8a284af3
2 changed files with 20 additions and 10 deletions
|
@ -34,14 +34,7 @@ class CollectionsService {
|
|||
await _db.insert(collections);
|
||||
collections = await _db.getAll();
|
||||
for (final collection in collections) {
|
||||
if (collection.ownerID == _config.getUserID()) {
|
||||
var path = utf8.decode(CryptoUtil.decryptSync(
|
||||
Sodium.base642bin(collection.encryptedPath),
|
||||
_config.getKey(),
|
||||
Sodium.base642bin(collection.pathDecryptionNonce)));
|
||||
_localCollections[path] = collection;
|
||||
}
|
||||
_collectionIDToCollection[collection.id] = collection;
|
||||
_cacheCollectionAttributes(collection);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,7 +120,7 @@ class CollectionsService {
|
|||
null,
|
||||
null,
|
||||
));
|
||||
_localCollections[path] = collection;
|
||||
_cacheCollectionAttributes(collection);
|
||||
return collection;
|
||||
}
|
||||
|
||||
|
@ -143,4 +136,16 @@ class CollectionsService {
|
|||
return Collection.fromMap(response.data["collection"]);
|
||||
});
|
||||
}
|
||||
|
||||
void _cacheCollectionAttributes(Collection collection) {
|
||||
if (collection.ownerID == _config.getUserID()) {
|
||||
var path = utf8.decode(CryptoUtil.decryptSync(
|
||||
Sodium.base642bin(collection.encryptedPath),
|
||||
_config.getKey(),
|
||||
Sodium.base642bin(collection.pathDecryptionNonce)));
|
||||
_localCollections[path] = collection;
|
||||
}
|
||||
_collectionIDToCollection[collection.id] = collection;
|
||||
getCollectionKey(collection.id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:photos/core/configuration.dart';
|
|||
import 'package:photos/core/constants.dart';
|
||||
import 'package:photos/models/file.dart';
|
||||
import 'package:photos/models/upload_url.dart';
|
||||
import 'package:photos/services/collections_service.dart';
|
||||
import 'package:photos/utils/crypto_util.dart';
|
||||
import 'package:photos/utils/file_name_util.dart';
|
||||
import 'package:photos/utils/file_util.dart';
|
||||
|
@ -44,6 +45,10 @@ class FileUploader {
|
|||
Future<File> encryptAndUploadFile(File file) async {
|
||||
_logger.info("Uploading " + file.toString());
|
||||
|
||||
file.collectionID = (await CollectionsService.instance
|
||||
.getOrCreateForPath(file.deviceFolder))
|
||||
.id;
|
||||
|
||||
final encryptedFileName = file.generatedID.toString() + ".encrypted";
|
||||
final tempDirectory = Configuration.instance.getTempDirectory();
|
||||
final encryptedFilePath = tempDirectory + encryptedFileName;
|
||||
|
@ -78,7 +83,7 @@ class FileUploader {
|
|||
|
||||
final encryptedFileKeyData = CryptoUtil.encryptSync(
|
||||
fileAttributes.key,
|
||||
Configuration.instance.getKey(),
|
||||
CollectionsService.instance.getCollectionKey(file.collectionID),
|
||||
);
|
||||
|
||||
final encryptedKey = Sodium.bin2base64(encryptedFileKeyData.encryptedData);
|
||||
|
|
Loading…
Add table
Reference in a new issue