issue #42 #38 \n review build system, \n issue #38 added clang format
New file |
| | |
| | | BasedOnStyle: Google |
| | | Language: Cpp |
| | | Standard: Cpp11 |
| | | IndentWidth: 4 |
| | | TabWidth: 4 |
| | | ColumnLimit: 120 |
| | | UseTab: Always |
| | | AccessModifierOffset: -4 |
| | | AlignTrailingComments: false |
| | | FixNamespaceComments: true |
| | | SortIncludes: false |
| | | SortUsingDeclarations : true |
| | |
| | | [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 |
| | |
| | | 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) |
| | |
| | | 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}" ) |
| | |
| | | |
| | | 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}) |
| | |
| | | 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") |
| | |
| | | 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) |
| | |
| | | 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") |
| | |
| | | # 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) |
| | | |
| | |
| | | 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). |
| | |
| | | * 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 |
New file |
| | |
| | | # 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) |
| | | |
| | | |
New file |
| | |
| | | ../../olm-license-generator/ |
| | |
| | | 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" |
| | | ) |
| | |
| | | #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" |
| | |
| | | |
| | | #ifndef LOG_DISABLED |
| | | #include <errno.h> |
| | | #include <string.h> |
| | | #ifdef __cplusplus |
| | | extern "C" { |
| | | #endif |
| | |
| | | |
| | | #include "EnvironmentVarData.hpp" |
| | | |
| | | #include <build_properties.h> |
| | | #include <licensecc_properties.h> |
| | | #include <cstdlib> |
| | | #include <regex> |
| | | #include <string> |
| | |
| | | * Author: Gabriele Contini |
| | | */ |
| | | |
| | | #include <build_properties.h> |
| | | #include <licensecc_properties.h> |
| | | |
| | | #include "../base/FileUtils.hpp" |
| | | #include "../base/StringUtils.h" |
| | |
| | | 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); |
| | |
| | | //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); |
| | | } |
| | |
| | | return licenseFileFoundWithEnvVariable; |
| | | } |
| | | |
| | | } |
| | | } |
| | | } // namespace locate |
| | | } // namespace license |
| | |
| | | * Author: Gabriele Contini |
| | | */ |
| | | |
| | | #include "build_properties.h" |
| | | #include "licensecc_properties.h" |
| | | |
| | | #include "LocatorStrategy.hpp" |
| | | #include "LocatorFactory.hpp" |
| | |
| | | namespace license { |
| | | namespace locate { |
| | | |
| | | FUNCTION_RETURN LocatorFactory::get_active_strategies( |
| | | std::vector<std::unique_ptr<LocatorStrategy>> &strategies, |
| | | 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())); |
| | | 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())); |
| | | 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 |
| | |
| | | * Author: Gabriele Contini |
| | | */ |
| | | |
| | | #include <build_properties.h> |
| | | #include <licensecc_properties.h> |
| | | |
| | | #include "../base/FileUtils.hpp" |
| | | #include "LocatorStrategy.hpp" |
| | |
| | | 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 |
| | |
| | | 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 |
| | | ) |
| | | ENDIF(UNIX) |
| | | |
| | | |
| | | |
| | | install(TARGETS os ARCHIVE DESTINATION lib) |
New file |
| | |
| | | /* |
| | | * 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 */ |
| | |
| | | } |
| | | |
| | | 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) { |
New file |
| | |
| | | /* |
| | | * 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_ */ |
New file |
| | |
| | | /* |
| | | * 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 */ |
New file |
| | |
| | | #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 |
New file |
| | |
| | | #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 |
| | |
| | | #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_LEN {{ public_key_len }} |
| | | #endif |
| | |
| | | link_directories ( ${Boost_LIBRARY_DIR} ) |
| | | |
| | | add_subdirectory(library) |
| | | add_subdirectory(functional) |
| | | #add_subdirectory(functional) |
| | |
| | | #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" |
| | |
| | | ELSE() |
| | | ADD_TEST(NAME test_event_registry COMMAND test_event_registry) |
| | | 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) |
| | |
| | | #include <stdlib.h> |
| | | #include <cstdio> |
| | | |
| | | #include <build_properties.h> |
| | | |
| | | #include "../../src/library/base/EventRegistry.h" |
| | | |
| | | namespace test { |
| | |
| | | #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" |
| | |
| | | #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 { |
| | |
| | | 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()); |
| | | } |
| | |
| | | * 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 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_CHECK_EQUAL(PRODUCT_NOT_LICENSED, registry.getLastFailure()->event_type); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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_CHECK_EQUAL(LICENSE_FILE_NOT_FOUND, registry.getLastFailure()->event_type); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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_CHECK_EQUAL(ENVIRONMENT_VARIABLE_NOT_DEFINED, registry.getLastFailure()->event_type); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 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"; |
| | | 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 }; |
| | | 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_CHECK_EQUAL(LICENSE_FILE_NOT_FOUND, registry.getLastFailure()->event_type); |
| | | UNSETENV(LICENSE_LOCATION_ENV_VAR); |
| | | } |
| | | } /* namespace test*/ |
| | |
| | | #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 ) { |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | } |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | /* |
| | | * 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 */ |