mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-27 23:17:13 +03:00
[CSE] Create the Encrypted File on Disk
This commit is contained in:
parent
3760b86e07
commit
7e83f0591b
2 changed files with 42 additions and 1 deletions
|
@ -7,6 +7,8 @@
|
|||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
#include <QFile>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
namespace OCC {
|
||||
|
||||
|
@ -111,9 +113,44 @@ void PropagateUploadEncrypted::slotFolderEncriptedMetadataReceived(const QJsonDo
|
|||
{
|
||||
qDebug() << "Metadata Received, Preparing it for the new file." << json.toVariant();
|
||||
|
||||
// Encrypt File!
|
||||
FolderMetadata metaData(_propagator->account(), json.toJson(QJsonDocument::Compact));
|
||||
qDebug() << "Unlockign folder because I didn't finished the metadata yet.";
|
||||
|
||||
QFileInfo info(_item->_file);
|
||||
|
||||
//Todo: Move this to the MetadataHandler.
|
||||
/* This should actually first verify if we don't have this file on the metadata already
|
||||
* and construct this code if there isn't.
|
||||
*/
|
||||
|
||||
qDebug() << "Creating the encrypted file metadata helper.";
|
||||
EncryptedFile encryptedFile;
|
||||
encryptedFile.authenticationTag = "NOISE"; // TODO: Remove the noise.
|
||||
encryptedFile.encryptedFilename = EncryptionHelper::generateRandom(20);
|
||||
encryptedFile.encryptionKey = EncryptionHelper::generateRandom(16);
|
||||
encryptedFile.fileVersion = 1;
|
||||
encryptedFile.initializationVector = EncryptionHelper::generateRandom(16);
|
||||
encryptedFile.metadataKey = 1;
|
||||
encryptedFile.originalFilename = info.fileName();
|
||||
metaData.addEncryptedFile(encryptedFile);
|
||||
|
||||
qDebug() << "Encrypting the file";
|
||||
QFile *input = new QFile(info.absoluteFilePath());
|
||||
|
||||
//TODO: Perhaps I should use a QTemporaryFile?
|
||||
QFile *output = new QFile(QDir::tempPath() + encryptedFile.encryptedFilename);
|
||||
|
||||
EncryptionHelper::fileEncryption(encryptedFile.encryptionKey,
|
||||
encryptedFile.initializationVector,
|
||||
input, output);
|
||||
|
||||
|
||||
qDebug() << "Removing Temporary File Temporarely";
|
||||
output->remove();
|
||||
input->deleteLater();
|
||||
output->deleteLater();
|
||||
|
||||
qDebug() << "Unlockign folder because I didn't finished the metadata yet.";
|
||||
auto *unlockJob = new UnlockEncryptFolderApiJob(_propagator->account(), _folderId, _folderToken, this);
|
||||
connect(unlockJob, &UnlockEncryptFolderApiJob::success, this, &PropagateUploadEncrypted::slotUnlockEncryptedFolderSuccess);
|
||||
connect(unlockJob, &UnlockEncryptFolderApiJob::error, this, &PropagateUploadEncrypted::slotUnlockEncryptedFolderError);
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include <QByteArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QNetworkReply>
|
||||
#include <QFile>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
#include "owncloudpropagator.h"
|
||||
|
||||
|
@ -57,6 +59,8 @@ private:
|
|||
bool _currentLockingInProgress;
|
||||
QByteArray _folderToken;
|
||||
QByteArray _folderId;
|
||||
QByteArray _generatedKey;
|
||||
QByteArray _generatedIv;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue