| | |
| | | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -fmessage-length=0 -Wall -Wuninitialized -fPIC") |
| | | SET(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -pipe" CACHE INTERNAL "Linker flags") |
| | | SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS} -Wl,--strip-all") |
| | | #SET(CMAKE_FIND_LIBRARY_SUFFIXES .a) #.so for dynamic libraries |
| | | SET(CMAKE_FIND_LIBRARY_SUFFIXES .a) #.so for dynamic libraries |
| | | #you need to "force" the change in cmake_install_prefix after the project keyword |
| | | IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| | | SET(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "Install path prefix" FORCE) |
| | |
| | | #include_directories(${CRYPTOPP_INCLUDE_DIRS}) |
| | | #link_directories ( ${Boost_LIBRARY_DIRS} ) |
| | | |
| | | find_package(OpenSSL REQUIRED) |
| | | include_directories(${OPENSSL_INCLUDE_DIR}) |
| | | list(APPEND EXTERNAL_LIBS ${OPENSSL_CRYPTO_LIBRARY}) |
| | | #link_directories ( ${OPENSSL_LIBRARIES} ) |
| | | |
| | | |
| | | SET(Boost_USE_STATIC_LIBS ON) |
| | | # static runtime requires /MT |
| | |
| | | #include_directories(${Boost_INCLUDE_DIRS}) |
| | | #link_directories ( ${Boost_LIBRARY_DIRS} ) |
| | | |
| | | #find a static version of openssl crypto library |
| | | find_package(OpenSSL REQUIRED) |
| | | include_directories(${OPENSSL_INCLUDE_DIR}) |
| | | list(APPEND EXTERNAL_LIBS ${OPENSSL_CRYPTO_LIBRARY}) |
| | | |
| | | FIND_PACKAGE(Doxygen) |
| | | |
| | | IF (DOXYGEN_FOUND) |
| | |
| | | char* pem_key = (char*) (calloc(keylen + 1, 1)); /* Null-terminate */ |
| | | BIO_read(bio_private, pem_key, keylen); |
| | | std::string dest = replaceAll(string(pem_key), string("\n"), |
| | | string("\" \\\n\"")); |
| | | string("\\n\" \\\n\"")); |
| | | FILE* fp = fopen(public_fname.c_str(), "w"); |
| | | fprintf(fp, "//file generated by bootstrap.c, do not edit.\n\n"); |
| | | fprintf(fp, "#ifndef PUBLIC_KEY_H_\n#define PUBLIC_KEY_H_\n"); |
| | |
| | | license++_static |
| | | reader |
| | | os |
| | | ${EXTERNAL_LIBS} |
| | | ) |
| | | |
| | | ADD_LIBRARY(license++ SHARED |
| | | license++.cpp |
| | | ) |
| | | |
| | | SET_TARGET_PROPERTIES(license++ PROPERTIES LINK_SEARCH_START_STATIC OFF) |
| | | SET_TARGET_PROPERTIES(license++ PROPERTIES LINK_SEARCH_END_STATIC OFF) |
| | | |
| | | target_link_libraries( |
| | | license++ |
| | | reader_dynl |
| | | #os |
| | | #${EXTERNAL_LIBS} |
| | | ) |
| | | set_target_properties(license++ PROPERTIES PREFIX "lib") |
| | |
| | | LICENSE_MALFORMED = 5,//some mandatory field are missing, or data can't be fully read. |
| | | PRODUCT_NOT_LICENSED = 6, //this product was not licensed |
| | | PRODUCT_EXPIRED = 7, |
| | | LICENSE_CORRUPTED = 8, //License serial and calculated one didn't match |
| | | LICENSE_CORRUPTED = 8, //License signature didn't match with current license |
| | | IDENTIFIERS_MISMATCH = 9, //Calculated identifier and the one provided in license didn't match |
| | | |
| | | LICENSE_FILE_FOUND = 100 |
| | | LICENSE_FILE_FOUND = 100, |
| | | LICENSE_VERIFIED = 101 |
| | | |
| | | }; |
| | | |
| | |
| | | }; |
| | | |
| | | enum SEVERITY { |
| | | INFO, WARN, SEVERITY_ERROR |
| | | INFO, SEVERITY_WARN, SEVERITY_ERROR |
| | | }; |
| | | |
| | | |
| | |
| | | #include "EventRegistry.h" |
| | | #include <cstddef> |
| | | #include <string.h> |
| | | #include <algorithm> |
| | | |
| | | namespace license { |
| | | EventRegistry::EventRegistry() { |
| | |
| | | logs.push_back(audit); |
| | | } |
| | | |
| | | bool EventRegistry::turnErrosIntoWarnings() { |
| | | bool eventFound = false; |
| | | for (auto it = logs.begin(); it != logs.end(); ++it) { |
| | | if (it->severity == SEVERITY_ERROR) { |
| | | it->severity = SEVERITY_WARN; |
| | | eventFound = true; |
| | | } |
| | | } |
| | | return eventFound; |
| | | } |
| | | |
| | | void EventRegistry::exportLastEvents(AuditEvent* auditEvents, int nlogs) { |
| | | int sizeToCopy = std::min(nlogs, (int) logs.size()); |
| | | std::copy(logs.begin(), logs.begin() + sizeToCopy, auditEvents); |
| | | } |
| | | } |
| | | |
| | |
| | | os-linux.cpp |
| | | ) |
| | | |
| | | |
| | | target_link_libraries( |
| | | os |
| | | base |
| | |
| | | char *pubKey = PUBLIC_KEY |
| | | ; |
| | | |
| | | BIO* bio = BIO_new_mem_buf((void*) (pubKey), sizeof(pubKey)); |
| | | EVP_PKEY *pktmp = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL); |
| | | BIO* bio = BIO_new_mem_buf((void*) (pubKey), strlen(pubKey)); |
| | | RSA *rsa = PEM_read_bio_RSAPublicKey(bio, NULL,NULL,NULL); |
| | | BIO_free(bio); |
| | | if (pktmp == NULL) { |
| | | if (rsa == NULL) { |
| | | throw new logic_error("Error reading public key"); |
| | | } |
| | | EVP_PKEY *pkey = EVP_PKEY_new(); |
| | | |
| | | EVP_PKEY_assign_RSA(pkey, rsa); |
| | | |
| | | /*BIO* bo = BIO_new(BIO_s_mem()); |
| | | BIO_write(bo, pubKey, strlen(pubKey)); |
| | | RSA *key = 0; |
| | |
| | | if (!(mdctx = EVP_MD_CTX_create())) { |
| | | throw new logic_error("Error creating context"); |
| | | } |
| | | if (1 != EVP_DigestVerifyInit(mdctx, NULL, EVP_sha256(), NULL, pktmp)) { |
| | | if (1 != EVP_DigestVerifyInit(mdctx, NULL, EVP_sha256(), NULL, pkey)) { |
| | | throw new logic_error("Error initializing digest"); |
| | | } |
| | | |
| | |
| | | ${EXTERNAL_LIBS} |
| | | ) |
| | | |
| | | ADD_LIBRARY(reader_dynl STATIC |
| | | ConvertUTF.c |
| | | LicenseReader.cpp |
| | | ) |
| | | |
| | | SET_TARGET_PROPERTIES(reader_dynl PROPERTIES LINK_SEARCH_START_STATIC OFF) |
| | | SET_TARGET_PROPERTIES(reader_dynl PROPERTIES LINK_SEARCH_END_STATIC OFF) |
| | | target_link_libraries( |
| | | reader_dynl |
| | | os |
| | | #base |
| | | #${EXTERNAL_LIBS} |
| | | ) |
| | |
| | | extra_data(extra_data) { |
| | | } |
| | | |
| | | EventRegistry FullLicenseInfo::validate(int sw_version) { |
| | | EventRegistry er; |
| | | bool sigVerified = OsFunctions::verifySignature(printForSign().c_str(), |
| | | license_signature.c_str()); |
| | | if (sigVerified) { |
| | | er.addEvent(LICENSE_VERIFIED, INFO); |
| | | } else { |
| | | er.addEvent(LICENSE_CORRUPTED, SEVERITY_ERROR); |
| | | } |
| | | if(has_expiry){ |
| | | time_t now = time(NULL); |
| | | if(this->to_date<now){ |
| | | er.addEvent(PRODUCT_EXPIRED, SEVERITY_ERROR, ""); |
| | | } |
| | | if(this->from_date>now){ |
| | | er.addEvent(PRODUCT_EXPIRED, SEVERITY_ERROR); |
| | | } |
| | | } |
| | | return er; |
| | | } |
| | | |
| | | void FullLicenseInfo::toLicenseInfo(LicenseInfo* license) const { |
| | | if (license != NULL) { |
| | | strncpy(license->proprietary_data, extra_data.c_str(), |
| | |
| | | ini.Reset(); |
| | | SI_Error rc = ini.LoadFile((*it).c_str()); |
| | | if (rc < 0) { |
| | | result.addEvent(FILE_FORMAT_NOT_RECOGNIZED, WARN, *it); |
| | | result.addEvent(FILE_FORMAT_NOT_RECOGNIZED, SEVERITY_WARN, *it); |
| | | continue; |
| | | } else { |
| | | loadAtLeastOneFile = true; |
| | |
| | | const char* productNamePtr = product.c_str(); |
| | | int sectionSize = ini.GetSectionSize(productNamePtr); |
| | | if (sectionSize <= 0) { |
| | | result.addEvent(PRODUCT_NOT_LICENSED, WARN, *it); |
| | | result.addEvent(PRODUCT_NOT_LICENSED, SEVERITY_WARN, *it); |
| | | continue; |
| | | } else { |
| | | atLeastOneProductLicensed = true; |
| | |
| | | licenseInfoOut.push_back(licInfo); |
| | | atLeastOneLicenseComplete = true; |
| | | } else { |
| | | result.addEvent(LICENSE_MALFORMED, WARN, *it); |
| | | result.addEvent(LICENSE_MALFORMED, SEVERITY_WARN, *it); |
| | | } |
| | | } |
| | | if (!loadAtLeastOneFile) { |
| | |
| | | } |
| | | } |
| | | } else { |
| | | eventRegistry.addEvent(LICENSE_FILE_NOT_FOUND, WARN, varName); |
| | | eventRegistry.addEvent(LICENSE_FILE_NOT_FOUND, SEVERITY_WARN, |
| | | varName); |
| | | } |
| | | } |
| | | return licenseFoundWithExplicitLocation; |
| | |
| | | eventRegistry.addEvent(LICENSE_FILE_FOUND, INFO, *it); |
| | | } |
| | | } else { |
| | | eventRegistry.addEvent(LICENSE_FILE_NOT_FOUND, WARN, |
| | | env_var_value); |
| | | eventRegistry.addEvent(LICENSE_FILE_NOT_FOUND, |
| | | SEVERITY_WARN, env_var_value); |
| | | } |
| | | } else { |
| | | eventRegistry.addEvent(ENVIRONMENT_VARIABLE_NOT_DEFINED, WARN); |
| | | eventRegistry.addEvent(ENVIRONMENT_VARIABLE_NOT_DEFINED, |
| | | SEVERITY_WARN); |
| | | } |
| | | } else { |
| | | eventRegistry.addEvent(ENVIRONMENT_VARIABLE_NOT_DEFINED, WARN); |
| | | eventRegistry.addEvent(ENVIRONMENT_VARIABLE_NOT_DEFINED, |
| | | SEVERITY_WARN); |
| | | } |
| | | } |
| | | return licenseFileFoundWithEnvVariable; |
| | |
| | | diskFiles.push_back(temptativeLicense); |
| | | eventRegistry.addEvent(LICENSE_FILE_FOUND, INFO, temptativeLicense); |
| | | } else { |
| | | eventRegistry.addEvent(LICENSE_FILE_NOT_FOUND, WARN, |
| | | eventRegistry.addEvent(LICENSE_FILE_NOT_FOUND, SEVERITY_WARN, |
| | | temptativeLicense); |
| | | } |
| | | f.close(); |
| | |
| | | const string& extra_data = ""); |
| | | string printForSign() const; |
| | | void printAsIni(ostream & a_ostream) const; |
| | | inline bool signatureVerified() const { |
| | | return OsFunctions::verifySignature(printForSign().c_str(), license_signature.c_str()); |
| | | } |
| | | |
| | | void toLicenseInfo(LicenseInfo* license) const; |
| | | EventRegistry validate(int sw_version); |
| | | }; |
| | |
| | | ${Boost_LIBRARIES} |
| | | ${EXTERNAL_LIBS} |
| | | ) |
| | | #SET_TARGET_PROPERTIES(license_generator_lib PROPERTIES LINK_SEARCH_START_STATIC ON) |
| | | #SET_TARGET_PROPERTIES(license_generator_lib PROPERTIES LINK_SEARCH_END_STATIC ON) |
| | | |
| | | add_executable( |
| | | license_generator |
| | |
| | | |
| | | add_subdirectory(library) |
| | | add_subdirectory(license-generator) |
| | | add_subdirectory(functional) |
| | |
| | | |
| | | target_link_libraries( |
| | | standard_license_test |
| | | license_generator_lib |
| | | license++_static |
| | | license_generator_lib |
| | | ) |
| | | |
| | | SET_TARGET_PROPERTIES(standard_license_test PROPERTIES LINK_SEARCH_START_STATIC ON) |
| | |
| | | #include "../../../src/library/api/license++.h" |
| | | #include <build_properties.h> |
| | | #include <boost/filesystem.hpp> |
| | | #include "../../src/library/reader/SimpleIni.h" |
| | | |
| | | |
| | | namespace fs = boost::filesystem; |
| | |
| | | |
| | | target_link_libraries( |
| | | license_reader_test |
| | | ${Boost_LIBRARIES} |
| | | reader |
| | | os |
| | | base |
| | | ${PLATFORM_LIBS} |
| | | ${Boost_LIBRARIES} |
| | | ) |
| | | |
| | | SET_TARGET_PROPERTIES(license_reader_test PROPERTIES LINK_SEARCH_START_STATIC ON) |