.clang-format
New file @@ -0,0 +1,12 @@ BasedOnStyle: Google Language: Cpp Standard: Cpp11 IndentWidth: 4 TabWidth: 4 ColumnLimit: 120 UseTab: Always AccessModifierOffset: -4 AlignTrailingComments: false FixNamespaceComments: true SortIncludes: false SortUsingDeclarations : true .gitmodules
@@ -1,4 +1,4 @@ [submodule "extern/license-generator"] path = extern/license-generator url = https://github.com/open-license-manager/olm-license-generator.git url = https://github.com/open-license-manager/lcc-license-generator.git branch = develop CMakeLists.txt
@@ -14,7 +14,7 @@ IF(NOT LCC_PROJECT_NAME) message(WARNING "You should define a variable LCC_PROJECT_NAME containing the name of the software you want to add a license to." "A mock product named DEFAULT has been added for you.") set(LCC_PROJECT_NAME "DEFAULT") set(LCC_PROJECT_NAME "DEFAULT" CACHE STRING "Project name (name of the software for which you want to issue a license)") ENDIF(NOT LCC_PROJECT_NAME) #base folder where projects are stored (/projects) @@ -26,8 +26,69 @@ SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") #find olm executable or build it. find_package(olm REQUIRED) #find lcc executable or build it. find_package(lcc REQUIRED) #Not sure about this. My system doesn't support binfmt misc IF( ( CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" ) AND CMAKE_CROSSCOMPILING AND NOT DEFINED CMAKE_CROSSCOMPILING_EMULATOR ) SET(CMAKE_CROSSCOMPILING_EMULATOR "wine") ENDIF() if(MSVC) include(target_arch) target_architecture( TARGET_ARCHITECTURE ) message(STATUS "architecture detected: ${TARGET_ARCHITECTURE}") #Boost > 3.15 handle the /MD flag more nicely than this if(${STATIC_RUNTIME}) string(REPLACE "/MD" "/MT" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}") string(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") string(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") SET(Boost_USE_STATIC_RUNTIME ON) endif(${STATIC_RUNTIME}) add_definitions("/D _CRT_SECURE_NO_WARNINGS") else(MSVC) if(MINGW) list(APPEND EXTERNAL_LIBS "-lcrypt32 -lws2_32 -liphlpapi") SET(CMAKE_EXE_LINKER_FLAGS "-static") endif(MINGW) endif(MSVC) if(UNIX) #this is true for all the linux systems but not for cross compiling "linux->windows" #find a static version of openssl crypto library SET ( OPENSSL_USE_STATIC_LIBS ON ) find_package(OpenSSL REQUIRED COMPONENTS Crypto) include_directories(${OPENSSL_INCLUDE_DIR}) #list(APPEND EXTERNAL_LIBS ${OPENSSL_CRYPTO_LIBRARY}) #find_package(Threads) #if(THREADS_HAVE_PTHREAD_ARG) # list(APPEND EXTERNAL_LIBS "-pthread") #else(THREADS_HAVE_PTHREAD_ARG) # if(CMAKE_THREAD_LIBS_INIT) # list(APPEND EXTERNAL_LIBS "${CMAKE_THREAD_LIBS_INIT}") # endif() #endif(THREADS_HAVE_PTHREAD_ARG) MESSAGE(STATUS "Found openssl version ${OPENSSL_VERSION} ") #Zlib required when openssl version < 1.0.1f #SET ( ZLIB_USE_STATIC_LIBS ON ) #find_package(ZLIB REQUIRED) #MESSAGE(STATUS "Found zlib version ${ZLIB_VERSION} ") find_program( MEMORYCHECK_COMMAND valgrind ) set( MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full" ) if(USE_DBUS_IDENTIFIER) FIND_PACKAGE(Dbus REQUIRED) add_definitions(-DUSE_DBUS) include_directories(${DBUS_INCLUDE_DIR}) include_directories(${DBUS_ARCH_INCLUDE_DIR}) list(APPEND EXTERNAL_LIBS ${DBUS_LIBRARIES}) endif(USE_DBUS_IDENTIFIER) if(NOT MINGW) list(APPEND EXTERNAL_LIBS ${CMAKE_DL_LIBS}) endif(NOT MINGW) endif(UNIX) #load the current project from files or find it from environment variables or create a default one set(LCC_INCLUDE_DIR "${LCC_PROJECTS_BASE_DIR}/${LCC_PROJECT_NAME}/include/${PROJECT_NAME}/${LCC_PROJECT_NAME}" ) @@ -36,18 +97,14 @@ add_custom_command( OUTPUT "${LCC_PROJECT_PUBLIC_KEY}" "${LCC_PROJECT_PRIVATE_KEY}" COMMAND license_generator::olm project initialize -t "${PROJECT_SOURCE_DIR}/src/templates" -n "${LCC_PROJECT_NAME}" -p "${LCC_PROJECTS_BASE_DIR}" COMMAND license_generator::lcc project initialize -t "${PROJECT_SOURCE_DIR}/src/templates" -n "${LCC_PROJECT_NAME}" -p "${LCC_PROJECTS_BASE_DIR}" COMMENT "generating ${LCC_PROJECT_PUBLIC_KEY}" USES_TERMINAL ) add_custom_target(project_initialize DEPENDS "${LCC_PROJECT_PUBLIC_KEY}" "${LCC_PROJECT_PRIVATE_KEY}") configure_file ( "src/templates/build_properties.h.in" "${LCC_INCLUDE_DIR}/build_properties.h" ) include_directories( ${LCC_INCLUDE_DIR} ) include_directories( ${LCC_INCLUDE_DIR} ${CMAKE_BINARY_DIR} ) message( STATUS "C compiler : " ${CMAKE_C_COMPILER}) message( STATUS "C compiler flags : " ${CMAKE_C_FLAGS}) @@ -62,6 +119,8 @@ message( STATUS "Project name : " ${LCC_PROJECT_NAME} ) message( STATUS "Project base dir : " ${LCC_PROJECTS_BASE_DIR}/${LCC_PROJECT_NAME} ) add_subdirectory(src) #boost is required only for tests #bug in cmake win32 - can't find boost compiled with mingw if(WIN32 AND "x${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "x") @@ -73,14 +132,8 @@ endif() message(STATUS "Compiler architecture: ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}") endif() add_subdirectory(src) SET( Boost_USE_STATIC_LIBS ON ) find_package(Boost REQUIRED COMPONENTS date_time unit_test_framework program_options system filesystem) #set below in case of dynamic linking in debug. #set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:BOOST_TEST_DYN_LINK>) #if boost is found enable tests IF(Boost_FOUND) @@ -91,7 +144,7 @@ add_definitions(-DBOOST_ALL_NO_LIB) #Disable Boost Microsoft magic, all dependencies are handled by cmake add_definitions(-DBOOST_LIB_DIAGNOSTIC) #Check it is really disabled include_directories(${Boost_INCLUDE_DIRS}) # add_subdirectory(test) add_subdirectory(test) ENDIF(BUILD_TESTING) ELSE(Boost_FOUND) message(WARNING "Boost not found, disabling tests") README.md
@@ -1,10 +1,8 @@ # Open License Manager [](https://isocpp.org/) [](https://en.wikipedia.org/wiki/C%2B%2B#Standardization) [](http://github.com/badges/stability-badges)[](https://opensource.org/licenses/BSD-3-Clause) [](https://travis-ci.org/open-license-manager/open-license-manager) [](https://codecov.io/gh/jinja2cpp/Jinja2Cpp) [](https://www.codacy.com/manual/gcontini/open-license-manager?utm_source=github.com&utm_medium=referral&utm_content=open-license-manager/open-license-manager&utm_campaign=Badge_Grade) [)](http://github.com/open-license-manager/open-license-manager/issues) @@ -19,11 +17,10 @@ The project is donated to the community. It comes with a very large freedom of use for everyone, and it will always be. It uses a [BSD 3 clauses](https://opensource.org/licenses/BSD-3-Clause) licensing schema, that allows free modification and inclusion in commercial software. ## Project Structure The software is made by 2 main sub-components: * a C++ library with a nice C api, `licensecc` with minimal (or no) external dependencies (the part you have to integrate in your software). * a license generator open-license-manager `olm` that allows you to generate a license. * a license generator lcc-license-generator `lcc` for customizing the library and generate the licenses. these modules are planned.... * a license [backoffice](../../issues/7) in php (in order to handle multiple licenses). @@ -31,12 +28,13 @@ * a [log descriptor](../../issues/8) in order to decrypt logs generated by the license system. # How to build Below an overview of the basic build procedure, you can find detailed instructions for each [supported environment](https://github.com/open-license-manager/open-license-manager/wiki/Build-the-library) in the wiki. Below an overview of the basic build procedure, you can find [detailed instructions](https://github.com/open-license-manager/open-license-manager/wiki/Build-the-library) for your environment in the wiki. ## prerequisites * compilsers: GCC (Linux) MINGW (Linux cross compile for Windows), MINGW or MSVC (Windows) * tools/libs: cmake, boost. If target is linux openssl is necessary. * compilers: GCC (Linux) MINGW (Linux cross compile for Windows), MINGW or MSVC (Windows) * tools : cmake, git, make/ninja(linux) * libs : If target is linux Openssl is required. Windows depends only on system libraries. Boost is necessary to build license generator and to run the tests but it's NOT a dependency of the `licensecc` library. ``` git clone https://github.com/open-license-manager/open-license-manager.git cmake/Findlcc.cmake
New file @@ -0,0 +1,84 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. #[=======================================================================[.rst: Findlcc ------- Find or build the lcc executable. Imported Targets ^^^^^^^^^^^^^^^^ This module provides the following imported targets, if found: ``license_generator::lcc`` The lcc executable If lcc is not found this module will try to download it as a submodule Git must be installed. Input variables ^^^^^^^^^^^^^^^^ ``LCC_LOCATION`` Hint for locating the lcc executable Result Variables ^^^^^^^^^^^^^^^^ This will define the following variables: ``LCC_FOUND`` True if the system has the Foo library. ``lcc_VERSION`` Cache Variables ^^^^^^^^^^^^^^^ The following cache variables will also be set: ``LCC_EXECUTABLE`` Path to the lcc executable. #]=======================================================================] set(lcc_names lcc lcc.exe) set (failure_messge "Error finding lcc executable.") find_package(PkgConfig) if(LCC_LOCATION) # First search the PATH and specific locations. find_program(LCC_EXECUTABLE NAMES ${lcc_names} HINTS ${LCC_LOCATION} DOC "lcc command line client") FIND_PACKAGE_HANDLE_STANDARD_ARGS(lcc FOUND_VAR LCC_FOUND REQUIRED_VARS LCC_EXECUTABLE FAIL_MESSAGE "Error finding lcc executable. variable LCC_LOCATION non set correctly.") add_executable(license_generator::lcc IMPORTED GLOBAL) set_property(TARGET license_generator::lcc PROPERTY IMPORTED_LOCATION ${LCC_EXECUTABLE}) ELSE(LCC_LOCATION) find_package(lcc HINTS ${CMAKE_BINARY_DIR} NO_CMAKE_PATH) #try to find it without looping on this module IF(NOT lcc_FOUND) find_package(Git QUIET) if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git") # Update submodules as needed option(GIT_SUBMODULE "Check submodules during build" ON) if(GIT_SUBMODULE) message(STATUS "Submodule update") # execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} # RESULT_VARIABLE GIT_SUBMOD_RESULT) # if(NOT GIT_SUBMOD_RESULT EQUAL "0") # set(failure_messge "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules") # endif() endif() endif() if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/license-generator/CMakeLists.txt") set(failure_messge "All the options to find lcc executable failed. And i can't compile one from source GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") endif() add_subdirectory("${PROJECT_SOURCE_DIR}/extern/license-generator") ENDIF(NOT lcc_FOUND) set(LCC_EXECUTABLE $<TARGET_FILE:license_generator::lcc>) ENDIF(LCC_LOCATION) cmake/Findolm.cmake
File was deleted extern/license-generator
File was deleted extern/license-generator
New file @@ -0,0 +1 @@ ../../olm-license-generator/ src/CMakeLists.txt
@@ -1,4 +1,11 @@ add_subdirectory("library") configure_file ( "templates/licensecc_properties_test.h.in" "${CMAKE_BINARY_DIR}/licensecc_properties_test.h" ) configure_file ( "templates/licensecc_properties.h.in" "${LCC_INCLUDE_DIR}/licensecc_properties.h" ) src/library/LicenseReader.cpp
@@ -23,9 +23,9 @@ #include <math.h> #include <public_key.h> #include <licensecc_properties.h> #include "pc-identifiers.h" #include "build_properties.h" #include "LicenseReader.hpp" #include "base/StringUtils.h" #include "base/logger.h" src/library/base/logger.h
@@ -3,6 +3,7 @@ #ifndef LOG_DISABLED #include <errno.h> #include <string.h> #ifdef __cplusplus extern "C" { #endif src/library/locate/EnvironmentVarData.cpp
@@ -7,7 +7,7 @@ #include "EnvironmentVarData.hpp" #include <build_properties.h> #include <licensecc_properties.h> #include <cstdlib> #include <regex> #include <string> src/library/locate/EnvironmentVarLocation.cpp
@@ -5,7 +5,7 @@ * Author: Gabriele Contini */ #include <build_properties.h> #include <licensecc_properties.h> #include "../base/FileUtils.hpp" #include "../base/StringUtils.h" @@ -15,26 +15,21 @@ namespace locate { using namespace std; EnvironmentVarLocation::EnvironmentVarLocation() : LocatorStrategy("EnvironmentVarLocation") { } EnvironmentVarLocation::EnvironmentVarLocation() : LocatorStrategy("EnvironmentVarLocation") {} EnvironmentVarLocation::~EnvironmentVarLocation() { } EnvironmentVarLocation::~EnvironmentVarLocation() {} const vector<string> EnvironmentVarLocation::license_locations( EventRegistry &eventRegistry) { const vector<string> EnvironmentVarLocation::license_locations(EventRegistry &eventRegistry) { vector<string> licenseFileFoundWithEnvVariable; const string varName(LICENSE_LOCATION_ENV_VAR); if (varName.length() > 0) { //var name is defined in header files. // var name is defined in header files. char *env_var_value = getenv(LICENSE_LOCATION_ENV_VAR); if (env_var_value != nullptr && env_var_value[0] != '\0') { const vector<string> declared_positions = license::split_string( string(env_var_value), ';'); licenseFileFoundWithEnvVariable = license::filter_existing_files( declared_positions, eventRegistry, LICENSE_LOCATION_ENV_VAR); const vector<string> declared_positions = license::split_string(string(env_var_value), ';'); licenseFileFoundWithEnvVariable = license::filter_existing_files(declared_positions, eventRegistry, LICENSE_LOCATION_ENV_VAR); } else { eventRegistry.addEvent(ENVIRONMENT_VARIABLE_NOT_DEFINED); } @@ -42,5 +37,5 @@ return licenseFileFoundWithEnvVariable; } } } } // namespace locate } // namespace license src/library/locate/LocatorFactory.cpp
@@ -5,7 +5,7 @@ * Author: Gabriele Contini */ #include "build_properties.h" #include "licensecc_properties.h" #include "LocatorStrategy.hpp" #include "LocatorFactory.hpp" @@ -17,30 +17,20 @@ namespace license { namespace locate { FUNCTION_RETURN LocatorFactory::get_active_strategies( std::vector<std::unique_ptr<LocatorStrategy>> &strategies, const LicenseLocation *locationHint) { #if(FIND_LICENSE_NEAR_MODULE) strategies.push_back( std::unique_ptr<LocatorStrategy>( (LocatorStrategy*) new ApplicationFolder())); FUNCTION_RETURN LocatorFactory::get_active_strategies(std::vector<std::unique_ptr<LocatorStrategy>> &strategies, const LicenseLocation *locationHint) { #if (FIND_LICENSE_NEAR_MODULE) strategies.push_back(std::unique_ptr<LocatorStrategy>((LocatorStrategy *)new ApplicationFolder())); #endif #if(FIND_LICENSE_WITH_ENV_VAR) strategies.push_back( std::unique_ptr<LocatorStrategy>( (LocatorStrategy*) new EnvironmentVarLocation())); strategies.push_back( std::unique_ptr<LocatorStrategy>( (LocatorStrategy*) new EnvironmentVarData())); #if (FIND_LICENSE_WITH_ENV_VAR) strategies.push_back(std::unique_ptr<LocatorStrategy>((LocatorStrategy *)new EnvironmentVarLocation())); strategies.push_back(std::unique_ptr<LocatorStrategy>((LocatorStrategy *)new EnvironmentVarData())); #endif if (locationHint != nullptr) { strategies.push_back( std::unique_ptr<LocatorStrategy>( (LocatorStrategy*) new ExternalDefinition(locationHint))); strategies.push_back(std::unique_ptr<LocatorStrategy>((LocatorStrategy *)new ExternalDefinition(locationHint))); } return strategies.size() > 0 ? FUNC_RET_OK : FUNC_RET_NOT_AVAIL; } } } } // namespace locate } // namespace license src/library/locate/LocatorStrategy.cpp
@@ -5,7 +5,7 @@ * Author: Gabriele Contini */ #include <build_properties.h> #include <licensecc_properties.h> #include "../base/FileUtils.hpp" #include "LocatorStrategy.hpp" @@ -14,10 +14,9 @@ namespace locate { using namespace std; const string LocatorStrategy::retrieve_license_content( const string &licenseLocation) const { const string LocatorStrategy::retrieve_license_content(const string &licenseLocation) const { return get_file_contents(licenseLocation.c_str(), MAX_LICENSE_LENGTH); } } } } // namespace locate } // namespace license src/library/os/CMakeLists.txt
@@ -1,18 +1,30 @@ IF(WIN32) IF(UNIX) ADD_LIBRARY(os STATIC os.c os-win.c) ELSE(WIN32) ADD_LIBRARY(os STATIC linux/verifier.cpp os.c os-linux.c network_id.c) ENDIF(WIN32) target_link_libraries( os base OpenSSL::Crypto ${EXTERNAL_LIBS} ##ZLIB::ZLIB ) ELSE(UNIX) ADD_LIBRARY(os STATIC windows/verifier.cpp os.c os-win.c) target_link_libraries( os base ${EXTERNAL_LIBS} ) target_link_libraries( os base ) ENDIF(UNIX) install(TARGETS os ARCHIVE DESTINATION lib) src/library/os/linux/verifier.cpp
New file @@ -0,0 +1,105 @@ /* * verifier.cpp * * Created on: Nov 16, 2019 * Author: GC */ #include <openssl/pem.h> #include <openssl/err.h> #include <stdlib.h> #include <errno.h> #include <public_key.h> #include "../verifier.hpp" namespace license { #include "../../base/logger.h" static void free_resources(EVP_PKEY* pkey, EVP_MD_CTX* mdctx) { if (pkey) { EVP_PKEY_free(pkey); } if (mdctx) { EVP_MD_CTX_destroy(mdctx); } } Verifier::Verifier() { static int initialized = 0; if (initialized == 0) { initialized = 1; ERR_load_ERR_strings(); ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); } } FUNCTION_RETURN Verifier::verifySignature(const std::string& stringToVerify, const std::string& signatureB64) { EVP_MD_CTX* mdctx = NULL; const unsigned char pubKey[] = PUBLIC_KEY; int func_ret = 0; BIO* bio = BIO_new_mem_buf((void*)(pubKey), PUBLIC_KEY_LEN); RSA* rsa = PEM_read_bio_RSAPublicKey(bio, NULL, NULL, NULL); BIO_free(bio); if (rsa == NULL) { LOG_ERROR("Error reading public key"); return FUNC_RET_ERROR; } EVP_PKEY* pkey = EVP_PKEY_new(); EVP_PKEY_assign_RSA(pkey, rsa); /*BIO* bo = BIO_new(BIO_s_mem()); BIO_write(bo, pubKey, strlen(pubKey)); RSA *key = 0; PEM_read_bio_RSAPublicKey(bo, &key, 0, 0); BIO_free(bo);*/ // RSA* rsa = EVP_PKEY_get1_RSA( key ); // RSA * pubKey = d2i_RSA_PUBKEY(NULL, <der encoded byte stream pointer>, <num bytes>); unsigned char buffer[512]; BIO* b64 = BIO_new(BIO_f_base64()); BIO* encoded_signature = BIO_new_mem_buf((const void*)signatureB64.c_str(), signatureB64.size()); BIO* biosig = BIO_push(b64, encoded_signature); BIO_set_flags(biosig, BIO_FLAGS_BASE64_NO_NL); // Do not use newlines to flush buffer unsigned int len = BIO_read(biosig, (void*)buffer, signatureB64.size()); // Can test here if len == decodeLen - if not, then return an error buffer[len] = 0; BIO_free_all(biosig); /* Create the Message Digest Context */ if (!(mdctx = EVP_MD_CTX_create())) { free_resources(pkey, mdctx); LOG_ERROR("Error creating context"); return FUNC_RET_ERROR; } if (1 != EVP_DigestVerifyInit(mdctx, NULL, EVP_sha256(), NULL, pkey)) { LOG_ERROR("Error initializing digest"); free_resources(pkey, mdctx); return FUNC_RET_ERROR; } func_ret = EVP_DigestVerifyUpdate(mdctx, (const void*)stringToVerify.c_str(), stringToVerify.size()); if (1 != func_ret) { LOG_ERROR("Error verifying digest %d", func_ret); free_resources(pkey, mdctx); return FUNC_RET_ERROR; } FUNCTION_RETURN result; func_ret = EVP_DigestVerifyFinal(mdctx, buffer, len); if (1 != func_ret) { LOG_ERROR("Error verifying digest %d", func_ret); } result = (1 == func_ret ? FUNC_RET_OK : FUNC_RET_ERROR); free_resources(pkey, mdctx); return result; } Verifier::~Verifier() { } } /* namespace license */ src/library/os/os-linux.c
@@ -203,13 +203,7 @@ } void os_initialize() { static int initialized = 0; if (initialized == 0) { initialized = 1; ERR_load_ERR_strings(); ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); } } static void _getCpuid(unsigned int *p, unsigned int ax) { src/library/os/verifier.hpp
New file @@ -0,0 +1,26 @@ /* * verifier.hpp * * Created on: Nov 16, 2019 * Author: GC */ #ifndef SRC_LIBRARY_OS_VERIFIER_HPP_ #define SRC_LIBRARY_OS_VERIFIER_HPP_ #include <string> #include "../base/base.h" namespace license { class Verifier { public: Verifier(); FUNCTION_RETURN verifySignature(const std::string& stringToVerify, const std::string& signatureB64); ~Verifier(); }; } /* namespace license */ #endif /* SRC_LIBRARY_OS_VERIFIER_HPP_ */ src/library/os/windows/verifier.cpp
New file @@ -0,0 +1,20 @@ /* * verifier.cpp * * Created on: Nov 15, 2019 * Author: devel */ #include "verifier.hpp" namespace license { verifier::verifier() { // TODO Auto-generated constructor stub } verifier::~verifier() { // TODO Auto-generated destructor stub } } /* namespace license */ src/templates/build_properties.h.in
File was deleted src/templates/licensecc_properties.h.in
New file @@ -0,0 +1,17 @@ #ifndef BUILD_PROPERTIES_H_ #define BUILD_PROPERTIES_H_ #define PROJECT_INT_VERSION @LICENSECC_INT_VERSION@ #define PROJECT_VERSION "@LICENSECC_VERSION@" //License retrieval configuration #define FIND_LICENSE_NEAR_MODULE 1 #define FIND_LICENSE_WITH_ENV_VAR 1 #define LICENSE_LOCATION_ENV_VAR "LICENSE_LOCATION" #define LICENSE_DATA_ENV_VAR "LICENSE_DATA" //Internal data structures limits #define MAX_LICENSE_LENGTH 256*1024 #endif src/templates/licensecc_properties_test.h.in
New file @@ -0,0 +1,13 @@ #ifndef BUILD_PROPERTIES_TEST_H_ #define BUILD_PROPERTIES_TEST_H_ //Build locations and parameters for tests #define PROJECT_BINARY_DIR "@CMAKE_BINARY_DIR@" #define PROJECT_SRC_DIR "@CMAKE_CURRENT_LIST_DIR@" #define PROJECT_BASE_DIR "@CMAKE_SOURCE_DIR@" #define PROJECT_TEST_SRC_DIR "@CMAKE_SOURCE_DIR@/test" #define PROJECT_TEST_TEMP_DIR "@CMAKE_BINARY_DIR@/Testing/Temporary" #define BUILD_TYPE "@CMAKE_BUILD_TYPE@" #define LCC_EXE "@LCC_EXECUTABLE@" #endif src/templates/public_key.inja
@@ -1,4 +1,10 @@ #ifndef PUBLIC_KEY_H_ #define PUBLIC_KEY_H_ #define PRODUCT_NAME {{ product_name }} #define PUBLIC_KEY { \ {%for i in public_key%}{% if loop.index1 > 1 %},{% endif %}{{ i }}{%endfor%}\ #define PUBLIC_KEY {\ {%for i in public_key%}{% if loop.index1 > 1 %},{% endif %}{{ i }}{%endfor%}\ } #define PUBLIC_KEY_LEN {{ public_key_len }} #endif test/CMakeLists.txt
@@ -4,4 +4,4 @@ link_directories ( ${Boost_LIBRARY_DIR} ) add_subdirectory(library) add_subdirectory(functional) #add_subdirectory(functional) test/functional/volid_test.cpp
@@ -6,8 +6,9 @@ #include <cstring> #include "../../src/tools/license-generator/license-generator.h" #include "../../src/library/api/license++.h" #include <build_properties.h> #include <boost/filesystem.hpp> #include <licensecc_properties.h> #include <licensecc_properties_test.h> #include "../../src/library/ini/SimpleIni.h" #include "generate-license.h" #include "../../src/library/pc-identifiers.h" test/library/CMakeLists.txt
@@ -69,4 +69,18 @@ ADD_TEST(NAME test_event_registry COMMAND wine ${CMAKE_CURRENT_BINARY_DIR}/test_event_registry) ELSE() ADD_TEST(NAME test_event_registry COMMAND test_event_registry) ENDIF() ENDIF() ### verifier tests add_executable( test_verifier verifier_test.cpp ) target_link_libraries( test_verifier base ${Boost_LIBRARIES} ) ADD_TEST(NAME test_verifier COMMAND test_verfier) test/library/EventRegistry_test.cpp
@@ -13,8 +13,6 @@ #include <stdlib.h> #include <cstdio> #include <build_properties.h> #include "../../src/library/base/EventRegistry.h" namespace test { @@ -26,7 +24,7 @@ * The error reported is for the license that advanced most in the validation process * */ BOOST_AUTO_TEST_CASE( test_most_advanced_license_error ) { BOOST_AUTO_TEST_CASE(test_most_advanced_license_error) { EventRegistry er; er.addEvent(LICENSE_SPECIFIED, "lic2"); er.addEvent(LICENSE_FOUND, "lic1"); @@ -38,4 +36,4 @@ BOOST_CHECK_MESSAGE(LICENSE_CORRUPTED == event->event_type, "Error is for LICENSE_CORRUPTED"); } } //namespace test } // namespace test test/library/LicenseLocator_test.cpp
@@ -11,7 +11,8 @@ #include <boost/test/unit_test.hpp> #include <stdlib.h> #include <build_properties.h> #include <licensecc_properties.h> #include <licensecc_properties_test.h> #include "../../src/library/os/os.h" #include "../../src/library/base/EventRegistry.h" test/library/LicenseReader_test.cpp
@@ -5,13 +5,12 @@ #include <vector> #include <stdlib.h> #include <licensecc_properties.h> #include <licensecc_properties_test.h> #include "../../src/library/api/datatypes.h" #include "../../src/library/base/EventRegistry.h" #include "../../src/library/os/os.h" #include <build_properties.h> #include "../../src/library/LicenseReader.hpp" namespace test { @@ -20,14 +19,13 @@ /** * Read license at fixed location */ BOOST_AUTO_TEST_CASE( read_single_file ) { BOOST_AUTO_TEST_CASE(read_single_file) { const char *licLocation = PROJECT_TEST_SRC_DIR "/library/test_reader.ini"; const LicenseLocation location = { licLocation, nullptr }; const LicenseLocation location = {licLocation, nullptr}; LicenseReader licenseReader(&location); vector<FullLicenseInfo> licenseInfos; const EventRegistry registry = licenseReader.readLicenses("PrODUCT", licenseInfos); const EventRegistry registry = licenseReader.readLicenses("PrODUCT", licenseInfos); BOOST_CHECK(registry.isGood()); BOOST_CHECK_EQUAL(1, licenseInfos.size()); } @@ -35,76 +33,66 @@ /** * Test the error return if the product code is not found in the license */ BOOST_AUTO_TEST_CASE( product_not_licensed ) { const char *licLocation = PROJECT_TEST_SRC_DIR "/library/test_reader.ini"; const LicenseLocation location = { licLocation, nullptr }; BOOST_AUTO_TEST_CASE(product_not_licensed) { const char *licLocation = PROJECT_TEST_SRC_DIR "/library/test_reader.ini"; const LicenseLocation location = {licLocation, nullptr}; LicenseReader licenseReader(&location); vector<FullLicenseInfo> licenseInfos; const EventRegistry registry = licenseReader.readLicenses("PRODUCT-NOT", licenseInfos); const EventRegistry registry = licenseReader.readLicenses("PRODUCT-NOT", licenseInfos); BOOST_CHECK(!registry.isGood()); BOOST_CHECK_EQUAL(0, licenseInfos.size()); BOOST_ASSERT(registry.getLastFailure()!=NULL); BOOST_CHECK_EQUAL(PRODUCT_NOT_LICENSED, registry.getLastFailure()->event_type); BOOST_ASSERT(registry.getLastFailure() != NULL); BOOST_CHECK_EQUAL(PRODUCT_NOT_LICENSED, registry.getLastFailure()->event_type); } /** * Test the error code if the license file is specified but doesn't exists */ BOOST_AUTO_TEST_CASE( file_not_found ) { BOOST_AUTO_TEST_CASE(file_not_found) { const char *licLocation = PROJECT_TEST_SRC_DIR "/library/not_found.ini"; //const char * envName = "MYVAR"; const LicenseLocation location = { licLocation, nullptr }; // const char * envName = "MYVAR"; const LicenseLocation location = {licLocation, nullptr}; LicenseReader licenseReader(&location); vector<FullLicenseInfo> licenseInfos; const EventRegistry registry = licenseReader.readLicenses("PRODUCT", licenseInfos); const EventRegistry registry = licenseReader.readLicenses("PRODUCT", licenseInfos); BOOST_CHECK(!registry.isGood()); BOOST_CHECK_EQUAL(0, licenseInfos.size()); BOOST_ASSERT(registry.getLastFailure()!=NULL); BOOST_CHECK_EQUAL(LICENSE_FILE_NOT_FOUND, registry.getLastFailure()->event_type); BOOST_ASSERT(registry.getLastFailure() != NULL); BOOST_CHECK_EQUAL(LICENSE_FILE_NOT_FOUND, registry.getLastFailure()->event_type); } /** * Test the error code if the license default environment variable isn't specified */ BOOST_AUTO_TEST_CASE( env_var_not_defined ) { BOOST_AUTO_TEST_CASE(env_var_not_defined) { UNSETENV(LICENSE_LOCATION_ENV_VAR); const LicenseLocation location = { nullptr, nullptr }; const LicenseLocation location = {nullptr, nullptr}; LicenseReader licenseReader(&location); vector<FullLicenseInfo> licenseInfos; const EventRegistry registry = licenseReader.readLicenses("PRODUCT", licenseInfos); const EventRegistry registry = licenseReader.readLicenses("PRODUCT", licenseInfos); BOOST_CHECK(!registry.isGood()); BOOST_CHECK_EQUAL(0, licenseInfos.size()); BOOST_ASSERT(registry.getLastFailure()!=NULL); BOOST_CHECK_EQUAL(ENVIRONMENT_VARIABLE_NOT_DEFINED, registry.getLastFailure()->event_type); BOOST_ASSERT(registry.getLastFailure() != NULL); BOOST_CHECK_EQUAL(ENVIRONMENT_VARIABLE_NOT_DEFINED, registry.getLastFailure()->event_type); } /** * Test the error code if the license default environment variable is * specified but points to a non existent file. */ BOOST_AUTO_TEST_CASE( env_var_point_to_wrong_file ) { const char *environment_variable_value = PROJECT_TEST_SRC_DIR "/this/file/doesnt/exist"; BOOST_AUTO_TEST_CASE(env_var_point_to_wrong_file) { const char *environment_variable_value = PROJECT_TEST_SRC_DIR "/this/file/doesnt/exist"; SETENV(LICENSE_LOCATION_ENV_VAR, environment_variable_value) const LicenseLocation location = { nullptr, nullptr }; const LicenseLocation location = {nullptr, nullptr}; LicenseReader licenseReader(&location); vector<FullLicenseInfo> licenseInfos; const EventRegistry registry = licenseReader.readLicenses("PRODUCT", licenseInfos); const EventRegistry registry = licenseReader.readLicenses("PRODUCT", licenseInfos); cout << registry << endl; BOOST_CHECK(!registry.isGood()); BOOST_CHECK_EQUAL(0, licenseInfos.size()); BOOST_ASSERT(registry.getLastFailure()!=NULL); BOOST_CHECK_EQUAL(LICENSE_FILE_NOT_FOUND, registry.getLastFailure()->event_type); BOOST_ASSERT(registry.getLastFailure() != NULL); BOOST_CHECK_EQUAL(LICENSE_FILE_NOT_FOUND, registry.getLastFailure()->event_type); UNSETENV(LICENSE_LOCATION_ENV_VAR); } } /* namespace test*/ test/library/Os_Linux_test.cpp
@@ -1,73 +1,70 @@ #define BOOST_TEST_MODULE os_linux_test #include <boost/test/unit_test.hpp> #include "../../src/library/os/os.h" #include <build_properties.h> #include <string> #include <iostream> #include <boost/test/unit_test.hpp> #include <licensecc_properties.h> #include <licensecc_properties_test.h> #include "../../src/library/os/os.h" using namespace std; BOOST_AUTO_TEST_CASE( read_disk_id ) { BOOST_AUTO_TEST_CASE(read_disk_id) { VIRTUALIZATION virt = getVirtualization(); if(virt == NONE || virt == VM) { DiskInfo * diskInfos = NULL; if (virt == NONE || virt == VM) { DiskInfo *diskInfos = NULL; size_t disk_info_size = 0; FUNCTION_RETURN result = getDiskInfos(NULL, &disk_info_size); BOOST_CHECK_EQUAL(result, FUNC_RET_OK); BOOST_CHECK_GT(disk_info_size, 0); diskInfos = (DiskInfo*) malloc(sizeof(DiskInfo) * disk_info_size); diskInfos = (DiskInfo *)malloc(sizeof(DiskInfo) * disk_info_size); result = getDiskInfos(diskInfos, &disk_info_size); BOOST_CHECK_EQUAL(result, FUNC_RET_OK); BOOST_CHECK_GT(strlen(diskInfos[0].device), 0); BOOST_CHECK_GT(strlen(diskInfos[0].label), 0); BOOST_CHECK_GT(diskInfos[0].disk_sn[0], 0); free(diskInfos); } else if(virt == CONTAINER){ //docker or lxc diskInfo is not meaningful DiskInfo * diskInfos = NULL; } else if (virt == CONTAINER) { // docker or lxc diskInfo is not meaningful DiskInfo *diskInfos = NULL; size_t disk_info_size = 0; FUNCTION_RETURN result = getDiskInfos(NULL, &disk_info_size); BOOST_CHECK_EQUAL(result, FUNC_RET_NOT_AVAIL); } } BOOST_AUTO_TEST_CASE( read_network_adapters ) { OsAdapterInfo * adapter_info = NULL; BOOST_AUTO_TEST_CASE(read_network_adapters) { OsAdapterInfo *adapter_info = NULL; size_t adapter_info_size = 0; FUNCTION_RETURN result = getAdapterInfos(NULL, &adapter_info_size); BOOST_CHECK_EQUAL(result, FUNC_RET_OK); BOOST_CHECK_GT(adapter_info_size, 0); adapter_info = (OsAdapterInfo*) malloc( sizeof(OsAdapterInfo) * adapter_info_size); adapter_info = (OsAdapterInfo *)malloc(sizeof(OsAdapterInfo) * adapter_info_size); result = getAdapterInfos(adapter_info, &adapter_info_size); BOOST_CHECK_EQUAL(result, FUNC_RET_OK); for (size_t i = 0; i < adapter_info_size; i++) { cout << "Interface found: " << string(adapter_info[i].description) << endl; cout << "Interface found: " << string(adapter_info[i].description) << endl; BOOST_CHECK_GT(strlen(adapter_info[i].description), 0); //lo mac address is always 0 but it has ip //other interfaces may not be connected // lo mac address is always 0 but it has ip // other interfaces may not be connected if (string(adapter_info[i].description) == "lo") { BOOST_CHECK_NE(adapter_info[i].ipv4_address[0], 0); } else { bool mac_is_0 = true; for(int j=0;j<6;j++){ mac_is_0 = mac_is_0 && (adapter_info[i].mac_address[j]==0); for (int j = 0; j < 6; j++) { mac_is_0 = mac_is_0 && (adapter_info[i].mac_address[j] == 0); } BOOST_CHECK_MESSAGE( !mac_is_0, "Mac address for interface " << adapter_info[i].description << " is 0"); BOOST_CHECK_MESSAGE(!mac_is_0, "Mac address for interface " << adapter_info[i].description << " is 0"); } } free(adapter_info); } BOOST_AUTO_TEST_CASE( get_cpuid ) { BOOST_CHECK_EQUAL(1, 1); } BOOST_AUTO_TEST_CASE(get_cpuid) { BOOST_CHECK_EQUAL(1, 1); } //To test if virtualization is detected correctly define an env variable VIRT_ENV //otherwise the test is skipped BOOST_AUTO_TEST_CASE( test_virtualization ) { // To test if virtualization is detected correctly define an env variable VIRT_ENV // otherwise the test is skipped BOOST_AUTO_TEST_CASE(test_virtualization) { const char *env = getenv("VIRT_ENV"); if (env != NULL) { if (strcmp(env, "CONTAINER") == 0) { @@ -83,4 +80,3 @@ } } } test/library/verifier_test.cpp
New file @@ -0,0 +1,27 @@ /* * verifier_test.cpp * * Created on: Nov 16, 2019 * Author: GC */ #define BOOST_TEST_MODULE "test_verifier" #include <iostream> #include <iterator> #include <fstream> #include <string> #include <vector> #include <boost/filesystem.hpp> #include <boost/optional.hpp> #include <boost/test/unit_test.hpp> #include <stdlib.h> #include <cstdio> #include "../../src/library/os/verifier.hpp" namespace license { BOOST_AUTO_TEST_CASE(verify_string) {} } /* namespace license */