diff --git a/CHANGELOG.md b/CHANGELOG.md index f5b0a8d..8ddfe41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [1.0.3] - 10-01-2018 +### Fixes +- Fix date format across different timezones + ## [1.0.2] - 09-01-2018 ### Updates - Removed unnecessary zlib dependency diff --git a/CMakeLists.txt b/CMakeLists.txt index 013eb21..17b3281 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ option (travis "Travis CI" OFF) set (LICENSEPP_MAJOR "1") set (LICENSEPP_MINOR "0") -set (LICENSEPP_PATCH "2") +set (LICENSEPP_PATCH "3") set (LICENSEPP_SOVERSION "${LICENSEPP_MAJOR}.${LICENSEPP_MINOR}.${LICENSEPP_PATCH}") set (LICENSEPP_NAME "licensepp") diff --git a/license++/license.h b/license++/license.h index cac9e16..f3e21c6 100644 --- a/license++/license.h +++ b/license++/license.h @@ -96,9 +96,16 @@ class License /// /// \brief Loads itself from base64 input + /// \throws LicenseException if license is invalid /// bool load(const std::string& licenseBase64); + /// + /// \brief Loads itself from license file containing base64 license + /// \throws LicenseException if license is invalid + /// + bool loadFromFile(const std::string& licensefile); + protected: unsigned long m_issueDate; diff --git a/sample/README.md b/sample/README.md new file mode 100644 index 0000000..8e2eaed --- /dev/null +++ b/sample/README.md @@ -0,0 +1,11 @@ +### Sample + +After you build using `make` run: + +``` +./license-manager-sample --license sample.licensepp +``` + +``` +./license-manager-sample --license sample-with-signature.licensepp --signature sample-signature +``` diff --git a/sample/license-manager.h b/sample/license-manager.h index 8638ef7..f2fed8a 100644 --- a/sample/license-manager.h +++ b/sample/license-manager.h @@ -23,15 +23,12 @@ class LicenseKeysRegister const unsigned char LicenseKeysRegister::LICENSE_MANAGER_SIGNATURE_KEY[] = { - 0x27, 0xD4, 0x91, 0x55, 0xE6, 0x6D, 0xC3, 0x11, 0x8D, 0xC0, 0x52, 0x0B, 0x2C, 0x9F, 0x84, 0xF3, + 0x5B, 0x6A, 0xF5, 0x93, 0xED, 0xAB, 0xB3, 0x10, 0xF5, 0xBE, 0x00, 0xE6, 0x4F, 0x1B, 0x70, 0xC8 }; const std::vector LicenseKeysRegister::LICENSE_ISSUING_AUTHORITIES = { - IssuingAuthority("custom-license-manager-1", "Muflihun Labs 1", "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlDV3dJQkFBS0JnUUMrTU9RbGhUUlhRTXRuK1JpdjNwVWNWdmdZdkpiWG5SeHdSL24xcTFPR1llUWlEdVY4CmlOOVcyQlVDQWVjVE1CVEJMK0xZSndpMnErWEVWclZZZjF6NTVPRWpicmJyK3hRQitJYU5uNTIzWUpRRGdQd1IKU0ROMnp5dzhmSDRBUVVENjk3VnRYamJaVXFaL1ZOZU1iaFJoRnhJV2lkMDVIVkE1THM5bkdFMllNd0lCRVFLQgpnRTVRWGZGVTkyODR6RG5mQ2lwTWw4QmdDODN6VFN1YkM3WERTTTZSMXhrM1hlL29CQ1E0Vy9hVk5kT21ialVUCnpFK01NRHJpNVhoazVpT3JPNXpwSmtnUjJpVGszb2xJK1YvUVNacXBnZ2xBRnJ5aVMzVW1IMTlLVmVKdERaTmgKK2ZtU21WL0Y0T0xhNTFIVTY5eEYzZUdTRmlMVnNiY2ZMUVhtdVpUNDBJNDVBa0VBMWVkMDJOdDd0VUp2VU5vdApoWGUwTk1FTWFUdFZsbVk3WHFxcTNNOG5kRFhoTkxmL1loVFQ1MVNRQkp6U1hYa2pNRnI1NU5NclhQMkxjdnFkClhTeXNwd0pCQU9PZXdyTXN0U2JocWZiNW4xbnFOZGxTbXJJdURPZUJDdUNNYTd0cFRrelFseFhTRjYzYlRETWcKS0pSSEVOU2s5WVB2RVRCYWRaa3VldFNrWC9FbWJaVUNRUUN3S0FYZnc4OUorbm5LSFJadDZodnZOWkhBRXI3MApWRERrakl5MTE4WWpkNnBucHBZVWlaOXpOcFM0Z1NXMlk4S2dTdXZwbnRocXNxOFRaUG9RZnlURkFrQnJ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OG8rc3hQWnYrWXpWdTVHV0xONmRDc3ExYWgvNXhyQWF4WlRVSFRWUG4KYy9YMHNJbGhUM0Q0TUNSbnNWRGJsZVdKL2R3V25MNm02TFA5RlpOckZFTXAzamFyanhPWVNkcTA1NmpnUW5EUQpXbFA4SWJLTi9udC9TVU1zZXcrbDFaM01vMW43aE1FL3VPbkxzYWNJZi9ZR1ArbWlJYXVFTDc1cVpwZGpzK1ZQCjRqUWFoTUxFUkZHMWRzK002MWJFbU9SRFRtY3pabWozRmMzQ01tRzVwSG41ZFFmaWNNSmdDZ29ZT3RBLzUwYzAKVjZWUXZyYnhFTXRGRmxjamZKRmpXZjFpaGJXbWdPMmVudDZUUzFqTjd5MD0KLS0tLS1FTkQgUlNBIFBSSVZBVEUgS0VZLS0tLS0K:LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlHZE1BMEdDU3FHU0liM0RRRUJBUVVBQTRHTEFEQ0Jod0tCZ1FEZytydnlLWlRqSGhsWVB2Uy8yeUlWaDRlRQpOZ09Eb2U5YmhFbVFiZ1hHSVJYbjY5azhnejdUWnFRbzNFUzQ3Vy9uR2Q4K2tYWk82azZTd0ZrS2FMTjlMbzJhCk5XbkhMQUxLa3lOVU5wTGs4Z3Excko1cFErS3ZlSGMvcjdOUVM1Y0RzaW95aXp0T281Y3puNTRxdTFzajlLbVEKd0xNS0trVy8wcjFEazk4Z0lRSUJFUT09Ci0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQo=", 25U, true), // 25 hours - secret: unit-test-issuer-secret + IssuingAuthority("sample-license-authority", "Sample License Authority", "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb1FJQkFBS0NBUUVBdHhnSlBDVklIUGp4VmpnMDVlMnVaNURqNDNIdDF0WFlUK3VkVVRTL3RrSlgyQzltCnFoOGpLUHVPZkF1enFiUCtlenJBdENIQ3ptRE5sZkUwamVOU1VUZlFWbFhxNzd3UGh6ajZWNm1lWTNlcm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NSUlCQ0FLQ0FRRUF0eGdKUENWSUhQanhWamcwNWUydQpaNURqNDNIdDF0WFlUK3VkVVRTL3RrSlgyQzltcWg4aktQdU9mQXV6cWJQK2V6ckF0Q0hDem1ETmxmRTBqZU5TClVUZlFWbFhxNzd3UGh6ajZWNm1lWTNlcmYxK0pUY0dROTVDRTdBbFFmaW9ObVoxTU45MFI5ejZCWUkwUmlUeHUKQVFXckZqdm1rMUsrZ1RRN2dPbVV1WEx1MzJ2R2k1UTRwSUpUcEkwTFhCSnlCclU0SzVlN1ZNWFowdCtvV1Fzdwpjcm05bkJYWVpleVRJcUZ2VmVkbEpxZTArTm9GTzN4T3VUdjFKK2Jxa1Z4UW5CVzNDZ3JHa2NPRlZFa0RDRE44CkZoZ0N5SEpJRDliZkdsNlBJUEp0TE94UlF2M21KK25qS01ycXlrcE9panpZc3JSNFJZeURXTDZ2bWEyWlJkaVkKS1FJQkVRPT0KLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg==", 87600U, true), // 10 years max }; - class LicenseManager : public BaseLicenseManager { public: diff --git a/sample/main.cc b/sample/main.cc index 301b008..f1201b7 100644 --- a/sample/main.cc +++ b/sample/main.cc @@ -27,24 +27,21 @@ int main(int argc, char* argv[]) } } - LicenseManager licenseManager; if (!licenseFile.empty()) { - std::ifstream stream(licenseFile); - if (!stream.is_open()) { - std::cerr << "Failed to open file " << licenseFile << std::endl; - } else { - - std::string licenseKey = std::string((std::istreambuf_iterator(stream)), - (std::istreambuf_iterator())); - stream.close(); - License license; - license.load(licenseKey); - if (!licenseManager.validate(&license, true, signature)) { - std::cout << "License is not valid"; - } else { - std::cout << "Licensed to " << license.licensee() << std::endl; - std::cout << "Subscription is active until " << license.formattedExpiry() << std::endl << std::endl; + License license; + try { + if (license.loadFromFile(licenseFile)) { + LicenseManager licenseManager; + if (!licenseManager.validate(&license, true, signature)) { + std::cout << "License is not valid"; + } else { + std::cout << "Licensed to " << license.licensee() << std::endl; + std::cout << "Subscription is active until " << license.formattedExpiry() << std::endl << std::endl; + } + } + } catch (LicenseException& e) { + std::cerr << "Exception thrown " << e.what() << std::endl; } } else { std::cout << "License file not provided" << std::endl; diff --git a/sample/sample-with-signature.licensepp b/sample/sample-with-signature.licensepp new file mode 100644 index 0000000..7f56beb --- /dev/null +++ b/sample/sample-with-signature.licensepp @@ -0,0 +1 @@ +eyJhdXRob3JpdHlfc2lnbmF0dXJlIjoiOEE5MTVGMTAyQzgzQjJDQUY4MEEwNTEyNTJBQjJEODQ0NUVGM0YyRkFEQjBGOERGOUI1MURFMUUwMDg3NUI2NEZBRDNGOTk3Q0EzREQ3QjJCMTFGRjNBMTk5MEU3RkEwMzU1NTczNUY5QTI5MjIyQ0RFNDJBMjQ1OEM3NEM1MkJGRTRDMzA4N0REOUJDQ0U5MEZDQUJGNUY5NzUzMzA0NTcyQTM1NTNGN0VEOTgyOTE0MUQ1QUNGREQ0QzY4MERGRUVEMjk5QjA1ODBFRkQ5MkFDMTA3NDhDOEI0MUM2QTk0NUI2QTBEOTk0RTNBRjQzRDA1RDBBQzJFRTMzOUZEMDMxMDk3NDU4RjdFNzU2MThDMEEyODE3RDBCMzE3NjUyMkNBQjlBRjdENkYzNzA0NjFFRkIxRUNFOTBENEY5NjkyQkE4QkZDRjk3QTg2OENFNkFDRDRDMzcwQUZBQzg4MTVBMEZEMTA5MzBENTBDN0EzNDk2M0M4NzhFMzA1M0UwRTlGOERERjA2OTA3QTc0RjEyREY4RDc0MEM1M0JBQkE4NzQ4MEY3MzIzOEIxMjE0MUVCNzMyRDg5NjQxRjU3QUZEOTI1OEY0RDI3NTIwNDQyQzVBQzZENjFBODE1NzIzOTE2NUVENTg4OTBBNzgwRURBQzk1Q0U5RTg0NDkwNkYiLCJleHBpcnlfZGF0ZSI6MTgzMDg2MDY5MiwiaXNzdWVfZGF0ZSI6MTUxNTUwMDY5MiwiaXNzdWluZ19hdXRob3JpdHkiOiJzYW1wbGUtbGljZW5zZS1hdXRob3JpdHkiLCJsaWNlbn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wQTkzNkUzNzg1REY0RkFEMzdGMUMzMDQzNjFDM0JEMDZGOTQiLCJleHBpcnlfZGF0ZSI6MTgzMDg2MDU4NSwiaXNzdWVfZGF0ZSI6MTUxNTUwMDU4NSwiaXNzdWluZ19hdXRob3JpdHkiOiJzYW1wbGUtbGljZW5zZS1hdXRob3JpdHkiLCJsaWNlbnNlZSI6InNhbXBsZS1saWNlbnNlIn0= diff --git a/src/license.cc b/src/license.cc index 3a26a78..372f291 100644 --- a/src/license.cc +++ b/src/license.cc @@ -6,6 +6,8 @@ // #include +#include +#include #include #include #include "src/crypto/base64.h" @@ -18,7 +20,6 @@ License::License() : m_issueDate(0), m_expiryDate(0) { - } License::License(const License& other): @@ -47,7 +48,6 @@ std::string License::formattedExpiry() const return Utils::timevalToString(tval, "%d %b, %Y %H:%m UTC"); } - std::string License::toString() { JsonObject::Json j; @@ -95,3 +95,20 @@ bool License::load(const std::string& licenseBase64) } return false; } + +bool License::loadFromFile(const std::string& licenseFile) +{ + if (!licenseFile.empty()) { + std::ifstream stream(licenseFile); + if (!stream.is_open()) { + std::cerr << "Failed to open file " << licenseFile << std::endl; + return false; + } else { + std::string licenseContents = std::string((std::istreambuf_iterator(stream)), + (std::istreambuf_iterator())); + stream.close(); + return load(licenseContents); + } + } + return false; +} diff --git a/src/utils.cc b/src/utils.cc index 6b88b7c..921245a 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -10,11 +10,18 @@ using namespace licensepp; - -const char* Utils::kDays[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; -const char* Utils::kDaysAbbrev[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; -const char* Utils::kMonths[12] = { "January", "February", "March", "Apri", "May", "June", "July", "August", "September", "October", "November", "December" }; -const char* Utils::kMonthsAbbrev[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; +const char* Utils::kDays[7] = { "Sunday", "Monday", "Tuesday", + "Wednesday", "Thursday", "Friday", + "Saturday" }; +const char* Utils::kDaysAbbrev[7] = { "Sun", "Mon", "Tue", + "Wed", "Thu", "Fri", "Sat" }; +const char* Utils::kMonths[12] = { "January", "February", "March", + "Apri", "May", "June", "July", + "August", "September", "October", + "November", "December" }; +const char* Utils::kMonthsAbbrev[12] = { "Jan", "Feb", "Mar", "Apr", + "May", "Jun", "Jul", "Aug", + "Sep", "Oct", "Nov", "Dec" }; unsigned long long Utils::nowUtc() { @@ -38,7 +45,7 @@ struct ::tm* Utils::buildTimeInfo(struct timeval* currTime, struct ::tm* timeInf { #if LICENSEPP_OS_UNIX time_t rawTime = currTime->tv_sec; - ::localtime_r(&rawTime, timeInfo); + ::gmtime_r(&rawTime, timeInfo); return timeInfo; #else # ifdef (_MSC_VER) @@ -49,12 +56,12 @@ struct ::tm* Utils::buildTimeInfo(struct timeval* currTime, struct ::tm* timeInf # else _time64(&t); # endif - localtime_s(timeInfo, &t); + gmtime_s(timeInfo, &t); return timeInfo; # else // For any other compilers that don't have CRT warnings issue e.g, MinGW or TDM GCC- we use different method time_t rawTime = currTime->tv_sec; - struct tm* tmInf = localtime(&rawTime); + struct tm* tmInf = gmtime(&rawTime); *timeInfo = *tmInf; return timeInfo; # endif // _MSC_VER @@ -73,10 +80,8 @@ char* Utils::convertAndAddToBuff(std::size_t n, int len, char* buf, const char* *--p = '0'; --len; } - if (zeroPadded) { - while (p > localBuff && len-- > 0) { - *--p = static_cast('0'); - } + while (zeroPadded && p > localBuff && len-- > 0) { + *--p = static_cast('0'); } return addToBuff(p, buf, bufLim); } @@ -105,19 +110,19 @@ char* Utils::parseFormat(char* buf, std::size_t bufSz, const char* format, const buf = convertAndAddToBuff(tInfo->tm_mday, 2, buf, bufLim); continue; case 'a': // Day of week (short) - buf = addToBuff(Utils::kDaysAbbrev[tInfo->tm_wday], buf, bufLim); + buf = addToBuff(kDaysAbbrev[tInfo->tm_wday], buf, bufLim); continue; case 'A': // Day of week (long) - buf = addToBuff(Utils::kDays[tInfo->tm_wday], buf, bufLim); + buf = addToBuff(kDays[tInfo->tm_wday], buf, bufLim); continue; case 'M': // month buf = convertAndAddToBuff(tInfo->tm_mon + 1, 2, buf, bufLim); continue; case 'b': // month (short) - buf = addToBuff(Utils::kMonthsAbbrev[tInfo->tm_mon], buf, bufLim); + buf = addToBuff(kMonthsAbbrev[tInfo->tm_mon], buf, bufLim); continue; case 'B': // month (long) - buf = addToBuff(Utils::kMonths[tInfo->tm_mon], buf, bufLim); + buf = addToBuff(kMonths[tInfo->tm_mon], buf, bufLim); continue; case 'y': // year (two digits) buf = convertAndAddToBuff(tInfo->tm_year + 1900, 2, buf, bufLim); diff --git a/test/license-manager-test.h b/test/license-manager-test.h index 02354d4..0369829 100644 --- a/test/license-manager-test.h +++ b/test/license-manager-test.h @@ -83,6 +83,7 @@ TEST(LicenseManagerTest, VerificationUsingSecureAuthorityAndSignature) ASSERT_TRUE(licenseManager.validate(&license, true, "unittest-signature")); ASSERT_FALSE(licenseManager.validate(&license, true, "wrong-signature")); ASSERT_FALSE(licenseManager.validate(&license, false)); + ASSERT_EQ(license.formattedExpiry(), "06 Jan, 2028 17:11 UTC"); } #endif // LICENSE_MANAGER_TEST_H