// Copyright (c) 2013, IOnU Security, Inc. // Copyright (c) 2016, Sequence Logic, Inc. All rights reserved. /** * The CloudGuardURN helper... */ #ifndef CLOUD_GUARD_URN #define CLOUD_GUARD_URN #include "../../libeye/eyeconstants.h" #include #include #if defined(WIN32) && !defined(SL_SHELL_EXT) #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 { /** * All objects managed by CloudGuard use an URN: scheme. Format is generallly: *
     * General URN syntax:
     * 		'urn:sl:'NSS
     * where NSS is the Namespace Specific String (our namespace is sl) and is of the form:
     * 		[VANID]:[PMOID]:[DEVICEID]:[DOCUMENTID]
     * VANID is a 6 hex char VAN ID; always required
     * PMOID is an 8 hex char PMO ID; optional
     * DEVICEID is a 4 hex char Device ID; optional
     * DOCUMENTID is a 12 char Document ID; optional
     * 
     * Note that CG URN's will be max length 40 (plus a null byte in C-ville).
     * 
* * @see http://www.ietf.org/rfc/rfc2141.txt * @author tim * @author Viggy (for the C++ code) * */ class CloudGuardURN; typedef std::shared_ptr CloudGuardURNPtr; class SL_CPPCORE_EXPORT CloudGuardURN { public: enum URN_TYPE { INVALID, VAN, PMO, PMO_DEVICE, PMO_DEVICE_DOCUMENT }; static const char NAMESPACE[]; /** * Exact length of NSS specific part of URN. */ static const int NSS_LENGTH; /** * Regular expression of id's to not generate UUID's for. */ #if defined(WIN32) || defined(_WIN32) #pragma warning(push) #pragma warning(disable:4251) #endif static std::string DO_NOT_GENERATE_UUIDS; #if defined(WIN32) || defined(_WIN32) #pragma warning(pop) #endif /** * Is this an ID not to generate UUID? */ static bool isDoNotGenerateUUID(const char *pIdStr); static bool isDoNotGenerateUUID(const std::string &idStr) { return isDoNotGenerateUUID(idStr.c_str()); } CloudGuardURN() : _type(INVALID) {} CloudGuardURN(const CloudGuardURN &oldURN) : _type(INVALID) { setUrn(oldURN.getUrn()); } CloudGuardURN(const std::string &urnStr) : _type(INVALID) { setUrn(urnStr); } CloudGuardURN(const std::string &van, const std::string &pmo, const std::string &dev = "", const std::string &doc = "") : _type(INVALID) { setUrn(std::string(NAMESPACE) + van + ":" + pmo + ":" + dev + ":" + doc); } CloudGuardURN(const CloudGuardURN &urnBase, const std::string &docUUID) : _type(INVALID) { setUrn(std::string(NAMESPACE) + urnBase.getVANID() + ":" + urnBase.getPMOID() + ":" + urnBase.getDeviceID() + ":" + docUUID); } ~CloudGuardURN() {} CloudGuardURN& operator=(const CloudGuardURN &rhs); /** * Less then operator, for sorting. */ bool operator<(const CloudGuardURN &rhs) const { return (_urn < rhs._urn); } /** * Comparators... */ bool operator==(const CloudGuardURN &rhs) const { return (_urn == rhs._urn); } bool operator!=(const CloudGuardURN &rhs) const { return !(operator==(rhs)); } /** * Get the complete URN. */ std::string getUrn() const { return _urn; } /** * Get the URN type. */ URN_TYPE getType() const { return _type; } /** * Get the VAN ID. */ std::string getVANID() const { return _vanID; } /** * Get the PMO ID. */ std::string getPMOID() const { return _pmoID; } /** * Get the device ID. */ std::string getDeviceID() const { return _deviceID; } /** * Get the document ID. */ std::string getDocumentID() const { return _docID; } /** * Get the NSS part of the URN string... */ std::string toNSS() const; /** * Group documents always use GROUP_DOC_DEVICE_ID for the device. They are sort of like a * PMO URN with a 0001 for device and a document value. */ bool isGroupURN() const { return (getDeviceID() == GROUP_DOC_DEVICE_ID); } /** * Set the URN strings. * Return false if setting failed. */ bool setUrn(const std::string &urnStr); /** * Reset an URN (clear it out). */ void reset(); /** * Get an URN as type X. */ CloudGuardURN as(URN_TYPE nType) const; /** * Generate a unique (probabilistically anyway) UUID of length given. * Does not generate reserved values. * @param len * @return */ static std::string generateUUID(int len); private: #if defined(WIN32) || defined(_WIN32) #pragma warning(push) #pragma warning(disable:4251) // Disable the dumbass XXXX needs to have dll-interface. Clients can't access this data anyway! #endif /** * The complete URN. */ std::string _urn; /** * URN parts. Makes querying easier, rather then splitting the complete URN string * apart for every query of the individual parts. */ std::string _vanID; std::string _pmoID; std::string _deviceID; std::string _docID; /** * URN type. */ URN_TYPE _type; /** * Overloaded 'setUrn' function. Set the URN using just the parts we're interested in. Don't make 'pmo' have a default value, * as this will interfere with the public version of 'setUrn' (ambiguous function call) */ bool setUrn(const std::string &van, const std::string &pmo, const std::string &dev = "", const std::string &doc = ""); #if defined(WIN32) || defined(_WIN32) #pragma warning(pop) #endif }; SL_CPPCORE_EXPORT std::ostream &operator<<(std::ostream &out, const CloudGuardURN *pUrn); inline std::ostream &operator<<(std::ostream &out, const CloudGuardURN &urn) { return operator<<(out, &urn); } }; #endif