gcontini
2020-01-01 61d11d6996e0bb78555793ad755cd98438185952
add magic number
3个文件已修改
1个文件已添加
77 ■■■■ 已修改文件
src/CMakeLists.txt 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/limits/license_verifier.cpp 28 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/templates/licensecc_properties.h.in 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/functional/crack_test.cpp 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/CMakeLists.txt
@@ -1,7 +1,12 @@
add_subdirectory("library")
#for no reason overwrite it (maybe it's manually customized)
IF (NOT LCC_PROJECT_MAGIC_NUM)
    set(LCC_PROJECT_MAGIC_NUM 0)
ENDIF (NOT LCC_PROJECT_MAGIC_NUM)
IF(NOT EXISTS "${LCC_INCLUDE_DIR}/licensecc_properties.h")
    configure_file ("templates/licensecc_properties.h.in" 
        "${LCC_INCLUDE_DIR}/licensecc_properties.h")
ENDIF(NOT EXISTS "${LCC_INCLUDE_DIR}/licensecc_properties.h")
add_subdirectory("library")
src/library/limits/license_verifier.cpp
@@ -6,11 +6,12 @@
 */
#include <cmath>
#include <algorithm>
#include <licensecc_properties.h>
#include "license_verifier.hpp"
#include "../pc_identifier_facade.hpp"
#include "../os/signature_verifier.h"
#include "../base/StringUtils.h"
#include "../pc-identifiers.h"
namespace license {
using namespace std;
@@ -34,10 +35,13 @@
// TODO: split in different classes
FUNCTION_RETURN LicenseVerifier::verify_limits(const FullLicenseInfo& licInfo) {
    bool is_valid = true;
    const time_t now = time(nullptr);
    bool is_valid = VERIFY_MAGIC;
    if (!is_valid) {
        m_event_registry.addEvent(LICENSE_CORRUPTED, licInfo.source.c_str());
    }
    const const time_t now = time(nullptr);
    auto expiry = licInfo.m_limits.find(PARAM_EXPIRY_DATE);
    if (expiry != licInfo.m_limits.end()) {
    if (is_valid && expiry != licInfo.m_limits.end()) {
        if (seconds_from_epoch(expiry->second) < now) {
            /*
                        eventRegistryOut.addEvent(PRODUCT_EXPIRED, source.c_str(),
@@ -46,7 +50,7 @@
            is_valid = false;
        }
    }
    auto start_date = licInfo.m_limits.find(PARAM_BEGIN_DATE);
    const auto start_date = licInfo.m_limits.find(PARAM_BEGIN_DATE);
    if (is_valid && start_date != licInfo.m_limits.end()) {
        if (seconds_from_epoch(start_date->second) > now) {
            /*eventRegistryOut.addEvent(PRODUCT_EXPIRED, source.c_str(),
@@ -56,11 +60,9 @@
            is_valid = false;
        }
    }
    auto client_sig = licInfo.m_limits.find(PARAM_CLIENT_SIGNATURE);
    const auto client_sig = licInfo.m_limits.find(PARAM_CLIENT_SIGNATURE);
    if (is_valid && client_sig != licInfo.m_limits.end()) {
        PcSignature str_code;
        strncpy(str_code, client_sig->second.c_str(), sizeof(str_code) - 1);
        const EVENT_TYPE event = validate_pc_signature(str_code);
        const EVENT_TYPE event = PcIdentifierFacade::validate_pc_signature(client_sig->second);
        m_event_registry.addEvent(event, licInfo.source);
        is_valid = is_valid && (event == LICENSE_OK);
    }
@@ -71,7 +73,7 @@
    LicenseInfo info;
    info.license_type = LOCAL;
    auto expiry = fullLicInfo.m_limits.find(PARAM_EXPIRY_DATE);
    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));
        info.has_expiry = true;
@@ -83,14 +85,14 @@
        info.expiry_date[0] = '\0';
    }
    auto start_date = fullLicInfo.m_limits.find(PARAM_BEGIN_DATE);
    const auto start_date = fullLicInfo.m_limits.find(PARAM_BEGIN_DATE);
    if (start_date != fullLicInfo.m_limits.end()) {
    }
    auto client_sig = fullLicInfo.m_limits.find(PARAM_CLIENT_SIGNATURE);
    const auto client_sig = fullLicInfo.m_limits.find(PARAM_CLIENT_SIGNATURE);
    info.linked_to_pc = (client_sig != fullLicInfo.m_limits.end());
    auto proprietary_data = fullLicInfo.m_limits.find(PARAM_EXTRA_DATA);
    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(), PROPRIETARY_DATA_SIZE);
    }
src/templates/licensecc_properties.h.in
@@ -13,5 +13,7 @@
//Internal data structures limits
#define MAX_LICENSE_LENGTH 256*1024
#define VERIFY_MAGIC (lic_info.m_magic == @LCC_PROJECT_MAGIC_NUM@)
#endif
test/functional/crack_test.cpp
New file
@@ -0,0 +1,38 @@
#define BOOST_TEST_MODULE standard_license_test
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
#include <licensecc/licensecc.h>
#include <licensecc_properties_test.h>
#include <licensecc_properties.h>
#include <iostream>
#include "../../src/library/ini/SimpleIni.h"
#include "generate-license.h"
#include "../../src/library/base/FileUtils.hpp"
namespace license {
namespace test {
namespace fs = boost::filesystem;
using namespace license;
using namespace std;
/**
 * Test a generic license, passing a bad license number trough the api.
 * see projects/DEFAULT/include/licensecc/DEFAULT/licensecc_properties.h (magic should be 0)
 */
BOOST_AUTO_TEST_CASE(test_bad_magic_number) {
    const vector<string> extraArgs;
    const string licLocation = generate_license("standard_license", extraArgs);
    /* */
    LicenseInfo license;
    LicenseLocation location = {LICENSE_PATH};
    std::copy(licLocation.begin(), licLocation.end(), location.licenseData);
    // magic should be 0 for this build...
    CallerInformations callInfo{{0}, {0}, 42};
    const EVENT_TYPE result = acquire_license(&callInfo, &location, &license);
    BOOST_CHECK_EQUAL(result, LICENSE_CORRUPTED);
}
}  // namespace test
}  // namespace license