From 6d24300f9c7c9081f7588455d6061555d7409b80 Mon Sep 17 00:00:00 2001 From: Majid Q Date: Thu, 20 Jul 2023 21:03:03 +1000 Subject: [PATCH] 1.1.0 changes --- .github/FUNDING.yml | 1 - .gitignore | 1 + .travis.yml | 2 +- CHANGELOG.md | 6 + CMakeLists.txt | 36 +- README.md | 20 +- cli/Makefile | 2 +- cli/licensing/license-manager-key-register.cc | 2 +- cli/licensing/license-manager-key-register.h | 3 +- cli/main.cc | 6 +- cmake/FindRipe.cmake | 39 ++ cmake/config.h.cmake | 10 - doxygen/README_DOXYGEN.md | 5 +- doxygen/customdoxygen.css | 2 +- {src/external => external}/json.h | 0 license++/base-license-manager.h | 19 +- license++/c-bindings.h | 227 +++++++ license++/issuing-authority.h | 10 +- license++/license-exception.h | 6 +- license++/license.h | 17 +- sample/README.md | 26 +- sample/license-manager.h | 4 +- src/c-bindings.cc | 271 ++++++++ src/crypto/aes.cc | 3 +- src/crypto/aes.h | 6 +- src/crypto/base16.cc | 2 +- src/crypto/base16.h | 6 +- src/crypto/base64.cc | 3 +- src/crypto/base64.h | 6 +- src/crypto/rsa.cc | 3 +- src/crypto/rsa.h | 6 +- src/external/Ripe.cc | 624 ------------------ src/external/Ripe.h | 470 ------------- src/issuing-authority.cc | 2 +- src/json-object.h | 8 +- src/license.cc | 17 +- src/utils.h | 6 +- test/license-manager-for-test.h | 12 +- test/test.h | 2 +- test/testx.h | 16 +- 40 files changed, 667 insertions(+), 1240 deletions(-) delete mode 100644 .github/FUNDING.yml create mode 100644 cmake/FindRipe.cmake delete mode 100644 cmake/config.h.cmake rename {src/external => external}/json.h (100%) create mode 100644 license++/c-bindings.h create mode 100644 src/c-bindings.cc delete mode 100644 src/external/Ripe.cc delete mode 100644 src/external/Ripe.h diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index ffa17d3..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1 +0,0 @@ -custom: https://amrayn.com/donate diff --git a/.gitignore b/.gitignore index 9be39f9..09cbd40 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ CMakeLists.txt.user build +.vscode \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index fbe797e..6a3e190 100644 --- a/.travis.yml +++ b/.travis.yml @@ -96,7 +96,7 @@ install: ## Crypto++ (We dont need this for residue, we need it for ripe and mine) - git clone https://github.com/weidai11/cryptopp.git - - git clone https://github.com/amraynweb/cryptopp-pem.git + - git clone https://github.com/abumq/cryptopp-pem.git - cp cryptopp-pem/* cryptopp/ - cd cryptopp - make diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aec63f..6da1661 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## [1.1.0] - 20-07-2023 +- Updated Crypto++ dep to 8.8.0 +- Change C++ dependency to C++14 +- Using `std::array` instead of raw array +- C bindings (special shout out to [`spotzai`](https://github.com/spotzai) for PR) + ## [1.0.6] - 24-11-2018 - Updated license diff --git a/CMakeLists.txt b/CMakeLists.txt index b6cce99..731e955 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,15 +6,16 @@ option (test "Build all tests" OFF) option (BUILD_SHARED_LIBS "build shared libraries" ON) option (travis "Travis CI" OFF) +set (EXTERNAL_INCLUDE_DIR "external") + set (LICENSEPP_MAJOR "1") -set (LICENSEPP_MINOR "0") -set (LICENSEPP_PATCH "6") +set (LICENSEPP_MINOR "1") +set (LICENSEPP_PATCH "0") set (LICENSEPP_SOVERSION "${LICENSEPP_MAJOR}.${LICENSEPP_MINOR}.${LICENSEPP_PATCH}") set (LICENSEPP_NAME "licensepp") add_definitions (-DLICENSEPP_SOVERSION="${LICENSEPP_SOVERSION}") -add_definitions (-DRIPE_VERSION="4.0.1-custom-static") if (travis) add_definitions (-DLICENSEPP_ON_CI) endif() @@ -36,7 +37,7 @@ if (APPLE) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -Wall -Werror") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -O3 -Wall -Werror -Wno-return-stack-address") endif() # Check for cryptopp (static) @@ -45,13 +46,18 @@ find_package(CryptoPP REQUIRED) message ("-- Crypto++ binary: " ${CRYPTOPP_LIBRARY}) include_directories (${CRYPTOPP_INCLUDE_DIRS}) +# Ripe (static) +set(RIPE_USE_STATIC_LIBS OFF) +find_package(Ripe REQUIRED) + +include_directories (${EXTERNAL_INCLUDE_DIR}) set(LICENSEPP_SOURCE_FILES license++/license-exception.h license++/license.h license++/issuing-authority.h license++/base-license-manager.h - src/external/Ripe.cc + license++/c-bindings.h src/utils.cc src/json-object.cc src/crypto/aes.cc @@ -60,6 +66,7 @@ set(LICENSEPP_SOURCE_FILES src/crypto/rsa.cc src/issuing-authority.cc src/license.cc + src/c-bindings.cc ) add_library (licensepp-lib ${LICENSEPP_SOURCE_FILES}) @@ -68,8 +75,10 @@ set_target_properties (licensepp-lib PROPERTIES VERSION ${LICENSEPP_SOVERSION} ) target_include_directories (licensepp-lib PUBLIC $) + target_link_libraries (licensepp-lib ${CRYPTOPP_LIBRARIES} + ${RIPE_LIBRARY} ) set_target_properties (licensepp-lib PROPERTIES OUTPUT_NAME "licensepp") @@ -78,6 +87,7 @@ install (FILES license++/base-license-manager.h DESTINATION "include/license++") install (FILES license++/issuing-authority.h DESTINATION "include/license++") install (FILES license++/license.h DESTINATION "include/license++") install (FILES license++/license-exception.h DESTINATION "include/license++") +install (FILES license++/c-bindings.h DESTINATION "include/license++") install (EXPORT licensepp-config DESTINATION share/licensepp/cmake) export (TARGETS licensepp-lib FILE licensepp-config.cmake) @@ -95,20 +105,14 @@ set (CPACK_SOURCE_IGNORE_FILES ) include (CPack) -# Compile-time configuration. -configure_file ( - ${CMAKE_SOURCE_DIR}/cmake/config.h.cmake - ${CMAKE_BINARY_DIR}/config.h -) - include_directories (${CMAKE_BINARY_DIR}) include_directories (${CMAKE_SOURCE_DIR}) if (test) - find_package (gtest REQUIRED) + find_package (GTest REQUIRED) - include_directories (${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) + include_directories (${GTEST_INCLUDE_DIRS}) enable_testing() @@ -120,12 +124,12 @@ if (test) ) # Standard linking to gtest stuff. - target_link_libraries (licensepp-unit-tests gtest gtest_main) + target_link_libraries (licensepp-unit-tests + ${GTEST_LIBRARIES} + ) # Extra linking for the project. target_link_libraries (licensepp-unit-tests licensepp-lib) - 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 08ec2aa..ae8f0dc 100644 --- a/README.md +++ b/README.md @@ -23,21 +23,23 @@ I created a concept of digital software licence and implemented it under this pr ### Dependencies - * C++11 + * C++11 (C++14 if building with test since latest Google C++ Testing Library requires C++14) * [Crypto++](https://www.cryptopp.com/) v5.6.5+ [with Pem Pack](https://abumq.github.io/downloads/pem_pack.zip) * [cmake](https://cmake.org/) v2.8.12+ + * [Ripe](https://github.com/abumq/ripe) ### Installation * [Download](https://github.com/abumq/licensepp/archive/master.zip) or [clone](git@github.com:abumq/licensepp.git) the repository * Install Crypto++ ``` - git clone https://github.com/abumq/licensepp - git clone https://github.com/weidai11/cryptopp.git - git clone https://github.com/noloader/cryptopp-pem.git - cp cryptopp-pem/* cryptopp/ - cd cryptopp - make - sudo make install + wget https://raw.githubusercontent.com/abumq/abumq.github.io/master/downloads/cryptocpp.tar.gz + tar xf cryptocpp.tar.gz + cd cryptopp-CRYPTOPP_5_6_5 + wget https://raw.githubusercontent.com/abumq/abumq.github.io/master/downloads/pem_pack.zip + unzip pem_pack.zip + cmake . + make + sudo make install ``` * Use CMake to build the project ``` @@ -48,7 +50,7 @@ I created a concept of digital software licence and implemented it under this pr make sudo make install - ## build with test + ## build with test (make sure you have Google C++ Testing Library) cmake -Dtest=ON .. make sudo make install diff --git a/cli/Makefile b/cli/Makefile index 8b29257..1fef8ec 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -1,4 +1,4 @@ license-manager: main.cc licensing/license-manager-key-register.cc - g++ main.cc licensing/license-manager-key-register.cc -I/usr/local/lib -llicensepp -lcryptopp -std=c++11 -O3 -o license-manager + g++ main.cc licensing/license-manager-key-register.cc -I/usr/local/lib -llicensepp -std=c++11 -O3 -o license-manager diff --git a/cli/licensing/license-manager-key-register.cc b/cli/licensing/license-manager-key-register.cc index 4e6b158..d50d68e 100644 --- a/cli/licensing/license-manager-key-register.cc +++ b/cli/licensing/license-manager-key-register.cc @@ -2,7 +2,7 @@ using namespace licensepp; -const unsigned char LicenseManagerKeyRegister::LICENSE_MANAGER_SIGNATURE_KEY[16] = { +const std::array LicenseManagerKeyRegister::LICENSE_MANAGER_SIGNATURE_KEY = { 0x5B, 0x6A, 0xF5, 0x93, 0xED, 0xAB, 0xB3, 0x10, 0xF5, 0xBE, 0x00, 0xE6, 0x4F, 0x1B, 0x70, 0xC8 }; diff --git a/cli/licensing/license-manager-key-register.h b/cli/licensing/license-manager-key-register.h index 5036bbf..2e38f41 100644 --- a/cli/licensing/license-manager-key-register.h +++ b/cli/licensing/license-manager-key-register.h @@ -10,6 +10,7 @@ #ifndef LicenseManagerKeyRegister_h #define LicenseManagerKeyRegister_h +#include #include #include #include @@ -17,7 +18,7 @@ class LicenseManagerKeyRegister { public: - static const unsigned char LICENSE_MANAGER_SIGNATURE_KEY[]; + static const std::array LICENSE_MANAGER_SIGNATURE_KEY; static const std::vector LICENSE_ISSUING_AUTHORITIES; }; diff --git a/cli/main.cc b/cli/main.cc index c0dca8f..8db8179 100644 --- a/cli/main.cc +++ b/cli/main.cc @@ -3,7 +3,7 @@ // // Copyright © 2018-present @abumq (Majid Q.) // -// See https://github.com/amrayn/licensepp/blob/master/LICENSE +// See https://github.com/abumq/licensepp/blob/master/LICENSE // #include @@ -18,7 +18,7 @@ void displayUsage() { } void displayVersion() { - std::cout << "License Manager v1.0.0" << std::endl; + std::cout << "License Manager v1.1.0" << std::endl; } int main(int argc, char* argv[]) @@ -91,7 +91,7 @@ int main(int argc, char* argv[]) std::cout << "Invalid issuing authority." << std::endl; return 1; } - licensepp::License license = licenseManager.issue(licensee, period, issuingAuthority, secret, signature,additionalPayload); + licensepp::License license = licenseManager.issue(licensee, period, issuingAuthority, secret, signature, additionalPayload); std::cout << license.toString() << std::endl; std::cout << "Licensed to " << license.licensee() << std::endl; std::cout << "Subscription is active until " << license.formattedExpiry() << std::endl << std::endl; diff --git a/cmake/FindRipe.cmake b/cmake/FindRipe.cmake new file mode 100644 index 0000000..bf0130f --- /dev/null +++ b/cmake/FindRipe.cmake @@ -0,0 +1,39 @@ +# +# CMake module for Ripe cryptography wrapper +# +# Creates ${RIPE_INCLUDE_DIR} and ${RIPE_LIBRARY} +# +# If ${RIPE_USE_STATIC_LIBS} is ON then static libs are preferred over shared +# +# Copyright 2017-present @abumq (Majid Q.) +# +# https://github.com/abumq/ripe +# + +set(RIPE_PATHS ${RIPE_ROOT} $ENV{RIPE_ROOT}) + +find_path(RIPE_INCLUDE_DIR + Ripe.h + PATH_SUFFIXES include + PATHS ${RIPE_PATHS} +) + +if (RIPE_USE_STATIC_LIBS) + message ("-- Ripe: Static linking") + find_library(RIPE_LIBRARY + NAMES libripe.a + HINTS "${CMAKE_PREFIX_PATH}/lib" + ) +else() + message ("-- Ripe: Dynamic linking") + find_library(RIPE_LIBRARY + NAMES libripe.dylib + HINTS "${CMAKE_PREFIX_PATH}/lib" + ) +endif() + +message ("-- Ripe: Include: " ${RIPE_INCLUDE_DIR} ", Binary: " ${RIPE_LIBRARY}) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(Ripe REQUIRED_VARS RIPE_INCLUDE_DIR RIPE_LIBRARY) \ No newline at end of file diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake deleted file mode 100644 index 874da97..0000000 --- a/cmake/config.h.cmake +++ /dev/null @@ -1,10 +0,0 @@ -#define VERSION "@RESIDUE_VERSION@" - -#cmakedefine HAVE_ATTR_XATTR_H -#cmakedefine HAVE_SYS_XATTR_H -#cmakedefine XATTR_ADD_OPT - -#cmakedefine HAVE_LCHMOD - -#cmakedefine CMAKE_USE_PTHREADS_INIT - diff --git a/doxygen/README_DOXYGEN.md b/doxygen/README_DOXYGEN.md index d9fd4d8..16d739a 100644 --- a/doxygen/README_DOXYGEN.md +++ b/doxygen/README_DOXYGEN.md @@ -8,10 +8,9 @@ License++ is a cross platform software licensing library which allows you to imp ## Licence ``` -Copyright (c) 2018-present Amrayn Web Services +Copyright (c) 2018-present @abumq (Majid Q.) -https://github.com/amrayn/ -https://muflihun.com +https://github.com/abumq/ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/doxygen/customdoxygen.css b/doxygen/customdoxygen.css index 7eebd40..b8e4219 100644 --- a/doxygen/customdoxygen.css +++ b/doxygen/customdoxygen.css @@ -1399,7 +1399,7 @@ tr.heading h2 { text-shadow: none; } -div.image img[src="https://raw.githubusercontent.com/amrayn/residue/master/docs/Residue.png"] { +div.image img[src="https://raw.githubusercontent.com/abumq/residue/master/docs/Residue.png"] { width: 50%; max-width: 446px; } diff --git a/src/external/json.h b/external/json.h similarity index 100% rename from src/external/json.h rename to external/json.h diff --git a/license++/base-license-manager.h b/license++/base-license-manager.h index 90d5df8..242e03d 100644 --- a/license++/base-license-manager.h +++ b/license++/base-license-manager.h @@ -7,8 +7,8 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#ifndef BaseLicenseManager_h -#define BaseLicenseManager_h +#ifndef LICENSEPP_BaseLicenseManager_h +#define LICENSEPP_BaseLicenseManager_h #include #include @@ -27,7 +27,7 @@ namespace licensepp { /// key register. /// /// The key register must contains two static members. -/// 1. static const unsigned char LICENSE_MANAGER_SIGNATURE_KEY[]; +/// 1. static const std:array LICENSE_MANAGER_SIGNATURE_KEY; /// 2. static const std::vector LICENSE_ISSUING_AUTHORITIES; /// /// Definitions must be provided as well. @@ -37,12 +37,12 @@ namespace licensepp { /// class LicenseKeysRegister /// { /// public: -/// static const unsigned char LICENSE_MANAGER_SIGNATURE_KEY[]; +/// static const std::array LICENSE_MANAGER_SIGNATURE_KEY; /// /// static const std::vector LICENSE_ISSUING_AUTHORITIES; /// }; /// -/// const unsigned char LicenseKeysRegister::LICENSE_MANAGER_SIGNATURE_KEY[] = +/// const std::array LicenseKeysRegister::LICENSE_MANAGER_SIGNATURE_KEY = /// { /// 0x27, 0xD4, 0x91, 0x55, 0xE6, 0x6D, 0xC3, 0x11, /// 0x8D, 0xC0, 0x52, 0x0B, 0x2C, 0x9F, 0x84, 0xF3, @@ -65,7 +65,7 @@ namespace licensepp { /// }; /// /// -/// \see https://github.com/amrayn/licensepp/blob/master/sample/ +/// \see https://github.com/abumq/licensepp/blob/master/sample/ /// template class BaseLicenseManager @@ -145,12 +145,11 @@ class BaseLicenseManager { const std::string b16list = "0123456789ABCDEF"; std::stringstream ss; - for (auto i = 0; i < 16; ++i) { - ss << b16list[LicenseKeysRegister::LICENSE_MANAGER_SIGNATURE_KEY[i] >> 4] - << b16list[LicenseKeysRegister::LICENSE_MANAGER_SIGNATURE_KEY[i] & 0xf]; + for (const auto c : LicenseKeysRegister::LICENSE_MANAGER_SIGNATURE_KEY) { + ss << b16list[c >> 4] << b16list[c & 0xf]; } return ss.str(); } }; } -#endif // BaseLicenseManager_h +#endif // LICENSEPP_BaseLicenseManager_h diff --git a/license++/c-bindings.h b/license++/c-bindings.h new file mode 100644 index 0000000..edca1eb --- /dev/null +++ b/license++/c-bindings.h @@ -0,0 +1,227 @@ +#ifndef LICENSEPP_C_Bindings_h +#define LICENSEPP_C_Bindings_h + +#include + +// License +#ifdef __cplusplus +extern "C" +#endif + void* + license_create(); + +#ifdef __cplusplus +extern "C" +#endif + void + license_delete(void* license); + +#ifdef __cplusplus +extern "C" +#endif + int + license_load(void* license, const char* license_contents_base64); + +#ifdef __cplusplus +extern "C" +#endif + void + license_set_licensee(void* license, const char* licensee); + +#ifdef __cplusplus +extern "C" +#endif + void + license_set_issuing_authority_id(void* license, + const char* issuing_authority_id); + +#ifdef __cplusplus +extern "C" +#endif + void + license_set_licensee_signature(void* license, + const char* licensee_signature); + +#ifdef __cplusplus +extern "C" +#endif + void + license_set_authority_signature(void* license, + const char* authority_signature); + +#ifdef __cplusplus +extern "C" +#endif + void + license_set_expiry_date(void* license, const uint64_t expiry_date); + +#ifdef __cplusplus +extern "C" +#endif + void + license_set_issue_date(void* license, const uint64_t issue_date); + +#ifdef __cplusplus +extern "C" +#endif + void + license_set_additional_payload(void* license, + const char* additional_payload); + +#ifdef __cplusplus +extern "C" +#endif + const char* + license_get_licensee(const void* license); + +#ifdef __cplusplus +extern "C" +#endif + const char* + license_get_issuing_authority_id(const void* license); + +#ifdef __cplusplus +extern "C" +#endif + const char* + license_get_licensee_signature(const void* license); + +#ifdef __cplusplus +extern "C" +#endif + const char* + license_get_authority_signature(const void* license); + +#ifdef __cplusplus +extern "C" +#endif + uint64_t + license_get_expiry_date(const void* license); + +#ifdef __cplusplus +extern "C" +#endif + uint64_t + license_get_issue_date(const void* license); + +#ifdef __cplusplus +extern "C" +#endif + const char* + license_get_additional_payload(const void* license); + +// Issuing Authority +#ifdef __cplusplus +extern "C" +#endif + void* + issuing_authority_create(const char* id, const char* name, + const char* keypair, unsigned int max_validity, + int active); + +#ifdef __cplusplus +extern "C" +#endif + void + issuing_authority_delete(void* issuing_authority); + +#ifdef __cplusplus +extern "C" +#endif + const char* + issuing_authority_get_id(const void* issuing_authority); + +#ifdef __cplusplus +extern "C" +#endif + const char* + issuing_authority_get_name(const void* issuing_authority); + +#ifdef __cplusplus +extern "C" +#endif + int + issuing_authority_get_active(const void* issuing_authority); + +#ifdef __cplusplus +extern "C" +#endif + unsigned int + issuing_authority_get_max_validity(const void* issuing_authority); + +#ifdef __cplusplus +extern "C" +#endif + void* + issuing_authority_issue(const void* issuing_authority, const char* licensee, + unsigned int validity_period, + const char* master_key, const char* secret, + const char* licensee_signature, + const char* additional_payload); + +#ifdef __cplusplus +extern "C" +#endif + int + issuing_authority_validate(const void* issuing_authority, + const void* license, const char* master_key, + int validate_signature, + const char* licensee_signature); + +// License Manager +#ifdef __cplusplus +extern "C" +#endif + void* + license_manager_create(); + +#ifdef __cplusplus +extern "C" +#endif + void + license_manager_delete(void* license_manager); + +#ifdef __cplusplus +extern "C" +#endif + const void* + license_manager_get_issuing_authority(const void* license_manager, + const void* license); + +#ifdef __cplusplus +extern "C" +#endif + const void* + license_manager_issue(const void* license_manager, const char* licensee, + unsigned int validity_period, + const void* issuing_authority, + const char* issuing_authority_secret, + const char* licensee_signature, + const char* additional_payload); + +#ifdef __cplusplus +extern "C" +#endif + int + license_manager_validate(const void* license_manager, const void* license, + int verify_licensee_signature, + const char* licensee_signature); + +typedef struct IssuingAuthorityParameters { + const char* authority_id; + const char* authority_name; + const char* keypair; + unsigned int max_validity; + int active; + struct IssuingAuthorityParameters* next; +} IssuingAuthorityParameters; + +#ifdef __cplusplus +extern "C" +#endif + void + license_key_register_init( + const unsigned char* license_manager_signature_key, + const IssuingAuthorityParameters* issuing_authority_parameters); + +#endif /* LICENSEPP_C_Bindings_h */ \ No newline at end of file diff --git a/license++/issuing-authority.h b/license++/issuing-authority.h index 53eff38..819e3d6 100644 --- a/license++/issuing-authority.h +++ b/license++/issuing-authority.h @@ -7,8 +7,8 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#ifndef IssuingAuthority_h -#define IssuingAuthority_h +#ifndef LICENSEPP_IssuingAuthority_h +#define LICENSEPP_IssuingAuthority_h #include #include @@ -28,12 +28,12 @@ class IssuingAuthority IssuingAuthority(const IssuingAuthority&); IssuingAuthority& operator=(IssuingAuthority); - inline std::string id() const + inline const std::string& id() const { return m_id; } - inline std::string name() const + inline const std::string& name() const { return m_name; } @@ -87,4 +87,4 @@ class IssuingAuthority }; } -#endif /* IssuingAuthority_h */ +#endif /* LICENSEPP_IssuingAuthority_h */ diff --git a/license++/license-exception.h b/license++/license-exception.h index 044ee3a..5264a8f 100644 --- a/license++/license-exception.h +++ b/license++/license-exception.h @@ -7,8 +7,8 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#ifndef LicenseException_h -#define LicenseException_h +#ifndef LICENSEPP_LicenseException_h +#define LICENSEPP_LicenseException_h #include @@ -30,4 +30,4 @@ class LicenseException : public LicenseExceptionBase, public std::runtime_error }; } -#endif /* LicenseException_h */ +#endif /* LICENSEPP_LicenseException_h */ diff --git a/license++/license.h b/license++/license.h index c9a8e3e..ab6c984 100644 --- a/license++/license.h +++ b/license++/license.h @@ -7,8 +7,8 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#ifndef License_h -#define License_h +#ifndef LICENSEPP_License_h +#define LICENSEPP_License_h #include @@ -57,22 +57,22 @@ class License m_additionalPayload = additionalPayload; } - inline std::string licensee() const + inline const std::string& licensee() const { return m_licensee; } - inline std::string issuingAuthorityId() const + inline const std::string& issuingAuthorityId() const { return m_issuingAuthorityId; } - inline std::string licenseeSignature() const + inline const std::string& licenseeSignature() const { return m_licenseeSignature; } - inline std::string authoritySignature() const + inline const std::string& authoritySignature() const { return m_authoritySignature; } @@ -87,12 +87,11 @@ class License return m_issueDate; } - inline std::string additionalPayload() const + inline const std::string& additionalPayload() const { return m_additionalPayload; } - std::string toString(); /// @@ -130,4 +129,4 @@ class License }; } -#endif /* License_h */ +#endif /* LICENSEPP_License_h */ diff --git a/sample/README.md b/sample/README.md index 5c490e9..9e9ceb3 100644 --- a/sample/README.md +++ b/sample/README.md @@ -3,25 +3,19 @@ After you build using `make` run: ``` -./license-manager-sample --license sample.licensepp -``` -or -``` -LD_LIBRARY_PATH=/usr/local/lib/ ./license-manager-sample --license sample.licensepp -``` -or -``` -LD_LIBRARY_PATH=../build ./license-manager-sample --license sample.licensepp +┗━━━━ $ ./license-manager-sample --license sample.licensepp +Licensed to sample-license +Subscription is active until 07 Jan, 2028 12:23 UTC ``` ``` -./license-manager-sample --license sample-with-signature.licensepp --signature sample-signature +┗━━━━ $ ./license-manager-sample --license sample-with-signature.licensepp --signature sample-signature +Licensed to sample-license +Subscription is active until 07 Jan, 2028 12:24 UTC ``` -or -``` -LD_LIBRARY_PATH=/usr/local/lib/ ./license-manager-sample --license sample-with-signature.licensepp --signature sample-signature -``` -or + ``` -LD_LIBRARY_PATH=../build ./license-manager-sample --license sample-with-signature.licensepp --signature sample-signature +┗━━━━ $ ./license-manager-sample --license sample-with-signature.licensepp +License is not valid ``` + diff --git a/sample/license-manager.h b/sample/license-manager.h index 22ab512..ccf3f9e 100644 --- a/sample/license-manager.h +++ b/sample/license-manager.h @@ -18,12 +18,12 @@ using namespace licensepp; class LicenseKeysRegister { public: - static const unsigned char LICENSE_MANAGER_SIGNATURE_KEY[]; + static const std::array LICENSE_MANAGER_SIGNATURE_KEY; static const std::vector LICENSE_ISSUING_AUTHORITIES; }; -const unsigned char LicenseKeysRegister::LICENSE_MANAGER_SIGNATURE_KEY[] = +const std::array LicenseKeysRegister::LICENSE_MANAGER_SIGNATURE_KEY = { 0x5B, 0x6A, 0xF5, 0x93, 0xED, 0xAB, 0xB3, 0x10, 0xF5, 0xBE, 0x00, 0xE6, 0x4F, 0x1B, 0x70, 0xC8 }; diff --git a/src/c-bindings.cc b/src/c-bindings.cc new file mode 100644 index 0000000..a7aa06d --- /dev/null +++ b/src/c-bindings.cc @@ -0,0 +1,271 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "license++/base-license-manager.h" + +namespace licensepp { +class CLicenseKeysRegister { + public: + static const std::array LICENSE_MANAGER_SIGNATURE_KEY; + static const std::vector<::licensepp::IssuingAuthority> + LICENSE_ISSUING_AUTHORITIES; + + static void initialize_license_issuing_authorities( + const unsigned char* license_manager_signature_key, + const IssuingAuthorityParameters* issuing_authority_parameters) { + auto authorities = (std::vector*)&CLicenseKeysRegister:: + LICENSE_ISSUING_AUTHORITIES; + authorities->clear(); + + auto p = issuing_authority_parameters; + while (p) { + authorities->emplace_back(::licensepp::IssuingAuthority( + p->authority_id, p->authority_name, p->keypair, p->max_validity, + p->active)); + p = p->next; + } + + auto signature_key = + (std::array*)&CLicenseKeysRegister::LICENSE_MANAGER_SIGNATURE_KEY; + memcpy(signature_key->data(), license_manager_signature_key, + 16 * sizeof(unsigned char)); + } +}; + +const std::array + CLicenseKeysRegister::LICENSE_MANAGER_SIGNATURE_KEY = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +const std::vector<::licensepp::IssuingAuthority> + CLicenseKeysRegister::LICENSE_ISSUING_AUTHORITIES = + std::vector(); + +} // namespace licensepp + +// License Key Register +extern "C" void license_key_register_init( + const unsigned char* license_manager_signature_key, + const IssuingAuthorityParameters* issuing_authority_parameters) { + ::licensepp::CLicenseKeysRegister::initialize_license_issuing_authorities( + license_manager_signature_key, issuing_authority_parameters); +} + +// License +extern "C" void* license_create() { return new ::licensepp::License(); } + +extern "C" void license_delete(void* license) { + ::licensepp::License* p = (::licensepp::License*)license; + delete p; +} + +extern "C" int license_load(void* license, + const char* license_contents_base64) { + ::licensepp::License* p = (::licensepp::License*)license; + return p->load(license_contents_base64); +} + +extern "C" void license_set_licensee(void* license, const char* licensee) { + ::licensepp::License* p = (::licensepp::License*)license; + p->setLicensee(licensee); +} + +extern "C" void license_set_issuing_authority_id( + void* license, const char* issuing_authority_id) { + ::licensepp::License* p = (::licensepp::License*)license; + p->setIssuingAuthorityId(issuing_authority_id); +} + +extern "C" void license_set_licensee_signature(void* license, + const char* licensee_signature) { + ::licensepp::License* p = (::licensepp::License*)license; + p->setLicenseeSignature(licensee_signature); +} + +extern "C" void license_set_authority_signature( + void* license, const char* authority_signature) { + ::licensepp::License* p = (::licensepp::License*)license; + p->setAuthoritySignature(authority_signature); +} + +extern "C" void license_set_expiry_date(void* license, + const uint64_t expiry_date) { + ::licensepp::License* p = (::licensepp::License*)license; + p->setExpiryDate(expiry_date); +} + +extern "C" void license_set_issue_date(void* license, + const uint64_t issue_date) { + ::licensepp::License* p = (::licensepp::License*)license; + p->setIssueDate(issue_date); +} + +extern "C" void license_set_additional_payload(void* license, + const char* additional_payload) { + ::licensepp::License* p = (::licensepp::License*)license; + p->setAdditionalPayload(additional_payload); +} + +extern "C" const char* license_get_licensee(const void* license) { + ::licensepp::License* p = (::licensepp::License*)license; + return p->licensee().c_str(); +} + +extern "C" const char* license_get_issuing_authority_id(const void* license) { + ::licensepp::License* p = (::licensepp::License*)license; + return p->issuingAuthorityId().c_str(); +} + +extern "C" const char* license_get_licensee_signature(const void* license) { + ::licensepp::License* p = (::licensepp::License*)license; + return p->licenseeSignature().c_str(); +} + +extern "C" const char* license_get_authority_signature(const void* license) { + ::licensepp::License* p = (::licensepp::License*)license; + return p->authoritySignature().c_str(); +} + +extern "C" uint64_t license_get_expiry_date(const void* license) { + ::licensepp::License* p = (::licensepp::License*)license; + return p->expiryDate(); +} + +extern "C" uint64_t license_get_issue_date(const void* license) { + ::licensepp::License* p = (::licensepp::License*)license; + return p->issueDate(); +} + +extern "C" const char* license_get_additional_payload(const void* license) { + ::licensepp::License* p = (::licensepp::License*)license; + return p->additionalPayload().c_str(); +} + +// Issuing Authority +extern "C" void* issuing_authority_create(const char* id, const char* name, + const char* keypair, + unsigned int max_validity, + int active) { + std::string _id(id); + std::string _name(name); + std::string _keypair(keypair); + return new ::licensepp::IssuingAuthority(_id, _name, _keypair, max_validity, + active); +} + +extern "C" void issuing_authority_delete(void* issuing_authority) { + ::licensepp::IssuingAuthority* p = + (::licensepp::IssuingAuthority*)issuing_authority; + delete p; +} + +extern "C" const char* issuing_authority_get_id(const void* issuing_authority) { + ::licensepp::IssuingAuthority* p = + (::licensepp::IssuingAuthority*)issuing_authority; + return p->id().c_str(); +} + +extern "C" const char* issuing_authority_get_name( + const void* issuing_authority) { + ::licensepp::IssuingAuthority* p = + (::licensepp::IssuingAuthority*)issuing_authority; + return p->name().c_str(); +} + +extern "C" int issuing_authority_get_active(const void* issuing_authority) { + ::licensepp::IssuingAuthority* p = + (::licensepp::IssuingAuthority*)issuing_authority; + return p->active(); +} + +extern "C" unsigned int issuing_authority_get_max_validity( + const void* issuing_authority) { + ::licensepp::IssuingAuthority* p = + (::licensepp::IssuingAuthority*)issuing_authority; + return p->maxValidity(); +} + +extern "C" void* issuing_authority_issue( + const void* issuing_authority, const char* licensee, + unsigned int validity_period, const char* master_key, const char* secret, + const char* licensee_signature, const char* additional_payload) { + ::licensepp::IssuingAuthority* p = + (::licensepp::IssuingAuthority*)issuing_authority; + std::string _licensee(licensee); + std::string _master_key(master_key); + std::string _secret(secret); + std::string _licensee_signature(licensee_signature); + std::string _additional_payload(additional_payload); + + auto license = p->issue(_licensee, validity_period, _master_key, _secret, + _licensee_signature, _additional_payload); + return new ::licensepp::License(license); +} + +extern "C" int issuing_authority_validate(const void* issuing_authority, + const void* license, + const char* master_key, + int validate_signature, + const char* licensee_signature) { + ::licensepp::IssuingAuthority* p = + (::licensepp::IssuingAuthority*)issuing_authority; + ::licensepp::License* _license = (::licensepp::License*)license; + std::string _master_key(master_key); + std::string _licensee_signature(licensee_signature); + return p->validate(_license, _master_key, validate_signature, + _licensee_signature); +} + +// License Manager +extern "C" void* license_manager_create() { + return new ::licensepp::BaseLicenseManager< + ::licensepp::CLicenseKeysRegister>(); +} + +extern "C" void license_manager_delete(void* license_manager) { + ::licensepp::BaseLicenseManager<::licensepp::CLicenseKeysRegister>* p = + (::licensepp::BaseLicenseManager<::licensepp::CLicenseKeysRegister>*) + license_manager; + delete p; +} + +extern "C" const void* license_manager_get_issuing_authority( + const void* license_manager, const void* license) { + ::licensepp::BaseLicenseManager<::licensepp::CLicenseKeysRegister>* p = + (::licensepp::BaseLicenseManager<::licensepp::CLicenseKeysRegister>*) + license_manager; + return p->getIssuingAuthority((const ::licensepp::License*)license); +} + +extern "C" const void* license_manager_issue( + const void* license_manager, const char* licensee, + unsigned int validity_period, const void* issuing_authority, + const char* issuing_authority_secret, const char* licensee_signature, + const char* additional_payload) { + ::licensepp::BaseLicenseManager<::licensepp::CLicenseKeysRegister>* p = + (::licensepp::BaseLicenseManager<::licensepp::CLicenseKeysRegister>*) + license_manager; + return new ::licensepp::License(p->issue( + licensee, validity_period, + (const ::licensepp::IssuingAuthority*)issuing_authority, + issuing_authority_secret, licensee_signature, additional_payload)); +} + +extern "C" int license_manager_validate(const void* license_manager, + const void* license, + int verify_licensee_signature, + const char* licensee_signature) { + ::licensepp::BaseLicenseManager<::licensepp::CLicenseKeysRegister>* p = + (::licensepp::BaseLicenseManager<::licensepp::CLicenseKeysRegister>*) + license_manager; + return p->validate((const ::licensepp::License*)license, + verify_licensee_signature, licensee_signature); +} \ No newline at end of file diff --git a/src/crypto/aes.cc b/src/crypto/aes.cc index aaf2bdc..99248f5 100644 --- a/src/crypto/aes.cc +++ b/src/crypto/aes.cc @@ -7,7 +7,8 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#include "src/external/Ripe.h" +#include + #include "src/crypto/aes.h" using namespace licensepp; diff --git a/src/crypto/aes.h b/src/crypto/aes.h index b78fb67..7f6d92e 100644 --- a/src/crypto/aes.h +++ b/src/crypto/aes.h @@ -7,8 +7,8 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#ifndef AES_h -#define AES_h +#ifndef LICENSEPP_AES_h +#define LICENSEPP_AES_h #include @@ -43,4 +43,4 @@ class AES }; } -#endif /* AES_h */ +#endif /* LICENSEPP_AES_h */ diff --git a/src/crypto/base16.cc b/src/crypto/base16.cc index e0619fa..8190bca 100644 --- a/src/crypto/base16.cc +++ b/src/crypto/base16.cc @@ -7,7 +7,7 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#include "src/external/Ripe.h" +#include #include "src/crypto/base16.h" using namespace licensepp; diff --git a/src/crypto/base16.h b/src/crypto/base16.h index d979476..db82a5c 100644 --- a/src/crypto/base16.h +++ b/src/crypto/base16.h @@ -7,8 +7,8 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#ifndef Base16_h -#define Base16_h +#ifndef LICENSEPP_Base16_h +#define LICENSEPP_Base16_h #include @@ -25,4 +25,4 @@ class Base16 }; } -#endif /* Base16_h */ +#endif /* LICENSEPP_Base16_h */ diff --git a/src/crypto/base64.cc b/src/crypto/base64.cc index 1249dbc..017c748 100644 --- a/src/crypto/base64.cc +++ b/src/crypto/base64.cc @@ -7,7 +7,8 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#include "src/external/Ripe.h" +#include + #include "src/crypto/base64.h" using namespace licensepp; diff --git a/src/crypto/base64.h b/src/crypto/base64.h index ea2adcb..d9909a0 100644 --- a/src/crypto/base64.h +++ b/src/crypto/base64.h @@ -7,8 +7,8 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#ifndef Base64_h -#define Base64_h +#ifndef LICENSEPP_Base64_h +#define LICENSEPP_Base64_h #include @@ -25,4 +25,4 @@ class Base64 }; } -#endif /* Base64_h */ +#endif /* LICENSEPP_Base64_h */ diff --git a/src/crypto/rsa.cc b/src/crypto/rsa.cc index 79c571a..266afb6 100644 --- a/src/crypto/rsa.cc +++ b/src/crypto/rsa.cc @@ -7,7 +7,8 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#include "src/external/Ripe.h" +#include + #include "src/crypto/rsa.h" #include "src/crypto/base64.h" diff --git a/src/crypto/rsa.h b/src/crypto/rsa.h index dd8576e..fcf732c 100644 --- a/src/crypto/rsa.h +++ b/src/crypto/rsa.h @@ -7,8 +7,8 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#ifndef RSA_h -#define RSA_h +#ifndef LICENSEPP_RSA_h +#define LICENSEPP_RSA_h #include @@ -51,4 +51,4 @@ class RSA }; } -#endif /* RSA_h */ +#endif /* LICENSEPP_RSA_h */ diff --git a/src/external/Ripe.cc b/src/external/Ripe.cc deleted file mode 100644 index 7a82dac..0000000 --- a/src/external/Ripe.cc +++ /dev/null @@ -1,624 +0,0 @@ -// -// Ripe -// -// Copyright 2017-present @abumq (Majid Q.) -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "Ripe.h" - -#define RIPE_UNUSED(x) (void)x - -using namespace CryptoPP; - -const std::string Ripe::PACKET_DELIMITER = "\r\n\r\n"; -const std::size_t Ripe::PACKET_DELIMITER_SIZE = Ripe::PACKET_DELIMITER.size(); -const char Ripe::DATA_DELIMITER = ':'; -const int Ripe::DEFAULT_RSA_LENGTH = 2048; -const int Ripe::ZLIB_BUFFER_SIZE = 32768; -const int Ripe::AES_BLOCK_SIZE = AES::BLOCKSIZE; -const std::string Ripe::BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; -const std::string Ripe::PRIVATE_RSA_ALGORITHM = "AES-256-CBC"; - -bool loadPrivateKey(const std::string& key, RSA::PrivateKey& keyOut, const std::string& secret) -{ - StringSource source(key, true); - if (secret.empty()) { - PEM_Load(source, keyOut); - } else { - PEM_Load(source, keyOut, secret.data(), secret.size()); - } - AutoSeededRandomPool prng; - return keyOut.Validate(prng, 3); -} - -bool loadPublicKey(const std::string& key, RSA::PublicKey& keyOut) -{ - StringSource source(key, true); - PEM_Load(source, keyOut); - AutoSeededRandomPool prng; - return keyOut.Validate(prng, 3); -} - -std::string Ripe::encryptRSA(const std::string& data, const std::string& publicKeyPEM) -{ - RSA::PublicKey publicKey; - bool rsaKeyValid = loadPublicKey(publicKeyPEM, publicKey); - if (!rsaKeyValid) { - throw std::invalid_argument("Could not load public key"); - } - - RSAES::Encryptor e(publicKey); - - std::string result; - AutoSeededRandomPool rng; - StringSource ss(data, true, - new PK_EncryptorFilter(rng, e, - new StringSink(result) - ) - ); - RIPE_UNUSED(ss); - return result; -} - -std::string Ripe::encryptRSA(std::string& data, const std::string& key, const std::string& outputFile, bool isRaw) -{ - try { - std::string encryptedData = Ripe::encryptRSA(data, key); - if (!isRaw) { - encryptedData = Ripe::base64Encode(encryptedData); - } - if (!outputFile.empty()) { - std::ofstream out(outputFile.c_str()); - out.write(encryptedData.c_str(), encryptedData.size()); - out.flush(); - out.close(); - return ""; - } - return encryptedData; - } catch (const std::exception& e) { - throw e; - } -} - -std::string Ripe::decryptRSA(const std::string& data, const std::string& privateKeyPEM, const std::string& secret) -{ - RSA::PrivateKey privateKey; - bool rsaKeyValid = loadPrivateKey(privateKeyPEM, privateKey, secret); - if (!rsaKeyValid) { - throw std::invalid_argument("Could not load private key"); - } - - std::string result; - AutoSeededRandomPool rng; - RSAES::Decryptor d(privateKey); - - StringSource ss(data, true, - new PK_DecryptorFilter(rng, d, - new StringSink(result) - ) - ); - RIPE_UNUSED(ss); - return result; -} - -std::string Ripe::decryptRSA(std::string& data, const std::string& key, bool isBase64, bool isHex, const std::string& secret) -{ - if (isBase64) { - data = Ripe::base64Decode(data); - } - - if (isHex) { - data = Ripe::hexToString(data); - } - return Ripe::decryptRSA(data, key, secret); -} - -bool Ripe::verifyRSA(const std::string& data, const std::string& signatureHex, const std::string& publicKeyPEM) -{ - RSA::PublicKey publicKey; - bool rsaKeyValid = loadPublicKey(publicKeyPEM, publicKey); - if (!rsaKeyValid) { - throw std::invalid_argument("Could not load public key"); - } - std::string decodedSignature = Ripe::hexToString(signatureHex); - bool result = false; - RSASS::Verifier verifier(publicKey); - StringSource ss2(decodedSignature + data, true, - new SignatureVerificationFilter(verifier, - new ArraySink((RipeByte*)&result, sizeof(result)))); - return result; -} - -std::string Ripe::signRSA(const std::string& data, const std::string& privateKeyPEM, const std::string& privateKeySecret) -{ - RSA::PrivateKey privateKey; - bool rsaKeyValid = loadPrivateKey(privateKeyPEM, privateKey, privateKeySecret); - if (!rsaKeyValid) { - throw std::invalid_argument("Could not load private key"); - } - - // sign message - std::string signature; - RSASS::Signer signer(privateKey); - AutoSeededRandomPool rng; - - StringSource ss(data, true, - new SignerFilter(rng, signer, - new HexEncoder( - new StringSink(signature)))); - return signature; -} - -bool Ripe::writeRSAKeyPair(const std::string& publicFile, const std::string& privateFile, int length, const std::string& secret) -{ - bool result = true; - KeyPair keypair = Ripe::generateRSAKeyPair(length, secret); - if (keypair.privateKey.size() > 0 && keypair.publicKey.size() > 0) { - std::ofstream fs(privateFile.c_str(), std::ios::out); - if (fs.is_open()) { - fs.write(keypair.privateKey.c_str(), keypair.privateKey.size()); - fs.close(); - } else { - throw std::runtime_error( - std::string("Unable to open private file for writing [" + privateFile + "] " + std::strerror(errno)).data() - ); - result = false; - } - fs.open(publicFile.c_str(), std::ios::out); - if (fs.is_open()) { - fs.write(keypair.publicKey.c_str(), keypair.publicKey.size()); - fs.close(); - result = result && true; - } else { - throw std::runtime_error( - std::string("Unable to open public file for writing [" + publicFile + "] " + std::strerror(errno)).data() - ); - result = false; - } - } - if (!result) { - throw std::runtime_error("Failed to generate key pair."); - } - return result; -} - -std::string Ripe::generateRSAKeyPairBase64(int length, const std::string& secret) -{ - Ripe::KeyPair pair = Ripe::generateRSAKeyPair(length, secret); - if (pair.privateKey.empty() || pair.publicKey.empty()) { - throw std::runtime_error("Failed to generate key pair."); - } - return Ripe::base64Encode(pair.privateKey) + ":" + Ripe::base64Encode(pair.publicKey); -} - -Ripe::KeyPair Ripe::generateRSAKeyPair(unsigned int length, const std::string& secret) -{ - AutoSeededRandomPool rng; - InvertibleRSAFunction params; - params.GenerateRandomWithKeySize(rng, length); - RSA::PrivateKey privateKey(params); - RSA::PublicKey publicKey(params); - - Ripe::KeyPair pair; - { - StringSink snk(pair.privateKey); - if (secret.empty()) { - PEM_Save(snk, privateKey); - } else { - PEM_Save(snk, privateKey, rng, PRIVATE_RSA_ALGORITHM, secret.data(), secret.size()); - } - snk.MessageEnd(); - } - { - StringSink snk(pair.publicKey); - PEM_Save(snk, publicKey); - snk.MessageEnd(); - } - return pair; -} - -std::string Ripe::base64Encode(const std::string& input) -{ - std::string encoded; - StringSource ss(input, true, new Base64Encoder( - new StringSink(encoded), false /* insert line breaks */) - ); - RIPE_UNUSED(ss); - return encoded; -} - -std::string Ripe::base64Decode(const std::string& base64Encoded) -{ - std::string decoded; - StringSource ss(base64Encoded, true, new Base64Decoder( - new StringSink(decoded)) - ); - RIPE_UNUSED(ss); - return decoded; -} - -std::string Ripe::generateNewKey(int length) -{ - if (!(length == 16 || length == 24 || length == 32)) { - throw std::invalid_argument( "Invalid key length. Acceptable lengths are 16, 24 or 32" ); - } - AutoSeededRandomPool rnd; - SecByteBlock key(length); - rnd.GenerateBlock(key, key.size()); - std::string s; - HexEncoder hex(new StringSink(s)); - hex.Put(key.data(), key.size()); - hex.MessageEnd(); - return s; -} - -std::string Ripe::encryptAES(const std::string& buffer, const RipeByte* key, std::size_t keySize, std::vector& iv) -{ - SecByteBlock keyBlock(key, keySize); - - RipeByte ivArr[Ripe::AES_BLOCK_SIZE] = {0}; - - if (iv.empty()) { - AutoSeededRandomPool rnd; - rnd.GenerateBlock(ivArr, sizeof ivArr); - } else { - for (std::size_t i = 0; i < iv.size(); ++i) { - ivArr[i] = iv.at(i); - } - } - - - std::string cipher; - - CBC_Mode::Encryption e; - e.SetKeyWithIV(keyBlock, keyBlock.size(), ivArr); - - if (iv.empty()) { - // store for user - iv.resize(sizeof ivArr); - std::copy(ivArr, ivArr + Ripe::AES_BLOCK_SIZE, iv.begin()); - } - - // The StreamTransformationFilter adds padding as required. - StringSource ss(buffer, true, - new StreamTransformationFilter(e, new StringSink(cipher)) - ); - RIPE_UNUSED(ss); - return cipher; -} - -std::string Ripe::encryptAES(std::string& data, const std::string& hexKey, const std::string& clientId, const std::string& outputFile, const std::string& ivec) -{ - std::stringstream ss; - if (!outputFile.empty()) { - std::vector iv; - if (!ivec.empty()) { - RipeByte* ivBytes = reinterpret_cast(const_cast(ivec.data())); - iv = Ripe::RipeByteToVec(ivBytes); - } - std::string encrypted = Ripe::encryptAES(data, hexKey, iv); - - std::ofstream out(outputFile.c_str()); - out << encrypted.data(); - out.close(); - ss << "IV: " << std::hex << std::setfill('0'); - for (std::vector::const_iterator it = iv.begin(); it < iv.end(); ++it) { - ss << std::setw(2) << static_cast(*it); - } - ss << std::endl; - } else { - ss << Ripe::prepareData(data, hexKey, clientId.c_str(), ivec); - } - return ss.str(); -} - -std::string Ripe::decryptAES(const std::string& data, const RipeByte* key, std::size_t keySize, std::vector& iv) -{ - std::string result; - SecByteBlock keyBlock(key, keySize); - - RipeByte ivArr[Ripe::AES_BLOCK_SIZE] = {0}; - std::copy(iv.begin(), iv.end(), ivArr); - - CBC_Mode::Decryption d; - d.SetKeyWithIV(keyBlock, keyBlock.size(), ivArr); - - StringSource ss(data, true, - new StreamTransformationFilter( d, new StringSink(result)) - ); - RIPE_UNUSED(ss); - return result; -} - -std::string Ripe::decryptAES(std::string& data, const std::string& hexKey, std::string& ivec, bool isBase64, bool isHex) -{ - if (ivec.empty() && isBase64) { - // Extract IV from data - std::size_t pos = data.find_first_of(':'); - if (pos == 32) { - ivec = data.substr(0, pos); - Ripe::normalizeHex(ivec); - data = data.substr(pos + 1); - pos = data.find_first_of(':'); - if (pos != std::string::npos) { - // We ignore clientId which is = data.substr(0, pos); - data = data.substr(pos + 1); - } - } - } - if (ivec.size() == 32) { - // Condensed form needs to be normalized - Ripe::normalizeHex(ivec); - } - - RipeByte* iv = reinterpret_cast(const_cast(ivec.data())); - std::vector ivHex = Ripe::RipeByteToVec(iv); - - if (isBase64) { - data = Ripe::base64Decode(data); - } - if (isHex) { - data = Ripe::hexToString(data); - } - 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 != NULL ? zs.msg : "no 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 != NULL ? zs.msg : "no msg"); - throw std::runtime_error(oss.str()); - } - - return outstring; -} - -std::string Ripe::sha256Hash(const std::string& data) -{ - std::string digest; - SHA256 hasher; - StringSource ss(data, true, new HashFilter(hasher, new HexEncoder(new StringSink(digest)))); - return digest; -} - -std::string Ripe::sha512Hash(const std::string& data) -{ - std::string digest; - CryptoPP::SHA512 hasher; - StringSource ss(data, true, new HashFilter(hasher, new HexEncoder(new StringSink(digest)))); - return digest; -} - -std::string Ripe::prepareData(const std::string& data, const std::string& hexKey, const char* clientId, const std::string& ivec) -{ - std::vector iv; - if (!ivec.empty()) { - std::string ivector(ivec); - if (ivector.size() == 32) { - Ripe::normalizeHex(ivector); - } - RipeByte* ivBytes = reinterpret_cast(const_cast(ivector.data())); - iv = Ripe::RipeByteToVec(ivBytes); - } - std::string encrypted = Ripe::encryptAES(data, hexKey, iv); - // Encryption Base64 encoding - std::string base64Encoded = Ripe::base64Encode(encrypted); - - // IV Hex - std::stringstream ss; - ss << std::hex << std::setfill('0'); - for (std::vector::const_iterator it = iv.begin(); it < iv.end(); ++it) { - ss << std::setw(2) << static_cast(*it); - } - ss << Ripe::DATA_DELIMITER; - if (strlen(clientId) > 0) { - ss << clientId << Ripe::DATA_DELIMITER; - } - ss << base64Encoded; - std::stringstream fss; - fss << ss.str() << PACKET_DELIMITER; - return fss.str(); -} - -bool Ripe::normalizeHex(std::string& iv) -{ - if (iv.size() == 32) { - for (int j = 2; j < 32 + 15; j += 2) { - iv.insert(j, " "); - j++; - } - return true; - } - return false; -} - -std::string Ripe::vecToString(const std::vector& iv) -{ - std::stringstream ss; - ss << std::hex << std::setfill('0'); - for (std::vector::const_iterator it = iv.begin(); it < iv.end(); ++it) { - ss << std::setw(2) << static_cast(*it); - } - return ss.str(); -} - -std::vector Ripe::RipeByteToVec(const RipeByte* b) -{ - std::vector hexData; - - std::istringstream ss(reinterpret_cast(b)); - - unsigned int c; - while (ss >> std::hex >> c) { - hexData.push_back(c); - } - return hexData; -} - -std::string Ripe::hexToString(const std::string& hex) -{ - std::string result; - StringSource ss(hex, true, - new HexDecoder( - new StringSink(result) - ) - ); - RIPE_UNUSED(ss); - return result; -} - -std::string Ripe::stringToHex(const std::string& raw) -{ - std::string result; - StringSource ss(raw, true, - new HexEncoder( - new StringSink(result) - ) - ); - RIPE_UNUSED(ss); - return result; -} - -std::size_t Ripe::expectedDataSize(std::size_t plainDataSize, std::size_t clientIdSize) -{ - std::size_t dataSize = 32 /* IV */ - + sizeof(DATA_DELIMITER) /* : */ - + (clientIdSize > 0 ? clientIdSize + sizeof(DATA_DELIMITER) : 0) - + expectedBase64Length(expectedAESCipherLength(plainDataSize)); - return dataSize + PACKET_DELIMITER_SIZE; -} - -std::string Ripe::version() -{ - return RIPE_VERSION; -} diff --git a/src/external/Ripe.h b/src/external/Ripe.h deleted file mode 100644 index f5b499f..0000000 --- a/src/external/Ripe.h +++ /dev/null @@ -1,470 +0,0 @@ -// -// Ripe -// -// Copyright 2017-present @abumq (Majid Q.) -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#ifndef Ripe_h -#define Ripe_h - -#include -#include -#include - -typedef unsigned char RipeByte; - -#ifdef RIPE_DLL -#ifdef RIPE_EXPORTS -#define RIPE_API __declspec(dllexport) -#else -#define RIPE_API __declspec(dllimport) -#endif -#else -#define RIPE_API -#endif - -/// -/// \brief The Ripe class is core of Ripe library and contains all -/// the required cryptography API supported by Ripe -/// -RIPE_API class Ripe { -public: - - /// - /// \brief Constant for end of data delimiter - /// - static const std::string PACKET_DELIMITER; - - /// - /// \brief Size of PACKET_DELIMITER - /// \see PACKET_DELIMITER - /// - static const std::size_t PACKET_DELIMITER_SIZE; - - /// - /// \brief Data delimiter for prepared data - /// \see prepareData(const char*, const std::string&, const char*) - /// - static const char DATA_DELIMITER; - - /// - /// \brief Constant value default rsa length - /// - static const int DEFAULT_RSA_LENGTH; - - /// - /// \brief Constant value for AES block size - /// - static const int AES_BLOCK_SIZE; - - /// - /// \brief Possible base64 characters - /// - static const std::string BASE64_CHARS; - - /// - /// \brief Algorithm for private rsa key - /// - static const std::string PRIVATE_RSA_ALGORITHM; - - /// - /// \brief Buffer size for zlib - /// - static const int ZLIB_BUFFER_SIZE; - - /// - /// \brief RSA Key pair - /// - struct KeyPair { - /// - /// \brief Private key of this pair - /// - std::string privateKey; - - /// - /// \brief Public key of this pair - /// - std::string publicKey; - }; - - /*****************************************************************************************************/ - - /*******************************************************************\ - * AES * - ******************************************************************* - ******************************************************************* - * * - * CRYPTO * - * * - ******************************************************************* - ******************************************************************* - \*******************************************************************/ - - - /// - /// \brief Encrypts data of length with symmetric key of size = keySize with specified initialization vector - /// - static std::string encryptAES(const std::string& data, const RipeByte* key, std::size_t keySize, std::vector& iv); - - /// - /// \brief Decrypts data of specified length with specified key and initialization vector - /// - static std::string decryptAES(const std::string& data, const RipeByte* key, std::size_t keySize, std::vector& iv); - - /// - /// \brief Generate random AES key - /// \param length Length of key, must be 16, 24 or 32 - /// \return Hexadecimal value of key - /// - static std::string generateNewKey(int length); - - - - - /*****************************************************************************************************/ - - /*******************************************************************\ - * AES * - ******************************************************************* - ******************************************************************* - * * - * HELPERS * - * * - ******************************************************************* - ******************************************************************* - \*******************************************************************/ - - - /// - /// \brief encryptAES Encrypts data with provided symmetric key - /// \param outputFile Optional, if provided instead of printing it to console data is saved to file and IV is printed on console - /// - static std::string encryptAES(std::string& data, const std::string& hexKey, const std::string& clientId, const std::string& outputFile, const std::string& iv = ""); - - /// - /// \brief Helper function that takes hex key - /// \see encryptAES(std::string& data, const std::string& hexKey, const std::string& clientId, const std::string& outputFile) - /// - inline static std::string encryptAES(const std::string& buffer, const std::string& hexKey, std::vector& iv) - { - return encryptAES(buffer, reinterpret_cast(hexToString(hexKey).c_str()), hexKey.size() / 2, iv); - } - - /// - /// \brief decryptAES Decrypts data using specified symmetric key. - /// \param isBase64 If true, first base64 decoding is done on data and then decryption is processed - /// \param isHex If true, hex string is decoded. If base64 is true, base64 decoding is done before hex decoding - /// - static std::string decryptAES(std::string& data, const std::string& hexKey, std::string& iv, bool isBase64 = false, bool isHex = false); - - - /// - /// \brief Exceptect size of AES cipher when plainDataSize size data is encrypted - /// - inline static std::size_t expectedAESCipherLength(std::size_t plainDataSize) - { - return (plainDataSize / AES_BLOCK_SIZE + 1) * AES_BLOCK_SIZE; - } - - /// - /// \brief normalizeIV If IV with no space is provided e.g,
67e56fee50e22a8c2ba05c0fb2932bfa:
normalized IV - /// is
67 e5 6f ee 50 e2 2a 8c 2b a0 5c 0f b2 93 2b fa:
- /// - static bool normalizeHex(std::string& iv); - - - - /*****************************************************************************************************/ - - /*******************************************************************\ - * RSA * - ******************************************************************* - ******************************************************************* - * * - * CRYPTO * - * * - ******************************************************************* - ******************************************************************* - \*******************************************************************/ - - - /// - /// \brief Encrypts data of length = dataLength using RSA key and puts it in destination - /// - /// Ripe uses PKCS #1 v1.5 padding scheme - /// - /// \return The size of the encrypted data. On error -1 is returned. use printLastError(const char*) to see the error details - /// - static std::string encryptRSA(const std::string& data, const std::string& publicKeyPEM); - - /// - /// \brief Decrypts encryptedData of length dataLength with RSA key and puts result in destination - /// - /// Ripe uses PKCS #1 v1.5 padding scheme - /// - /// \return The size of the recovered plaintext. On error -1 is returned. use printLastError(const char* name) to see the error details - /// - static std::string decryptRSA(const std::string& data, const std::string& privateKeyPEM, const std::string& secret = ""); - - /// - /// \brief Verifies the data is signed by associated private key - /// \param data The data to verify - /// \param signatureHex Signature in hex format - /// \param publicKeyPEM Public key to verify the data from - /// - static bool verifyRSA(const std::string& data, const std::string& signatureHex, const std::string& publicKeyPEM); - - /// - /// \brief Signs the data with private key - /// \param data The data to sign - /// \param privateKeyPEM private key to sign the data with - /// \param secret Private key secret - /// \return Hex format signature - /// - static std::string signRSA(const std::string& data, const std::string& privateKeyPEM, const std::string& secret = ""); - - /// - /// \brief Generate key pair and returns KeyPair - /// \param length Length of the key (2048 for 256-bit key, ...) - /// \param secret Password for private RSA key (if any) - /// \see KeyPair - /// - static KeyPair generateRSAKeyPair(unsigned int length = DEFAULT_RSA_LENGTH, const std::string& secret = ""); - - - - - /*****************************************************************************************************/ - - /*******************************************************************\ - * RSA * - ******************************************************************* - ******************************************************************* - * * - * HELPERS * - * * - ******************************************************************* - ******************************************************************* - \*******************************************************************/ - - /// - /// \brief Maximum size of RSA block with specified key size - /// \param keySize 2048 for 256-bit key, ... - /// - inline static unsigned int maxRSABlockSize(std::size_t keySize) - { - return (keySize / 8) - 11; - } - - /// - /// \brief Minimum size of RSA key to encrypt data of dataSize size - /// - inline static unsigned int minRSAKeySize(std::size_t dataSize) - { - return (dataSize + 11) * 8; - } - - /// - /// \brief encryptRSA Encrypts using RSA key - /// \param outputFile Optional, if provided instead of printing it to console data is saved to file - /// \param isRaw Outputs raw data - /// - static std::string encryptRSA(std::string& data, const std::string& key, const std::string& outputFile, bool isRaw = false); - - /// - /// \brief decryptRSA Decrypts using RSA key - /// \param isHex If true, hex string is decoded. If base64 is true, base64 decoding is done before hex decoding - /// \param isBase64 If true, first base64 decoding is done on data and then decryption is processed - /// - static std::string decryptRSA(std::string& data, const std::string& key, bool isBase64, bool isHex = false, const std::string& secret = ""); - - /// - /// \brief writeRSAKeyPair Writes RSA key pair to public and private file paths. - /// \param publicFile Output path for public file. It must be wriable. - /// \param privateFile Output path for private file. It must be writable. - /// \param length Length of the key (2048 for 256-bit key, ...) - /// \param secret Password for private RSA key (if any) - /// - static bool writeRSAKeyPair(const std::string& publicFile, const std::string& privateFile, int length = DEFAULT_RSA_LENGTH, const std::string& secret = ""); - - /// - /// \brief generateRSAKeyPair Generates RSA key pair and returns colon seperated base64 where first part is private key and second part is public key. - /// - static std::string generateRSAKeyPairBase64(int length = DEFAULT_RSA_LENGTH, const std::string& secret = ""); - - - - /*****************************************************************************************************/ - - /*******************************************************************\ - * MISC * - ******************************************************************* - ******************************************************************* - * * - * Base64 * - * * - ******************************************************************* - ******************************************************************* - \*******************************************************************/ - - /// - /// \brief Decodes encoded base64 - /// - static std::string base64Decode(const std::string& base64Encoded); - - /// - /// \brief Encodes input of length to base64 encoding - /// - static std::string base64Encode(const std::string& binaryData); - - /// - /// \brief expectedBase64Length Returns expected base64 length - /// \param n Length of input (plain data) - /// - inline static std::size_t expectedBase64Length(std::size_t n) - { - return ((4 * n / 3) + 3) & ~0x03; - } - - /// - /// \brief Finds whether data is base64 encoded. This is done - /// by finding non-base64 character. So it is not necessary - /// a valid base64 encoding. - /// - inline static bool isBase64(const std::string& data) - { - return data.find_first_not_of(BASE64_CHARS) == std::string::npos; - } - - - /*****************************************************************************************************/ - - /*******************************************************************\ - * MISC * - ******************************************************************* - ******************************************************************* - * * - * ZLib * - * * - ******************************************************************* - ******************************************************************* - \*******************************************************************/ - - /** - * @brief Compress input file (path) and create new file - * @param gzFilename Output file path - * @param inputFile Input file path - * @return True if successful, otherwise false - */ - static bool compressFile(const std::string& gzFilename, const std::string& inputFile); - - /** - * @brief Compresses string using zlib (inflate) - * @param str Input plain text - * @return Raw output (binary) - */ - static std::string compressString(const std::string& str); - - /** - * @brief Decompresses string using zlib (deflate) - * @param str Raw input - * @return Plain output - */ - static std::string decompressString(const std::string& str); - - /*****************************************************************************************************/ - - /*******************************************************************\ - * MISC * - ******************************************************************* - ******************************************************************* - * * - * SHA * - * * - ******************************************************************* - ******************************************************************* - \*******************************************************************/ - - /** - * @brief Generate SHA-256 hash of given string - */ - static std::string sha256Hash(const std::string&); - - - /** - * @brief Generate SHA-512 hash of given string - */ - static std::string sha512Hash(const std::string&); - - - /*****************************************************************************************************/ - - /*******************************************************************\ - * MISC * - ******************************************************************* - ******************************************************************* - * * - * OTHERS * - * * - ******************************************************************* - ******************************************************************* - \*******************************************************************/ - - /// - /// \brief prepareData Helper method to encrypt data with symmetric key and convert it in to tranferable data. - /// \param clientId Extra text in between representing client ID (leave empty if you don't need it) - /// \param ivec Init vector, if empty, random is generated - /// \return Base64 format of encrypted data with format:
[LENGTH]:[IV]:[[Client_ID]:]:[Base64 Data]
- /// - static std::string prepareData(const std::string& data, const std::string& hexKey, const char* clientId = "", const std::string& ivec = ""); - - /// - /// \brief Calculates expected data size. Assumed IV size = 32 - /// \see prepareData(const char*, const std::string&, const char*) - /// - static std::size_t expectedDataSize(std::size_t plainDataSize, std::size_t clientIdSize = 16); - - /// - /// \brief Helper function to convert string to hexdecimal e.g, khn = 6b686e. - /// - static std::string stringToHex(const std::string& raw); - - /// - /// \brief Helper function to convert hexadecimal input to raw data - /// - static std::string hexToString(const std::string& hex); - - /// - /// \brief Converts vector of RipeByte to raw string - /// - static std::string vecToString(const std::vector& iv); - - /// - /// \brief ivToVector Converts plain (unsigned char*) IV to std::vector - /// - static std::vector RipeByteToVec(const RipeByte* iv); - - /// - /// \brief version Version of Ripe library - /// - static std::string version(); - -private: - - Ripe() {} - Ripe(const Ripe&) {} - Ripe& operator=(const Ripe&) { return *this; } -}; -#endif /* Ripe_h */ diff --git a/src/issuing-authority.cc b/src/issuing-authority.cc index adf8298..54ed635 100644 --- a/src/issuing-authority.cc +++ b/src/issuing-authority.cc @@ -115,7 +115,7 @@ License IssuingAuthority::issue(const std::string& licensee, } if (!validate(&license, masterKey, true, licenseeSignature)) { - throw LicenseException("Failed to validate new license. Please report it @https://github.com/amrayn/licensepp"); + throw LicenseException("Failed to validate new license. Please report it @https://github.com/abumq/licensepp"); } return license; } diff --git a/src/json-object.h b/src/json-object.h index 931d567..06d88d0 100644 --- a/src/json-object.h +++ b/src/json-object.h @@ -7,11 +7,11 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#ifndef JsonObject_h -#define JsonObject_h +#ifndef LICENSEPP_JsonObject_h +#define LICENSEPP_JsonObject_h #include -#include "src/external/json.h" +#include namespace licensepp { @@ -108,4 +108,4 @@ class JsonObject }; } -#endif /* JsonObject_h */ +#endif /* LICENSEPP_JsonObject_h */ diff --git a/src/license.cc b/src/license.cc index 0cfbc30..e75566c 100644 --- a/src/license.cc +++ b/src/license.cc @@ -33,19 +33,7 @@ std::string License::formattedExpiry() const std::string License::toString() { - JsonObject::Json j; - j["licensee"] = m_licensee; - if (!m_licenseeSignature.empty()) { - j["licensee_signature"] = m_licenseeSignature; - } - j["issue_date"] = m_issueDate; - j["expiry_date"] = m_expiryDate; - j["issuing_authority"] = m_issuingAuthorityId; - j["authority_signature"] = m_authoritySignature; - if(!m_additionalPayload.empty()) { - j["additional_payload"] = m_additionalPayload; - } - return Base64::encode(j.dump()); + return Base64::encode(raw()); } std::string License::raw() const @@ -58,7 +46,8 @@ std::string License::raw() const j["issue_date"] = m_issueDate; j["expiry_date"] = m_expiryDate; j["issuing_authority"] = m_issuingAuthorityId; - if(!m_additionalPayload.empty()) { + j["authority_signature"] = m_authoritySignature; + if (!m_additionalPayload.empty()) { j["additional_payload"] = m_additionalPayload; } return j.dump(); diff --git a/src/utils.h b/src/utils.h index 1963522..0575e61 100644 --- a/src/utils.h +++ b/src/utils.h @@ -7,8 +7,8 @@ // See https://github.com/abumq/licensepp/blob/master/LICENSE // -#ifndef Utils_h -#define Utils_h +#ifndef LICENSEPP_Utils_h +#define LICENSEPP_Utils_h #if (defined(_WIN32) || defined(_WIN64)) # define LICENSEPP_OS_WINDOWS 1 @@ -94,4 +94,4 @@ class Utils static char* parseFormat(char* buf, std::size_t bufSz, const char* format, const struct tm* tInfo, std::size_t msec); }; } -#endif /* Utils_h */ +#endif /* LICENSEPP_Utils_h */ diff --git a/test/license-manager-for-test.h b/test/license-manager-for-test.h index d0e3b5c..d00d162 100644 --- a/test/license-manager-for-test.h +++ b/test/license-manager-for-test.h @@ -19,21 +19,21 @@ using namespace licensepp; class LicenseManagerKeyRegister { public: - static const unsigned char LICENSE_MANAGER_SIGNATURE_KEY[]; + static const std::array LICENSE_MANAGER_SIGNATURE_KEY; static const std::vector LICENSE_ISSUING_AUTHORITIES; }; -const unsigned char LicenseManagerKeyRegister::LICENSE_MANAGER_SIGNATURE_KEY[] = +const std::array LicenseManagerKeyRegister::LICENSE_MANAGER_SIGNATURE_KEY = { 0x82, 0xF3, 0x6C, 0x25, 0xA9, 0x12, 0x38, 0x9A, 0xBF, 0xF8, 0x09, 0x1C, 0x75, 0x93, 0x03, 0xD2 }; const std::vector LicenseManagerKeyRegister::LICENSE_ISSUING_AUTHORITIES = { - IssuingAuthority("unittest-issuer-1", "Amrayn Web Services (development)", "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlDV3dJQkFBS0JnUUMrTU9RbGhUUlhRTXRuK1JpdjNwVWNWdmdZdkpiWG5SeHdSL24xcTFPR1llUWlEdVY4CmlOOVcyQlVDQWVjVE1CVEJMK0xZSndpMnErWEVWclZZZjF6NTVPRWpicmJyK3hRQitJYU5uNTIzWUpRRGdQd1IKU0ROMnp5dzhmSDRBUVVENjk3VnRYamJaVXFaL1ZOZU1iaFJoRnhJV2lkMDVIVk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TiBQVUJMSUMgS0VZLS0tLS0KTUlHZE1BMEdDU3FHU0liM0RRRUJBUVVBQTRHTEFEQ0Jod0tCZ1FEZytydnlLWlRqSGhsWVB2Uy8yeUlWaDRlRQpOZ09Eb2U5YmhFbVFiZ1hHSVJYbjY5azhnejdUWnFRbzNFUzQ3Vy9uR2Q4K2tYWk82azZTd0ZrS2FMTjlMbzJhCk5XbkhMQUxLa3lOVU5wTGs4Z3Excko1cFErS3ZlSGMvcjdOUVM1Y0RzaW95aXp0T281Y3puNTRxdTFzajlLbVEKd0xNS0trVy8wcjFEazk4Z0lRSUJFUT09Ci0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQo=", 25U, true), // 25 hours - secret: unit-test-issuer-secret - IssuingAuthority("sample-license-authority", "Amrayn Web Services (dev)", "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb1FJQkFBS0NBUUVBdHhnSlBDVklIUGp4VmpnMDVlMnVaNURqNDN IdDF0WFlUK3VkVVRTL3RrSlgyQzltCnFoOGpLUHVPZkF1enFiUCtlenJBdENIQ3ptRE5sZkUwamVOU1VUZlFWbFhxNzd3UGh6ajZWNm1lWTNlcmYxK0oKVGNHUTk1Q0U3QWxRZmlvTm1aMU1OOTBSOXo2QllJMFJpVHh1QVFXckZqdm1r MUsrZ1RRN2dPbVV1WEx1MzJ2RwppNVE0cElKVHBJMExYQkp5QnJVNEs1ZTdWTVhaMHQrb1dRc3djcm05bkJYWVpleVRJcUZ2VmVkbEpxZTArTm9GCk8zeE91VHYxSiticWtWeFFuQlczQ2dyR2tjT0ZWRWtEQ0ROOEZoZ0N5SEpJRDliZ kdsNlBJUEp0TE94UlF2M20KSituaktNcnF5a3BPaWp6WXNyUjRSWXlEV0w2dm1hMlpSZGlZS1FJQkVRS0NBUUFKYklnQk5wL3licklSblQ3MQpQdzZmcnZ5cnRPdzk0WmhQYUZ6TmwydS8rQjdmMVVObTM3aGwzOFZ6ajZrL1VxMFpLbz J1Nn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0FLQ0FRRUF0eGdKUENWSUhQanhWamcwNWUydQpaNURqNDNIdDF0WFlUK3VkVVRTL3RrSlgyQzltcWg 4aktQdU9mQXV6cWJQK2V6ckF0Q0hDem1ETmxmRTBqZU5TClVUZlFWbFhxNzd3UGh6ajZWNm1lWTNlcmYxK0pUY0dROTVDRTdBbFFmaW9ObVoxTU45MFI5ejZCWUkwUmlUeHUKQVFXckZqdm1rMUsrZ1RRN2dPbVV1WEx1MzJ2R2k1UTRw SUpUcEkwTFhCSnlCclU0SzVlN1ZNWFowdCtvV1Fzdwpjcm05bkJYWVpleVRJcUZ2VmVkbEpxZTArTm9GTzN4T3VUdjFKK2Jxa1Z4UW5CVzNDZ3JHa2NPRlZFa0RDRE44CkZoZ0N5SEpJRDliZkdsNlBJUEp0TE94UlF2M21KK25qS01yc XlrcE9panpZc3JSNFJZeURXTDZ2bWEyWlJkaVkKS1FJQkVRPT0KLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==", 87600U, true), }; class LicenseManagerForTest : public BaseLicenseManager diff --git a/test/test.h b/test/test.h index eee8476..f2bd812 100644 --- a/test/test.h +++ b/test/test.h @@ -15,6 +15,6 @@ #define PARAM(v) std::get(item) -using namespace muflihun::testx; +using namespace abumq::testx; #endif // TEST_H diff --git a/test/testx.h b/test/testx.h index 0e63932..914de6a 100644 --- a/test/testx.h +++ b/test/testx.h @@ -4,21 +4,19 @@ // TestX 1.0.1 // Single header, header only helper for creating test data // -// Copyright (c) 2017 Amrayn Web Services +// Copyright (c) 2017 @abumq (Majid Q.) // // This library is released under the MIT Licence. // -// https://github.com/amrayn/testx -// https://amrayn.com -// http://muflihun.com +// https://github.com/abumq/testx // -#ifndef MUFLIHUN_TEST_X_H -#define MUFLIHUN_TEST_X_H +#ifndef ABUMQ_TEST_X_H +#define ABUMQ_TEST_X_H #include #include -namespace muflihun { +namespace abumq { namespace testx { template @@ -30,6 +28,6 @@ std::tuple TestCase(T... f) { } } // namespace testx -} // namespace muflihun +} // namespace abumq -#endif // MUFLIHUN_TEST_X_H +#endif // ABUMQ_TEST_X_H