open-license-manager
2014-04-14 f77e1e4d2adf4422943c10a1906854c3027391d8
first roundtrip test
15个文件已修改
136 ■■■■■ 已修改文件
CMakeLists.txt 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/bootstrap/bootstrap.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/CMakeLists.txt 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/api/datatypes.h 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/base/EventRegistry.cpp 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/os/linux/CMakeLists.txt 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/os/linux/os-linux.cpp 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/reader/CMakeLists.txt 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/reader/LicenseReader.cpp 42 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/reader/LicenseReader.h 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/license-generator/CMakeLists.txt 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/CMakeLists.txt 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/functional/CMakeLists.txt 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/functional/standard-license_test.cpp 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/library/reader/CMakeLists.txt 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CMakeLists.txt
@@ -29,7 +29,7 @@
    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)
@@ -49,10 +49,7 @@
#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 
@@ -62,6 +59,11 @@
#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)
src/bootstrap/bootstrap.cpp
@@ -44,7 +44,7 @@
    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");
src/library/CMakeLists.txt
@@ -14,20 +14,5 @@
     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")
src/library/api/datatypes.h
@@ -35,10 +35,11 @@
    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
};
@@ -47,7 +48,7 @@
};
enum SEVERITY {
    INFO, WARN, SEVERITY_ERROR
    INFO, SEVERITY_WARN, SEVERITY_ERROR
};
src/library/base/EventRegistry.cpp
@@ -8,6 +8,7 @@
#include "EventRegistry.h"
#include <cstddef>
#include <string.h>
#include <algorithm>
namespace license {
EventRegistry::EventRegistry() {
@@ -97,4 +98,20 @@
    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);
}
}
src/library/os/linux/CMakeLists.txt
@@ -2,7 +2,6 @@
    os-linux.cpp
)
target_link_libraries(
     os
     base
src/library/os/linux/os-linux.cpp
@@ -69,12 +69,16 @@
    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;
@@ -87,7 +91,7 @@
    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");
    }
src/library/reader/CMakeLists.txt
@@ -11,16 +11,3 @@
     ${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}
)
src/library/reader/LicenseReader.cpp
@@ -50,6 +50,27 @@
        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(),
@@ -88,7 +109,7 @@
        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;
@@ -96,7 +117,7 @@
        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;
@@ -120,7 +141,7 @@
            licenseInfoOut.push_back(licInfo);
            atLeastOneLicenseComplete = true;
        } else {
            result.addEvent(LICENSE_MALFORMED, WARN, *it);
            result.addEvent(LICENSE_MALFORMED, SEVERITY_WARN, *it);
        }
    }
    if (!loadAtLeastOneFile) {
@@ -155,7 +176,8 @@
                }
            }
        } else {
            eventRegistry.addEvent(LICENSE_FILE_NOT_FOUND, WARN, varName);
            eventRegistry.addEvent(LICENSE_FILE_NOT_FOUND, SEVERITY_WARN,
                    varName);
        }
    }
    return licenseFoundWithExplicitLocation;
@@ -183,14 +205,16 @@
                        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;
@@ -209,7 +233,7 @@
            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();
src/library/reader/LicenseReader.h
@@ -46,9 +46,7 @@
            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);
};
src/license-generator/CMakeLists.txt
@@ -13,8 +13,6 @@
     ${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
test/CMakeLists.txt
@@ -5,3 +5,4 @@
add_subdirectory(library)
add_subdirectory(license-generator)
add_subdirectory(functional)
test/functional/CMakeLists.txt
@@ -6,8 +6,8 @@
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)
test/functional/standard-license_test.cpp
@@ -6,6 +6,7 @@
#include "../../../src/library/api/license++.h"
#include <build_properties.h>
#include <boost/filesystem.hpp>
#include "../../src/library/reader/SimpleIni.h"
namespace fs = boost::filesystem;
test/library/reader/CMakeLists.txt
@@ -7,11 +7,8 @@
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)