// Copyright (c) 2014, IOnU Security, Inc. // Copyright (c) 2016, Sequence Logic, Inc. All rights reserved. #ifndef STORAGELOCATION_H #define STORAGELOCATION_H #include #include "../../cppjson/jsonobject.h" #ifdef WIN32 #ifdef SL_CPPCORE_DLLEXPORT #define SL_CPPCORE_EXPORT __declspec(dllexport) #else #define SL_CPPCORE_EXPORT __declspec(dllimport) #endif #else #define SL_CPPCORE_EXPORT #endif namespace sequencelogic { #if defined(WIN32) || defined(_WIN32) #pragma warning(push) #pragma warning(disable:4251 4275) // This exported class contains a data member that is an STL object. #endif /** * @brief For a regular or directory file, a single persistent location * managed by storage guard * @details * A set of StorageLocation objects describes all of the places a given * StorageNode can be found. If a user moves a secured file from the managed * directory structure, data migration will stop working for that file. * Uses getAsJson instead of IS-A JSONObject. *
* On a storage guard client, a StorageNode has local location data and * optionally remote location data. The storage guard web server might work * differrently. TODO: For StorageNode, prohibit duplicates in the locations * array. */ class SL_CPPCORE_EXPORT StorageLocation { public: /** * @brief The kind of secure file access needed * @details * */ enum class LOCATE_KIND : char { AZURE, // windows cloud drive (client SG accessible) BOX, // Box service endpoint (client SG accessible) DROPBOX, // Dropbox service endpoint (client SG accessible) FS, // host filesystem in the storage guard managed area GOOGLE_DRIVE, // Google Drive service endpoint (client SG accessible) SGWS, // remote web storage guard server, can be regional S3, // servlet accessible cloud storage UNKNOWN }; /** * @details * */ enum class LOCATE_STATUS : char { OK, PENDING, FLUSHED, LOCERROR, UNKNOWN }; /** * @brief TODO: seems redundant to KIND. There are known comparison operators * that rely on ordinal value on the Java side, perhaps this is the sole purpose. * @details * *
* SG (L2) in Chicago <----------> SG (L2) in Paris * * | \ / | * | \ / | * | \ / | * * device A (L1) S3 (CS) backup device B (L1) */ enum class LOCATE_TYPE : int { L1 = 0, L2 = 1, CS = 2, UNKNOWN }; private: /** * @brief One of the device URN, DNS host name, or name of service endpoint */ std::string m_bucket_id; /** * @brief The kind of secure file access needed for the location */ LOCATE_KIND m_kind; /** * @brief The status of the data for the location */ LOCATE_STATUS m_status; /** * @brief Models proximity of the data to the device running our SG client */ LOCATE_TYPE m_type; std::string toString(const StorageLocation::LOCATE_KIND k) const; std::string toString(const StorageLocation::LOCATE_STATUS s) const; std::string toString(const StorageLocation::LOCATE_TYPE t) const; StorageLocation::LOCATE_KIND toLocKind(const std::string& s) const; StorageLocation::LOCATE_STATUS toLocStatus(const std::string& s) const; StorageLocation::LOCATE_TYPE toLocType(const std::string& s) const; public: /** * @brief The default location is host file access with a status of "FLUSHED" * @details * Does not set the device URN, the returned object is not ready for use. */ StorageLocation() : m_type(LOCATE_TYPE::L1), m_kind(LOCATE_KIND::FS), m_status(LOCATE_STATUS::FLUSHED) {} /** * @brief Creates a storage location from a json document * @details * StorageLocation does not model IS-A JSON document. Does not assume ownership * for the given JSONObject. */ StorageLocation(const JSONObject& json); StorageLocation(LOCATE_TYPE loc_type, LOCATE_KIND loc_kind, const std::string& bucket_id, LOCATE_STATUS loc_status) : m_type(loc_type), m_kind(loc_kind), m_bucket_id(bucket_id), m_status(loc_status) {} /** * @brief Supports copy */ StorageLocation(const StorageLocation& other) : m_type(other.m_type), m_kind(other.m_kind), m_bucket_id(other.m_bucket_id), m_status(other.m_status) {} /** * @brief Supports assignment */ StorageLocation& operator=(const StorageLocation& other); virtual ~StorageLocation() {} /** * @brief One of a device URN, DNS host name, or custom value depending * on the pair of LOCATE_KIND and LOCATE_TYPE values * @details * When a device URN, the structure is: *
urn:sl:VAN:PMO:device
*
*
       * TYPE  KIND     Bucket Id
       * ----  ------   ----------------
       * L1    FS       Device URN
       * L2    FS       local host name
       * L2    SGWS     DNS host name
       * CS    S3       Custom S3 bucket id
       * CS    AZURE    MS cloud service endpoint?
       * CS    BOX      Box service endpoint
       * CS    DROPBOX  Dropbox service endpoint
       * CS    S3       Custom S3 bucket id
       * 
*/ std::string getBucketId() const { return m_bucket_id; } /** * @brief Returns the kind of secure file access for the location */ LOCATE_KIND getKind() const { return m_kind; } /** * @brief Returns the status of the data for the location */ LOCATE_STATUS getStatus() const { return m_status; } /** * @brief Returns the proximity of the data to the device running our SG client */ LOCATE_TYPE getType() const { return m_type; } /** * @brief Serializes the storage location and returns a JSON document */ std::shared_ptr getAsJson() const; void setBucketId(std::string& bucket_id) { m_bucket_id = bucket_id; } void updateStatus(LOCATE_STATUS value) { m_status = value; } }; #if defined(WIN32) || defined(_WIN32) #pragma warning(pop) #endif } // end namespace sequencelogic #endif