From 9119e2b9bbb11b4ae21618fbaacfe6edaeb2a62b Mon Sep 17 00:00:00 2001 From: Gabriele Contini <contini.mailing@gmail.com> Date: 周六, 15 2月 2020 23:49:50 +0800 Subject: [PATCH] pc identifiers work --- src/library/hw_identifier/hw_identifier_facade.hpp | 32 +++ src/library/hw_identifier/default_strategy.hpp | 10 .gitignore | 2 src/library/limits/license_verifier.cpp | 4 src/library/hw_identifier/hw_identifier_facade.cpp | 18 src/library/hw_identifier/identification_strategy.cpp | 23 + test/library/hw_identifier/hw_identifier_facade_test.cpp | 4 doc/Integration.md | 2 src/inspector/inspector.cpp | 6 src/library/hw_identifier/CMakeLists.txt | 12 + src/library/hw_identifier/hw_identifier.hpp | 32 +- src/library/hw_identifier/identification_strategy.hpp | 23 + test/library/hw_identifier/ethernet_test.cpp | 0 test/library/hw_identifier/hw_identifier_test.cpp | 28 +- doc/Hardware-identifiers.md | 2 src/library/os/CMakeLists.txt | 2 src/library/hw_identifier/hw_identifier.cpp | 99 +++++++++ test/library/CMakeLists.txt | 2 test/library/hw_identifier/disk_strategy_test.cpp | 0 test/functional/CMakeLists.txt | 2 test/functional/standard-license_test.cpp | 4 test/functional/hw_identifier_it_test.cpp | 26 +- src/templates/licensecc_properties.h.in | 2 src/library/CMakeLists.txt | 4 src/library/hw_identifier/pc-identifiers.h | 0 doc/features.md | 2 test/library/hw_identifier/CMakeLists.txt | 16 + src/library/hw_identifier/pc-identifiers.c | 0 src/library/hw_identifier/ethernet.hpp | 9 /dev/null | 12 - test/library/os/CMakeLists.txt | 6 src/library/hw_identifier/disk_strategy.cpp | 41 +--- src/library/licensecc.cpp | 6 src/library/os/windows/signature_verifier.cpp | 11 src/library/hw_identifier/ethernet.cpp | 78 +++++++ src/library/hw_identifier/default_strategy.cpp | 15 include/licensecc/licensecc.h | 2 src/library/hw_identifier/disk_strategy.hpp | 9 38 files changed, 383 insertions(+), 163 deletions(-) diff --git a/.gitignore b/.gitignore index 8b11b9e..2d30086 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ #Visual studio files .vs +/out # Compiled Static libraries *.lai @@ -33,3 +34,4 @@ **/CMakeCache.txt **/CMakeFiles +/CMakeSettings.json diff --git a/doc/Hardware-identifiers.md b/doc/Hardware-identifiers.md index 1967f3f..7a18fe6 100644 --- a/doc/Hardware-identifiers.md +++ b/doc/Hardware-identifiers.md @@ -7,7 +7,7 @@ This is straightforward case. If the software is executing on a physical hardware it is possible to identify the hardware by various parameters (cpu type/memory/disk label/mac address) ### Execution in a virtual machine -Generating a pc identifier on a virtual machine doesn't make much sense, since the vm can be copied as a whole elsewhere +Generating a hardware identifier on a virtual machine doesn't make much sense, since the vm can be copied as a whole elsewhere and there are few ways to detect this without using an external license server. * Usually when the machine is copied the MAC address is changed. But sometimes it changes on its own. Software publishers may want to use this as a last resort to prevent the vm for being cloned. It has to be verified case by case. diff --git a/doc/Integration.md b/doc/Integration.md index f721be3..92ed11c 100644 --- a/doc/Integration.md +++ b/doc/Integration.md @@ -6,7 +6,7 @@ The file containing the public api is `include/licensecc/licensecc.h`. Functions in there are considered stable. -### Print a pc identifier +### Print a hardware identifier ```CPP bool identify_pc(IDENTIFICATION_STRATEGY pc_id_method, char* identifier_out, size_t bufSize); diff --git a/doc/features.md b/doc/features.md index 06141ae..b2c516c 100644 --- a/doc/features.md +++ b/doc/features.md @@ -32,7 +32,7 @@ A licensed software may be composed by many features (functions) each one activable independently. Licensing system tells the licensed software which features are enabled, and which features are disabled. ## License Management (planned) -It is necessary to keep track of the licenses that have been issued, of the clients, and their pc identifier. +It is necessary to keep track of the licenses that have been issued, of the clients, and their hardware identifier. A web application is planned that will provide integration with payment systems to allow licensed software customers to buy licenses. ## Customizable execution limits (planned) diff --git a/include/licensecc/licensecc.h b/include/licensecc/licensecc.h index dd0d9c6..0b0391c 100644 --- a/include/licensecc/licensecc.h +++ b/include/licensecc/licensecc.h @@ -22,7 +22,7 @@ void print_error(char out_buffer[LCC_API_ERROR_BUFFER_SIZE], LicenseInfo* licenseInfo); /** - * This method calculates the pc identifier. The string need to be shown to the user and given back to the software + * This method calculates the hardware identifier. The string need to be shown to the user and given back to the software * editor when issuing a license. * pc_id_method = STRATEGY_DEFAULT usually works. */ diff --git a/src/inspector/inspector.cpp b/src/inspector/inspector.cpp index 160c016..ee3a483 100644 --- a/src/inspector/inspector.cpp +++ b/src/inspector/inspector.cpp @@ -42,11 +42,11 @@ cout << "Virtual machine:" << cpu.cpu_virtual() << endl; cout << "Cpu model : 0x" << std::hex << ((long)cpu.model()) << std::dec << endl; - char pc_identifier[LCC_API_PC_IDENTIFIER_SIZE + 1]; + char hw_identifier[LCC_API_PC_IDENTIFIER_SIZE + 1]; size_t bufSize = LCC_API_PC_IDENTIFIER_SIZE + 1; for (const auto& x : stringByStrategyId) { - if (identify_pc(x.first, pc_identifier, &bufSize)) { - std::cout << x.second << ':' << pc_identifier << std::endl; + if (identify_pc(x.first, hw_identifier, &bufSize)) { + std::cout << x.second << ':' << hw_identifier << std::endl; } else { std::cout << x.second << ": NA" << endl; diff --git a/src/library/CMakeLists.txt b/src/library/CMakeLists.txt index 9a70020..c616db0 100644 --- a/src/library/CMakeLists.txt +++ b/src/library/CMakeLists.txt @@ -1,14 +1,14 @@ add_subdirectory("base") add_subdirectory("os") add_subdirectory("locate") -add_subdirectory("pc_identifier") +add_subdirectory("hw_identifier") ADD_LIBRARY(licensecc_static STATIC licensecc.cpp LicenseReader.cpp limits/license_verifier.cpp ini/ConvertUTF.c - $<TARGET_OBJECTS:pc_identifier> + $<TARGET_OBJECTS:hw_identifier> $<TARGET_OBJECTS:locate> $<TARGET_OBJECTS:os> $<TARGET_OBJECTS:base> diff --git a/src/library/hw_identifier/CMakeLists.txt b/src/library/hw_identifier/CMakeLists.txt new file mode 100644 index 0000000..09ba5e0 --- /dev/null +++ b/src/library/hw_identifier/CMakeLists.txt @@ -0,0 +1,12 @@ +add_library(hw_identifier OBJECT + hw_identifier_facade.cpp + default_strategy.cpp + ethernet.cpp + disk_strategy.cpp + identification_strategy.cpp + hw_identifier.cpp +) + +if(CODE_COVERAGE AND UNIX) + target_compile_options(hw_identifier PUBLIC -O0 -g --coverage) +endif(CODE_COVERAGE AND UNIX) \ No newline at end of file diff --git a/src/library/pc_identifier/default_strategy.cpp b/src/library/hw_identifier/default_strategy.cpp similarity index 84% rename from src/library/pc_identifier/default_strategy.cpp rename to src/library/hw_identifier/default_strategy.cpp index 0ef4561..a770512 100644 --- a/src/library/pc_identifier/default_strategy.cpp +++ b/src/library/hw_identifier/default_strategy.cpp @@ -6,13 +6,12 @@ */ #include <vector> -#include "pc_identifier_facade.hpp" #include "../os/execution_environment.hpp" #include "default_strategy.hpp" using namespace std; namespace license { -namespace pc_identifier { +namespace hw_identifier { static vector<LCC_API_IDENTIFICATION_STRATEGY> available_strategies() { ExecutionEnvironment exec; @@ -42,7 +41,7 @@ LCC_API_IDENTIFICATION_STRATEGY DefaultStrategy::identification_strategy() const { return STRATEGY_DEFAULT; } -FUNCTION_RETURN DefaultStrategy::identify_pc(PcIdentifier& pc_id) const { +FUNCTION_RETURN DefaultStrategy::identify_pc(HwIdentifier& pc_id) const { vector<LCC_API_IDENTIFICATION_STRATEGY> strategy_to_try = available_strategies(); FUNCTION_RETURN ret = FUNC_RET_NOT_AVAIL; for (auto it : strategy_to_try) { @@ -56,23 +55,23 @@ return ret; } -std::vector<PcIdentifier> DefaultStrategy::alternative_ids() const { +std::vector<HwIdentifier> DefaultStrategy::alternative_ids() const { vector<LCC_API_IDENTIFICATION_STRATEGY> strategy_to_try = available_strategies(); - vector<PcIdentifier> identifiers; + vector<HwIdentifier> identifiers; FUNCTION_RETURN ret = FUNC_RET_NOT_AVAIL; for (auto it : strategy_to_try) { LCC_API_IDENTIFICATION_STRATEGY strat_to_try = it; unique_ptr<IdentificationStrategy> strategy_ptr = IdentificationStrategy::get_strategy(strat_to_try); - vector<PcIdentifier> alt_ids = strategy_ptr->alternative_ids(); + vector<HwIdentifier> alt_ids = strategy_ptr->alternative_ids(); identifiers.insert(alt_ids.begin(), alt_ids.end(), identifiers.end()); } return identifiers; } -LCC_EVENT_TYPE DefaultStrategy::validate_identifier(const PcIdentifier& identifier) const { +LCC_EVENT_TYPE DefaultStrategy::validate_identifier(const HwIdentifier& identifier) const { // default strategy should always realize itself as a concrete strategy return IDENTIFIERS_MISMATCH; } -} // namespace pc_identifier +} // namespace hw_identifier } /* namespace license */ diff --git a/src/library/pc_identifier/default_strategy.hpp b/src/library/hw_identifier/default_strategy.hpp similarity index 69% rename from src/library/pc_identifier/default_strategy.hpp rename to src/library/hw_identifier/default_strategy.hpp index cefb9f8..8f43827 100644 --- a/src/library/pc_identifier/default_strategy.hpp +++ b/src/library/hw_identifier/default_strategy.hpp @@ -10,18 +10,18 @@ #include "identification_strategy.hpp" namespace license { -namespace pc_identifier { +namespace hw_identifier { class DefaultStrategy : public IdentificationStrategy { public: DefaultStrategy(); virtual ~DefaultStrategy(); virtual LCC_API_IDENTIFICATION_STRATEGY identification_strategy() const; - virtual FUNCTION_RETURN identify_pc(PcIdentifier &pc_id) const; - virtual std::vector<PcIdentifier> alternative_ids() const; - virtual LCC_EVENT_TYPE validate_identifier(const PcIdentifier &identifier) const; + virtual FUNCTION_RETURN identify_pc(HwIdentifier &pc_id) const; + virtual std::vector<HwIdentifier> alternative_ids() const; + virtual LCC_EVENT_TYPE validate_identifier(const HwIdentifier &identifier) const; }; -} // namespace pc_identifier +} // namespace hw_identifier } /* namespace license */ #endif /* SRC_LIBRARY_PC_IDENTIFIER_DEFAULT_STRATEGY_HPP_ */ diff --git a/src/library/pc_identifier/disk_strategy.cpp b/src/library/hw_identifier/disk_strategy.cpp similarity index 66% rename from src/library/pc_identifier/disk_strategy.cpp rename to src/library/hw_identifier/disk_strategy.cpp index 20fe310..cec5da8 100644 --- a/src/library/pc_identifier/disk_strategy.cpp +++ b/src/library/hw_identifier/disk_strategy.cpp @@ -10,9 +10,9 @@ using namespace std; namespace license { -namespace pc_identifier { +namespace hw_identifier { -static FUNCTION_RETURN generate_disk_pc_id(vector<array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA>> &v_disk_id, +static FUNCTION_RETURN generate_disk_pc_id(vector<array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA>> &v_disk_id, bool use_id) { size_t disk_num, available_disk_info = 0; FUNCTION_RETURN result_diskinfos; @@ -47,7 +47,7 @@ } v_disk_id.reserve(available_disk_info); for (i = 0; i < disk_num; i++) { - array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA> a_disk_id; + array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA> a_disk_id; if (use_id) { if (diskInfos[i].disk_sn[0] != 0) { memcpy(&a_disk_id[0], &diskInfos[i].disk_sn[2], a_disk_id.size()); @@ -65,33 +65,22 @@ return FUNC_RET_OK; } -DiskStrategy::DiskStrategy(bool use_id) : m_use_id(use_id) { -} +DiskStrategy::DiskStrategy(bool use_id) : m_use_id(use_id) {} -DiskStrategy::~DiskStrategy() { -} +DiskStrategy::~DiskStrategy() {} LCC_API_IDENTIFICATION_STRATEGY DiskStrategy::identification_strategy() const { return m_use_id ? STRATEGY_DISK_NUM : STRATEGY_DISK_LABEL; } -FUNCTION_RETURN DiskStrategy::identify_pc(PcIdentifier &pc_id) const { - vector<array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA>> data; +std::vector<HwIdentifier> DiskStrategy::alternative_ids() const { + vector<array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA>> data; FUNCTION_RETURN result = generate_disk_pc_id(data, m_use_id); - if (result == FUNC_RET_OK) { - pc_id.set_data(data[0]); - } - return result; -} - -std::vector<PcIdentifier> DiskStrategy::alternative_ids() const { - vector<array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA>> data; - FUNCTION_RETURN result = generate_disk_pc_id(data, m_use_id); - vector<PcIdentifier> identifiers; + vector<HwIdentifier> identifiers; if (result == FUNC_RET_OK) { identifiers.resize(data.size()); for (auto &it : data) { - PcIdentifier pc_id; + HwIdentifier pc_id; pc_id.set_identification_strategy(identification_strategy()); pc_id.set_data(it); identifiers.push_back(pc_id); @@ -100,15 +89,5 @@ return identifiers; } -LCC_EVENT_TYPE DiskStrategy::validate_identifier(const PcIdentifier &identifier) const { - vector<array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA>> data; - FUNCTION_RETURN generate_ethernet = generate_disk_pc_id(data, m_use_id); - LCC_EVENT_TYPE result = IDENTIFIERS_MISMATCH; - if (generate_ethernet == FUNC_RET_OK) { - result = validate_identifier(identifier, data); - } - return result; -} - -} // namespace pc_identifier +} // namespace hw_identifier } /* namespace license */ diff --git a/src/library/pc_identifier/disk_strategy.hpp b/src/library/hw_identifier/disk_strategy.hpp similarity index 63% rename from src/library/pc_identifier/disk_strategy.hpp rename to src/library/hw_identifier/disk_strategy.hpp index dd095d3..67f5998 100644 --- a/src/library/pc_identifier/disk_strategy.hpp +++ b/src/library/hw_identifier/disk_strategy.hpp @@ -11,7 +11,7 @@ #include "identification_strategy.hpp" namespace license { -namespace pc_identifier { +namespace hw_identifier { class DiskStrategy : public IdentificationStrategy { private: @@ -20,13 +20,10 @@ DiskStrategy(bool use_id); virtual ~DiskStrategy(); virtual LCC_API_IDENTIFICATION_STRATEGY identification_strategy() const; - virtual FUNCTION_RETURN identify_pc(PcIdentifier &pc_id) const; - virtual std::vector<PcIdentifier> alternative_ids() const; - using IdentificationStrategy::validate_identifier; - virtual LCC_EVENT_TYPE validate_identifier(const PcIdentifier &identifier) const; + virtual std::vector<HwIdentifier> alternative_ids() const; }; -} // namespace pc_identifier +} // namespace hw_identifier } /* namespace license */ #endif /* SRC_LIBRARY_PC_IDENTIFIER_DISK_STRATEGY_HPP_ */ diff --git a/src/library/hw_identifier/ethernet.cpp b/src/library/hw_identifier/ethernet.cpp new file mode 100644 index 0000000..1d923e6 --- /dev/null +++ b/src/library/hw_identifier/ethernet.cpp @@ -0,0 +1,78 @@ +/* + * ethernet.cpp + * + * Created on: Jan 11, 2020 + * Author: GC + */ + +#include <array> +#include <vector> + +#include <licensecc/datatypes.h> +#include <licensecc_properties.h> +#include "../base/base.h" +#include "../os/network.hpp" +#include "hw_identifier.hpp" +#include "ethernet.hpp" + +namespace license { +namespace hw_identifier { +using namespace std; + +static FUNCTION_RETURN generate_ethernet_pc_id(vector<array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA>> &data, + const bool use_ip) { + vector<os::OsAdapterInfo> adapters; + + FUNCTION_RETURN result_adapterInfos = getAdapterInfos(adapters); + if (result_adapterInfos != FUNC_RET_OK) { + return result_adapterInfos; + } + if (adapters.size() == 0) { + return FUNC_RET_NOT_AVAIL; + } + + for (auto &it : adapters) { + unsigned int k, data_len, data_byte; + array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA> identifier; + data_len = use_ip ? sizeof(os::OsAdapterInfo::ipv4_address) : sizeof(os::OsAdapterInfo::mac_address); + + for (k = 0; k < HW_IDENTIFIER_PROPRIETARY_DATA; k++) { + if (k < data_len) { + identifier[k] = use_ip ? it.ipv4_address[k] : it.mac_address[k]; + } else { + identifier[k] = 42; + } + } + identifier[0] = identifier[0] & 0x1F; + data.push_back(identifier); + } + + return result_adapterInfos; +} + +Ethernet::Ethernet(bool useIp) : use_ip(useIp) {} + +Ethernet::~Ethernet() {} + +LCC_API_IDENTIFICATION_STRATEGY Ethernet::identification_strategy() const { + return use_ip ? STRATEGY_IP_ADDRESS : STRATEGY_ETHERNET; +} + +std::vector<HwIdentifier> Ethernet::alternative_ids() const { + vector<array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA>> data; + FUNCTION_RETURN result = generate_ethernet_pc_id(data, use_ip); + vector<HwIdentifier> identifiers; + if (result == FUNC_RET_OK) { + identifiers.resize(data.size()); + for (auto &it : data) { + HwIdentifier pc_id; + pc_id.set_identification_strategy(identification_strategy()); + pc_id.set_data(it); + identifiers.push_back(pc_id); + } + } + return identifiers; +} + +} // namespace hw_identifier +} /* namespace license */ diff --git a/src/library/pc_identifier/ethernet.hpp b/src/library/hw_identifier/ethernet.hpp similarity index 62% rename from src/library/pc_identifier/ethernet.hpp rename to src/library/hw_identifier/ethernet.hpp index f857ba4..e02d2c1 100644 --- a/src/library/pc_identifier/ethernet.hpp +++ b/src/library/hw_identifier/ethernet.hpp @@ -11,7 +11,7 @@ #include "identification_strategy.hpp" namespace license { -namespace pc_identifier { +namespace hw_identifier { class Ethernet : public IdentificationStrategy { private: @@ -20,13 +20,10 @@ Ethernet(bool use_ip); virtual ~Ethernet(); virtual LCC_API_IDENTIFICATION_STRATEGY identification_strategy() const; - virtual FUNCTION_RETURN identify_pc(PcIdentifier &pc_id) const; - virtual std::vector<PcIdentifier> alternative_ids() const; - using IdentificationStrategy::validate_identifier; - virtual LCC_EVENT_TYPE validate_identifier(const PcIdentifier &identifier) const; + virtual std::vector<HwIdentifier> alternative_ids() const; }; -} // namespace pc_identifier +} // namespace hw_identifier } /* namespace license */ #endif /* SRC_LIBRARY_PC_IDENTIFIER_ETHERNET_HPP_ */ diff --git a/src/library/hw_identifier/hw_identifier.cpp b/src/library/hw_identifier/hw_identifier.cpp new file mode 100644 index 0000000..b0d31f8 --- /dev/null +++ b/src/library/hw_identifier/hw_identifier.cpp @@ -0,0 +1,99 @@ +/* + * hw_identifier.cpp + * + * Created on: Dec 22, 2019 + * Author: GC + */ + +#include <algorithm> +#include "hw_identifier.hpp" +#include "../base/base64.h" + +namespace license { +namespace hw_identifier { + +using namespace std; + +HwIdentifier::HwIdentifier() {} + +HwIdentifier::HwIdentifier(const std::string& param) { + string tmp_str(param); // throw away const + std::replace(tmp_str.begin(), tmp_str.end(), '-', '\n'); + vector<uint8_t> decoded = unbase64(tmp_str); + if (decoded.size() != HW_IDENTIFIER_PROPRIETARY_DATA + 1) { + cerr << decoded.size(); + throw logic_error("wrong identifier size " + param); + } + std::copy_n(decoded.begin(), HW_IDENTIFIER_PROPRIETARY_DATA + 1, m_data.begin()); +} + +HwIdentifier::~HwIdentifier() {} + +HwIdentifier::HwIdentifier(const HwIdentifier& other) : m_data(other.m_data) {} + +void HwIdentifier::set_identification_strategy(LCC_API_IDENTIFICATION_STRATEGY strategy) { + if (strategy == STRATEGY_NONE || strategy == STRATEGY_DEFAULT) { + throw logic_error("Only known strategies are permitted"); + } + uint8_t stratMov = (strategy << 5); + m_data[1] = (m_data[1] & 0x1F) | stratMov; +} + +void HwIdentifier::set_use_environment_var(bool use_env_var) { + if (use_env_var) { + m_data[0] = m_data[0] | 0x40; + } else { + m_data[0] = m_data[0] & ~0x40; + } +} + +void HwIdentifier::set_virtual_environment(VIRTUALIZATION virt) { + // 110000 0x30 + m_data[0] = (m_data[0] & ~0x30) | virt << 4; +} + +void HwIdentifier::set_virtualization(VIRTUALIZATION_DETAIL virtualization_detail) { + m_data[0] = (m_data[0] & ~0x0F) | virtualization_detail; +} + +void HwIdentifier::set_cloud_provider(CLOUD_PROVIDER cloud_provider) { + m_data[0] = (m_data[0] & ~0x0F) | cloud_provider | 0x08; +} + +void HwIdentifier::set_data(const std::array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA>& data) { + m_data[1] = (m_data[1] & (~0x1f)) | (data[0] & 0x1f); + for (int i = 1; i < HW_IDENTIFIER_PROPRIETARY_DATA; i++) { + m_data[i + 1] = data[i]; + } +} + +std::string HwIdentifier::print() const { + string result = base64(m_data.data(), m_data.size(), 5); + std::replace(result.begin(), result.end(), '\n', '-'); + return result.substr(0, result.size() - 1); +} + +LCC_API_IDENTIFICATION_STRATEGY HwIdentifier::get_identification_strategy() const { + uint8_t stratMov = m_data[1] >> 5; + return static_cast<LCC_API_IDENTIFICATION_STRATEGY>(stratMov); +} + +bool HwIdentifier::data_match(const std::array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA>& data) const { + bool equals = true; + for (int i = 0; i < HW_IDENTIFIER_PROPRIETARY_DATA && equals; i++) { + equals = (i == 0) ? ((data[i] & 0x1f) == (m_data[i + 1] & 0x1f)) : (data[i] == m_data[i + 1]); + } + return equals; +} + +bool operator==(const HwIdentifier& lhs, const HwIdentifier& rhs) { + bool equals = lhs.get_identification_strategy() == rhs.get_identification_strategy(); + for (int i = 0; i < HW_IDENTIFIER_PROPRIETARY_DATA && equals; i++) { + equals = (i == 0) ? ((rhs.m_data[i + 1] & 0x1f) == (lhs.m_data[i + 1] & 0x1f)) + : (lhs.m_data[i + 1] == rhs.m_data[i + 1]); + } + return equals; +} + +} // namespace hw_identifier +} /* namespace license */ diff --git a/src/library/pc_identifier/pc_identifier.hpp b/src/library/hw_identifier/hw_identifier.hpp similarity index 66% rename from src/library/pc_identifier/pc_identifier.hpp rename to src/library/hw_identifier/hw_identifier.hpp index 81957c2..d7cec0e 100644 --- a/src/library/pc_identifier/pc_identifier.hpp +++ b/src/library/hw_identifier/hw_identifier.hpp @@ -1,5 +1,5 @@ /* - * pc_identifier.h + * hw_identifier.h * * Created on: Dec 22, 2019 * Author: GC @@ -18,9 +18,9 @@ #include "../os/cpu_info.hpp" namespace license { -namespace pc_identifier { +namespace hw_identifier { -#define PC_IDENTIFIER_PROPRIETARY_DATA 8 +#define HW_IDENTIFIER_PROPRIETARY_DATA 8 /** * data[0] @@ -33,38 +33,40 @@ * if on premise vm bits 2-1-0 are virtualization technology * if cloud vm bits 2-1-0 identify cloud provider * - * if bit 7 = 1 pc identifier is used to enable some flag that we don't want to show openly in the license + * if bit 7 = 1 hardware identifier is used to enable some flag that we don't want to show openly in the license * bit 6 = 1 enable magic file/registry key * ---- * data[1] bit 7-6-5 define identification strategy. - * data[1] bits 4-0, data[2-8] are pc identifier proprietary strategy data. + * data[1] bits 4-0, data[2-8] are hardware identifier proprietary strategy data. */ -class PcIdentifier { +class HwIdentifier { private: - std::array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA + 1> m_data = {}; + std::array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA + 1> m_data = {}; + friend bool operator==(const HwIdentifier &lhs, const HwIdentifier &rhs); public: - PcIdentifier(); - PcIdentifier(const std::string ¶m); - virtual ~PcIdentifier(); - PcIdentifier(const PcIdentifier &other); + HwIdentifier(); + HwIdentifier(const std::string ¶m); + virtual ~HwIdentifier(); + HwIdentifier(const HwIdentifier &other); void set_identification_strategy(LCC_API_IDENTIFICATION_STRATEGY strategy); LCC_API_IDENTIFICATION_STRATEGY get_identification_strategy() const; void set_use_environment_var(bool use_env_var); void set_virtual_environment(VIRTUALIZATION virtualization); void set_virtualization(VIRTUALIZATION_DETAIL virtualization_detail); void set_cloud_provider(CLOUD_PROVIDER cloud_provider); - void set_data(const std::array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA> &data); - bool data_match(const std::array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA> &data) const; + void set_data(const std::array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA> &data); + bool data_match(const std::array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA> &data) const; std::string print() const; - friend std::ostream &operator<<(std::ostream &output, const PcIdentifier &d) { + friend std::ostream &operator<<(std::ostream &output, const HwIdentifier &d) { output << d.print(); return output; }; }; -} // namespace pc_identifier + +} // namespace hw_identifier } /* namespace license */ #endif /* SRC_LIBRARY_PC_IDENTIFIER_PC_IDENTIFIER_HPP_ */ diff --git a/src/library/pc_identifier/pc_identifier_facade.cpp b/src/library/hw_identifier/hw_identifier_facade.cpp similarity index 85% rename from src/library/pc_identifier/pc_identifier_facade.cpp rename to src/library/hw_identifier/hw_identifier_facade.cpp index a9aa9b8..45abb5d 100644 --- a/src/library/pc_identifier/pc_identifier_facade.cpp +++ b/src/library/hw_identifier/hw_identifier_facade.cpp @@ -1,11 +1,11 @@ /* - * pc_identifier_facade.cpp + * hw_identifier_facade.cpp * * Created on: Dec 26, 2019 * Author: devel */ -#include "pc_identifier_facade.hpp" +#include "hw_identifier_facade.hpp" #include <cstdlib> #include <stdexcept> @@ -15,15 +15,15 @@ #include "../os/cpu_info.hpp" #include "../os/execution_environment.hpp" #include "identification_strategy.hpp" -#include "pc_identifier.hpp" +#include "hw_identifier.hpp" namespace license { -namespace pc_identifier { +namespace hw_identifier { using namespace std; -LCC_EVENT_TYPE PcIdentifierFacade::validate_pc_signature(const std::string& str_code) { - PcIdentifier pc_id(str_code); +LCC_EVENT_TYPE HwIdentifierFacade::validate_pc_signature(const std::string& str_code) { + HwIdentifier pc_id(str_code); LCC_API_IDENTIFICATION_STRATEGY id_strategy = pc_id.get_identification_strategy(); LCC_EVENT_TYPE result = IDENTIFIERS_MISMATCH; try { @@ -35,7 +35,7 @@ return result; } -std::string PcIdentifierFacade::generate_user_pc_signature(LCC_API_IDENTIFICATION_STRATEGY strategy) { +std::string HwIdentifierFacade::generate_user_pc_signature(LCC_API_IDENTIFICATION_STRATEGY strategy) { bool use_env_var = false; vector<LCC_API_IDENTIFICATION_STRATEGY> strategies_to_try; if (strategy == STRATEGY_DEFAULT) { @@ -52,7 +52,7 @@ } unique_ptr<IdentificationStrategy> strategy_ptr = IdentificationStrategy::get_strategy(strategy); - PcIdentifier pc_id; + HwIdentifier pc_id; FUNCTION_RETURN result = strategy_ptr->identify_pc(pc_id); if (result != FUNC_RET_OK) { /// FIXME @@ -73,5 +73,5 @@ return pc_id.print(); } -} // namespace pc_identifier +} // namespace hw_identifier } /* namespace license */ diff --git a/src/library/hw_identifier/hw_identifier_facade.hpp b/src/library/hw_identifier/hw_identifier_facade.hpp new file mode 100644 index 0000000..bd198b3 --- /dev/null +++ b/src/library/hw_identifier/hw_identifier_facade.hpp @@ -0,0 +1,32 @@ +/* + * hw_identifier_facade.hpp + * + * Created on: Dec 26, 2019 + * Author: devel + */ + +#ifndef SRC_LIBRARY_PC_IDENTIFIER_HW_IDENTIFIER_FACADE_HPP_ +#define SRC_LIBRARY_PC_IDENTIFIER_HW_IDENTIFIER_FACADE_HPP_ +#include "hw_identifier_facade.hpp" + +#include <string> +#include <unordered_map> +#include <licensecc/datatypes.h> +#include "identification_strategy.hpp" + +namespace license { +namespace hw_identifier { + +class HwIdentifierFacade { +private: + HwIdentifierFacade(){}; + virtual ~HwIdentifierFacade(){}; +public: + static LCC_EVENT_TYPE validate_pc_signature(const std::string& str_code); + static std::string generate_user_pc_signature(LCC_API_IDENTIFICATION_STRATEGY strategy); +}; + +} // namespace hw_identifier +} /* namespace license */ + +#endif /* SRC_LIBRARY_PC_IDENTIFIER_HW_IDENTIFIER_FACADE_HPP_ */ diff --git a/src/library/pc_identifier/identification_strategy.cpp b/src/library/hw_identifier/identification_strategy.cpp similarity index 68% rename from src/library/pc_identifier/identification_strategy.cpp rename to src/library/hw_identifier/identification_strategy.cpp index db9c107..49ed768 100644 --- a/src/library/pc_identifier/identification_strategy.cpp +++ b/src/library/hw_identifier/identification_strategy.cpp @@ -4,16 +4,16 @@ #include "ethernet.hpp" #include "disk_strategy.hpp" namespace license { -namespace pc_identifier { +namespace hw_identifier { using namespace std; -LCC_EVENT_TYPE IdentificationStrategy::validate_identifier( - const PcIdentifier& identifier, const vector<array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA>>& available_ids) const { +LCC_EVENT_TYPE IdentificationStrategy::validate_identifier(const HwIdentifier& identifier) const { LCC_EVENT_TYPE result = IDENTIFIERS_MISMATCH; if (identifier.get_identification_strategy() == identification_strategy()) { - for (auto& it : available_ids) { - if (identifier.data_match(it)) { + const vector<HwIdentifier> available_ids = alternative_ids(); + for (const auto& it : available_ids) { + if (it == identifier) { result = LICENSE_OK; break; } @@ -22,6 +22,16 @@ return result; } +FUNCTION_RETURN IdentificationStrategy::identify_pc(HwIdentifier& pc_id) const { + vector<array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA>> data; + const vector<HwIdentifier> available_ids = alternative_ids(); + FUNCTION_RETURN result = FUNC_RET_NOT_AVAIL; + if (available_ids.size() > 0) { + pc_id = available_ids[0]; + result = FUNC_RET_OK; + } + return result; +} std::unique_ptr<IdentificationStrategy> IdentificationStrategy::get_strategy(LCC_API_IDENTIFICATION_STRATEGY strategy) { unique_ptr<IdentificationStrategy> result; switch (strategy) { @@ -45,6 +55,5 @@ } return result; } -} // namespace pc_identifier +} // namespace hw_identifier } // namespace license - diff --git a/src/library/pc_identifier/identification_strategy.hpp b/src/library/hw_identifier/identification_strategy.hpp similarity index 63% rename from src/library/pc_identifier/identification_strategy.hpp rename to src/library/hw_identifier/identification_strategy.hpp index 8eef0c8..ad3e2de 100644 --- a/src/library/pc_identifier/identification_strategy.hpp +++ b/src/library/hw_identifier/identification_strategy.hpp @@ -13,26 +13,31 @@ #include <vector> #include <bits/unique_ptr.h> #include "../base/base.h" -#include "pc_identifier.hpp" +#include "hw_identifier.hpp" + namespace license { -namespace pc_identifier { +namespace hw_identifier { class IdentificationStrategy { protected: - LCC_EVENT_TYPE validate_identifier(const PcIdentifier& identifier, - const std::vector<std::array<uint8_t, 8>>& available_ids) const; + IdentificationStrategy(){}; public: - IdentificationStrategy(){}; virtual ~IdentificationStrategy(){}; virtual LCC_API_IDENTIFICATION_STRATEGY identification_strategy() const = 0; - virtual FUNCTION_RETURN identify_pc(PcIdentifier& identifier) const = 0; - virtual std::vector<PcIdentifier> alternative_ids() const = 0; - virtual LCC_EVENT_TYPE validate_identifier(const PcIdentifier& identifier) const = 0; + virtual FUNCTION_RETURN identify_pc(HwIdentifier& identifier_out) const; + virtual std::vector<HwIdentifier> alternative_ids() const = 0; + virtual LCC_EVENT_TYPE validate_identifier(const HwIdentifier& identifier_in) const; + + /** + * Factory method to create an instance of IdentificationStrategy + * @param strategy + * @return + */ static std::unique_ptr<IdentificationStrategy> get_strategy(LCC_API_IDENTIFICATION_STRATEGY strategy); }; -} // namespace pc_identifier +} // namespace hw_identifier } /* namespace license */ #endif /* SRC_LIBRARY_PC_IDENTIFIER_IDENTIFICATION_STRATEGY_HPP_ */ diff --git a/src/library/pc_identifier/pc-identifiers.c b/src/library/hw_identifier/pc-identifiers.c similarity index 100% rename from src/library/pc_identifier/pc-identifiers.c rename to src/library/hw_identifier/pc-identifiers.c diff --git a/src/library/pc_identifier/pc-identifiers.h b/src/library/hw_identifier/pc-identifiers.h similarity index 100% rename from src/library/pc_identifier/pc-identifiers.h rename to src/library/hw_identifier/pc-identifiers.h diff --git a/src/library/licensecc.cpp b/src/library/licensecc.cpp index f4e6063..5378638 100644 --- a/src/library/licensecc.cpp +++ b/src/library/licensecc.cpp @@ -18,7 +18,7 @@ #include <licensecc_properties.h> #include "base/logger.h" -#include "pc_identifier/pc_identifier_facade.hpp" +#include "hw_identifier/hw_identifier_facade.hpp" #include "limits/license_verifier.hpp" #include "base/StringUtils.h" #include "LicenseReader.hpp" @@ -32,11 +32,11 @@ bool result = false; if (*bufSize > LCC_API_PC_IDENTIFIER_SIZE && chbuffer != nullptr) { try { - string pc_id = license::pc_identifier::PcIdentifierFacade::generate_user_pc_signature(pc_id_method); + string pc_id = license::hw_identifier::HwIdentifierFacade::generate_user_pc_signature(pc_id_method); strncpy(chbuffer, pc_id.c_str(), *bufSize); result = true; } catch (const std::exception& ex) { - LOG_ERROR("Error calculating pc_identifier: %s", ex.what()); + LOG_ERROR("Error calculating hw_identifier: %s", ex.what()); #ifdef _DEBUG cout << "Error occurred: " << ex.what() << std::endl; diff --git a/src/library/limits/license_verifier.cpp b/src/library/limits/license_verifier.cpp index 86e3181..71c2cc8 100644 --- a/src/library/limits/license_verifier.cpp +++ b/src/library/limits/license_verifier.cpp @@ -9,9 +9,9 @@ #include <licensecc_properties.h> #include "license_verifier.hpp" -#include "../pc_identifier/pc_identifier_facade.hpp" #include "../base/StringUtils.h" #include "../os/signature_verifier.hpp" +#include "../hw_identifier/hw_identifier_facade.hpp" namespace license { using namespace std; @@ -57,7 +57,7 @@ } const auto client_sig = lic_info.m_limits.find(PARAM_CLIENT_SIGNATURE); if (is_valid && client_sig != lic_info.m_limits.end()) { - const LCC_EVENT_TYPE event = pc_identifier::PcIdentifierFacade::validate_pc_signature(client_sig->second); + const LCC_EVENT_TYPE event = hw_identifier::HwIdentifierFacade::validate_pc_signature(client_sig->second); m_event_registry.addEvent(event, lic_info.source); is_valid = is_valid && (event == LICENSE_OK); } diff --git a/src/library/os/CMakeLists.txt b/src/library/os/CMakeLists.txt index 35e3f80..986550f 100644 --- a/src/library/os/CMakeLists.txt +++ b/src/library/os/CMakeLists.txt @@ -12,7 +12,7 @@ cpu_info_common.cpp openssl/signature_verifier.cpp windows/os-win.c) ENDIF(UNIX) ELSE(UNIX OR OPENSSL_FOUND) - target_sources(os OBJECT + add_library(os OBJECT cpu_info_common.cpp windows/signature_verifier.cpp windows/os-win.c) ENDIF(UNIX OR OPENSSL_FOUND) diff --git a/src/library/os/windows/signature_verifier.cpp b/src/library/os/windows/signature_verifier.cpp index 05849b4..6e9b62d 100644 --- a/src/library/os/windows/signature_verifier.cpp +++ b/src/library/os/windows/signature_verifier.cpp @@ -136,13 +136,13 @@ DWORD status; FUNCTION_RETURN result = FUNC_RET_ERROR; PBYTE pbSignature = nullptr; - DWORD dwSigLen; BYTE* sigBlob = nullptr; BCRYPT_ALG_HANDLE hSignAlg = nullptr; - // FIXME!! - sigBlob = unbase64(signatureBuffer.c_str(), (int)signatureBuffer.size(), (int*)&dwSigLen); - + vector<uint8_t> signatureBlob = unbase64(signatureBuffer); + DWORD dwSigLen = signatureBlob.size(); + sigBlob = &signatureBlob[0]; + if (NT_SUCCESS(status = BCryptOpenAlgorithmProvider(&hSignAlg, BCRYPT_RSA_ALGORITHM, NULL, 0))) { if ((result = readPublicKey(hSignAlg, &phKey)) == FUNC_RET_OK) { BCRYPT_PKCS1_PADDING_INFO paddingInfo; @@ -160,7 +160,8 @@ } else { LOG_DEBUG("Error reading public key"); } - } else { + } + else { result = FUNC_RET_NOT_AVAIL; #ifdef _DEBUG formatError(status, "error opening RSA provider"); diff --git a/src/library/pc_identifier/CMakeLists.txt b/src/library/pc_identifier/CMakeLists.txt deleted file mode 100644 index 506c25c..0000000 --- a/src/library/pc_identifier/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_library(pc_identifier OBJECT - pc_identifier_facade.cpp - identification_strategy.cpp - ethernet.cpp - disk_strategy.cpp - pc_identifier.cpp - default_strategy.cpp -) - -if(CODE_COVERAGE AND UNIX) - target_compile_options(pc_identifier PUBLIC -O0 -g --coverage) -endif(CODE_COVERAGE AND UNIX) \ No newline at end of file diff --git a/src/library/pc_identifier/ethernet.cpp b/src/library/pc_identifier/ethernet.cpp deleted file mode 100644 index 80bb4b7..0000000 --- a/src/library/pc_identifier/ethernet.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ethernet.cpp - * - * Created on: Jan 11, 2020 - * Author: devel - */ - - -#include <array> -#include <vector> - -#include <licensecc/datatypes.h> -#include <licensecc_properties.h> -#include "../base/base.h" -#include "../os/network.hpp" -#include "pc_identifier.hpp" -#include "ethernet.hpp" - -namespace license { -namespace pc_identifier { -using namespace std; - -static FUNCTION_RETURN generate_ethernet_pc_id(vector<array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA>> &data, - const bool use_ip) { - vector<os::OsAdapterInfo> adapters; - - FUNCTION_RETURN result_adapterInfos = getAdapterInfos(adapters); - if (result_adapterInfos != FUNC_RET_OK) { - return result_adapterInfos; - } - if (adapters.size() == 0) { - return FUNC_RET_NOT_AVAIL; - } - - for (auto &it : adapters) { - unsigned int k, data_len, data_byte; - array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA> identifier; - data_len = use_ip ? sizeof(os::OsAdapterInfo::ipv4_address) : sizeof(os::OsAdapterInfo::mac_address); - - for (k = 0; k < PC_IDENTIFIER_PROPRIETARY_DATA; k++) { - if (k < data_len) { - identifier[k] = use_ip ? it.ipv4_address[k] : it.mac_address[k]; - } else { - identifier[k] = 42; - } - } - identifier[0] = identifier[0] & 0x1F; - data.push_back(identifier); - } - - return result_adapterInfos; -} - -Ethernet::Ethernet(bool useIp) : use_ip(useIp) {} - -Ethernet::~Ethernet() {} - -LCC_API_IDENTIFICATION_STRATEGY Ethernet::identification_strategy() const { return STRATEGY_ETHERNET; } - -FUNCTION_RETURN Ethernet::identify_pc(PcIdentifier &pc_id) const { - vector<array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA>> data; - FUNCTION_RETURN result = generate_ethernet_pc_id(data, use_ip); - if (result == FUNC_RET_OK) { - pc_id.set_data(data[0]); - } - return result; -} - -std::vector<PcIdentifier> Ethernet::alternative_ids() const { - vector<array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA>> data; - FUNCTION_RETURN result = generate_ethernet_pc_id(data, use_ip); - vector<PcIdentifier> identifiers; - if (result == FUNC_RET_OK) { - identifiers.resize(data.size()); - for (auto &it : data) { - PcIdentifier pc_id; - pc_id.set_identification_strategy(identification_strategy()); - pc_id.set_data(it); - identifiers.push_back(pc_id); - } - } - return identifiers; -} - -LCC_EVENT_TYPE Ethernet::validate_identifier(const PcIdentifier &identifier) const { - vector<array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA>> data; - FUNCTION_RETURN generate_ethernet = generate_ethernet_pc_id(data, use_ip); - LCC_EVENT_TYPE result = IDENTIFIERS_MISMATCH; - if (generate_ethernet == FUNC_RET_OK) { - result = validate_identifier(identifier, data); - } - return result; -} - -} // namespace pc_identifier -} /* namespace license */ diff --git a/src/library/pc_identifier/pc_identifier.cpp b/src/library/pc_identifier/pc_identifier.cpp deleted file mode 100644 index 9bf9ea0..0000000 --- a/src/library/pc_identifier/pc_identifier.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * pc_identifier.cpp - * - * Created on: Dec 22, 2019 - * Author: GC - */ - -#include <algorithm> -#include "pc_identifier.hpp" -#include "../base/base64.h" - -namespace license { -namespace pc_identifier { - -using namespace std; - -PcIdentifier::PcIdentifier() {} - -PcIdentifier::PcIdentifier(const std::string& param) { - string tmp_str(param); // throw away const - std::replace(tmp_str.begin(), tmp_str.end(), '-', '\n'); - vector<uint8_t> decoded = unbase64(tmp_str); - if (decoded.size() != PC_IDENTIFIER_PROPRIETARY_DATA + 1) { - cerr << decoded.size(); - throw logic_error("wrong identifier size " + param); - } - std::copy_n(decoded.begin(), PC_IDENTIFIER_PROPRIETARY_DATA + 1, m_data.begin()); -} - -PcIdentifier::~PcIdentifier() {} - -PcIdentifier::PcIdentifier(const PcIdentifier& other) : m_data(other.m_data) {} - -void PcIdentifier::set_identification_strategy(LCC_API_IDENTIFICATION_STRATEGY strategy) { - if (strategy == STRATEGY_NONE || strategy == STRATEGY_DEFAULT) { - throw logic_error("Only known strategies are permitted"); - } - uint8_t stratMov = (strategy << 5); - m_data[1] = (m_data[1] & 0x1F) | stratMov; -} - -void PcIdentifier::set_use_environment_var(bool use_env_var) { - if (use_env_var) { - m_data[0] = m_data[0] | 0x40; - } else { - m_data[0] = m_data[0] & ~0x40; - } -} - -void PcIdentifier::set_virtual_environment(VIRTUALIZATION virt) { - // 110000 0x30 - m_data[0] = (m_data[0] && ~0x30) | virt << 4; -} - -void PcIdentifier::set_virtualization(VIRTUALIZATION_DETAIL virtualization_detail) { // TODO -} - -void PcIdentifier::set_cloud_provider(CLOUD_PROVIDER cloud_provider) { - // TODO -} - -void PcIdentifier::set_data(const std::array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA>& data) { - m_data[1] = (m_data[1] & (~0x1f)) | (data[0] & 0x1f); - for (int i = 1; i < PC_IDENTIFIER_PROPRIETARY_DATA; i++) { - m_data[i + 1] = data[i]; - } -} - -std::string PcIdentifier::print() const { - string result = base64(m_data.data(), m_data.size(), 5); - std::replace(result.begin(), result.end(), '\n', '-'); - return result.substr(0, result.size() - 1); -} - -LCC_API_IDENTIFICATION_STRATEGY PcIdentifier::get_identification_strategy() const { - uint8_t stratMov = m_data[1] >> 5; - return static_cast<LCC_API_IDENTIFICATION_STRATEGY>(stratMov); -} - -bool PcIdentifier::data_match(const std::array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA>& data) const { - bool equals = true; - for (int i = 0; i < PC_IDENTIFIER_PROPRIETARY_DATA && equals; i++) { - equals = (i == 0) ? ((data[i] & 0x1f) == (m_data[i + 1] & 0x1f)) : (data[i] == m_data[i + 1]); - } - return equals; -} - -} // namespace pc_identifier -} /* namespace license */ - diff --git a/src/library/pc_identifier/pc_identifier_facade.hpp b/src/library/pc_identifier/pc_identifier_facade.hpp deleted file mode 100644 index 5494fe1..0000000 --- a/src/library/pc_identifier/pc_identifier_facade.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * pc_identifier_facade.hpp - * - * Created on: Dec 26, 2019 - * Author: devel - */ - -#ifndef SRC_LIBRARY_PC_IDENTIFIER_PC_IDENTIFIER_FACADE_HPP_ -#define SRC_LIBRARY_PC_IDENTIFIER_PC_IDENTIFIER_FACADE_HPP_ -#include <string> -#include <unordered_map> -#include <bits/unique_ptr.h> -#include <licensecc/datatypes.h> -#include "pc_identifier_facade.hpp" -#include "identification_strategy.hpp" - -namespace license { -namespace pc_identifier { - -class PcIdentifierFacade { -private: - PcIdentifierFacade(){}; - virtual ~PcIdentifierFacade(){}; -public: - static LCC_EVENT_TYPE validate_pc_signature(const std::string& str_code); - static std::string generate_user_pc_signature(LCC_API_IDENTIFICATION_STRATEGY strategy); -}; - -} // namespace pc_identifier -} /* namespace license */ - -#endif /* SRC_LIBRARY_PC_IDENTIFIER_PC_IDENTIFIER_FACADE_HPP_ */ diff --git a/src/templates/licensecc_properties.h.in b/src/templates/licensecc_properties.h.in index 402d91f..b8026f9 100644 --- a/src/templates/licensecc_properties.h.in +++ b/src/templates/licensecc_properties.h.in @@ -23,7 +23,7 @@ #define LCC_LICENSE_LOCATION_ENV_VAR "LICENSE_LOCATION" #define LCC_LICENSE_DATA_ENV_VAR "LICENSE_DATA" /** - * Environment variable that if defined will change the identification strategy used to generate the pc identifier. + * Environment variable that if defined will change the identification strategy used to generate the hardware identifier. * If a client has an unstable pc-identifier use this variable to generate one. * Valid values are integers defined in `LCC_IDENTIFICATION_STRATEGY` enum. */ diff --git a/test/functional/CMakeLists.txt b/test/functional/CMakeLists.txt index a72ac30..c081de9 100644 --- a/test/functional/CMakeLists.txt +++ b/test/functional/CMakeLists.txt @@ -46,7 +46,7 @@ ) -add_executable(test_it_pc_identifer pc_identifier_it_test.cpp) +add_executable(test_it_pc_identifer hw_identifier_it_test.cpp) target_link_libraries(test_it_pc_identifer licensecc_static diff --git a/test/functional/pc_identifier_it_test.cpp b/test/functional/hw_identifier_it_test.cpp similarity index 84% rename from test/functional/pc_identifier_it_test.cpp rename to test/functional/hw_identifier_it_test.cpp index ebafc0d..e1ae99a 100644 --- a/test/functional/pc_identifier_it_test.cpp +++ b/test/functional/hw_identifier_it_test.cpp @@ -1,4 +1,4 @@ -#define BOOST_TEST_MODULE integration_test_pc_identifier +#define BOOST_TEST_MODULE integration_test_hw_identifier #include <boost/test/unit_test.hpp> #include <fstream> @@ -11,7 +11,7 @@ #include <licensecc/licensecc.h> #include "../../src/library/ini/SimpleIni.h" -#include "../../src/library/pc_identifier/pc_identifier_facade.hpp" +#include "../../src/library/hw_identifier/hw_identifier_facade.hpp" #include "../../src/library/os/os.h" #include "../../src/library/os/network.hpp" #include "generate-license.h" @@ -21,16 +21,16 @@ namespace test { namespace fs = boost::filesystem; using namespace std; -using namespace pc_identifier; +using namespace hw_identifier; /** - * If the current pc has at least one disk generate a pc identifier using disk, generate a license, verify the license + * If the current pc has at least one disk generate a hardware identifier using disk, generate a license, verify the license * is OK */ static void generate_and_verify_license(LCC_API_IDENTIFICATION_STRATEGY strategy, const string& lic_fname) { BOOST_TEST_CHECKPOINT("Before generate"); - const string identifier_out = PcIdentifierFacade::generate_user_pc_signature(strategy); + const string identifier_out = HwIdentifierFacade::generate_user_pc_signature(strategy); BOOST_TEST_CHECKPOINT("After generate signature"); cout << "Identifier:" << identifier_out << endl; vector<string> extraArgs; @@ -48,24 +48,24 @@ } BOOST_AUTO_TEST_CASE(volid_lic_file) { - PcIdentifier identifier_out; + HwIdentifier identifier_out; size_t disk_num; FUNCTION_RETURN result_diskinfos = getDiskInfos(nullptr, &disk_num); if ((result_diskinfos == FUNC_RET_BUFFER_TOO_SMALL || result_diskinfos == FUNC_RET_OK) && disk_num > 0) { generate_and_verify_license(LCC_API_IDENTIFICATION_STRATEGY::STRATEGY_DISK_NUM, "volid_lic_file"); } else { - BOOST_TEST_MESSAGE("No disk found skipping testing disk pc identifier"); + BOOST_TEST_MESSAGE("No disk found skipping testing disk hardware identifier"); } } BOOST_AUTO_TEST_CASE(volume_name_lic_file) { - PcIdentifier identifier_out; + HwIdentifier identifier_out; size_t disk_num; FUNCTION_RETURN result_diskinfos = getDiskInfos(nullptr, &disk_num); if ((result_diskinfos == FUNC_RET_BUFFER_TOO_SMALL || result_diskinfos == FUNC_RET_OK) && disk_num > 0) { generate_and_verify_license(LCC_API_IDENTIFICATION_STRATEGY::STRATEGY_DISK_LABEL, "volume_name_lic_file"); } else { - BOOST_TEST_MESSAGE("No disk found skipping testing volume name disk pc identifier"); + BOOST_TEST_MESSAGE("No disk found skipping testing volume name disk hardware identifier"); } } @@ -76,10 +76,10 @@ adapters.size() > 0) { generate_and_verify_license(LCC_API_IDENTIFICATION_STRATEGY::STRATEGY_ETHERNET, "strategy_mac_address"); } else { - BOOST_TEST_MESSAGE("No ethernet adapter found skipping testing mac address pc identifier"); + BOOST_TEST_MESSAGE("No ethernet adapter found skipping testing mac address hardware identifier"); } } -/* + BOOST_AUTO_TEST_CASE(strategy_ip_address) { vector<os::OsAdapterInfo> adapters; FUNCTION_RETURN result_adapterInfos = os::getAdapterInfos(adapters); @@ -87,9 +87,9 @@ adapters.size() > 0) { generate_and_verify_license(LCC_API_IDENTIFICATION_STRATEGY::STRATEGY_IP_ADDRESS, "strategy_ip_address"); } else { - BOOST_TEST_MESSAGE("No ethernet adapter found skipping testing ip pc identifier"); + BOOST_TEST_MESSAGE("No ethernet adapter found skipping testing ip hardware identifier"); } } -*/ + } // namespace test } // namespace license diff --git a/test/functional/standard-license_test.cpp b/test/functional/standard-license_test.cpp index 5d3839c..8bb45b1 100644 --- a/test/functional/standard-license_test.cpp +++ b/test/functional/standard-license_test.cpp @@ -72,8 +72,8 @@ // BOOST_CHECK_EQUAL(license.linked_to_pc, false); //} // -// BOOST_AUTO_TEST_CASE( pc_identifier ) { -// const string licLocation(PROJECT_TEST_TEMP_DIR "/pc_identifier.lic"); +// BOOST_AUTO_TEST_CASE( hw_identifier ) { +// const string licLocation(PROJECT_TEST_TEMP_DIR "/hw_identifier.lic"); // const vector<string> extraArgs = { "-s", "Jaaa-aaaa-MG9F-ZhB1" }; // generate_license(licLocation, extraArgs); // diff --git a/test/library/CMakeLists.txt b/test/library/CMakeLists.txt index 467ce24..45bd810 100644 --- a/test/library/CMakeLists.txt +++ b/test/library/CMakeLists.txt @@ -61,4 +61,4 @@ ADD_TEST(NAME test_event_registry COMMAND test_event_registry) ADD_SUBDIRECTORY(os) -ADD_SUBDIRECTORY(pc_identifier) \ No newline at end of file +ADD_SUBDIRECTORY(hw_identifier) \ No newline at end of file diff --git a/test/library/hw_identifier/CMakeLists.txt b/test/library/hw_identifier/CMakeLists.txt new file mode 100644 index 0000000..0c4df23 --- /dev/null +++ b/test/library/hw_identifier/CMakeLists.txt @@ -0,0 +1,16 @@ +add_executable( test_hw_identifier + hw_identifier_test.cpp +) + +target_link_libraries( test_hw_identifier + licensecc_static + Boost::unit_test_framework + Boost::filesystem + Boost::system +) + +if(CODE_COVERAGE AND UNIX) + target_compile_options(test_hw_identifier PUBLIC -O0 -g --coverage) +endif(CODE_COVERAGE AND UNIX) + +ADD_TEST(NAME test_hw_identifier COMMAND test_hw_identifier) diff --git a/test/library/pc_identifier/disk_strategy_test.cpp b/test/library/hw_identifier/disk_strategy_test.cpp similarity index 100% rename from test/library/pc_identifier/disk_strategy_test.cpp rename to test/library/hw_identifier/disk_strategy_test.cpp diff --git a/test/library/pc_identifier/ethernet_test.cpp b/test/library/hw_identifier/ethernet_test.cpp similarity index 100% rename from test/library/pc_identifier/ethernet_test.cpp rename to test/library/hw_identifier/ethernet_test.cpp diff --git a/test/library/pc_identifier/pc_identifier_facade_test.cpp b/test/library/hw_identifier/hw_identifier_facade_test.cpp similarity index 96% rename from test/library/pc_identifier/pc_identifier_facade_test.cpp rename to test/library/hw_identifier/hw_identifier_facade_test.cpp index 45d4a88..1a47b38 100644 --- a/test/library/pc_identifier/pc_identifier_facade_test.cpp +++ b/test/library/hw_identifier/hw_identifier_facade_test.cpp @@ -1,11 +1,11 @@ /* - * pc_identifier_facade_test.cpp + * hw_identifier_facade_test.cpp * * Created on: Dec 26, 2019 * Author: devel */ -#include "pc_identifier_facade.hpp" +#include "../../../src/library/hw_identifier/hw_identifier_facade.hpp" namespace license { /* diff --git a/test/library/pc_identifier/pc_identifier_test.cpp b/test/library/hw_identifier/hw_identifier_test.cpp similarity index 66% rename from test/library/pc_identifier/pc_identifier_test.cpp rename to test/library/hw_identifier/hw_identifier_test.cpp index 82fc503..1e0062c 100644 --- a/test/library/pc_identifier/pc_identifier_test.cpp +++ b/test/library/hw_identifier/hw_identifier_test.cpp @@ -1,11 +1,11 @@ /* - * Test on class PcIdentifier + * Test on class HwIdentifier * * Created on: Dec 26, 2019 * Author: devel */ -#define BOOST_TEST_MODULE test_pc_identifier +#define BOOST_TEST_MODULE test_hw_identifier #include <boost/test/unit_test.hpp> #include <fstream> @@ -17,45 +17,45 @@ #include <licensecc_properties_test.h> #include <licensecc/licensecc.h> -#include "../../../src/library/pc_identifier/pc_identifier.hpp" +#include "../../../src/library/hw_identifier/hw_identifier.hpp" namespace license { namespace test { using namespace std; -using namespace license::pc_identifier; +using namespace license::hw_identifier; /** - * Test get and set and compare pc identifier data + * Test get and set and compare hardware identifier data */ BOOST_AUTO_TEST_CASE(set_and_compare_data) { - array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA> data = {0xFF, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42}; - PcIdentifier pc_id; + array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA> data = {0xFF, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42}; + HwIdentifier pc_id; pc_id.set_data(data); data[0] = data[0] & 0x1f; BOOST_CHECK_MESSAGE(pc_id.data_match(data), "Data match"); } /** - * Test get and set and compare pc identifier data + * Test get and set and compare hardware identifier data */ BOOST_AUTO_TEST_CASE(compare_wrong_data) { - array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA> data = {0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42}; - PcIdentifier pc_id; + array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA> data = {0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42}; + HwIdentifier pc_id; pc_id.set_data(data); data[4] = 0; BOOST_CHECK_MESSAGE(!pc_id.data_match(data), "Data shouldn't match"); } /** - * Print a pc identifier and read it from the same string, check the data matches + * Print a hardware identifier and read it from the same string, check the data matches */ BOOST_AUTO_TEST_CASE(print_and_read) { - array<uint8_t, PC_IDENTIFIER_PROPRIETARY_DATA> data = {0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42}; - PcIdentifier pc_id; + array<uint8_t, HW_IDENTIFIER_PROPRIETARY_DATA> data = {0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42}; + HwIdentifier pc_id; pc_id.set_data(data); pc_id.set_identification_strategy(LCC_API_IDENTIFICATION_STRATEGY::STRATEGY_ETHERNET); string pc_id_str = pc_id.print(); cout << pc_id_str << endl; - const PcIdentifier id2(pc_id_str); + const HwIdentifier id2(pc_id_str); BOOST_CHECK_MESSAGE(id2.get_identification_strategy() == LCC_API_IDENTIFICATION_STRATEGY::STRATEGY_ETHERNET, "Strategy decoded correctly"); BOOST_CHECK_MESSAGE(id2.data_match(data), "Data deserialized correctly"); diff --git a/test/library/os/CMakeLists.txt b/test/library/os/CMakeLists.txt index 2cda53e..4faf092 100644 --- a/test/library/os/CMakeLists.txt +++ b/test/library/os/CMakeLists.txt @@ -9,4 +9,8 @@ Boost::system ) -ADD_TEST(NAME test_network COMMAND test_network) \ No newline at end of file +ADD_TEST(NAME test_network COMMAND test_network) + +if(CODE_COVERAGE AND UNIX) + target_compile_options(test_network PUBLIC -O0 -g --coverage) +endif(CODE_COVERAGE AND UNIX) diff --git a/test/library/pc_identifier/CMakeLists.txt b/test/library/pc_identifier/CMakeLists.txt deleted file mode 100644 index 82b27e8..0000000 --- a/test/library/pc_identifier/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_executable( test_pc_identifier - pc_identifier_test.cpp -) - -target_link_libraries( test_pc_identifier - licensecc_static - Boost::unit_test_framework - Boost::filesystem - Boost::system -) - -ADD_TEST(NAME test_pc_identifier COMMAND test_pc_identifier) -- Gitblit v1.9.1