| | |
| | | #include <licensecc_properties.h> |
| | | |
| | | #include "license_verifier.hpp" |
| | | #include "../pc_identifier/pc_identifier_facade.hpp" |
| | | #include "../base/StringUtils.h" |
| | | #include "../base/string_utils.h" |
| | | #include "../os/signature_verifier.hpp" |
| | | #include "../hw_identifier/hw_identifier_facade.hpp" |
| | | |
| | | namespace license { |
| | | using namespace std; |
| | |
| | | } |
| | | |
| | | // TODO: split in different classes |
| | | FUNCTION_RETURN LicenseVerifier::verify_limits(const FullLicenseInfo& licInfo) { |
| | | bool is_valid = LCC_VERIFY_MAGIC(licInfo); |
| | | FUNCTION_RETURN LicenseVerifier::verify_limits(const FullLicenseInfo& lic_info) { |
| | | bool is_valid = LCC_VERIFY_MAGIC; |
| | | if (!is_valid) { |
| | | m_event_registry.addEvent(LICENSE_CORRUPTED, licInfo.source.c_str()); |
| | | m_event_registry.addEvent(LICENSE_CORRUPTED, lic_info.source.c_str()); |
| | | } |
| | | const time_t now = time(nullptr); |
| | | auto expiry = licInfo.m_limits.find(PARAM_EXPIRY_DATE); |
| | | if (is_valid && expiry != licInfo.m_limits.end()) { |
| | | auto expiry = lic_info.m_limits.find(PARAM_EXPIRY_DATE); |
| | | if (is_valid && expiry != lic_info.m_limits.end()) { |
| | | if (seconds_from_epoch(expiry->second) < now) { |
| | | m_event_registry.addEvent(PRODUCT_EXPIRED, licInfo.source.c_str(), ("Expired " + expiry->second).c_str()); |
| | | m_event_registry.addEvent(PRODUCT_EXPIRED, lic_info.source.c_str(), ("Expired " + expiry->second).c_str()); |
| | | is_valid = false; |
| | | } |
| | | } |
| | | const auto start_date = licInfo.m_limits.find(PARAM_BEGIN_DATE); |
| | | if (is_valid && start_date != licInfo.m_limits.end()) { |
| | | const auto start_date = lic_info.m_limits.find(PARAM_BEGIN_DATE); |
| | | if (is_valid && start_date != lic_info.m_limits.end()) { |
| | | if (seconds_from_epoch(start_date->second) > now) { |
| | | m_event_registry.addEvent(PRODUCT_EXPIRED, licInfo.source.c_str(), |
| | | m_event_registry.addEvent(PRODUCT_EXPIRED, lic_info.source.c_str(), |
| | | ("Valid from " + start_date->second).c_str()); |
| | | is_valid = false; |
| | | } |
| | | } |
| | | const auto client_sig = licInfo.m_limits.find(PARAM_CLIENT_SIGNATURE); |
| | | if (is_valid && client_sig != licInfo.m_limits.end()) { |
| | | const LCC_EVENT_TYPE event = pc_identifier::PcIdentifierFacade::validate_pc_signature(client_sig->second); |
| | | m_event_registry.addEvent(event, licInfo.source); |
| | | 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 = hw_identifier::HwIdentifierFacade::validate_pc_signature(client_sig->second); |
| | | m_event_registry.addEvent(event, lic_info.source); |
| | | is_valid = is_valid && (event == LICENSE_OK); |
| | | } |
| | | return is_valid ? FUNC_RET_OK : FUNC_RET_ERROR; |
| | |
| | | |
| | | const auto expiry = fullLicInfo.m_limits.find(PARAM_EXPIRY_DATE); |
| | | if (expiry != fullLicInfo.m_limits.end()) { |
| | | strncpy(info.expiry_date, expiry->second.c_str(), sizeof(info.expiry_date)); |
| | | mstrlcpy(info.expiry_date, expiry->second.c_str(), sizeof(info.expiry_date)); |
| | | info.has_expiry = true; |
| | | const double secs = difftime(seconds_from_epoch(expiry->second), time(nullptr)); |
| | | info.days_left = max((int)round(secs / (60 * 60 * 24)), 0); |
| | |
| | | |
| | | const auto proprietary_data = fullLicInfo.m_limits.find(PARAM_EXTRA_DATA); |
| | | if (proprietary_data != fullLicInfo.m_limits.end()) { |
| | | strncpy(info.proprietary_data, proprietary_data->second.c_str(), LCC_API_PROPRIETARY_DATA_SIZE); |
| | | mstrlcpy(info.proprietary_data, proprietary_data->second.c_str(), sizeof(info.proprietary_data)); |
| | | } |
| | | return info; |
| | | } |