gcontini
2019-09-21 0ec4d68600b83d41d2e48ad35d18e2a00f234619
Merge branch 'develop' of https://github.com/open-license-manager/open-license-manager into develop
19个文件已修改
1个文件已添加
837 ■■■■■ 已修改文件
.travis.yml 120 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CMakeLists.txt 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
README.md 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
example/CMakeLists.txt 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
modules/toolchain-ubuntu-mingw64.cmake 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/CMakeLists.txt 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/os/os-linux.c 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/os/os-win.c 435 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/os/os.c 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/pc-identifiers.c 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tools/base_lib/CMakeLists.txt 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tools/base_lib/CryptoHelper.cpp 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tools/base_lib/win/CryptoHelperWindows.cpp 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tools/bootstrap/CMakeLists.txt 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tools/license-generator/CMakeLists.txt 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/tools/license-generator/license-generator.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/functional/CMakeLists.txt 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/functional/volid_test.cpp 22 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/library/CMakeLists.txt 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/license-generator/CMakeLists.txt 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.travis.yml
@@ -21,6 +21,10 @@
             - libboost-system-dev
             - libboost-thread-dev
             - libboost-date-time-dev
     script:
         - cmake --build . --target install
         - ctest
         - ctest -T memcheck
   - os: linux
     dist: xenial
     name: "Ubuntu 16.04 - Travis CI VM"
@@ -39,64 +43,120 @@
             - libboost-system-dev
             - libboost-thread-dev
             - libboost-date-time-dev
   - os: linux
     dist: bionic
     name: "Ubuntu 18.04 - Travis CI VM - Debug build"
     addons:
        apt:
          packages:
             - cmake
             - valgrind
             - libssl-dev
             - zlib1g-dev
             - libboost-dev
             - libboost-test-dev
             - libboost-filesystem-dev
             - libboost-iostreams-dev
             - libboost-program-options-dev
             - libboost-system-dev
             - libboost-thread-dev
             - libboost-date-time-dev
     before_script:
         - mkdir build
         - cd build && cmake -DCMAKE_INSTALL_PREFIX=../../install -DCMAKE_BUILD_TYPE=Debug ..
     script:
         - cmake --build . --target install
         - ctest
         - ctest -T memcheck
   - os: linux
     dist: bionic
     name: "CentOS-7 Docker"
     before_script: 
        - docker run --name centos7_toconfigure -v `pwd`:/root/open-license-manager centos:centos7 /bin/bash -c 
            "yum -y update && yum -y install cmake boost boost-devel boost-static openssl openssl-devel gcc-c++ valgrind valgrind-devel glibc-static centos-release-scl-rh &&
              yum -y install devtoolset-3-gcc devtoolset-3-gcc-c++ && cd /root/open-license-manager && mkdir build && cd build &&
              CC=/opt/rh/devtoolset-3/root/usr/bin/gcc XX=/opt/rh/devtoolset-3/root/usr/bin/g++ cmake .."
            "yum -y update && yum -y install install centos-release-scl &&
              yum -y install cmake boost boost-devel boost-static openssl openssl-devel glibc-static devtoolset-7-toolchain devtoolset-7-gcc devtoolset-7-gcc-c++ devtoolset-7-valgrind-devel &&
              cd /root/open-license-manager && mkdir build && cd build &&
              CC=/opt/rh/devtoolset-7/root/usr/bin/gcc CXX=/opt/rh/devtoolset-7/root/usr/bin/g++ cmake .."
        - docker commit centos7_toconfigure centos7_configured
     script: 
        - docker run --name centos7_make -v `pwd`:/root/open-license-manager centos7_configured /bin/bash -c 
            "cd /root/open-license-manager/build && make && make install && VIRT_ENV=CONTAINER make test"
   - os: linux
     dist: bionic
     name: "Ubuntu 18.04 - MinGW cross-compile for Windows x64"
     addons:
        apt:
          packages:
             - cmake
             - binutils-mingw-w64
             - mingw-w64
             - mingw-w64-tools
             - mingw-w64-x86-64-dev
             - wine-development
     before_script:
        - mkdir build
        - cd build
        - wget -c https://dl.bintray.com/boostorg/release/1.71.0/source/boost_1_71_0.tar.bz2
        - tar xjf boost_1_71_0.tar.bz2
        - sudo ln -s /usr/bin/x86_64-w64-mingw32-g++ /usr/local/bin/g++-mingw
        - cd boost_1_71_0
        - ./bootstrap.sh
        - travis_wait 30 ./b2 toolset=gcc-mingw target-os=windows address-model=64 --with-date_time --with-test --with-filesystem --with-program_options --with-regex --with-serialization --with-system runtime-link=static --prefix=./dist release install
        - cd ..
        - cmake -DCMAKE_TOOLCHAIN_FILE=../modules/toolchain-ubuntu-mingw64.cmake -DCMAKE_INSTALL_PREFIX=../../install -DBOOST_ROOT=$PWD/boost_1_71_0/dist  ..
   - os: windows
     name: "Widnows server 1803 - Visual Studio 15 2017 Win64 - (/MD)"
     env:
        - CACHE_NAME=boost
     cache:
         directories:
             - "/C/local/boost"
     before_script:
         #- Regsvr32.exe "C:\Widnows\System32\rsaenh.dll"
         #Not sure this is necessary let's leave it here for some time, see if there are
         #differences with the build (/MT)
         - sc stop CryptSvc
         - travis_wait 30 ./windows_download_boost.bat
         - cd "/C/Users/travis/build/open-license-manager/open-license-manager"
         - travis_wait 40 ./windows_download_boost.bat
         - cd "${TRAVIS_BUILD_DIR}"
         - mkdir build
         - cd build && cmake -G "Visual Studio 15 2017 Win64" -DBOOST_ROOT="C:/local/boost" ..
     script:
         - cmake --build . --target install --config Release
         - ctest -C Release
   - os: windows
     name: "Widnows server 1803 - Visual Studio 15 2017 Win64 - (/MT)"
     before_script:
         - travis_wait 40 ./windows_download_boost.bat
         - cd "${TRAVIS_BUILD_DIR}"
         - mkdir build
         - cd build && cmake -G "Visual Studio 15 2017 Win64" -DBOOST_ROOT="C:/local/boost" -DSTATIC_RUNTIME=1 ..
   - os: windows
     name: "Widnows server 1803 - MinGW Win64"
     env:
        - CACHE_NAME=boost
        - CACHE_NAME=boost-mingw
     cache:
         name: boost-mingw
         directories:
             - "/C/local/boost"
     before_script:
         - travis_wait 30 ./windows_download_boost.bat
         - cd "/C/Users/travis/build/open-license-manager/open-license-manager"
         - |
           if [ -d "/C/local/boost/lib" ]; then
               echo "Boost already installed"
           else
               echo "Boost not cached, compiling it"
               wget -q https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.7z
               echo "Boost downloaded"
               travis_wait 20 7z x boost_1_68_0.7z -oC:/local
               cd "C:/local/boost_1_68_0"
               ./bootstrap.bat gcc
               travis_wait 40 ./b2.exe -d0 --with-date_time --with-test --with-filesystem --with-program_options --with-regex --with-serialization --with-system runtime-link=static toolset=gcc --prefix=C:/local/boost install
               echo "Boost installed"
               cd /C/local/boost/lib
               dir
           fi
         - cd "${TRAVIS_BUILD_DIR}"
         - mkdir build
         - cd build && cmake -G "Visual Studio 15 2017 Win64" -DBOOST_ROOT="C:/local/boost" -DSTATIC_RUNTIME=1 ..
     script:
         - cmake --build . --target install --config Release
         - ctest -C Release
         - cd build && cmake -G "MinGW Makefiles" --trace-expand -DBOOST_ROOT="C:/local/boost" -DBoost_ARCHITECTURE="-x64" -DCMAKE_CXX_COMPILER_ARCHITECTURE_ID="x64" -DCMAKE_SH="CMAKE_SH-NOTFOUND" ..
