16个文件已修改
5个文件已添加
16 文件已重命名
5个文件已删除
| | |
| | | |
| | | #Visual studio files |
| | | .vs |
| | | /out |
| | | |
| | | # Compiled Static libraries |
| | | *.lai |
| | |
| | | |
| | | **/CMakeCache.txt |
| | | **/CMakeFiles |
| | | /CMakeSettings.json |
| | |
| | | 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. |
| | |
| | | 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); |
| | |
| | | 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) |
| | |
| | | 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. |
| | | */ |
| | |
| | | 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; |
| | |
| | | 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> |
New file |
| | |
| | | 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) |
File was renamed from src/library/pc_identifier/default_strategy.cpp |
| | |
| | | */ |
| | | |
| | | #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; |
| | |
| | | |
| | | 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) { |
| | |
| | | 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 */ |
File was renamed from src/library/pc_identifier/default_strategy.hpp |
| | |
| | | #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_ */ |
File was renamed from src/library/pc_identifier/disk_strategy.cpp |
| | |
| | | |
| | | 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; |
| | |
| | | } |
| | | 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()); |
| | |
| | | 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); |
| | |
| | | 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 */ |
File was renamed from src/library/pc_identifier/disk_strategy.hpp |
| | |
| | | #include "identification_strategy.hpp" |
| | | |
| | | namespace license { |
| | | namespace pc_identifier { |
| | | namespace hw_identifier { |
| | | |
| | | class DiskStrategy : public IdentificationStrategy { |
| | | private: |
| | |
| | | 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_ */ |
New file |
| | |
| | | /* |
| | | * 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 */ |
File was renamed from src/library/pc_identifier/ethernet.hpp |
| | |
| | | #include "identification_strategy.hpp" |
| | | |
| | | namespace license { |
| | | namespace pc_identifier { |
| | | namespace hw_identifier { |
| | | |
| | | class Ethernet : public IdentificationStrategy { |
| | | private: |
| | |
| | | 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_ */ |
New file |
| | |
| | | /* |
| | | * 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 */ |
File was renamed from src/library/pc_identifier/pc_identifier.hpp |
| | |
| | | /* |
| | | * pc_identifier.h |
| | | * hw_identifier.h |
| | | * |
| | | * Created on: Dec 22, 2019 |
| | | * Author: GC |
| | |
| | | #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] |
| | |
| | | * 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_ */ |
File was renamed from src/library/pc_identifier/pc_identifier_facade.cpp |
| | |
| | | /* |
| | | * 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> |
| | |
| | | #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 { |
| | |
| | | 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) { |
| | |
| | | } |
| | | |
| | | 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 |
| | |
| | | return pc_id.print(); |
| | | } |
| | | |
| | | } // namespace pc_identifier |
| | | } // namespace hw_identifier |
| | | } /* namespace license */ |
New file |
| | |
| | | /* |
| | | * 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_ */ |
File was renamed from src/library/pc_identifier/identification_strategy.cpp |
| | |
| | | #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; |
| | | } |
| | |
| | | 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) { |
| | |
| | | } |
| | | return result; |
| | | } |
| | | } // namespace pc_identifier |
| | | } // namespace hw_identifier |
| | | } // namespace license |
| | | |
File was renamed from src/library/pc_identifier/identification_strategy.hpp |
| | |
| | | #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_ */ |
| | |
| | | #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" |
| | |
| | | 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; |
| | |
| | | #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; |
| | |
| | | } |
| | | 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); |
| | | } |
| | |
| | | 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) |
| | | |
| | |
| | | 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) { |
| | |
| | | } else { |
| | | LOG_DEBUG("Error reading public key"); |
| | | } |
| | | } else { |
| | | } |
| | | else { |
| | | result = FUNC_RET_NOT_AVAIL; |
| | | #ifdef _DEBUG |
| | | formatError(status, "error opening RSA provider"); |
| | |
| | | #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. |
| | | */ |
| | |
| | | ) |
| | | |
| | | |
| | | 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 |
File was renamed from test/functional/pc_identifier_it_test.cpp |
| | |
| | | #define BOOST_TEST_MODULE integration_test_pc_identifier |
| | | #define BOOST_TEST_MODULE integration_test_hw_identifier |
| | | |
| | | #include <boost/test/unit_test.hpp> |
| | | #include <fstream> |
| | |
| | | |
| | | #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" |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | 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"); |
| | | } |
| | | } |
| | | |
| | |
| | | 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); |
| | |
| | | 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 |
| | |
| | | // 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); |
| | | // |
| | |
| | | ADD_TEST(NAME test_event_registry COMMAND test_event_registry) |
| | | |
| | | ADD_SUBDIRECTORY(os) |
| | | ADD_SUBDIRECTORY(pc_identifier) |
| | | ADD_SUBDIRECTORY(hw_identifier) |
New file |
| | |
| | | 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) |
File was renamed from test/library/pc_identifier/pc_identifier_facade_test.cpp |
| | |
| | | /* |
| | | * 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 { |
| | | /* |
File was renamed from test/library/pc_identifier/pc_identifier_test.cpp |
| | |
| | | /* |
| | | * 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> |
| | |
| | | #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"); |
| | |
| | | ) |
| | | |
| | | 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) |