open-license-manager
2014-04-16 5d562274a4df36a38ad1a9fe3b68673535b31cf2
license signature 
3个文件已修改
53 ■■■■ 已修改文件
src/license-generator/LicenseSigner.cpp 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/license-generator/license-generator.cpp 44 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/license-generator/license-generator.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/license-generator/LicenseSigner.cpp
@@ -20,10 +20,11 @@
using namespace std;
LicenseSigner::LicenseSigner() {
    OsFunctions::initialize();
}
LicenseSigner::LicenseSigner(const std::string& alternatePrimaryKey) {
    OsFunctions::initialize();
}
string LicenseSigner::Opensslb64Encode(size_t slen, unsigned char* signature) {
@@ -49,9 +50,7 @@
}
string LicenseSigner::signString(const string& license) {
    ERR_load_ERR_strings();
    ERR_load_crypto_strings();
    OpenSSL_add_all_algorithms();
    size_t slen;
    unsigned char* signature;
    signature = NULL;
src/license-generator/license-generator.cpp
@@ -50,7 +50,7 @@
    ("begin_date,b", po::value<string>(),
            "Specify the start of the validity for this license. "
                    " Format YYYYMMDD. If not specified defaults to today") //
    ("end_date,e", po::value<string>(),
    ("expire_date,e", po::value<string>(),
            "Specify the expire date for this license. "
                    " Format YYYYMMDD. If not specified the license won't expire") //
    ("client_signature,s", po::value<string>(),
@@ -71,13 +71,16 @@
vector<FullLicenseInfo> LicenseGenerator::parseLicenseInfo(
        po::variables_map vm) {
    time_t begin_date = FullLicenseInfo::UNUSED_TIME;
    time_t end_date = FullLicenseInfo::UNUSED_TIME;
    if (vm.count("end_date")) {
        const std::string dt_end = vm["end_date"].as<string>();
    string begin_date = FullLicenseInfo::UNUSED_TIME;
    string end_date = FullLicenseInfo::UNUSED_TIME;
    if (vm.count("expire_date")) {
        const std::string dt_end = vm["expire_date"].as<string>();
        try {
            end_date = seconds_from_epoch(dt_end.c_str());
            begin_date = time(NULL);
            end_date = normalize_date(dt_end.c_str());
            char curdate[20];
            time_t curtime = time(NULL);
            strftime(curdate, 20, "%Y-%m-%d", localtime(&curtime));
            begin_date.assign(curdate);
        } catch (invalid_argument &e) {
            cerr << endl << "End date not recognized: " << dt_end
                    << " Please enter a valid date in format YYYYMMDD" << endl;
@@ -87,7 +90,7 @@
    if (vm.count("begin_date")) {
        const std::string begin_date_str = vm["begin_date"].as<string>();
        try {
            begin_date = seconds_from_epoch(begin_date_str.c_str());
            begin_date = normalize_date(begin_date_str.c_str());
        } catch (invalid_argument &e) {
            cerr << endl << "Begin date not recognized: " << begin_date_str
                    << " Please enter a valid date in format YYYYMMDD" << endl;
@@ -185,5 +188,30 @@
}
const std::locale formats[] = { std::locale(std::locale::classic(),
        new bt::time_input_facet("%Y-%m-%d")), //
std::locale(std::locale::classic(), new bt::time_input_facet("%Y/%m/%d")), //
std::locale(std::locale::classic(), new bt::time_input_facet("%Y%m%d")) };
const size_t formats_n = sizeof(formats) / sizeof(formats[0]);
string LicenseGenerator::normalize_date(const std::string& s) {
    bt::ptime pt;
    for (size_t i = 0; i < formats_n; ++i) {
        std::istringstream is(s);
        is.imbue(formats[i]);
        is >> pt;
        if (pt != bt::ptime()) {
            break;
        }
    }
    if (pt == bt::ptime()) {
        throw invalid_argument(string("Date not regognized") + s);
    }
    ostringstream oss;
    bt::time_facet *facet = new bt::time_facet("%Y-%m-%d");
    oss.imbue(locale(cout.getloc(), facet));
    oss << pt << endl;
    //delete (facet);
    return oss.str();
}
}
src/license-generator/license-generator.h
@@ -26,7 +26,7 @@
    static vector<FullLicenseInfo> parseLicenseInfo(po::variables_map vm);
    static void generateAndOutptuLicenses(const po::variables_map& vm,
            ostream& outputFile);
    static string normalize_date(const std::string& s);
public:
    static int generateLicense(int argc, const char** argv);
};