diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5319fbdc2..072e43963 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/libsync/clientsideencryption.cpp b/src/libsync/clientsideencryption.cpp index 7ff58efba..fecd719ee 100644 --- a/src/libsync/clientsideencryption.cpp +++ b/src/libsync/clientsideencryption.cpp @@ -9,7 +9,6 @@ #include #include -#include #include @@ -19,7 +18,6 @@ #include #include -#include #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", { + }} + }; } } diff --git a/src/libsync/clientsideencryption.h b/src/libsync/clientsideencryption.h index a6501c150..61ad3bfac 100644 --- a/src/libsync/clientsideencryption.h +++ b/src/libsync/clientsideencryption.h @@ -7,10 +7,13 @@ #include #include +#include #include "accountfwd.h" #include "networkjobs.h" +#include + 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 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 _files; QVector _metadataKeys; - - QJsonDocument _jsonMetadata; }; } // namespace OCC