From a662424e2b7a9b3042dcdd66c15dccea14241aa1 Mon Sep 17 00:00:00 2001 From: Andreas Stallinger Date: Tue, 29 Mar 2016 15:37:58 +0200 Subject: [PATCH] logic: Test License Test license for x days License_generator flag -e --- .gitignore | 1 + bin/test/data/log/test_log.txt | 287 +++++++----------- script/build.sh | 23 +- src/app/CMakeLists.txt | 17 ++ src/app/LicenseChecker.h | 4 + .../utility/commandline/CommandLineParser.cpp | 4 +- .../utility/commandline/CommandLineParser.h | 6 +- .../utility/headerSearch/ClangDetector.cpp | 0 src/app/utility/headerSearch/ClangDetector.h | 7 + .../headerSearch/CompilerDetectorBase.cpp | 23 ++ .../headerSearch/CompilerDetectorBase.h | 13 + src/app/utility/headerSearch/DetectorBase.cpp | 23 ++ src/app/utility/headerSearch/DetectorBase.h | 28 ++ src/app/utility/headerSearch/DetectorProxy.h | 13 + src/app/utility/headerSearch/GCCDetector.cpp | 16 + src/app/utility/headerSearch/GCCDetector.h | 15 + .../headerSearch/StandardHeaderDetection.cpp | 121 ++++++++ .../headerSearch/StandardHeaderDetection.h | 56 ++++ .../headerSearch/VisualStudioDetector.cpp | 38 +++ .../headerSearch/VisualStudioDetector.h | 16 + src/app/utility/utilityApp.cpp | 15 + src/app/utility/utilityApp.h | 13 + src/lib/utility/utilityString.cpp | 12 + src/lib/utility/utilityString.h | 2 + src/lib_gui/qt/window/QtLicense.cpp | 7 +- src/lib_license/Generator.cpp | 25 +- src/lib_license/Generator.h | 15 +- src/lib_license/License.cpp | 83 +++-- src/lib_license/License.h | 27 +- src/license_generator/main.cpp | 32 +- 30 files changed, 695 insertions(+), 247 deletions(-) create mode 100644 src/app/utility/headerSearch/ClangDetector.cpp create mode 100644 src/app/utility/headerSearch/ClangDetector.h create mode 100644 src/app/utility/headerSearch/CompilerDetectorBase.cpp create mode 100644 src/app/utility/headerSearch/CompilerDetectorBase.h create mode 100644 src/app/utility/headerSearch/DetectorBase.cpp create mode 100644 src/app/utility/headerSearch/DetectorBase.h create mode 100644 src/app/utility/headerSearch/DetectorProxy.h create mode 100644 src/app/utility/headerSearch/GCCDetector.cpp create mode 100644 src/app/utility/headerSearch/GCCDetector.h create mode 100644 src/app/utility/headerSearch/StandardHeaderDetection.cpp create mode 100644 src/app/utility/headerSearch/StandardHeaderDetection.h create mode 100644 src/app/utility/headerSearch/VisualStudioDetector.cpp create mode 100644 src/app/utility/headerSearch/VisualStudioDetector.h create mode 100644 src/app/utility/utilityApp.cpp create mode 100644 src/app/utility/utilityApp.h diff --git a/.gitignore b/.gitignore index d8a320e8..eb4de3d1 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ .ycm_extra_conf.py .ycm_extra_conf.pyc compile_commands.json +Makefile /deployment/windows/CoatiAppSetup/CoatiSetup/Debug /deployment/windows/CoatiAppSetup/CoatiSetup/Release diff --git a/bin/test/data/log/test_log.txt b/bin/test/data/log/test_log.txt index 523dd8f6..92ffdb6b 100644 --- a/bin/test/data/log/test_log.txt +++ b/bin/test/data/log/test_log.txt @@ -1,171 +1,22 @@ -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml -Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +ConfigManager.cpp WARNING: value path/to/nowhere is not present in config. +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:1:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:4:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:1:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:1:11 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:4:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:1:13 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:7:15 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:4:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:4:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:4:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:5:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:4:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:4:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:4:48 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:7:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:4:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:3:20 +CxxDeclNameResolver.cpp ERROR: could not resolve name of decl at: input.cc:4:20 Token.cpp ERROR: Location Id was not referenced by this Token. Node.cpp WARNING: Cannot change NodeType after it was already set from namespace to class Edge.cpp ERROR: Nodes are not plain copies. @@ -214,8 +65,106 @@ Edge.cpp ERROR: Nodes are not plain copies. NetworkProtocolHelper.cpp ERROR: Failed to parse message, invalid type token NetworkProtocolHelper.cpp ERROR: Failed to parse setActiveToken message, invalid token count Settings.cpp WARNING: File for Settings not found: data/SettingsTestSuite/wrong_settings.xml +ConfigManager.cpp WARNING: value Bool is not present in config. +ConfigManager.cpp WARNING: value Int is not present in config. +ConfigManager.cpp WARNING: value Float is not present in config. +ConfigManager.cpp WARNING: value String is not present in config. Settings.cpp WARNING: File for Settings not found: data/SettingsTestSuite/wrong_settings.xml -TextAccess.cpp ERROR: Could not open file path/to/test.h +ConfigManager.cpp WARNING: value Bool is not present in config. +ConfigManager.cpp WARNING: value Int is not present in config. +ConfigManager.cpp WARNING: value Float is not present in config. +ConfigManager.cpp WARNING: value String is not present in config. + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: typedef: type + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: class: Class + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: struct: Struct + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: global: Global + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: field: m_field + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: field: Struct::m_field + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: function: bool isTrue(char) + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: method: void isMethod(bool) + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: method: void Class::isMethod(bool) + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: namespace: utility + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: enum: Category + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: enum: Class::Category + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: enum constant: VALUE + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: class: ClassA + INFO: class: ClassB + INFO: inheritance: ClassB : ClassA + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: struct: StructA + INFO: struct: StructB + INFO: inheritance: StructB : StructA + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: method: void A::isMethod(bool) + INFO: method: void B::isMethod(bool) + INFO: override: void A::isMethod(bool) -> void B::isMethod(bool) + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: function: bool isTrue(char) + INFO: function: void func(bool) + INFO: call: bool isTrue(char) -> void func(bool) + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: global: global + INFO: function: bool isTrue(char) + INFO: call: global -> bool isTrue(char) + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: function: bool isTrue(char) + INFO: field: Foo::m_field + INFO: field usage: bool isTrue(char) -> Foo::m_field + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: function: bool isTrue(char) + INFO: global: global + INFO: global usage: bool isTrue(char) -> global + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: function: Struct isTrue(char) + INFO: struct: Struct + INFO: type usage: Struct isTrue(char) -> Struct + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: file: file.h < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.h + INFO: file: file.cpp < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.cpp + INFO: file: file.h < 0:0 0:0> +TextAccess.cpp ERROR: Could not open file file.h + INFO: file: file.cpp < 0:0 0:0> + INFO: include: file.h + INFO: file: file.cpp < 0:0 0:0> + INFO: file: file.h < 0:0 0:0> TextAccess.cpp WARNING: Index 'firstLine' has to be lower or equal index 'lastLine', is 3 > 2 TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8 TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8 diff --git a/script/build.sh b/script/build.sh index 8a64b809..15345453 100755 --- a/script/build.sh +++ b/script/build.sh @@ -3,6 +3,8 @@ # Determine path to script MY_PATH=`dirname "$0"` +$MY_PATH/buildonly.sh $@ + cd $MY_PATH/.. # Build and run target @@ -12,40 +14,35 @@ then if [ "$2" = "test" ] then #echo "release test" - cmake --build build/Release --target Coati_test && cd bin/test && Release/Coati_test + cd bin/test && Release/Coati_test elif [ "$2" = "trial" ] then - cmake --build build/Release --target Coati_trial && cd bin/app && Release/Coati_trial + cd bin/app && Release/Coati_trial elif [ "$2" = "keygen" ] then #echo "release keygen" - cmake --build build/Release --target Coati_license_generator && cd bin/license_generator && Release/Coati_license_generator + cd bin/license_generator && Release/Coati_license_generator else #echo "release app" - cmake --build build/Release --target Coati && cd bin/app && Release/Coati + cd bin/app && Release/Coati fi elif [ "$1" = "debug" ] || [ "$1" = "d" ] then if [ "$2" = "test" ] then #echo "debug test" - cmake --build build/Debug --target Coati_test && cd bin/test && Debug/Coati_test + cd bin/test && Debug/Coati_test elif [ "$2" = "trial" ] then - cmake --build build/Debug --target Coati_trial && cd bin/app && Debug/Coati_trial + cd bin/app && Debug/Coati_trial elif [ "$2" = "keygen" ] then #echo "debug keygen" - cmake --build build/Debug --target Coati_license_generator && cd bin/license_generator && Debug/Coati_license_generator_d + cd bin/license_generator && Debug/Coati_license_generator_d else #echo "debug app" - cmake --build build/Debug --target Coati && cd bin/app && Debug/Coati + cd bin/app && Debug/Coati fi -elif [ "$1" = "package" ] || [ "$1" = "p" ] -then - cmake --build build/Release --target package - mkdir -p distr && cp build/Release/Coati*.tar.gz distr #&& cp build/Release/Coati*.deb distr - echo "Packages copied into the distr folder" else echo "no arguments: first argument 'release' or 'debug', second argument 'test' for tests" fi diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 907787cb..04a296da 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -6,6 +6,23 @@ add_files( utility/commandline/CommandLineParser.cpp utility/commandline/CommandLineParser.h + utility/headerSearch/ClangDetector.cpp + utility/headerSearch/ClangDetector.h + utility/headerSearch/CompilerDetectorBase.cpp + utility/headerSearch/CompilerDetectorBase.h + utility/headerSearch/DetectorBase.cpp + utility/headerSearch/DetectorBase.h + utility/headerSearch/DetectorProxy.h + utility/headerSearch/GCCDetector.cpp + utility/headerSearch/GCCDetector.h + utility/headerSearch/StandardHeaderDetection.cpp + utility/headerSearch/StandardHeaderDetection.h + utility/headerSearch/VisualStudioDetector.cpp + utility/headerSearch/VisualStudioDetector.h + + utility/utilityApp.cpp + utility/utilityApp.h + isTrial.cpp LicenseChecker.h main.cpp diff --git a/src/app/LicenseChecker.h b/src/app/LicenseChecker.h index f5d05d3e..46b9c8d1 100644 --- a/src/app/LicenseChecker.h +++ b/src/app/LicenseChecker.h @@ -127,6 +127,10 @@ private: license.loadPublicKeyFromString(PublicKey); valid = license.isValid(); + if (license.isExpired()) + { + valid = false; + } } while (false); diff --git a/src/app/utility/commandline/CommandLineParser.cpp b/src/app/utility/commandline/CommandLineParser.cpp index d22cb532..01661c9e 100644 --- a/src/app/utility/commandline/CommandLineParser.cpp +++ b/src/app/utility/commandline/CommandLineParser.cpp @@ -13,10 +13,10 @@ namespace po = boost::program_options; CommandLineParser::CommandLineParser(int argc, char** argv, const std::string& version) - : m_withoutGUI(false) + : m_force(false) , m_quit(false) , m_withLicense(false) - , m_force(false) + , m_withoutGUI(false) { std::string projectfile; std::string projectfile_db; diff --git a/src/app/utility/commandline/CommandLineParser.h b/src/app/utility/commandline/CommandLineParser.h index 16a322aa..27e2b5a6 100644 --- a/src/app/utility/commandline/CommandLineParser.h +++ b/src/app/utility/commandline/CommandLineParser.h @@ -20,10 +20,12 @@ private: void processProjectfile(const std::string& file); void processLicense(const bool isLoaded); std::string m_projectFile; - bool m_withoutGUI; - bool m_quit; + bool m_force; + bool m_quit; bool m_withLicense; + bool m_withoutGUI; + License m_license; }; diff --git a/src/app/utility/headerSearch/ClangDetector.cpp b/src/app/utility/headerSearch/ClangDetector.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/app/utility/headerSearch/ClangDetector.h b/src/app/utility/headerSearch/ClangDetector.h new file mode 100644 index 00000000..b8c32048 --- /dev/null +++ b/src/app/utility/headerSearch/ClangDetector.h @@ -0,0 +1,7 @@ +#ifndef CLANG_DETECTOR_H +#define CLANG_DETECTOR_H + + + +#endif /* end of include guard: CLANG_DETECTOR_H */ + diff --git a/src/app/utility/headerSearch/CompilerDetectorBase.cpp b/src/app/utility/headerSearch/CompilerDetectorBase.cpp new file mode 100644 index 00000000..77aba3b9 --- /dev/null +++ b/src/app/utility/headerSearch/CompilerDetectorBase.cpp @@ -0,0 +1,23 @@ +#include "utility/headerSearch/CompilerDetectorBase.h" + +#include "utility/utilityApp.h" +#include "utility/utilityString.h" + +std::vector CompilerDetectorBase::getStandardHeaderPaths() +{ + std::string command = m_name + " -x c++ -v -E /dev/null"; + std::string clangOutput = utility::executeProcess(command.c_str()); + std::string standardHeaders = utility::substrBetween(clangOutput, "#include <...> search starts here:\n","\nEnd of search list"); + std::vector paths; + + if (!standardHeaders.empty()) + { + for (std::string s : utility::splitToVector(standardHeaders, '\n')) + { + paths.push_back(s); + } + } + + return paths; +} + diff --git a/src/app/utility/headerSearch/CompilerDetectorBase.h b/src/app/utility/headerSearch/CompilerDetectorBase.h new file mode 100644 index 00000000..7aed74d1 --- /dev/null +++ b/src/app/utility/headerSearch/CompilerDetectorBase.h @@ -0,0 +1,13 @@ +#ifndef COMPILER_DETECTOR_BASE_H +#define COMPILER_DETECTOR_BASE_H + +#include "utility/headerSearch/DetectorBase.h" + +class CompilerDetectorBase : public DetectorBase +{ +public: + virtual std::vector getStandardHeaderPaths(); +private: +}; + +#endif // COMPILER_DETECTOR_BASE_H diff --git a/src/app/utility/headerSearch/DetectorBase.cpp b/src/app/utility/headerSearch/DetectorBase.cpp new file mode 100644 index 00000000..ebc912b8 --- /dev/null +++ b/src/app/utility/headerSearch/DetectorBase.cpp @@ -0,0 +1,23 @@ +#include "utility/headerSearch/DetectorBase.h" + +#include + +bool DetectorBase::detect() +{ + return !getStandardHeaderPaths().empty(); +} + +std::string DetectorBase::getName() const +{ + return m_name; +} + +void DetectorBase::setName(const std::string& name) +{ + std::cout << "setName()" << std::endl; + if (!name.empty()) + { + std::cout << "name set to " << name << std::endl; + m_name = name; + } +} diff --git a/src/app/utility/headerSearch/DetectorBase.h b/src/app/utility/headerSearch/DetectorBase.h new file mode 100644 index 00000000..dd3c04bb --- /dev/null +++ b/src/app/utility/headerSearch/DetectorBase.h @@ -0,0 +1,28 @@ +#ifndef DETECTOR_BASE_H +#define DETECTOR_BASE_H + +#include +#include "utility/file/FilePath.h" + +class DetectorBase +{ +public: + virtual ~DetectorBase(){}; + virtual bool detect(); + virtual std::vector getStandardHeaderPaths() = 0; + virtual std::string getName() const; + virtual void setName(const std::string& name); +protected: + std::string m_name; +}; + +class Detector +{ +public: + virtual ~Detector(); + +}; + + +#endif // DETECTOR_BASE_H + diff --git a/src/app/utility/headerSearch/DetectorProxy.h b/src/app/utility/headerSearch/DetectorProxy.h new file mode 100644 index 00000000..6f5fbd42 --- /dev/null +++ b/src/app/utility/headerSearch/DetectorProxy.h @@ -0,0 +1,13 @@ +#ifndef DETECTOR_PROXY_H +#define DETECTOR_PROXY_H + +class DetectorProxyBase +{ +public: + + +}; + + +#endif // DETECTOR_PROXY_H + diff --git a/src/app/utility/headerSearch/GCCDetector.cpp b/src/app/utility/headerSearch/GCCDetector.cpp new file mode 100644 index 00000000..2a76e486 --- /dev/null +++ b/src/app/utility/headerSearch/GCCDetector.cpp @@ -0,0 +1,16 @@ +#include "utility/headerSearch/GCCDetector.h" +#include "utility/headerSearch/StandardHeaderDetection.h" + +GCCDetector::GCCDetector() +{ + +} + +GCCDetector::~GCCDetector() +{ +} + +static StandardHeaderDetection::Add gcc("gcc"); +static StandardHeaderDetection::Add clang("clang"); +static StandardHeaderDetection::Add fakecomplier("fakecompiler"); + diff --git a/src/app/utility/headerSearch/GCCDetector.h b/src/app/utility/headerSearch/GCCDetector.h new file mode 100644 index 00000000..766cc6f8 --- /dev/null +++ b/src/app/utility/headerSearch/GCCDetector.h @@ -0,0 +1,15 @@ +#ifndef GCC_DETECTOR_H +#define GCC_DETECTOR_H + +#include "utility/headerSearch/CompilerDetectorBase.h" + +class GCCDetector : public CompilerDetectorBase +{ +public: + GCCDetector (); + virtual ~GCCDetector (); +private: +}; + + +#endif // GCC_DETECTOR_H diff --git a/src/app/utility/headerSearch/StandardHeaderDetection.cpp b/src/app/utility/headerSearch/StandardHeaderDetection.cpp new file mode 100644 index 00000000..33ab2af2 --- /dev/null +++ b/src/app/utility/headerSearch/StandardHeaderDetection.cpp @@ -0,0 +1,121 @@ +#include "utility/headerSearch/StandardHeaderDetection.h" + +#include +#include +#include +#include +#include +#include + +#include "utility/file/FilePath.h" +#include "utility/logging/logging.h" +#include "utility/utilityApp.h" +#include "utility/utilityString.h" + +DetectorMap* StandardHeaderDetection::s_availableDetectors; + +StandardHeaderDetection::StandardHeaderDetection() +{ + detectHeaders(); +} + +StandardHeaderDetection::~StandardHeaderDetection() +{ + if ( s_availableDetectors != nullptr ) + { + delete s_availableDetectors; + } +} + +void StandardHeaderDetection::detectHeaders() +{ + for ( std::pair> detector : *s_availableDetectors) + { + if ( detector.second->detect() ) + { + m_detectedCompilers.insert(detector); + } + } +} + +std::vector StandardHeaderDetection::getDetectedCompilers() +{ + std::vector v; + for ( std::pair> detector : m_detectedCompilers) + { + v.push_back(detector.first); + } + return v; +} + +std::vector StandardHeaderDetection::getStandardHeaderPaths(std::string compiler) +{ + auto it = m_detectedCompilers.find(compiler); + if(it != m_detectedCompilers.end()) + { + return it->second->getStandardHeaderPaths(); + } + return std::vector(); +} + +void StandardHeaderDetection::printdetectedCompilers() +{ + std::cout << "Detected Compilers: " << std::endl; + std::vector compilers = getDetectedCompilers(); + for ( std::string compiler : compilers) + { + std::cout << compiler << std::endl; + } +} + +void StandardHeaderDetection::printAvailableDetectors() +{ + std::cout << "printAvailableDetectors: " << std::endl; + + for ( std::pair> detector : *s_availableDetectors) + { + std::cout << detector.first << std::endl; + } +} + + +//bool StandardHeaderDetection::detectFromCompiler(const std::string& compiler) +//{ + //LOG_INFO("Searching for " + compiler + " include paths"); + //std::string command = compiler + " -x c++ -v -E /dev/null"; + //std::string clangOutput = utility::executeProcess(command.c_str()); + //std::string standardHeaders = utility::substrBetween(clangOutput, "#include <...> search starts here:\n","\nEnd of search list"); + //if(standardHeaders.empty()) + //{ + //return false; + //} + //std::vector paths; + //for(std::string s : utility::splitToVector(standardHeaders, '\n')) + //{ + //paths.push_back(s); + //} + //m_standardHeaderPaths.insert(std::make_pair(compiler, paths)); + //LOG_INFO(compiler + " standard headers detected"); + //return true; +//} + +//bool StandardHeaderDetection::detectVisualStudioVersion(const std::string& version) +//{ + //LOG_INFO_STREAM(<< "Searching for Visual Studio Includes from Version: " << version); + //std::string vstoolstring = version + "COMNTOOLS"; + //if( const char* vs_env = std::getenv(vstoolstring.c_str())) + //{ + //FilePath VSHeaderPath(vs_env); + //VSHeaderPath = VSHeaderPath.concat("../VC/include"); + //if(VSHeaderPath.exists()) + //{ + //LOG_INFO_STREAM(<< "Visual Studio 20" << version.substr(2,version.length()-3) << " includes detected"); + //std::vector path; + //path.push_back(VSHeaderPath.str()); + //m_standardHeaderPaths.insert(std::make_pair(version, path)); + //return true; + //} + //} + //return false; +//} + diff --git a/src/app/utility/headerSearch/StandardHeaderDetection.h b/src/app/utility/headerSearch/StandardHeaderDetection.h new file mode 100644 index 00000000..a7031f46 --- /dev/null +++ b/src/app/utility/headerSearch/StandardHeaderDetection.h @@ -0,0 +1,56 @@ +#ifndef STANDARDHEADER_DETECTION_H +#define STANDARDHEADER_DETECTION_H + +#include +#include +#include + +#include "utility/headerSearch/DetectorBase.h" + +typedef std::map> DetectorMap; + +class FilePath; + +class StandardHeaderDetection +{ +public: + StandardHeaderDetection(); + ~StandardHeaderDetection(); + + /// Checks all availabe detectors and saves found Compilers + void detectHeaders(); + + /// Returns alls found compilers + std::vector getDetectedCompilers(); + + /// Returns the headerpaths from a found compiler + std::vector getStandardHeaderPaths(std::string compiler); + + /// Declare a instance of this class to add a detector + template + class Add + { + public: + Add(const std::string& name) + { + std::shared_ptr detector = std::shared_ptr(new U()); + if (!name.empty()) + { + detector->setName(name); + } + if (!s_availableDetectors) + { + s_availableDetectors = new DetectorMap(); + } + s_availableDetectors->insert(std::make_pair(detector->getName(), detector)); + } + }; + + void printAvailableDetectors(); + void printdetectedCompilers(); +private: + static DetectorMap* s_availableDetectors; + DetectorMap m_detectedCompilers; +}; + +#endif //STANDARDHEADER_DETECTION_H diff --git a/src/app/utility/headerSearch/VisualStudioDetector.cpp b/src/app/utility/headerSearch/VisualStudioDetector.cpp new file mode 100644 index 00000000..b2895463 --- /dev/null +++ b/src/app/utility/headerSearch/VisualStudioDetector.cpp @@ -0,0 +1,38 @@ +#include "utility/headerSearch/VisualStudioDetector.h" + +#include + +#include +#include "utility/file/FilePath.h" +#include "utility/logging/logging.h" +#include "utility/headerSearch/StandardHeaderDetection.h" + +VisualStudioDetector::~VisualStudioDetector() +{ + +} + +std::vector VisualStudioDetector::getStandardHeaderPaths() +{ + QSettings registry; + std::string vstoolstring = m_name + "COMNTOOLS"; + std::vector path; + if( const char* vs_env = std::getenv(vstoolstring.c_str())) + { + FilePath VSHeaderPath(vs_env); + VSHeaderPath = VSHeaderPath.concat("../VC/include"); + if(VSHeaderPath.exists()) + { + LOG_INFO_STREAM(<< "Visual Studio 20" << m_name.substr(2,m_name.length()-3) << " includes detected"); + path.push_back(VSHeaderPath.str()); + } + } + return path; +} + +// Add Visual Studio Version to the available detectors +static StandardHeaderDetection::Add vs2015("VS140"); +static StandardHeaderDetection::Add vs2013("VS120"); +static StandardHeaderDetection::Add vs2012("VS110"); +static StandardHeaderDetection::Add vs2010("VS90"); + diff --git a/src/app/utility/headerSearch/VisualStudioDetector.h b/src/app/utility/headerSearch/VisualStudioDetector.h new file mode 100644 index 00000000..91a0f9d3 --- /dev/null +++ b/src/app/utility/headerSearch/VisualStudioDetector.h @@ -0,0 +1,16 @@ +#ifndef VISUAL_STUDIO_DETECTOR_H +#define VISUAL_STUDIO_DETECTOR_H + +#include +#include "utility/headerSearch/DetectorBase.h" + +class FilePath; + +class VisualStudioDetector : public DetectorBase +{ +public: + virtual ~VisualStudioDetector(); + virtual std::vector getStandardHeaderPaths(); +}; + +#endif // VISUAL_STUDIO_DETECTOR_H diff --git a/src/app/utility/utilityApp.cpp b/src/app/utility/utilityApp.cpp new file mode 100644 index 00000000..1de698b6 --- /dev/null +++ b/src/app/utility/utilityApp.cpp @@ -0,0 +1,15 @@ +#include "utility/utilityApp.h" + +#include + +std::string utility::executeProcess(const char *cmd) +{ + QProcess process; + process.setProcessChannelMode(QProcess::MergedChannels); + process.start(cmd); + process.waitForFinished(); + std::string processoutput = process.readAll().toStdString(); + process.close(); + + return processoutput; +} diff --git a/src/app/utility/utilityApp.h b/src/app/utility/utilityApp.h new file mode 100644 index 00000000..ee6170ad --- /dev/null +++ b/src/app/utility/utilityApp.h @@ -0,0 +1,13 @@ +#ifndef UTILITY_APP_H +#define UTILITY_APP_H + +#include + +namespace utility +{ + std::string executeProcess(const char* cmd); +} + + +#endif // UTILITY_APP_H + diff --git a/src/lib/utility/utilityString.cpp b/src/lib/utility/utilityString.cpp index 81df0ce7..08810295 100644 --- a/src/lib/utility/utilityString.cpp +++ b/src/lib/utility/utilityString.cpp @@ -182,4 +182,16 @@ namespace utility auto wsback = std::find_if_not(str.rbegin(), str.rend(), [](int c){ return std::isspace(c); }).base(); return (wsback <= wsfront ? std::string() : std::string(wsfront, wsback)); } + + std::string substrBetween(const std::string &str, const std::string &delimiter1, const std::string &delimiter2) + { + size_t found_delimiter1 = str.find(delimiter1); + found_delimiter1 += delimiter1.length(); + size_t found_delimiter2 = str.find(delimiter2,found_delimiter1); + if(found_delimiter1 != str.npos && found_delimiter2 != str.npos) + { + return str.substr(found_delimiter1, found_delimiter2-found_delimiter1); + } + return ""; + } } diff --git a/src/lib/utility/utilityString.h b/src/lib/utility/utilityString.h index c7435bef..7b618e11 100644 --- a/src/lib/utility/utilityString.h +++ b/src/lib/utility/utilityString.h @@ -32,6 +32,8 @@ namespace utility std::string substrBefore(const std::string& str, char delimiter); std::string substrAfter(const std::string& str, char delimiter); + std::string substrBetween(const std::string& str, const std::string& delimiter1, const std::string& delimiter2); + bool isPrefix(const std::string& prefix, const std::string& text); std::string toUpperCase(const std::string& in); diff --git a/src/lib_gui/qt/window/QtLicense.cpp b/src/lib_gui/qt/window/QtLicense.cpp index d11e03a1..ee54979a 100644 --- a/src/lib_gui/qt/window/QtLicense.cpp +++ b/src/lib_gui/qt/window/QtLicense.cpp @@ -151,7 +151,12 @@ void QtLicense::handleNext() license.loadPublicKeyFromString(PublicKey); license.print(); - if (license.isValid()) + if (license.isExpired()) + { + m_errorLabel->setText("The entered license key is expired"); + return; + } + else if (license.isValid()) { ApplicationSettings* appSettings = ApplicationSettings::getInstance().get(); std::string appLocation = AppPath::getAppPath(); diff --git a/src/lib_license/Generator.cpp b/src/lib_license/Generator.cpp index af0881a3..c793b30e 100644 --- a/src/lib_license/Generator.cpp +++ b/src/lib_license/Generator.cpp @@ -6,10 +6,11 @@ #include "botan_all.h" #include "boost/filesystem.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" #include "License.h" -Generator::Generator(std::string version) +Generator::Generator(const std::string& version) : m_version(version) { } @@ -41,7 +42,7 @@ std::string Generator::getPublicKeyFilename() return m_publicKeyFile; } -void Generator::setVersion(std::string version) +void Generator::setVersion(const std::string& version) { if(!version.empty()) { @@ -49,7 +50,17 @@ void Generator::setVersion(std::string version) } } -std::string Generator::encodeLicense(std::string user, std::string licenseType) +std::string Generator::encodeLicense(const std::string& user, const int days) +{ + boost::gregorian::date today = boost::gregorian::day_clock::local_day(); + boost::gregorian::days daysToTry(days); + boost::gregorian::date expireDate = today + daysToTry; + + std::string testLicenseTypeString = "Test License - valid till " + boost::gregorian::to_simple_string(expireDate); + return encodeLicense(user, testLicenseTypeString); +} + +std::string Generator::encodeLicense(const std::string& user, const std::string& licenseType) { License license; @@ -69,7 +80,7 @@ std::string Generator::encodeLicense(std::string user, std::string licenseType) return license.getLicenseString(); } -bool Generator::verifyLicense(std::string filename) +bool Generator::verifyLicense(const std::string& filename) { License license; license.loadFromFile(filename); @@ -78,7 +89,7 @@ bool Generator::verifyLicense(std::string filename) return license.isValid(); } -void Generator::setCustomPrivateKeyFile(std::string file) +void Generator::setCustomPrivateKeyFile(const std::string& file) { if(!file.empty()) { @@ -86,7 +97,7 @@ void Generator::setCustomPrivateKeyFile(std::string file) } } -void Generator::setCustomPublicKeyFile(std::string file) +void Generator::setCustomPublicKeyFile(const std::string& file) { if(!file.empty()) { @@ -134,7 +145,7 @@ bool Generator::loadPrivateKeyFromFile() return true; } -bool Generator::loadPrivateKeyFromString(std::string key) +bool Generator::loadPrivateKeyFromString(const std::string& key) { Botan::DataSource_Memory in(key); Botan::Private_Key* privateKey= Botan::PKCS8::load_key(in, m_rng, PRIVATE_KEY_PASSWORD); diff --git a/src/lib_license/Generator.h b/src/lib_license/Generator.h index b09c2963..18772bde 100644 --- a/src/lib_license/Generator.h +++ b/src/lib_license/Generator.h @@ -8,21 +8,22 @@ class Generator { public: - Generator(std::string version = "x"); + Generator(const std::string& version = "x"); ~Generator(); - std::string encodeLicense(std::string message, std::string licenseType); - bool verifyLicense(std::string filename = "license.txt"); + std::string encodeLicense(const std::string& message, const std::string& licenseType); + std::string encodeLicense(const std::string& message, const int days); + bool verifyLicense(const std::string& filename = "license.txt"); void generateKeys(); void writeKeysToFiles(); - void setVersion(std::string version); - void setCustomPrivateKeyFile(std::string file); - void setCustomPublicKeyFile(std::string file); + void setVersion(const std::string& version); + void setCustomPrivateKeyFile(const std::string& file); + void setCustomPublicKeyFile(const std::string& file); std::string getPublicKeyPEMFileAsString(); std::string getPrivateKeyPEMFileAsString(); bool loadPrivateKeyFromFile(); - bool loadPrivateKeyFromString(std::string key); + bool loadPrivateKeyFromString(const std::string& key); void PrintLicense(); diff --git a/src/lib_license/License.cpp b/src/lib_license/License.cpp index 05ad2a21..3c2732b8 100644 --- a/src/lib_license/License.cpp +++ b/src/lib_license/License.cpp @@ -8,6 +8,7 @@ #include #include "botan_all.h" +#include "boost/date_time.hpp" #include "boost/filesystem.hpp" namespace @@ -69,7 +70,27 @@ std::string License::getLicenseTypeLine() const return lines[2]; } -void License::create(std::string user, std::string version, Botan::RSA_PrivateKey* privateKey, std::string type) +int License::getTimeLeft() const +{ + const std::string testText = "Test License - valid till "; + if(getLicenseTypeLine().substr(0, testText.length()) == testText) + { + boost::gregorian::date expireDate( + boost::gregorian::from_simple_string(getLicenseTypeLine().substr(testText.length(),11)) + ); + boost::gregorian::date today = boost::gregorian::day_clock::local_day(); + boost::gregorian::days daysLeft = expireDate - today; + return (daysLeft.days() < 0 ? 0 : daysLeft.days()); + } + else + { + return -1; + } +} + +void License::create( + const std::string& user, const std::string& version, + Botan::RSA_PrivateKey* privateKey, const std::string& type) { m_version = version; createMessage(user, version, type); @@ -85,7 +106,7 @@ void License::create(std::string user, std::string version, Botan::RSA_PrivateKe addSignature(signature); } -void License::createMessage(std::string user, std::string version, std::string type) +void License::createMessage(const std::string& user, const std::string& version, const std::string& type) { lines.clear(); lines.push_back(BEGIN_LICENSE); @@ -97,7 +118,7 @@ void License::createMessage(std::string user, std::string version, std::string t lines.push_back(pass9); } -void License::writeToFile(std::string filename) +void License::writeToFile(const std::string& filename) { std::ofstream licenseFile(filename); for(std::string line : lines) @@ -106,7 +127,7 @@ void License::writeToFile(std::string filename) } } -bool License::loadFromString(std::string licenseText) +bool License::loadFromString(const std::string& licenseText) { lines.clear(); std::istringstream license(licenseText); @@ -147,7 +168,7 @@ bool License::load(std::istream& stream) return true; } -bool License::loadFromFile(std::string filename) +bool License::loadFromFile(const std::string& filename) { lines.clear(); std::ifstream sigfile(filename); @@ -159,7 +180,7 @@ void License::print() std::cout << getLicenseString(); } -void License::addSignature(std::string signature) +void License::addSignature(const std::string& signature) { if(lines.size() > 5) { @@ -190,24 +211,38 @@ bool License::isValid() const std::cout << "No public key loaded" << std::endl; return false; } - if(Botan::check_passhash9("Coati "+ getVersion(), getHashLine())) - { -// std::cout << "Hash from Coati "+ getVersion() + " confirmed" << std::endl; - } + try + { - Botan::secure_vector sig = Botan::base64_decode(getSignature()); + if(Botan::check_passhash9("Coati "+ getVersion(), getHashLine())) + { + // std::cout << "Hash from Coati "+ getVersion() + " confirmed" << std::endl; + } - Botan::PK_Verifier verifier(*m_publicKey.get(), "EMSA4(SHA-256)"); + Botan::secure_vector sig = Botan::base64_decode(getSignature()); - Botan::DataSource_Memory in(getMessage()); - Botan::byte buf[4096] = {0}; - while(size_t got = in.read(buf, sizeof(buf))) - { - verifier.update(buf, got); - } + Botan::PK_Verifier verifier(*m_publicKey.get(), "EMSA4(SHA-256)"); - const bool ok = verifier.check_signature(sig); - return ok; + Botan::DataSource_Memory in(getMessage()); + Botan::byte buf[4096] = {0}; + while(size_t got = in.read(buf, sizeof(buf))) + { + verifier.update(buf, got); + } + + const bool ok = verifier.check_signature(sig); + return ok; + } + catch(...) + { + std::cout << "Invalid character in Licensekey" << std::endl; + } + return false; +} + +bool License::isExpired() const +{ + return !getTimeLeft(); } std::string License::getPublicKeyFilename() const @@ -228,7 +263,7 @@ std::string License::getVersion() const return m_version; } -bool License::loadPublicKeyFromFile(std::string filename) +bool License::loadPublicKeyFromFile(const std::string& filename) { if (!filename.empty()) { m_publicKeyFilename = filename; @@ -246,7 +281,7 @@ bool License::loadPublicKeyFromFile(std::string filename) return false; } -bool License::loadPublicKeyFromString(std::string publicKey) +bool License::loadPublicKeyFromString(const std::string& publicKey) { Botan::DataSource_Memory in(publicKey); Botan::RSA_PublicKey *rsaPublicKey = dynamic_cast(Botan::X509::load_key(in)); @@ -286,7 +321,7 @@ bool License::checkLocation(const std::string& location, const std::string& hash return Botan::check_passhash9(location, hash); } -std::string License::getLicenseEncodedString(std::string applicationLocation) const +std::string License::getLicenseEncodedString(const std::string& applicationLocation) const { Botan::AutoSeeded_RNG rng; std::vector file_contents; @@ -311,7 +346,7 @@ std::string License::getLicenseEncodedString(std::string applicationLocation) co return ret; } -bool License::loadFromEncodedString(std::string encodedLicense, std::string applicationLocation) +bool License::loadFromEncodedString(const std::string& encodedLicense, const std::string& applicationLocation) { try { //add cryptobox begin and end to loaded string diff --git a/src/lib_license/License.h b/src/lib_license/License.h index 3920da11..5eb4b9d1 100644 --- a/src/lib_license/License.h +++ b/src/lib_license/License.h @@ -28,23 +28,30 @@ public: std::string getPublicKeyFilename() const; std::string getVersion() const; - void create(std::string user, std::string version, Botan::RSA_PrivateKey* privateKey, std::string type="Private License"); + /// if Test License return >=0 else -1 + int getTimeLeft() const; + + void create( + const std::string& user, const std::string& version, + Botan::RSA_PrivateKey* privateKey, const std::string& type="Private License" + ); std::string getLicenseString() const; - std::string getLicenseEncodedString(std::string applicationLocation) const; + std::string getLicenseEncodedString(const std::string& applicationLocation) const; - void writeToFile(std::string filename); + void writeToFile(const std::string& filename); bool load(std::istream& stream); - bool loadFromString(std::string licenseText); - bool loadFromFile(std::string filename); - bool loadFromEncodedString(std::string encodedLicense, std::string applicationLocation); + bool loadFromString(const std::string& licenseText); + bool loadFromFile(const std::string& filename); + bool loadFromEncodedString(const std::string& encodedLicense, const std::string& applicationLocation); - bool loadPublicKeyFromFile(std::string); + bool loadPublicKeyFromFile(const std::string&); - bool loadPublicKeyFromString(std::string); + bool loadPublicKeyFromString(const std::string&); void setVersion(const std::string&); bool isValid() const; + bool isExpired() const; void print(); @@ -52,8 +59,8 @@ public: static bool checkLocation(const std::string&, const std::string&); private: - void createMessage(std::string user, std::string version, std::string type = 0); - void addSignature(std::string); + void createMessage(const std::string& user, const std::string& version, const std::string& type = 0); + void addSignature(const std::string&); std::string getEncodeKey(const std::string applicationLocation) const; std::string m_version; diff --git a/src/license_generator/main.cpp b/src/license_generator/main.cpp index ab596e70..ad57c31e 100644 --- a/src/license_generator/main.cpp +++ b/src/license_generator/main.cpp @@ -19,19 +19,21 @@ bool process_command_line(int argc, char** argv) std::string publicKey; std::string license = ""; std::string type = ""; + int days = 0; po::options_description desc("Coati Generator"); desc.add_options() - ("help,h", "Print this help message") - ("key,k", "Generate the private and public key") - ("generate,g", po::value(&user), "Generate a License, USERNAME as value") - ("check,c", "Validate a License") - ("version,v", po::value(&version), "Versionnumber of Coati") - ("licenseType,t", po::value(&type), "License Type of ") - ("public-file", po::value(&publicKey), "Custom public key file") - ("private-file", po::value(&privateKey), "Custom private key file") - ("license-file", po::value(&license), "Custom license") - ; + ("help,h", "Print this help message") + ("key,k", "Generate the private and public key") + ("generate,g", po::value(&user), "Generate a License, USERNAME as value") + ("check,c", "Validate a License") + ("version,v", po::value(&version), "Versionnumber of Coati") + ("licenseType,t", po::value(&type), "License Type of ") + ("testLicense,e", po::value(&days), "Generates a test license for days") + ("public-file", po::value(&publicKey), "Custom public key file") + ("private-file", po::value(&privateKey), "Custom private key file") + ("license-file", po::value(&license), "Custom license") + ; po::variables_map vm; po::store(po::parse_command_line(argc,argv,desc), vm); @@ -68,8 +70,14 @@ bool process_command_line(int argc, char** argv) std::cout << "Version of Coati is needed to generate a License" << std::endl; return false; } - - keygen.encodeLicense(user,type); + if(vm.count("testLicense")) + { + keygen.encodeLicense(user,days); + } + else + { + keygen.encodeLicense(user,type); + } } if(vm.count("check"))