.cproject | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
.settings/language.settings.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
README.md | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
build/modules/FindDbus.cmake | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/os/linux/os-linux.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/os/os.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/library/pc-identifiers.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/functional/CMakeLists.txt | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/functional/volid_test.cpp | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
.cproject
@@ -5,43 +5,41 @@ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.1941555127" moduleId="org.eclipse.cdt.core.settings" name="Default"> <externalSettings/> <extensions> <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> <extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/> <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> <extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/> </extensions> </storageModule> <storageModule moduleId="cdtBuildSystem" version="4.0.0"> <configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.1941555127" name="Default" parent="org.eclipse.cdt.build.core.emptycfg"> <configuration artifactName="${ProjName}" buildProperties="" description="" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GLDErrorParser" id="cdt.managedbuild.toolchain.gnu.base.1941555127" name="Default" parent="org.eclipse.cdt.build.core.emptycfg"> <folderInfo id="cdt.managedbuild.toolchain.gnu.base.1941555127.38772218" name="/" resourcePath=""> <toolChain id="cdt.managedbuild.toolchain.gnu.base.1610910832" name="cdt.managedbuild.toolchain.gnu.base" superClass="cdt.managedbuild.toolchain.gnu.base"> <toolChain errorParsers="" id="cdt.managedbuild.toolchain.gnu.base.1610910832" name="cdt.managedbuild.toolchain.gnu.base" nonInternalBuilderId="cdt.managedbuild.target.gnu.builder.base" superClass="cdt.managedbuild.toolchain.gnu.base"> <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF;org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.base.333980180" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/> <builder autoBuildTarget="" buildPath="${workspace_loc:/license-manager-cpp}/build/linux" enableAutoBuild="true" id="cdt.managedbuild.target.gnu.builder.base.516265988" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.base"> <outputEntries> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name=""/> </outputEntries> </builder> <builder buildPath="${workspace_loc:/license-manager-cpp/build/linux}" enableAutoBuild="true" enabledIncrementalBuild="true" id="cdt.managedbuild.target.gnu.builder.base.834186429" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.base"/> <tool id="cdt.managedbuild.tool.gnu.archiver.base.1063978701" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/> <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1465609732" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base"> <tool errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1465609732" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base"> <option id="gnu.cpp.compiler.option.preprocessor.def.1664583179" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols"> <listOptionValue builtIn="false" value="__GXX_EXPERIMENTAL_CXX0X__"/> </option> <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.18539696" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> </tool> <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.589770174" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base"> <tool errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.tool.gnu.c.compiler.base.589770174" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base"> <option id="gnu.c.compiler.option.include.paths.1362295159" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <listOptionValue builtIn="false" value="/usr/include/dbus-1.0"/> </option> <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1441923396" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> </tool> <tool id="cdt.managedbuild.tool.gnu.c.linker.base.1466986479" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/> <tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.233385682" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base"> <tool errorParsers="org.eclipse.cdt.core.GLDErrorParser" id="cdt.managedbuild.tool.gnu.cpp.linker.base.233385682" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base"> <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1900932213" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input"> <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> <additionalInput kind="additionalinput" paths="$(LIBS)"/> </inputType> </tool> <tool id="cdt.managedbuild.tool.gnu.assembler.base.1674253564" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base"> <tool errorParsers="" id="cdt.managedbuild.tool.gnu.assembler.base.1674253564" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base"> <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1912634158" superClass="cdt.managedbuild.tool.gnu.assembler.input"/> </tool> </toolChain> @@ -73,10 +71,21 @@ <resource resourceType="FOLDER" workspacePath="/license-manager-cpp/build/linux"/> </configuration> </storageModule> <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/> <storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"> <doc-comment-owner id="org.eclipse.cdt.ui.doxygen"> <path value=""/> </doc-comment-owner> </storageModule> <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"> <buildTargets> <target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <buildCommand>make</buildCommand> <buildArguments>-j4</buildArguments> <buildTarget>all</buildTarget> <stopOnError>true</stopOnError> <useDefaultCommand>true</useDefaultCommand> <runAllBuilders>true</runAllBuilders> </target> </buildTargets> </storageModule> </cproject> .settings/language.settings.xml
@@ -2,13 +2,12 @@ <project> <configuration id="cdt.managedbuild.toolchain.gnu.base.1941555127" name="Default"> <extension point="org.eclipse.cdt.core.LanguageSettingsProvider"> <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/> <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="true" env-hash="-1162336436791480065" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD --std=c++11 "${INPUTS}""> <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true" store-entries-with-project="true"/> <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="true" env-hash="-1161885277975224065" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD --std=c++11 "${INPUTS}"" store-entries-with-project="false"> <language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.g++"/> </provider> <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(gcc)|([gc]\+\+)|(clang)" prefer-non-shared="true" resource-scope="per-folder"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> </extension> </configuration> CMakeLists.txt
@@ -16,6 +16,8 @@ SET(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "CMake verbose" FORCE) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build/modules/") if(WIN32) SET(PLATFORM_LIBS "") if(CMAKE_CL_64) @@ -43,12 +45,9 @@ endif(CMAKE_SIZEOF_VOID_P EQUAL 8) set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS_DEBUG _DEBUG) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build/modules/") #find_package(CryptoPP REQUIRED) #include_directories(${CRYPTOPP_INCLUDE_DIRS}) #link_directories ( ${Boost_LIBRARY_DIRS} ) SET(Boost_USE_STATIC_LIBS ON) @@ -63,6 +62,13 @@ find_package(OpenSSL REQUIRED) include_directories(${OPENSSL_INCLUDE_DIR}) list(APPEND EXTERNAL_LIBS ${OPENSSL_CRYPTO_LIBRARY}) if(NOT WIN32) FIND_PACKAGE(Dbus REQUIRED) include_directories(${DBUS_INCLUDE_DIR}) include_directories(${DBUS_ARCH_INCLUDE_DIR}) list(APPEND EXTERNAL_LIBS ${DBUS_LIBRARIES}) endif(NOT WIN32) FIND_PACKAGE(Doxygen) @@ -100,7 +106,6 @@ #include build directory to find build_properties.h include_directories(${CMAKE_BINARY_DIR}) add_subdirectory(src) #test are done with boost_tests:disable them if boost not found. @@ -115,8 +120,6 @@ ENDIF(Boost_FOUND) #include(build/modules/CmakeDebugVariables.txt) message("") message( STATUS "C compiler: " ${CMAKE_C_COMPILER}) README.md
@@ -6,9 +6,10 @@ Linux =================== apt-get install libcrypto++dev (version 5.6.1) apt-get install libboost-dev libboost-filesystem-dev libboost-program-options-dev libboost-test-dev libboost-date-time-dev libssl-dev? libdbus-1-dev #libcrypto++dev (version 5.6.1) openssl genrsa -out src/license-generator/privkey.pem 2048 build/modules/FindDbus.cmake
New file @@ -0,0 +1,72 @@ # - Try to find the low-level D-Bus library # Once done this will define # # DBUS_FOUND - system has D-Bus # DBUS_INCLUDE_DIR - the D-Bus include directory # DBUS_ARCH_INCLUDE_DIR - the D-Bus architecture-specific include directory # DBUS_LIBRARIES - the libraries needed to use D-Bus # Copyright (c) 2008, Kevin Kofler, <kevin.kofler@chello.at> # modeled after FindLibArt.cmake: # Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org> # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. if (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) # in cache already SET(DBUS_FOUND TRUE) else (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) IF (NOT WIN32) FIND_PACKAGE(PkgConfig) IF (PKG_CONFIG_FOUND) # use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls pkg_check_modules(_DBUS_PC QUIET dbus-1) ENDIF (PKG_CONFIG_FOUND) ENDIF (NOT WIN32) FIND_PATH(DBUS_INCLUDE_DIR dbus/dbus.h ${_DBUS_PC_INCLUDE_DIRS} /usr/include /usr/include/dbus-1.0 /usr/local/include ) FIND_PATH(DBUS_ARCH_INCLUDE_DIR dbus/dbus-arch-deps.h ${_DBUS_PC_INCLUDE_DIRS} /usr/lib${LIB_SUFFIX}/include /usr/lib${LIB_SUFFIX}/dbus-1.0/include /usr/lib64/include /usr/lib64/dbus-1.0/include /usr/lib/include /usr/lib/dbus-1.0/include ) FIND_LIBRARY(DBUS_LIBRARIES NAMES dbus-1 dbus PATHS ${_DBUS_PC_LIBDIR} ) if (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) set(DBUS_FOUND TRUE) endif (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) if (DBUS_FOUND) if (NOT DBus_FIND_QUIETLY) message(STATUS "Found D-Bus: ${DBUS_LIBRARIES}") endif (NOT DBus_FIND_QUIETLY) else (DBUS_FOUND) if (DBus_FIND_REQUIRED) message(FATAL_ERROR "Could NOT find D-Bus") endif (DBus_FIND_REQUIRED) endif (DBUS_FOUND) MARK_AS_ADVANCED(DBUS_INCLUDE_DIR DBUS_ARCH_INCLUDE_DIR DBUS_LIBRARIES) endif (DBUS_INCLUDE_DIR AND DBUS_ARCH_INCLUDE_DIR AND DBUS_LIBRARIES) src/CMakeLists.txt
@@ -1,4 +1,3 @@ add_subdirectory("bootstrap") add_subdirectory("library") src/library/os/linux/os-linux.c
@@ -58,6 +58,11 @@ perror("getifaddrs"); return ERROR; } if (adapterInfos != NULL) { memset(adapterInfos, 0, (*adapter_info_size) * sizeof(AdapterInfo)); } /* count the maximum number of interfaces */ for (ifa = ifaddr, if_max = 0; ifa != NULL; ifa = ifa->ifa_next, n++) { if (ifa->ifa_addr == NULL) { @@ -111,8 +116,8 @@ */ #ifdef _DEBUG s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); NI_MAXHOST, NULL, 0, NI_NUMERICHOST); if (s != 0) { printf("getnameinfo() failed: %s\n", gai_strerror(s)); } @@ -190,7 +195,7 @@ hexuuid[j++] = '0'; } hexuuid[j] = '\0'; for (i = 0; i < j/2; i++) { for (i = 0; i < j / 2; i++) { sscanf(&hexuuid[i * 2], "%2hhx", &cur_character); buffer_out[i % out_size] = buffer_out[i % out_size] ^ cur_character; } @@ -204,7 +209,7 @@ /*static char discard[1024]; char device[64], name[64], type[64]; */ char path[MAX_PATH], cur_dir[MAX_PATH]; char cur_dir[MAX_PATH]; struct mntent *ent; int maxDrives, currentDrive, i, drive_found; @@ -224,20 +229,12 @@ } memset(tmpDrives, 0, sizeof(DiskInfo) * maxDrives); statDrives = (__ino64_t *) malloc(maxDrives * sizeof(__ino64_t )); memset(statDrives, 0, sizeof(__ino64_t ) * maxDrives);; memset(statDrives, 0, sizeof(__ino64_t ) * maxDrives); ; aFile = setmntent("/proc/mounts", "r"); if (aFile == NULL) { /*proc not mounted*/ return ERROR; } disk_by_uuid_dir = opendir("/dev/disk/by-uuid"); if (disk_by_uuid_dir == NULL) { #ifdef _DEBUG printf("Open /dev/disk/by-uuid fail"); #endif free(statDrives); return ERROR; } @@ -276,16 +273,25 @@ } } endmntent(aFile); if (diskInfos == NULL) { *disk_info_size = currentDrive; free(tmpDrives); result = OK; } else if (*disk_info_size >= currentDrive) { disk_by_uuid_dir = opendir("/dev/disk/by-uuid"); if (disk_by_uuid_dir == NULL) { #ifdef _DEBUG printf("Open /dev/disk/by-uuid fail"); #endif free(statDrives); return ERROR; } result = OK; *disk_info_size = currentDrive; while ((dir = readdir(disk_by_uuid_dir)) != NULL) { strcpy(cur_dir, "/dev/disk/by-uuid/"); strcat(cur_dir, dir->d_name); strncat(cur_dir, dir->d_name, 200); if (stat(cur_dir, &sym_stat) == 0) { for (i = 0; i < currentDrive; i++) { if (sym_stat.st_ino == statDrives[i]) { src/library/os/os.h
@@ -39,6 +39,25 @@ size_t * adapter_info_size); FUNCTION_RETURN getDiskInfos(DiskInfo * diskInfos, size_t * disk_info_size); FUNCTION_RETURN getUserHomePath(char[MAX_PATH]); /** * Get an identifier of the machine in an os specific way. * In Linux it uses: * http://stackoverflow.com/questions/328936/getting-a-unique-id-from-a-unix-like-system * * <ul> * <li>Dbus if available</li> * </ul> * Can be used as a fallback in case no other methods are available. * Windows: * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\ CurrentVersion\ProductId * http://sowkot.blogspot.it/2008/08/generating-unique-keyfinger-print-for.html * http://stackoverflow.com/questions/2842116/reliable-way-of-generating-unique-hardware-id * * * @param identifier * @return */ FUNCTION_RETURN getOsSpecificIdentifier(unsigned char identifier[6]); VIRTUALIZATION getVirtualization(); void os_initialize(); src/library/pc-identifiers.c
@@ -11,6 +11,7 @@ #include <string.h> #include <stdbool.h> #include "base/base64.h" #include <valgrind/memcheck.h> static FUNCTION_RETURN generate_default_pc_id(PcIdentifier * identifiers, unsigned int * num_identifiers) { @@ -98,33 +99,50 @@ static FUNCTION_RETURN generate_disk_pc_id(PcIdentifier * identifiers, unsigned int * num_identifiers, bool use_label) { size_t disk_num; size_t disk_num, available_disk_info=0; FUNCTION_RETURN result_diskinfos; unsigned int i, k; unsigned int i, k, j; char firstChar; DiskInfo * diskInfos; result_diskinfos = getDiskInfos(NULL, &disk_num); if (result_diskinfos != OK) { return result_diskinfos; } diskInfos = (DiskInfo*) malloc(disk_num * sizeof(DiskInfo)); //memset(diskInfos,0,disk_num * sizeof(DiskInfo)); result_diskinfos = getDiskInfos(diskInfos, &disk_num); if (result_diskinfos != OK) { free(diskInfos); return result_diskinfos; } for (i = 0; i < disk_num; i++) { firstChar = use_label ? diskInfos[i].label[0] : diskInfos[i].disk_sn[0]; available_disk_info += firstChar == 0 ? 0 : 1; } int defined_identifiers = *num_identifiers; *num_identifiers = disk_num; *num_identifiers = available_disk_info; if (identifiers == NULL) { free(diskInfos); return OK; } else if (disk_num > defined_identifiers) { } else if (available_disk_info > defined_identifiers) { free(diskInfos); return BUFFER_TOO_SMALL; } diskInfos = (DiskInfo*) malloc(disk_num * sizeof(DiskInfo)); result_diskinfos = getDiskInfos(diskInfos, &disk_num); j=0; for (i = 0; i < disk_num; i++) { for (k = 0; k < 6; k++) { if (use_label) { identifiers[i][k] = diskInfos[i].label[k]; } else { identifiers[i][k] = diskInfos[i].disk_sn[k + 2]; if(use_label){ if(diskInfos[i].label[0]!=0){ memset(identifiers[j],0,sizeof(PcIdentifier)); //!!!!!!! strncpy(identifiers[j],diskInfos[i].label,sizeof(PcIdentifier)); j++; } }else{ if(diskInfos[i].disk_sn[0]!=0){ memcpy(identifiers[j],&diskInfos[i].disk_sn[2],sizeof(PcIdentifier)); j++; } } } @@ -181,7 +199,7 @@ } //fill array if larger for (i = *array_size; i < original_array_size; i++) { identifiers[i][0] = STRATEGY_UNKNOWN; identifiers[i][0] = STRATEGY_UNKNOWN << 5; for (j = 1; j < sizeof(PcIdentifier); j++) { identifiers[i][j] = 42; //padding } @@ -215,11 +233,11 @@ FUNCTION_RETURN encode_pc_id(PcIdentifier identifier1, PcIdentifier identifier2, PcSignature pc_identifier_out) { //TODO base62 encoding, now uses base64 //TODO base62 encoding, now uses base64 PcIdentifier concat_identifiers[2]; int b64_size = 0; size_t concatIdentifiersSize = sizeof(PcIdentifier) * 2; //concat_identifiers = (PcIdentifier *) malloc(concatIdentifiersSize); //concat_identifiers = (PcIdentifier *) malloc(concatIdentifiersSize); memcpy(&concat_identifiers[0], identifier1, sizeof(PcIdentifier)); memcpy(&concat_identifiers[1], identifier2, sizeof(PcIdentifier)); char* b64_data = base64(concat_identifiers, concatIdentifiersSize, @@ -229,7 +247,7 @@ } sprintf(pc_identifier_out, "%.4s-%.4s-%.4s-%.4s", &b64_data[0], &b64_data[4], &b64_data[8], &b64_data[12]); //free(concat_identifiers); //free(concat_identifiers); free(b64_data); return OK; } @@ -258,7 +276,10 @@ free(identifiers); return result; } VALGRIND_CHECK_VALUE_IS_DEFINED(identifiers[0]); VALGRIND_CHECK_VALUE_IS_DEFINED(identifiers[1]); result = encode_pc_id(identifiers[0], identifiers[1], identifier_out); VALGRIND_CHECK_VALUE_IS_DEFINED(identifier_out); free(identifiers); return result; } @@ -272,7 +293,7 @@ */ static FUNCTION_RETURN decode_pc_id(PcIdentifier identifier1_out, PcIdentifier identifier2_out, PcSignature pc_signature_in) { //TODO base62 encoding, now uses base64 //TODO base62 encoding, now uses base64 unsigned char * concat_identifiers; char base64ids[17]; @@ -302,7 +323,7 @@ PcIdentifier* calculated_identifiers = NULL; unsigned int calc_identifiers_size = 0; int i = 0, j = 0; //bool found; //bool found; #ifdef _DEBUG printf("Comparing pc identifiers: \n"); #endif @@ -311,7 +332,7 @@ return result; } previous_strategy_id = STRATEGY_UNKNOWN; //found = false; //found = false; for (i = 0; i < 2; i++) { current_strategy_id = strategy_from_pc_id(user_identifiers[i]); if (current_strategy_id == STRATEGY_UNKNOWN) { test/functional/CMakeLists.txt
@@ -43,4 +43,4 @@ ADD_TEST(standard_license_test ${EXECUTABLE_OUTPUT_PATH}/standard_license_test) ADD_TEST(date_test ${EXECUTABLE_OUTPUT_PATH}/date_test) ADD_TEST(date_test ${EXECUTABLE_OUTPUT_PATH}/volid_test) ADD_TEST(volid_test ${EXECUTABLE_OUTPUT_PATH}/volid_test) test/functional/volid_test.cpp
@@ -11,89 +11,95 @@ #include "../../src/library/ini/SimpleIni.h" #include "generate-license.h" #include "../../src/library/pc-identifiers.h" #include <dbus/dbus.h> namespace fs = boost::filesystem; using namespace license; using namespace std; /* BOOST_AUTO_TEST_CASE( default_volid_lic_file ) { const string licLocation(PROJECT_TEST_TEMP_DIR "/volid_license.lic"); PcSignature identifier_out; BOOST_AUTO_TEST_CASE( default_volid_lic_file ) { const string licLocation(PROJECT_TEST_TEMP_DIR "/volid_license.lic"); PcSignature identifier_out; IDENTIFICATION_STRATEGY strategy = IDENTIFICATION_STRATEGY::ETHERNET; FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out, strategy); BOOST_ASSERT(generate_ok == FUNCTION_RETURN::OK); cout << "Identifier:" << identifier_out << endl; vector<string> extraArgs = { "-s", identifier_out }; generate_license(licLocation, extraArgs); IDENTIFICATION_STRATEGY strategy = IDENTIFICATION_STRATEGY::ETHERNET; FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out, strategy); BOOST_ASSERT(generate_ok == FUNCTION_RETURN::OK); cout << "Identifier:" << identifier_out << endl; vector<string> extraArgs = { "-s", identifier_out }; generate_license(licLocation, extraArgs); LicenseInfo license; LicenseLocation licenseLocation; licenseLocation.openFileNearModule = false; licenseLocation.licenseFileLocation = licLocation.c_str(); licenseLocation.environmentVariableName = ""; EVENT_TYPE result = acquire_license("TEST", licenseLocation, &license); BOOST_CHECK_EQUAL(result, LICENSE_OK); BOOST_CHECK_EQUAL(license.has_expiry, false); BOOST_CHECK_EQUAL(license.linked_to_pc, true); } LicenseInfo license; LicenseLocation licenseLocation; licenseLocation.openFileNearModule = false; licenseLocation.licenseFileLocation = licLocation.c_str(); licenseLocation.environmentVariableName = ""; EVENT_TYPE result = acquire_license("TEST", licenseLocation, &license); BOOST_CHECK_EQUAL(result, LICENSE_OK); BOOST_CHECK_EQUAL(license.has_expiry, false); BOOST_CHECK_EQUAL(license.linked_to_pc, true); } static void generate_reference_file(const string& idfileLocation, IDENTIFICATION_STRATEGY strategies[], int num_strategies) { ofstream idfile(idfileLocation); PcSignature identifier_out; for (int i = 0; i < num_strategies; i++) { FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out, strategies[i]); BOOST_ASSERT(generate_ok == FUNCTION_RETURN::OK); idfile << identifier_out << endl; } idfile.close(); } static void generate_reference_file(const string& idfileLocation, IDENTIFICATION_STRATEGY strategies[], int num_strategies) { ofstream idfile(idfileLocation); PcSignature identifier_out; for (int i = 0; i < num_strategies; i++) { FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out, strategies[i]); BOOST_ASSERT(generate_ok == FUNCTION_RETURN::OK); idfile << identifier_out << endl; } idfile.close(); } BOOST_AUTO_TEST_CASE(generated_identifiers_stability) { const string idfileLocation(PROJECT_TEST_TEMP_DIR "/identifiers_file"); IDENTIFICATION_STRATEGY strategies[] = { IDENTIFICATION_STRATEGY::DEFAULT, IDENTIFICATION_STRATEGY::DISK_LABEL, IDENTIFICATION_STRATEGY::DISK_NUM, IDENTIFICATION_STRATEGY::ETHERNET }; const int num_strategies = sizeof(strategies) / sizeof(strategies[0]); std::ifstream test_idfile_exist(idfileLocation); if (!test_idfile_exist.good()) { generate_reference_file(idfileLocation, strategies, num_strategies); } std::ifstream is(idfileLocation); std::istream_iterator<string> start(is), end; std::vector<string> reference_signatures(start, end); BOOST_ASSERT(reference_signatures.size() == num_strategies); PcSignature generated_identifier; BOOST_CHECKPOINT("Generating current signatures and comparing with past"); for (int i = 0; i < num_strategies; i++) { FUNCTION_RETURN generate_ok = generate_user_pc_signature( generated_identifier, strategies[i]); BOOST_ASSERT(generate_ok == FUNCTION_RETURN::OK); if (reference_signatures[i] != generated_identifier) { string message = string("pc signature compare fail: strategy:") + to_string(strategies[i]) + " generated: [" + generated_identifier + "] reference: [" + reference_signatures[i] + "]"; BOOST_FAIL(message); } } BOOST_AUTO_TEST_CASE(generated_identifiers_stability) { const string idfileLocation(PROJECT_TEST_TEMP_DIR "/identifiers_file"); IDENTIFICATION_STRATEGY strategies[] = { IDENTIFICATION_STRATEGY::DEFAULT, IDENTIFICATION_STRATEGY::DISK_LABEL, IDENTIFICATION_STRATEGY::DISK_NUM, IDENTIFICATION_STRATEGY::ETHERNET }; const int num_strategies = sizeof(strategies) / sizeof(strategies[0]); std::ifstream test_idfile_exist(idfileLocation); if (!test_idfile_exist.good()) { generate_reference_file(idfileLocation, strategies, num_strategies); } std::ifstream is(idfileLocation); std::istream_iterator<string> start(is), end; std::vector<string> reference_signatures(start, end); BOOST_ASSERT(reference_signatures.size() == num_strategies); PcSignature generated_identifier; BOOST_CHECKPOINT("Generating current signatures and comparing with past"); for (int i = 0; i < num_strategies; i++) { FUNCTION_RETURN generate_ok = generate_user_pc_signature( generated_identifier, strategies[i]); BOOST_ASSERT(generate_ok == FUNCTION_RETURN::OK); if (reference_signatures[i] != generated_identifier) { string message = string("pc signature compare fail: strategy:") + to_string(strategies[i]) + " generated: [" + generated_identifier + "] reference: [" + reference_signatures[i] + "]"; BOOST_FAIL(message); } } BOOST_CHECKPOINT("Verifying signatures"); for (int j = 0; j < 100; j++) { for (unsigned int i = 0; i < reference_signatures.size(); i++) { PcSignature pcsig; strncpy(pcsig, reference_signatures[i].c_str(), sizeof(PcSignature)); EVENT_TYPE val_result = validate_pc_signature(pcsig); string message = string("pc signature verification strategy:") + to_string(i) + " generated: [" + generated_identifier + "] reference: [" + reference_signatures[i] + "]"; BOOST_CHECKPOINT("Verifying signature: "); BOOST_CHECK_EQUAL(val_result, LICENSE_OK); } } BOOST_CHECKPOINT("Verifying signatures"); for (int j = 0; j < 100; j++) { for (unsigned int i = 0; i < reference_signatures.size(); i++) { PcSignature pcsig; strncpy(pcsig, reference_signatures[i].c_str(), sizeof(PcSignature)); EVENT_TYPE val_result = validate_pc_signature(pcsig); string message = string("pc signature verification strategy:") + to_string(i) + " generated: [" + generated_identifier + "] reference: [" + reference_signatures[i] + "]"; BOOST_CHECKPOINT("Verifying signature: "); BOOST_CHECK_EQUAL(val_result, LICENSE_OK); } } } */ BOOST_AUTO_TEST_CASE( ciiii ) { cout << dbus_get_local_machine_id() << endl; }