From 13b0d4be87739453f6cfbe79fae067fdd53a3c94 Mon Sep 17 00:00:00 2001 From: Majid Khan Date: Tue, 9 Jan 2018 22:59:19 +1100 Subject: [PATCH 1/2] static linking --- CHANGELOG.md | 4 ++ CMakeLists.txt | 15 ++---- README.md | 6 ++- src/external/Ripe.cc | 109 ------------------------------------------- 4 files changed, 12 insertions(+), 122 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c75de66..f2bccf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [1.0.2] - 09-01-2018 +### Updates +- Removed unnecessary zlib dependency + ## [1.0.1] - 09-01-2018 ### Updates - Docs update diff --git a/CMakeLists.txt b/CMakeLists.txt index afa24cb..32fa1d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ set (LICENSEPP_SOVERSION "${LICENSEPP_MAJOR}.${LICENSEPP_MINOR}.${LICENSEPP_PATC set (LICENSEPP_NAME "licensepp") add_definitions (-DLICENSEPP_SOVERSION="${LICENSEPP_SOVERSION}") -add_definitions (-DRIPE_VERSION="4.0.1-static") +add_definitions (-DRIPE_VERSION="4.0.1-static-no-zip") if (travis) add_definitions (-DLICENSEPP_ON_CI) endif() @@ -35,15 +35,7 @@ if (APPLE) endif() endif() -list (APPEND CMAKE_CXX_FLAGS " -std=c++11 -O3 -Wall -Werror -Wno-unknown-warning-option -Wno-pessimizing-move ") - -find_package(ZLIB REQUIRED) -if (ZLIB_FOUND) - include_directories(${ZLIB_INCLUDE_DIRS}) - message ("-- libz: " ${ZLIB_LIBRARIES} " version: " ${ZLIB_VERSION_STRING}) -else() - message ("--==> libz not found") -endif(ZLIB_FOUND) +list (APPEND CMAKE_CXX_FLAGS " -std=c++11 -O3 -Wall -Werror ") # Check for cryptopp (static) set(CryptoPP_USE_STATIC_LIBS ON) @@ -78,7 +70,6 @@ set_target_properties (licensepp-lib PROPERTIES VERSION ${LICENSEPP_SOVERSION} ) target_link_libraries (licensepp-lib - ${ZLIB_LIBRARIES} ${CRYPTOPP_LIBRARIES} ) @@ -133,7 +124,7 @@ if (test) # Extra linking for the project. target_link_libraries (licensepp-unit-tests licensepp) - target_link_libraries (licensepp-unit-tests ${SHARED_REQUIRED_LIBS}) + target_link_libraries (licensepp-unit-tests ${CRYPTOPP_LIBRARIES}) add_test (NAME licenseppUnitTests COMMAND licensepp-unit-tests) endif() ## test diff --git a/README.md b/README.md index 44e543c..4ccd230 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,6 @@ License++ is software licensing library that provides an abstract way to secure * C++11 * [Crypto++](https://www.cryptopp.com/) v5.6.5+ [with Pem Pack](https://raw.githubusercontent.com/muflihun/muflihun.github.io/master/downloads/pem_pack.zip) * [cmake](https://cmake.org/) v2.8.12+ - * [zlib-devel](https://zlib.net/) ### Installation * [Download](https://github.com/muflihun/licensepp/archive/master.zip) or [clone](git@github.com:muflihun/licensepp.git) the repository @@ -48,6 +47,11 @@ License++ is software licensing library that provides an abstract way to secure cd build cmake .. make install + + ## build with test + cmake -Dtest=ON .. + make install + ./licensepp-unit-tests ``` * You can build [cli](/cli) tool to ensure license++ is installed properly diff --git a/src/external/Ripe.cc b/src/external/Ripe.cc index b114121..800b4da 100644 --- a/src/external/Ripe.cc +++ b/src/external/Ripe.cc @@ -25,8 +25,6 @@ #include #include -#include - #include "src/external/Ripe.h" #define RIPE_UNUSED(x) (void)x @@ -386,113 +384,6 @@ std::string Ripe::decryptAES(std::string& data, const std::string& hexKey, std:: return Ripe::decryptAES(data, reinterpret_cast(Ripe::hexToString(hexKey).c_str()), hexKey.size() / 2, ivHex); } -bool Ripe::compressFile(const std::string& gzFilename, const std::string& inputFile) -{ - gzFile out = gzopen(gzFilename.c_str(), "wb"); - if (!out) { - throw std::runtime_error( - std::string("Unable to open file for writing [" + gzFilename + "] " + std::strerror(errno)).data() - ); - return false; - } - char buff[BUFSIZ]; - std::FILE* in = std::fopen(inputFile.c_str(), "rb"); - std::size_t nRead = 0; - while((nRead = std::fread(buff, sizeof(char), BUFSIZ, in)) > 0) { - int RipeBytes_written = gzwrite(out, buff, nRead); - if (RipeBytes_written == 0) { - int err_no = 0; - throw std::runtime_error( - std::string("Error during compression " + std::string(gzerror(out, &err_no))).data() - ); - gzclose(out); - return false; - } - } - gzclose(out); - std::fclose(in); - return true; -} - -std::string Ripe::compressString(const std::string& str) -{ - int compressionlevel = Z_BEST_COMPRESSION; - z_stream zs; - memset(&zs, 0, sizeof(zs)); - - if (deflateInit(&zs, compressionlevel) != Z_OK) { - throw std::runtime_error("Unable to initialize zlib deflate"); - } - - zs.next_in = reinterpret_cast(const_cast(str.data())); - zs.avail_in = str.size(); - - int ret; - char outbuffer[ZLIB_BUFFER_SIZE]; - std::string outstring; - - // retrieve the compressed RipeBytes blockwise - do { - zs.next_out = reinterpret_cast(outbuffer); - zs.avail_out = sizeof(outbuffer); - - ret = deflate(&zs, Z_FINISH); - - if (outstring.size() < zs.total_out) { - outstring.append(outbuffer, zs.total_out - outstring.size()); - } - } while (ret == Z_OK); - - deflateEnd(&zs); - - if (ret != Z_STREAM_END) { - std::ostringstream oss; - oss << "Exception during zlib compression: (" << ret << ") " << zs.msg; - throw std::runtime_error(oss.str()); - } - - return outstring; -} - -std::string Ripe::decompressString(const std::string& str) -{ - z_stream zs; - memset(&zs, 0, sizeof(zs)); - - if (inflateInit(&zs) != Z_OK) { - throw std::runtime_error("Unable to initialize zlib inflate"); - } - - zs.next_in = reinterpret_cast(const_cast(str.data())); - zs.avail_in = str.size(); - - int ret; - char outbuffer[ZLIB_BUFFER_SIZE]; - std::string outstring; - - do { - zs.next_out = reinterpret_cast(outbuffer); - zs.avail_out = sizeof(outbuffer); - - ret = inflate(&zs, 0); - - if (outstring.size() < zs.total_out) { - outstring.append(outbuffer, zs.total_out - outstring.size()); - } - - } while (ret == Z_OK); - - inflateEnd(&zs); - - if (ret != Z_STREAM_END) { - std::ostringstream oss; - oss << "Exception during zlib decompression: (" << ret << ") " << zs.msg; - throw std::runtime_error(oss.str()); - } - - return outstring; -} - std::string Ripe::prepareData(const std::string& data, const std::string& hexKey, const char* clientId, const std::string& ivec) { std::vector iv; From 96019cd046b1060527a68a86456adb0115e0cc75 Mon Sep 17 00:00:00 2001 From: Majid Khan Date: Tue, 9 Jan 2018 23:02:11 +1100 Subject: [PATCH 2/2] custom version ripe --- CMakeLists.txt | 2 +- src/external/Ripe.cc | 4 +++- src/external/Ripe.h | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32fa1d6..8c6cd98 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ set (LICENSEPP_SOVERSION "${LICENSEPP_MAJOR}.${LICENSEPP_MINOR}.${LICENSEPP_PATC set (LICENSEPP_NAME "licensepp") add_definitions (-DLICENSEPP_SOVERSION="${LICENSEPP_SOVERSION}") -add_definitions (-DRIPE_VERSION="4.0.1-static-no-zip") +add_definitions (-DRIPE_VERSION="4.0.1-custom-static") if (travis) add_definitions (-DLICENSEPP_ON_CI) endif() diff --git a/src/external/Ripe.cc b/src/external/Ripe.cc index 800b4da..a28a3fe 100644 --- a/src/external/Ripe.cc +++ b/src/external/Ripe.cc @@ -1,12 +1,14 @@ // // Ripe.cc // -// Copyright (c) 2017, Muflihun Labs +// Copyright (c) 2017-present Muflihun Labs // // https://muflihun.com // https://muflihun.github.io/ripe // https://github.com/muflihun // +// [This is custom version of Ripe for License++] +// #include #include diff --git a/src/external/Ripe.h b/src/external/Ripe.h index 61123b6..afe3bee 100644 --- a/src/external/Ripe.h +++ b/src/external/Ripe.h @@ -1,12 +1,14 @@ // // Ripe.cc // -// Copyright (c) 2017, Muflihun Labs +// Copyright (c) 2017-present, Muflihun Labs // // https://muflihun.com // https://muflihun.github.io/ripe // https://github.com/muflihun // +// [This is custom version of Ripe for License++] +// #ifndef Ripe_h #define Ripe_h