env:
    - CTEST_OUTPUT_ON_FAILURE=1      
before_script:
    - mkdir build
    - cd build && cmake -DCMAKE_INSTALL_PREFIX=../../install ..
script: 
    - make
    - make install
    - make test
    - cmake --build . --target install --config Release
    - ctest -C Release
    
CMakeLists.txt
@@ -22,7 +22,7 @@
    string(TOLOWER ${CMAKE_BUILD_TYPE} _CMAKE_BUILD_TYPE)
    EVAL_CONDITION(RELEASE_BUILD ${_CMAKE_BUILD_TYPE} STREQUAL "release")
else(CMAKE_BUILD_TYPE)
    set(RELEASE_BUILD 0)
    SET(RELEASE_BUILD 0)
endif(CMAKE_BUILD_TYPE)
if(MSVC)
@@ -43,32 +43,19 @@
    #SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib ) #${CMAKE_FIND_LIBRARY_SUFFIXES}
    add_definitions("/D _CRT_SECURE_NO_WARNINGS")
else(MSVC)
    #GCC or Mingw
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe -fmessage-length=0 -std=c++11 -Wuninitialized -fPIC") #-Wall
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -fmessage-length=0 -Wall -Wuninitialized -fPIC") 
    if(RELEASE_BUILD)
        SET(CMAKE_FIND_LIBRARY_SUFFIXES .a) #.so for dynamic libraries
    else()
        SET(CMAKE_FIND_LIBRARY_SUFFIXES .a .so)
    endif()
    set (CMAKE_EXE_LINKER_FLAGS  "-pthread")
    SET(CMAKE_EXE_LINKER_FLAGS  "-pthread -static-libstdc++")
    SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,--strip-all -static-libstdc++") #-static 
    #you need to "force" the change in cmake_install_prefix after the project keyword
    IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
        SET(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Install path prefix" FORCE)
    ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
        #find a static version of openssl crypto library
    find_package(OpenSSL REQUIRED)
    include_directories(${OPENSSL_INCLUDE_DIR})
    if(MINGW)
        list(APPEND EXTERNAL_LIBS "-lcrypto -liphlpapi")
    else(MINGW)
        list(APPEND EXTERNAL_LIBS ${OPENSSL_CRYPTO_LIBRARY})
        list(APPEND EXTERNAL_LIBS "-lcrypt32 -lws2_32 -liphlpapi")
        SET(CMAKE_EXE_LINKER_FLAGS "-static")
    endif(MINGW)
    MESSAGE(STATUS "Found openssl version ${OPENSSL_VERSION} ")
    #Zlib required when openssl version < 1.0.1f
    find_package(ZLIB REQUIRED)
    list(APPEND EXTERNAL_LIBS ${ZLIB_LIBRARIES})
    
    if(USE_DBUS_IDENTIFIER)
        FIND_PACKAGE(Dbus REQUIRED)
@@ -77,14 +64,28 @@
        include_directories(${DBUS_ARCH_INCLUDE_DIR})
        list(APPEND EXTERNAL_LIBS ${DBUS_LIBRARIES})
    endif(USE_DBUS_IDENTIFIER)    
    if(NOT MINGW)
        list(APPEND EXTERNAL_LIBS dl)
    endif(NOT MINGW)
    list(APPEND EXTERNAL_LIBS "-Wl,-Bdynamic")
endif(MSVC)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:_DEBUG>)
if(UNIX) #this is true for all the linux systems but not for cross compiling
    #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})
    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)
    list(APPEND EXTERNAL_LIBS ${ZLIB_LIBRARIES})
    MESSAGE(STATUS "Found zlib version ${ZLIB_VERSION} ")
    if(NOT MINGW)
         list(APPEND EXTERNAL_LIBS "-ldl")
    endif(NOT MINGW)
    find_program( MEMORYCHECK_COMMAND valgrind )
    set( MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full" )
endif(UNIX)
SET_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Debug>:_DEBUG>)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  SET(HAVE_64BIT_SIZE_T 1)
@@ -92,7 +93,18 @@
  SET(HAVE_64BIT_SIZE_T 0)
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set( Boost_USE_STATIC_LIBS ON )
#bug in cmake win32 - can't find boost compiled with mingw
if(WIN32 AND "x${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "x")
    message(WARNING "WIN32 compiler does not specify CMAKE_CXX_COMPILER_ARCHITECTURE_ID -- filling in manually")
    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
        set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID "x64")
    else()
        set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID "x86")
    endif()
    message(STATUS "Compiler architecture: ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
endif()
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>)
README.md
@@ -33,8 +33,8 @@
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. 
## prerequisites
 * compilsers: GCC (Linux), MINGW or MSVC (Windows)
 * tools/libs: cmake, boost, openssl (Linux/MINGW).
 * compilsers: GCC (Linux) MINGW (Linux cross compile for Windows), MINGW or MSVC (Windows)
 * tools/libs: cmake, boost. If target is linux openssl is necessary.
