2017-12-17 21:38:43 +00:00
|
|
|
#ifndef PROPAGATEUPLOADENCRYPTED_H
|
|
|
|
#define PROPAGATEUPLOADENCRYPTED_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QNetworkReply>
|
2023-01-11 18:46:01 +00:00
|
|
|
#include <QScopedPointer>
|
2017-12-20 21:32:38 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QTemporaryFile>
|
2017-12-17 21:38:43 +00:00
|
|
|
|
|
|
|
#include "owncloudpropagator.h"
|
2017-12-22 22:05:39 +00:00
|
|
|
#include "clientsideencryption.h"
|
2017-12-17 21:38:43 +00:00
|
|
|
|
|
|
|
namespace OCC {
|
2017-12-20 22:30:51 +00:00
|
|
|
class FolderMetadata;
|
|
|
|
|
|
|
|
/* This class is used if the server supports end to end encryption.
|
2017-12-17 21:38:43 +00:00
|
|
|
* It will fire for *any* folder, encrypted or not, because when the
|
|
|
|
* client starts the upload request we don't know if the folder is
|
|
|
|
* encrypted on the server.
|
|
|
|
*
|
|
|
|
* emits:
|
|
|
|
* finalized() if the encrypted file is ready to be uploaded
|
|
|
|
* error() if there was an error with the encryption
|
2020-06-17 10:52:06 +00:00
|
|
|
* folderNotEncrypted() if the file is within a folder that's not encrypted.
|
2017-12-17 21:38:43 +00:00
|
|
|
*
|
|
|
|
*/
|
2017-12-20 22:30:51 +00:00
|
|
|
|
2017-12-17 21:38:43 +00:00
|
|
|
class PropagateUploadEncrypted : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-06-30 09:21:02 +00:00
|
|
|
PropagateUploadEncrypted(OwncloudPropagator *propagator, const QString &remoteParentPath, SyncFileItemPtr item, QObject *parent = nullptr);
|
2021-08-17 10:39:31 +00:00
|
|
|
~PropagateUploadEncrypted() override = default;
|
2021-01-21 15:07:30 +00:00
|
|
|
|
2017-12-17 21:38:43 +00:00
|
|
|
void start();
|
|
|
|
|
2021-01-21 15:07:30 +00:00
|
|
|
void unlockFolder();
|
|
|
|
|
2022-09-30 17:12:08 +00:00
|
|
|
[[nodiscard]] bool isUnlockRunning() const { return _isUnlockRunning; }
|
|
|
|
[[nodiscard]] bool isFolderLocked() const { return _isFolderLocked; }
|
|
|
|
[[nodiscard]] const QByteArray folderToken() const { return _folderToken; }
|
2017-12-20 23:35:23 +00:00
|
|
|
|
2017-12-17 21:38:43 +00:00
|
|
|
private slots:
|
|
|
|
void slotFolderEncryptedIdReceived(const QStringList &list);
|
|
|
|
void slotFolderEncryptedIdError(QNetworkReply *r);
|
|
|
|
void slotFolderLockedSuccessfully(const QByteArray& fileId, const QByteArray& token);
|
|
|
|
void slotFolderLockedError(const QByteArray& fileId, int httpErrorCode);
|
|
|
|
void slotTryLock(const QByteArray& fileId);
|
2018-03-25 19:54:08 +00:00
|
|
|
void slotFolderEncryptedMetadataReceived(const QJsonDocument &json, int statusCode);
|
|
|
|
void slotFolderEncryptedMetadataError(const QByteArray& fileId, int httpReturnCode);
|
2017-12-22 22:05:39 +00:00
|
|
|
void slotUpdateMetadataSuccess(const QByteArray& fileId);
|
|
|
|
void slotUpdateMetadataError(const QByteArray& fileId, int httpReturnCode);
|
2017-12-17 21:38:43 +00:00
|
|
|
|
|
|
|
signals:
|
2023-06-02 11:55:08 +00:00
|
|
|
// Emitted after the file is encrypted and everything is setup.
|
2017-12-20 22:36:49 +00:00
|
|
|
void finalized(const QString& path, const QString& filename, quint64 size);
|
2017-12-17 21:38:43 +00:00
|
|
|
void error();
|
2021-01-21 11:19:41 +00:00
|
|
|
void folderUnlocked(const QByteArray &folderId, int httpStatus);
|
2017-12-17 21:38:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
OwncloudPropagator *_propagator;
|
2020-06-23 16:13:20 +00:00
|
|
|
QString _remoteParentPath;
|
2017-12-17 21:38:43 +00:00
|
|
|
SyncFileItemPtr _item;
|
|
|
|
|
2021-01-21 15:07:30 +00:00
|
|
|
QByteArray _folderToken;
|
|
|
|
QByteArray _folderId;
|
|
|
|
|
2017-12-17 21:38:43 +00:00
|
|
|
QElapsedTimer _folderLockFirstTry;
|
2018-04-03 19:38:10 +00:00
|
|
|
bool _currentLockingInProgress = false;
|
2017-12-20 23:35:23 +00:00
|
|
|
|
2021-01-21 15:07:30 +00:00
|
|
|
bool _isUnlockRunning = false;
|
|
|
|
bool _isFolderLocked = false;
|
|
|
|
|
2017-12-20 21:32:38 +00:00
|
|
|
QByteArray _generatedKey;
|
|
|
|
QByteArray _generatedIv;
|
2023-01-11 18:46:01 +00:00
|
|
|
QScopedPointer<FolderMetadata> _metadata;
|
2017-12-22 22:05:39 +00:00
|
|
|
EncryptedFile _encryptedFile;
|
2018-01-21 20:59:19 +00:00
|
|
|
QString _completeFileName;
|
2017-12-17 21:38:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|