mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-26 22:35:55 +03:00
[CSE] Implement the empty metadata
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
5420741edb
commit
c695c50c33
3 changed files with 60 additions and 11 deletions
|
@ -26,6 +26,10 @@ elseif(UNIX AND NOT APPLE)
|
|||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now")
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${CMAKE_SOURCE_DIR}/src/3rdparty
|
||||
)
|
||||
|
||||
add_subdirectory(csync)
|
||||
add_subdirectory(libsync)
|
||||
if (NOT BUILD_LIBRARIES_ONLY)
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <openssl/err.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
|
@ -19,7 +18,6 @@
|
|||
#include <QDir>
|
||||
#include <QJsonObject>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "wordlist.h"
|
||||
|
||||
namespace OCC
|
||||
|
@ -668,19 +666,55 @@ bool SetEncryptionFlagApiJob::finished()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
//TODO: Create an actuall encryption here.
|
||||
auto metadataKeyEnc(const QByteArray& data) -> QByteArray
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
auto metadataKeyDec(const QByteArray& data) -> QByteArray
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
FolderMetadata::FolderMetadata(const QByteArray& metadata)
|
||||
{
|
||||
// This is a new folder
|
||||
/*
|
||||
if (metadata.isEmpty()) {
|
||||
|
||||
setupEmptyMetadata();
|
||||
}
|
||||
QJsonParseError err;
|
||||
_doc = QJsonDocument::fromJson(metadata, err);
|
||||
*/
|
||||
}
|
||||
|
||||
// RSA/ECB/OAEPWithSHA-256AndMGF1Padding using private / public key.
|
||||
std::string FolderMetadata::encryptMetadataKeys(const nlohmann::json& metadataKeys) const {
|
||||
// pretend to encrypt for now.
|
||||
return metadataKeys.dump();
|
||||
}
|
||||
|
||||
std::string FolderMetadata::genMetadataPass() const {
|
||||
return "4randomdiceroll";
|
||||
}
|
||||
|
||||
// AES/GCM/NoPadding (128 bit key size)
|
||||
std::string FolderMetadata::encryptJsonObject(const nlohmann::json& obj,const std::string& pass) const {
|
||||
return obj.dump();
|
||||
}
|
||||
|
||||
void FolderMetadata::setupEmptyMetadata() {
|
||||
using namespace nlohmann;
|
||||
std::string newMetadataPass = genMetadataPass();
|
||||
json metadataKeyObj = {"0", newMetadataPass};
|
||||
json recepient = {"recipient", {}};
|
||||
json m = {
|
||||
{"metadata", {
|
||||
{"metadataKeys", encryptMetadataKeys(metadataKeyObj)},
|
||||
{"sharing", encryptJsonObject(recepient, newMetadataPass)},
|
||||
{"version",1}
|
||||
}},
|
||||
{"files", {
|
||||
}}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,10 +7,13 @@
|
|||
|
||||
#include <openssl/rsa.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <string>
|
||||
|
||||
#include "accountfwd.h"
|
||||
#include "networkjobs.h"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace OCC {
|
||||
|
||||
QString baseUrl();
|
||||
|
@ -174,6 +177,8 @@ struct EncryptedFile {
|
|||
int metadataKey;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class FolderMetadata {
|
||||
FolderMetadata(const QByteArray& metadata = QByteArray());
|
||||
QByteArray encryptedMetadata();
|
||||
|
@ -182,10 +187,16 @@ class FolderMetadata {
|
|||
QVector<EncryptedFile> files() const;
|
||||
|
||||
private:
|
||||
/* Use std::string and std::vector internally on this class
|
||||
* to ease the port to Nlohmann Json API
|
||||
*/
|
||||
void setupEmptyMetadata();
|
||||
std::string encryptMetadataKeys(const nlohmann::json& metadataKeys) const;
|
||||
std::string genMetadataPass() const;
|
||||
std::string encryptJsonObject(const nlohmann::json& obj, const std::string& pass) const;
|
||||
|
||||
QVector<EncryptedFile> _files;
|
||||
QVector<int> _metadataKeys;
|
||||
|
||||
QJsonDocument _jsonMetadata;
|
||||
};
|
||||
|
||||
} // namespace OCC
|
||||
|
|
Loading…
Reference in a new issue