```
git clone https://github.com/open-license-manager/open-license-manager.git
example/CMakeLists.txt
@@ -10,7 +10,7 @@
SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib )
else(MSVC)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a .so)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s -Wl,--exclude-libs,liblicense++_static.a")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s -Wl,--exclude-libs,liblicensepp_static.a")
find_package(OpenSSL REQUIRED)
endif(MSVC)
@@ -18,7 +18,7 @@
add_executable(example example.cpp)
target_link_libraries(example license++_static os base tools_base)
target_link_libraries(example licensepp_static os base tools_base)
if(NOT MSVC)
target_link_libraries(example crypto pthread dl z)
modules/toolchain-ubuntu-mingw64.cmake
New file
@@ -0,0 +1,27 @@
# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
#    *) install cross compiler: `sudo apt-get install mingw-w64 g++-mingw-w64`
#    *) cd build
#    *) cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-Ubuntu-mingw64.cmake ..
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_HOST_SYSTEM_NAME Linux)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
# cross compilers to use for C and C++
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
# target environment on the build host system
#   set 1st to dir with the cross compiler's C/C++ headers/libs
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
# modify default behavior of FIND_XXX() commands to
# search for headers/libs in the target environment and
# search for programs in the build host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
#set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
#set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
src/library/CMakeLists.txt
@@ -2,19 +2,19 @@
add_subdirectory("base")
add_subdirectory("ini")
ADD_LIBRARY(license++_static STATIC
ADD_LIBRARY(licensepp_static STATIC
    license++.cpp
    LicenseReader.cpp
    pc-identifiers.c
)
target_link_libraries(
     license++_static
     licensepp_static
     ini
     os
)
install(TARGETS license++_static ARCHIVE DESTINATION lib)
install(TARGETS licensepp_static ARCHIVE DESTINATION lib)
install(FILES api/datatypes.h api/license++.h DESTINATION include/api)
install(FILES base/base.h DESTINATION include/base)
install(FILES pc-identifiers.h DESTINATION include/)
src/library/os/os-linux.c
@@ -2,16 +2,16 @@
#include <sys/stat.h>
#include "os.h"
#include "../base/logger.h"
//#include <openssl/evp.h>
//#include <openssl/bio.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <mntent.h>
#include <dirent.h>
#include <sys/utsname.h>
#ifdef _DEBUG
#include <valgrind/memcheck.h>
#endif
#ifdef USE_DBUS
#include <dbus-1.0/dbus/dbus.h>
#endif
src/library/os/os-win.c
@@ -1,221 +1,214 @@
#ifdef _MSC_VER
#include <Windows.h>
#endif
#include <iphlpapi.h>
#include "../base/logger.h"
#include "os.h"
#pragma comment(lib, "IPHLPAPI.lib")
unsigned char* unbase64(const char* ascii, int len, int *flen);
FUNCTION_RETURN getOsSpecificIdentifier(unsigned char identifier[6]) {
    return FUNC_RET_NOT_AVAIL;
}
FUNCTION_RETURN getMachineName(unsigned char identifier[6]) {
    FUNCTION_RETURN result = FUNC_RET_ERROR;
    char buffer[MAX_COMPUTERNAME_LENGTH + 1];
    int bufsize = MAX_COMPUTERNAME_LENGTH + 1;
    const BOOL cmpName = GetComputerName(buffer, &bufsize);
    if (cmpName) {
        strncpy(identifier, buffer, 6);
        result = FUNC_RET_OK;
    }
    return result;
}
FUNCTION_RETURN getCpuId(unsigned char identifier[6]) {
    return FUNC_RET_NOT_AVAIL;
}
void os_initialize() {
}
//http://www.ok-soft-gmbh.com/ForStackOverflow/EnumMassStorage.c
//http://stackoverflow.com/questions/3098696/same-code-returns-diffrent-result-on-windows7-32-bit-system
#define MAX_UNITS 30
//bug check return with diskinfos == null func_ret_ok
FUNCTION_RETURN getDiskInfos(DiskInfo * diskInfos, size_t * disk_info_size) {
    DWORD FileMaxLen;
    int ndrives = 0;
    DWORD FileFlags;
    char volName[_MAX_FNAME], FileSysName[_MAX_FNAME];
    char* szSingleDrive;
    DWORD volSerial = 0;
    BOOL success;
    UINT driveType;
    const DWORD dwSize = MAX_PATH;
    char szLogicalDrives[MAX_PATH] = { 0 };
    unsigned char buf[8] = "";
    FUNCTION_RETURN return_value;
    const DWORD dwResult = GetLogicalDriveStrings(dwSize, szLogicalDrives);
    if (dwResult > 0 && dwResult <= MAX_PATH) {
        return_value = FUNC_RET_OK;
        szSingleDrive = szLogicalDrives;
        while (*szSingleDrive && ndrives < MAX_UNITS) {
            // get the next drive
            driveType = GetDriveType(szSingleDrive);
            if (driveType == DRIVE_FIXED) {
                success = GetVolumeInformation(szSingleDrive, volName, MAX_PATH,
                        &volSerial, &FileMaxLen, &FileFlags, FileSysName,
                        MAX_PATH);
                if (success) {
                    LOG_INFO("drive         : %s", szSingleDrive);
                    LOG_INFO("Volume Name   : %s", volName);
                    LOG_INFO("Volume Serial : 0x%x", volSerial);
                    LOG_DEBUG("Max file length : %d", FileMaxLen);
                    LOG_DEBUG("Filesystem      : %s", FileSysName);
                    if (diskInfos != NULL) {
                        if (ndrives < *disk_info_size) {
                            diskInfos[ndrives].id = ndrives;
                            strncpy(diskInfos[ndrives].device, volName, MAX_PATH);
                            strncpy(diskInfos[ndrives].label, FileSysName, MAX_PATH);
                            memcpy(diskInfos[ndrives].disk_sn, &buf, sizeof(buf));
                            memcpy(diskInfos[ndrives].disk_sn, &volSerial, sizeof(DWORD));
                            diskInfos[ndrives].preferred = (strncmp(szSingleDrive, "C", 1) != 0);
                        } else {
                            return_value = FUNC_RET_BUFFER_TOO_SMALL;
                        }
                    }
                    ndrives++;
                } else {
                    LOG_WARN("Unable to retrieve information of '%s'", szSingleDrive);
                }
            } else {
                LOG_INFO("This volume is not fixed : %s, type: %d",    szSingleDrive);
            }
            szSingleDrive += strlen(szSingleDrive) + 1;
        }
    }
    if (diskInfos == NULL || *disk_info_size == 0) {
        if (ndrives > 0) {
            return_value = FUNC_RET_OK;
        } else {
            return_value = FUNC_RET_NOT_AVAIL;
            LOG_INFO("No fixed drive was detected");
        }
        *disk_info_size = ndrives;
    } else {
        *disk_info_size = min(ndrives, *disk_info_size);
    }
    return return_value;
}
static int translate(char ipStringIn[16], unsigned char ipv4[4]) {
    char *str2;
    size_t index = 0;
    str2 = ipStringIn; /* save the pointer */
    while (*str2) {
        if (isdigit((unsigned char) *str2)) {
            ipv4[index] *= 10;
            ipv4[index] += *str2 - '0';
        } else {
            index++;
        }
        str2++;
    }
    return 0;
}
//http://stackoverflow.com/questions/18046063/mac-address-using-c
//TODO: count only interfaces with type (MIB_IF_TYPE_ETHERNET IF_TYPE_IEEE80211)
FUNCTION_RETURN getAdapterInfos(OsAdapterInfo * adapterInfos,
        size_t * adapter_info_size) {
    DWORD dwStatus;
    unsigned int i = 0;
    FUNCTION_RETURN result;
    PIP_ADAPTER_INFO pAdapterInfo, pAdapter = NULL;
    //IP_ADAPTER_INFO AdapterInfo[20];              // Allocate information for up to 16 NICs
    DWORD dwBufLen = sizeof(IP_ADAPTER_INFO); //10 * sizeof(IP_ADAPTER_INFO);  // Save the memory size of buffer
    i = 3;
    do {
        pAdapterInfo = (PIP_ADAPTER_INFO) malloc(dwBufLen);
        dwStatus = GetAdaptersInfo(               // Call GetAdapterInfo
                pAdapterInfo, // [out] buffer to receive data
                &dwBufLen   // [in] size of receive data buffer
                );
        if (dwStatus != NO_ERROR) {
            free(pAdapterInfo);
            pAdapterInfo = NULL;
        }
    } while (dwStatus == ERROR_BUFFER_OVERFLOW && i-- > 0);
    if (dwStatus == ERROR_BUFFER_OVERFLOW) {
        return FUNC_RET_ERROR;
    }
    if (adapterInfos == NULL || *adapter_info_size == 0) {
        *adapter_info_size = dwBufLen / sizeof(IP_ADAPTER_INFO);
        if (pAdapterInfo != NULL){
            free(pAdapterInfo);
        }
        return FUNC_RET_OK;
    }
  *adapter_info_size = dwBufLen / sizeof(IP_ADAPTER_INFO);
    memset(adapterInfos, 0, dwBufLen);
    pAdapter = pAdapterInfo;
    i = 0;
    result = FUNC_RET_OK;
    while (pAdapter) {
        strncpy(adapterInfos[i].description, pAdapter->Description,
                min(sizeof(adapterInfos->description),
                        MAX_ADAPTER_DESCRIPTION_LENGTH));
        memcpy(adapterInfos[i].mac_address, pAdapter->Address, 8);
        translate(pAdapter->IpAddressList.IpAddress.String,
                adapterInfos[i].ipv4_address);
        adapterInfos[i].type = IFACE_TYPE_ETHERNET;
        i++;
        pAdapter = pAdapter->Next;
        if (i == *adapter_info_size) {
            result = FUNC_RET_BUFFER_TOO_SMALL;
            break;
        }
    }
    free(pAdapterInfo);
    return result;
}
FUNCTION_RETURN getModuleName(char buffer[MAX_PATH]) {
    FUNCTION_RETURN result = FUNC_RET_OK;
    const DWORD wres = GetModuleFileName(NULL, buffer, MAX_PATH);
    if (wres == 0) {
        result = FUNC_RET_ERROR;
    }
    return result;
}
static void printHash(HCRYPTHASH* hHash) {
    BYTE *pbHash;
    DWORD dwHashLen;
    DWORD dwHashLenSize = sizeof(DWORD);
    char* hashStr;
    unsigned int i;
    if (CryptGetHashParam(*hHash, HP_HASHSIZE, (BYTE *) &dwHashLen,
            &dwHashLenSize, 0)) {
        pbHash = (BYTE*) malloc(dwHashLen);
        hashStr = (char*) malloc(dwHashLen * 2 + 1);
        if (CryptGetHashParam(*hHash, HP_HASHVAL, pbHash, &dwHashLen, 0)) {
            for (i = 0; i < dwHashLen; i++) {
                sprintf(&hashStr[i * 2], "%02x", pbHash[i]);
            } LOG_DEBUG("Hash to verify: %s", hashStr);
        }
        free(pbHash);
        free(hashStr);
    }
}
/**
 * Not implemented yet.
 */
VIRTUALIZATION getVirtualization() {
    return NONE;
}
#ifdef _MSC_VER
#include <Windows.h>
#endif
#include "../base/logger.h"
#include "os.h"
#include <iphlpapi.h>
#include <stdio.h>
#pragma comment(lib, "IPHLPAPI.lib")
unsigned char* unbase64(const char* ascii, int len, int *flen);
FUNCTION_RETURN getOsSpecificIdentifier(unsigned char identifier[6]) {
    return FUNC_RET_NOT_AVAIL;
}
FUNCTION_RETURN getMachineName(unsigned char identifier[6]) {
    FUNCTION_RETURN result = FUNC_RET_ERROR;
    char buffer[MAX_COMPUTERNAME_LENGTH + 1];
    int bufsize = MAX_COMPUTERNAME_LENGTH + 1;
    const BOOL cmpName = GetComputerName(buffer, (unsigned long*)&bufsize);
    if (cmpName) {
        strncpy((char*)identifier, buffer, 6);
        result = FUNC_RET_OK;
    }
    return result;
}
FUNCTION_RETURN getCpuId(unsigned char identifier[6]) {
    return FUNC_RET_NOT_AVAIL;
}
void os_initialize() {
}
//http://www.ok-soft-gmbh.com/ForStackOverflow/EnumMassStorage.c
//http://stackoverflow.com/questions/3098696/same-code-returns-diffrent-result-on-windows7-32-bit-system
#define MAX_UNITS 30
//bug check return with diskinfos == null func_ret_ok
FUNCTION_RETURN getDiskInfos(DiskInfo * diskInfos, size_t * disk_info_size) {
    DWORD FileMaxLen;
    int ndrives = 0;
    DWORD FileFlags;
    char volName[_MAX_FNAME], FileSysName[_MAX_FNAME];
    DWORD volSerial = 0;
    const DWORD dwSize = MAX_PATH;
    char szLogicalDrives[MAX_PATH] = { 0 };
    unsigned char buf[8] = "";
    FUNCTION_RETURN return_value;
    const DWORD dwResult = GetLogicalDriveStrings(dwSize, szLogicalDrives);
    if (dwResult > 0 && dwResult <= MAX_PATH) {
        return_value = FUNC_RET_OK;
        char* szSingleDrive = szLogicalDrives;
        while (*szSingleDrive && ndrives < MAX_UNITS) {
            // get the next drive
            UINT driveType = GetDriveType(szSingleDrive);
            if (driveType == DRIVE_FIXED) {
                BOOL success = GetVolumeInformation(szSingleDrive, volName, MAX_PATH,
                                                    &volSerial, &FileMaxLen, &FileFlags, FileSysName,
                                                    MAX_PATH);
                if (success) {
                    LOG_INFO("drive         : %s", szSingleDrive);
                    LOG_INFO("Volume Name   : %s", volName);
                    LOG_INFO("Volume Serial : 0x%x", volSerial);
                    LOG_DEBUG("Max file length : %d", FileMaxLen);
                    LOG_DEBUG("Filesystem      : %s", FileSysName);
                    if (diskInfos != NULL) {
                        if (ndrives < (int)*disk_info_size) {
                            diskInfos[ndrives].id = ndrives;
                            strncpy(diskInfos[ndrives].device, volName, MAX_PATH);
                            strncpy(diskInfos[ndrives].label, FileSysName, MAX_PATH);
                            memcpy(diskInfos[ndrives].disk_sn, &buf, sizeof(buf));
                            memcpy(diskInfos[ndrives].disk_sn, &volSerial, sizeof(DWORD));
                            diskInfos[ndrives].preferred = (strncmp(szSingleDrive, "C", 1) != 0);
                        } else {
                            return_value = FUNC_RET_BUFFER_TOO_SMALL;
                        }
                    }
                    ndrives++;
                } else {
                    LOG_WARN("Unable to retrieve information of '%s'", szSingleDrive);
                }
            } else {
                LOG_INFO("This volume is not fixed : %s, type: %d",    szSingleDrive);
            }
            szSingleDrive += strlen(szSingleDrive) + 1;
        }
    }
    if (diskInfos == NULL || *disk_info_size == 0) {
        if (ndrives > 0) {
            return_value = FUNC_RET_OK;
        } else {
            return_value = FUNC_RET_NOT_AVAIL;
            LOG_INFO("No fixed drive was detected");
        }
        *disk_info_size = ndrives;
    } else {
        *disk_info_size = min(ndrives, *disk_info_size);
    }
    return return_value;
}
static int translate(char ipStringIn[16], unsigned char ipv4[4]) {
    size_t index = 0;
    char* str2 = ipStringIn; /* save the pointer */
    while (*str2) {
        if (isdigit((unsigned char) *str2)) {
            ipv4[index] *= 10;
            ipv4[index] += *str2 - '0';
        } else {
            index++;
        }
        str2++;
    }
    return 0;
}
//http://stackoverflow.com/questions/18046063/mac-address-using-c
//TODO: count only interfaces with type (MIB_IF_TYPE_ETHERNET IF_TYPE_IEEE80211)
FUNCTION_RETURN getAdapterInfos(OsAdapterInfo * adapterInfos,
        size_t * adapter_info_size) {
    DWORD dwStatus;
    PIP_ADAPTER_INFO pAdapterInfo;
    //IP_ADAPTER_INFO AdapterInfo[20];              // Allocate information for up to 16 NICs
    DWORD dwBufLen = sizeof(IP_ADAPTER_INFO); //10 * sizeof(IP_ADAPTER_INFO);  // Save the memory size of buffer
    unsigned int i = 3;
    do {
        pAdapterInfo = (PIP_ADAPTER_INFO) malloc(dwBufLen);
        dwStatus = GetAdaptersInfo(               // Call GetAdapterInfo
                pAdapterInfo, // [out] buffer to receive data
                &dwBufLen   // [in] size of receive data buffer
                );
        if (dwStatus != NO_ERROR) {
            free(pAdapterInfo);
            pAdapterInfo = NULL;
        }
    } while (dwStatus == ERROR_BUFFER_OVERFLOW && i-- > 0);
    if (dwStatus == ERROR_BUFFER_OVERFLOW) {
        return FUNC_RET_ERROR;
    }
    if (adapterInfos == NULL || *adapter_info_size == 0) {
        *adapter_info_size = dwBufLen / sizeof(IP_ADAPTER_INFO);
        if (pAdapterInfo != NULL){
            free(pAdapterInfo);
        }
        return FUNC_RET_OK;
    }
    *adapter_info_size = dwBufLen / sizeof(IP_ADAPTER_INFO);
    memset(adapterInfos, 0, dwBufLen);
    PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
    i = 0;
    FUNCTION_RETURN result = FUNC_RET_OK;
    while (pAdapter) {
        strncpy(adapterInfos[i].description, pAdapter->Description,
                min(sizeof(adapterInfos->description),
                        MAX_ADAPTER_DESCRIPTION_LENGTH));
        memcpy(adapterInfos[i].mac_address, pAdapter->Address, 8);
        translate(pAdapter->IpAddressList.IpAddress.String,
                adapterInfos[i].ipv4_address);
        adapterInfos[i].type = IFACE_TYPE_ETHERNET;
        i++;
        pAdapter = pAdapter->Next;
        if (i == *adapter_info_size) {
            result = FUNC_RET_BUFFER_TOO_SMALL;
            break;
        }
    }
    free(pAdapterInfo);
    return result;
}
FUNCTION_RETURN getModuleName(char buffer[MAX_PATH]) {
    FUNCTION_RETURN result = FUNC_RET_OK;
    const DWORD wres = GetModuleFileName(NULL, buffer, MAX_PATH);
    if (wres == 0) {
        result = FUNC_RET_ERROR;
    }
    return result;
}
// TODO: remove unused
static void printHash(HCRYPTHASH* hHash) {
    DWORD dwHashLen;
    DWORD dwHashLenSize = sizeof(DWORD);
    if (CryptGetHashParam(*hHash, HP_HASHSIZE, (BYTE *) &dwHashLen,
            &dwHashLenSize, 0)) {
        BYTE* pbHash = (BYTE*)malloc(dwHashLen);
        char* hashStr = (char*)malloc(dwHashLen * 2 + 1);
        if (CryptGetHashParam(*hHash, HP_HASHVAL, pbHash, &dwHashLen, 0)) {
            for (unsigned int i = 0; i < dwHashLen; i++) {
                sprintf(&hashStr[i * 2], "%02x", pbHash[i]);
            } LOG_DEBUG("Hash to verify: %s", hashStr);
        }
        free(pbHash);
        free(hashStr);
    }
}
/**
 * Not implemented yet.
 */
VIRTUALIZATION getVirtualization() {
    return NONE;
}
src/library/os/os.c
@@ -1,10 +1,9 @@
//#include <stdlib.h>
#include <stdio.h>
#include "../base/logger.h"
#include "os.h"
#include "../base/logger.h"
#include "public-key.h"
#include <stdio.h>
#ifndef _MSC_VER
#ifdef __linux__
#include <openssl/pem.h>
@@ -85,7 +84,7 @@
#else
#include <iphlpapi.h>
#include <Windows.h>
#include <windows.h>
#pragma comment(lib, "IPHLPAPI.lib")
unsigned char* unbase64(const char* ascii, int len, int *flen);
@@ -117,9 +116,9 @@
    // Declare variables.
    //
    // hProv:           Cryptographic service provider (CSP). This example
    //                  uses the Microsoft Enhanced Cryptographic
    //                  uses the Microsoft Enhanced Cryptographic
    //                  Provider.
    // hKey:            Key to be used. In this example, you import the
    // hKey:            Key to be used. In this example, you import the
    //                  key as a PLAINTEXTKEYBLOB.
    // dwBlobLen:       Length of the plaintext key.
    // pbKeyBlob:       Pointer to the exported key.
@@ -137,10 +136,10 @@
    if (!CryptAcquireContext(&hProv,
    NULL, MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
        // If the key container cannot be opened, try creating a new
        // container by specifying a container name and setting the
        // container by specifying a container name and setting the
        // CRYPT_NEWKEYSET flag.
        LOG_INFO("Error in AcquireContext 0x%08x \n", GetLastError());
        if (NTE_BAD_KEYSET == GetLastError()) {
        if (NTE_BAD_KEYSET == (long)GetLastError()) {
            if (!CryptAcquireContext(&hProv, "license++verify",
                    MS_ENHANCED_PROV, PROV_RSA_FULL,
                    CRYPT_NEWKEYSET | CRYPT_VERIFYCONTEXT)) {
@@ -154,7 +153,7 @@
    }
    // Use the CryptImportKey function to import the PLAINTEXTKEYBLOB
    // BYTE array into the key container. The function returns a
    // BYTE array into the key container. The function returns a
    // pointer to an HCRYPTKEY variable that contains the handle of
    // the imported key.
    if (!CryptImportKey(hProv, &pubKey[0], sizeof(pubKey), 0, 0, &hKey)) {
@@ -170,7 +169,7 @@
        return FUNC_RET_ERROR;
    }
    if (!CryptHashData(hHash, stringToVerify, (DWORD) strlen(stringToVerify), 0)) {
    if (!CryptHashData(hHash, (const BYTE*)stringToVerify, (DWORD) strlen(stringToVerify), 0)) {
        LOG_ERROR("Error in hashing data 0x%08x ", GetLastError());
        CryptDestroyHash(hHash);
        CryptReleaseContext(hProv, 0);
@@ -180,7 +179,7 @@
    LOG_DEBUG("Lenght %d, hashed Data: [%s]", strlen(stringToVerify), stringToVerify);
    printHash(&hHash);
#endif
    sigBlob = unbase64(signatureB64, (int) strlen(signatureB64), &dwSigLen);
    sigBlob = unbase64(signatureB64, (int) strlen(signatureB64), (int*)&dwSigLen);
    LOG_DEBUG("raw signature lenght %d", dwSigLen);
    if (!CryptVerifySignature(hHash, sigBlob, dwSigLen, hKey, NULL, 0)) {
        LOG_ERROR("Signature not validated!  0x%08x ", GetLastError());
src/library/pc-identifiers.c
@@ -388,9 +388,12 @@
    //found = false;
    for (i = 0; i < 2; i++) {
        current_strategy_id = strategy_from_pc_id(user_identifiers[i]);
        if (current_strategy_id == STRATEGY_UNKNOWN) {
        if (current_strategy_id == STRATEGY_UNKNOWN && previous_strategy_id == STRATEGY_UNKNOWN && i==1) {
            free(calculated_identifiers);
            printf("Comparing pc identifiers: %d %d %d %s\n",current_strategy_id,previous_strategy_id,i, str_code);
            return LICENSE_MALFORMED;
        } else if (current_strategy_id == STRATEGY_UNKNOWN ){
            continue;
        }
        if (current_strategy_id != previous_strategy_id) {
            if (calculated_identifiers != NULL) {
src/tools/base_lib/CMakeLists.txt
@@ -1,17 +1,17 @@
if(MSVC)
if(WIN32)
ADD_LIBRARY(
    tools_base STATIC
    CryptoHelper.cpp
    win/CryptoHelperWindows.cpp
)
else(MSVC)
else(WIN32)
ADD_LIBRARY(
    tools_base STATIC
    CryptoHelper.cpp
    linux/CryptoHelperLinux.cpp
)
ENDIF(MSVC)
ENDIF(WIN32)
target_link_libraries(
     tools_base
src/tools/base_lib/CryptoHelper.cpp
@@ -1,8 +1,8 @@
#include <memory>
#include "CryptoHelper.h"
#ifndef _MSC_VER
#ifdef __linux__
#include"linux/CryptoHelperLinux.h"
#else
#elif _WIN32
#include"win/CryptoHelperWindows.h"
#endif
@@ -10,11 +10,12 @@
namespace license {
unique_ptr<CryptoHelper> CryptoHelper::getInstance() {
#ifndef _MSC_VER
#ifdef __linux__
    unique_ptr<CryptoHelper> ptr((CryptoHelper*) new CryptoHelperLinux());
#else
    unique_ptr<CryptoHelper> ptr((CryptoHelper*) new CryptoHelperWindows());
#elif _WIN32
    unique_ptr<CryptoHelper> ptr((CryptoHelper*) new CryptoHelperWindows());
#endif
    return ptr;
}
}
src/tools/base_lib/win/CryptoHelperWindows.cpp
@@ -21,14 +21,14 @@
CryptoHelperWindows::CryptoHelperWindows() {
    m_hCryptProv = NULL;
    m_hCryptKey = NULL;
    if (!CryptAcquireContext(&m_hCryptProv, "license_sign", NULL, PROV_RSA_FULL, 0)) {
    if (!CryptAcquireContext(&m_hCryptProv, "license_sign", NULL , PROV_RSA_FULL, 0)) {
        // If the key container cannot be opened, try creating a new
        // container by specifying a container name and setting the
        // CRYPT_NEWKEYSET flag.
        DWORD lastError = GetLastError();
        printf("Error in CryptAcquireContext (1) 0x%08x \n", lastError);
        if (NTE_BAD_KEYSET == lastError) {
            if (!CryptAcquireContext(&m_hCryptProv, "license_sign", NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
            if (!CryptAcquireContext(&m_hCryptProv, "license_sign", NULL , PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
                printf("Warn in CryptAcquireContext: acquiring new user keyset failed 0x%08x, trying less secure mackine keyset \n", GetLastError());
                //maybe access to protected storage disabled. Try with machine keys (less secure)
                if (!CryptAcquireContext(&m_hCryptProv, "license_sign", NULL, PROV_RSA_FULL, CRYPT_MACHINE_KEYSET)) {
@@ -71,6 +71,13 @@
                string("Error generating keys ")
                        + to_string(static_cast<long long>(dwErrCode)));
    }
    //double check the key is really generated
    if(m_hCryptKey == NULL) {
        dwErrCode = GetLastError();
        throw logic_error(
                string("Error generating keys (2)")
                        + to_string(static_cast<long long>(dwErrCode)));
    }
}
/* This method calls the CryptExportKey function to get the Public key
src/tools/bootstrap/CMakeLists.txt
@@ -3,8 +3,7 @@
 bootstrap.cpp
)
SET_TARGET_PROPERTIES(bootstrap PROPERTIES LINK_SEARCH_START_STATIC ON)
#SET_TARGET_PROPERTIES(bootstrap PROPERTIES LINK_SEARCH_START_STATIC ON)
SET_TARGET_PROPERTIES(bootstrap PROPERTIES LINK_SEARCH_END_STATIC OFF)
target_link_libraries(
     bootstrap
@@ -12,22 +11,29 @@
     ${EXTERNAL_LIBS}
)
# add the command to generate the source code
if(MINGW)
add_custom_command (
  OUTPUT "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h"
  COMMAND ./bootstrap.exe "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h"
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  DEPENDS bootstrap)
    #Cross compiling from linux host to windows
    IF( ( CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") AND CMAKE_CROSSCOMPILING)
        #this is to avoid to install binfmt_misc (for builds in docker, or LXC)
        add_custom_command (
          OUTPUT "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h"
          COMMAND wine ${CMAKE_CURRENT_BINARY_DIR}/bootstrap.exe "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h"
          WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
          DEPENDS bootstrap)
    ELSE()
        add_custom_command (
          OUTPUT "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h"
          COMMAND ./bootstrap.exe "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h"
          WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
          DEPENDS bootstrap)
    ENDIF()
else(MINGW)
add_custom_command (
  OUTPUT "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h"
  COMMAND bootstrap "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h"
  WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
  DEPENDS bootstrap)
    add_custom_command (
      OUTPUT "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h"
      COMMAND bootstrap "${CMAKE_BINARY_DIR}/private-key.h" "${CMAKE_BINARY_DIR}/public-key.h"
      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
      DEPENDS bootstrap)
endif(MINGW)
add_custom_target(private_key DEPENDS "${CMAKE_BINARY_DIR}/private-key.h")
add_custom_target(public_key DEPENDS "${CMAKE_BINARY_DIR}/public-key.h")
src/tools/license-generator/CMakeLists.txt
@@ -1,8 +1,6 @@
include_directories(${Boost_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
link_directories ( ${Boost_LIBRARY_DIR} )
ADD_LIBRARY(
    license_generator_lib STATIC
@@ -12,7 +10,7 @@
target_link_libraries(
     license_generator_lib
     tools_base
     license++_static
     licensepp_static
     $<$<CONFIG:Debug>:${Boost_PROGRAM_OPTIONS_LIBRARY_DEBUG}>
     $<$<NOT:$<CONFIG:Debug>>:${Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE}>     
     $<$<CONFIG:Debug>:${Boost_SYSTEM_LIBRARY_DEBUG}>
@@ -33,5 +31,3 @@
install(TARGETS license_generator RUNTIME DESTINATION bin)
#SET_TARGET_PROPERTIES(license_generator PROPERTIES LINK_SEARCH_START_STATIC ON)
#SET_TARGET_PROPERTIES(license_generator PROPERTIES LINK_SEARCH_END_STATIC ON)
src/tools/license-generator/license-generator.cpp
@@ -146,7 +146,7 @@
        ostream& outputFile) {
    vector<FullLicenseInfo> licenseInfo = parseLicenseInfo(vm);
    const unique_ptr<CryptoHelper> helper = CryptoHelper::getInstance();
    const char pkey[] = PRIVATE_KEY;
    const unsigned char pkey[] = PRIVATE_KEY;
    const size_t len = sizeof(pkey);
    for (auto it = licenseInfo.begin(); it != licenseInfo.end(); ++it) {
        const string license = it->printForSign();
test/functional/CMakeLists.txt
@@ -14,12 +14,10 @@
target_link_libraries(
 standard_license_test
 license++_static
 licensepp_static
 license_generator_snippet
 ${Boost_LIBRARIES}
)
#SET_TARGET_PROPERTIES(standard_license_test PROPERTIES LINK_SEARCH_START_STATIC ON)
#add_dependencies( standard_license_test boost_test boost_filesystem )
add_executable(
 date_test
@@ -28,12 +26,10 @@
target_link_libraries(
 date_test
 license++_static
 licensepp_static
 license_generator_snippet
 ${Boost_LIBRARIES}
)
#SET_TARGET_PROPERTIES(date_test PROPERTIES LINK_SEARCH_START_STATIC ON)
#add_dependencies( date_test boost_test boost_filesystem )
add_executable(
 volid_test
@@ -42,15 +38,21 @@
target_link_libraries(
 volid_test
 license++_static
 licensepp_static
 license_generator_snippet
 ${Boost_LIBRARIES}
)
#SET_TARGET_PROPERTIES(volid_test PROPERTIES LINK_SEARCH_START_STATIC ON)
#add_dependencies( volid_test boost_test boost_filesystem )
ADD_TEST(NAME standard_license_test COMMAND standard_license_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
ADD_TEST(NAME date_test COMMAND date_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
ADD_TEST(NAME volid_test COMMAND volid_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
IF( ( CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") AND CMAKE_CROSSCOMPILING)
#binfmt_misc doesn't work in my system :(
    ADD_TEST(NAME standard_license_test COMMAND wine ${CMAKE_CURRENT_BINARY_DIR}/standard_license_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
    ADD_TEST(NAME date_test COMMAND wine ${CMAKE_CURRENT_BINARY_DIR}/date_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
    ADD_TEST(NAME volid_test COMMAND wine ${CMAKE_CURRENT_BINARY_DIR}/volid_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
ELSE()
    ADD_TEST(NAME standard_license_test COMMAND standard_license_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
    ADD_TEST(NAME date_test COMMAND date_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
    ADD_TEST(NAME volid_test COMMAND volid_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
ENDIF()
test/functional/volid_test.cpp
@@ -52,11 +52,11 @@
    for (int i = 0; i < num_strategies; i++) {
        FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out,
                strategies[i]);
        BOOST_ASSERT(generate_ok == FUNC_RET_OK);
        if (generate_ok != FUNC_RET_OK) {
            BOOST_ERROR(
                    "Generating identifier for strategy " << strategies[i] << " failed with: " << generate_ok);
            idfile << "0000-0000-0000-0000" << endl;
            BOOST_ASSERT(generate_ok == FUNC_RET_OK);
        } else
            idfile << identifier_out << endl;
    }
@@ -66,12 +66,26 @@
BOOST_AUTO_TEST_CASE(generated_identifiers_stability) {
    const string idfileLocation(PROJECT_TEST_TEMP_DIR "/identifiers_file");
    std::vector<IDENTIFICATION_STRATEGY> strategies;
    if (getVirtualization() != CONTAINER) {
        strategies = { DEFAULT, DISK_LABEL, DISK_NUM, ETHERNET };
    size_t disk_num;
    getDiskInfos(NULL, &disk_num);
    if (disk_num >0) {
        strategies = { DEFAULT, DISK_NUM, DISK_LABEL };
    } else {
        strategies = { DEFAULT, ETHERNET };
        BOOST_TEST_CHECKPOINT("if no disk default strategy fails see #49");
        //strategies = { DEFAULT };
        strategies = {};
    }
    size_t adapters;
    getAdapterInfos(nullptr, &adapters);
    if(adapters > 0){
        strategies.push_back(ETHERNET);
    }
    int num_strategies = strategies.size();
    if(num_strategies == 0) {
        //see issue #49 can't use default
        return;
    }
    std::ifstream test_idfile_exist(idfileLocation);
    if (!test_idfile_exist.good()) {
        generate_reference_file(idfileLocation, strategies.data(),
test/library/CMakeLists.txt
@@ -2,17 +2,19 @@
 license_reader_test
 LicenseReader_test.cpp
)
#add_dependencies( license_reader_test boost_filesystem )
target_link_libraries(
 license_reader_test
 license++_static
 licensepp_static
 ${Boost_LIBRARIES}
)
#SET_TARGET_PROPERTIES(license_reader_test PROPERTIES LINK_SEARCH_START_STATIC ON)
#SET_TARGET_PROPERTIES(license_reader_test PROPERTIES LINK_SEARCH_END_STATIC OFF)
ADD_TEST(NAME license_reader_test COMMAND license_reader_test)
IF( ( CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") AND CMAKE_CROSSCOMPILING)
#binfmt_misc doesn't work in my system :(
    ADD_TEST(NAME license_reader_test COMMAND wine ${CMAKE_CURRENT_BINARY_DIR}/license_reader_test)
ELSE()
    ADD_TEST(NAME license_reader_test COMMAND license_reader_test)
ENDIF()
IF(WIN32)
#test windows
@@ -27,9 +29,6 @@
         os
         ${Boost_LIBRARIES}
    )
    #add_dependencies( os_linux_test )
    #SET_TARGET_PROPERTIES(os_linux_test PROPERTIES LINK_SEARCH_START_STATIC ON)
    ADD_TEST(NAME os_linux_test COMMAND os_linux_test)
ENDIF(WIN32)
test/license-generator/CMakeLists.txt
@@ -10,6 +10,8 @@
 ${Boost_LIBRARIES}
)
#add_dependencies( license_generator_test boost_test boost_filesystem )
#SET_TARGET_PROPERTIES(license_generator_test PROPERTIES LINK_SEARCH_START_STATIC ON)
ADD_TEST(NAME license_generator_test COMMAND license_generator_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
IF( ( CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") AND CMAKE_CROSSCOMPILING)
    ADD_TEST(NAME license_generator_test COMMAND wine ${CMAKE_CURRENT_BINARY_DIR}/license_generator_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
ELSE()
    ADD_TEST(NAME license_generator_test COMMAND license_generator_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
ENDIF()