| | |
| | | EventRegistry FullLicenseInfo::validate(int sw_version) { |
| | | EventRegistry er; |
| | | os_initialize(); |
| | | FUNCTION_RETURN sigVer = verifySignature(printForSign().c_str(), |
| | | const FUNCTION_RETURN sigVer = verifySignature(printForSign().c_str(), |
| | | license_signature.c_str()); |
| | | bool sigVerified = sigVer == FUNC_RET_OK; |
| | | const bool sigVerified = sigVer == FUNC_RET_OK; |
| | | if (sigVerified) { |
| | | er.addEvent(LICENSE_VERIFIED, SVRT_INFO); |
| | | } else { |
| | | er.addEvent(LICENSE_CORRUPTED, SVRT_ERROR); |
| | | } |
| | | if (has_expiry) { |
| | | time_t now = time(NULL); |
| | | const time_t now = time(NULL); |
| | | if (expires_on() < now) { |
| | | er.addEvent(PRODUCT_EXPIRED, SVRT_ERROR, ""); |
| | | } |
| | |
| | | if (has_client_sig) { |
| | | PcSignature str_code; |
| | | strncpy(str_code, client_signature.c_str(), sizeof(str_code)-1); |
| | | EVENT_TYPE event = validate_pc_signature(str_code); |
| | | const EVENT_TYPE event = validate_pc_signature(str_code); |
| | | if (event != LICENSE_OK) { |
| | | er.addEvent(event, SVRT_ERROR); |
| | | } |
| | |
| | | license->days_left = 999999; |
| | | } else { |
| | | strncpy(license->expiry_date, to_date.c_str(), 11); |
| | | double secs = difftime( |
| | | const double secs = difftime( |
| | | seconds_from_epoch(to_date.c_str()), |
| | | time(NULL)); |
| | | license->days_left = round(secs / (60 * 60 * 24)); |
| | |
| | | CSimpleIniA ini; |
| | | for (auto it = diskFiles.begin(); it != diskFiles.end(); it++) { |
| | | ini.Reset(); |
| | | SI_Error rc = ini.LoadFile((*it).c_str()); |
| | | const SI_Error rc = ini.LoadFile((*it).c_str()); |
| | | if (rc < 0) { |
| | | result.addEvent(FILE_FORMAT_NOT_RECOGNIZED, SVRT_WARN, *it); |
| | | continue; |
| | |
| | | loadAtLeastOneFile = true; |
| | | } |
| | | const char* productNamePtr = product.c_str(); |
| | | int sectionSize = ini.GetSectionSize(productNamePtr); |
| | | const int sectionSize = ini.GetSectionSize(productNamePtr); |
| | | if (sectionSize <= 0) { |
| | | result.addEvent(PRODUCT_NOT_LICENSED, SVRT_WARN, *it); |
| | | continue; |
| | |
| | | */ |
| | | const char * license_signature = ini.GetValue(productNamePtr, |
| | | "license_signature", NULL); |
| | | long license_version = ini.GetLongValue(productNamePtr, |
| | | const long license_version = ini.GetLongValue(productNamePtr, |
| | | "license_version", -1); |
| | | if (license_signature != NULL && license_version > 0) { |
| | | string from_date = trim_copy( |
| | | const string from_date = trim_copy( |
| | | ini.GetValue(productNamePtr, "from_date", |
| | | FullLicenseInfo::UNUSED_TIME)); |
| | | string to_date = trim_copy( |
| | | const string to_date = trim_copy( |
| | | ini.GetValue(productNamePtr, "to_date", |
| | | FullLicenseInfo::UNUSED_TIME)); |
| | | string client_signature = trim_copy( |
| | |
| | | /*client_signature.erase( |
| | | std::remove(client_signature.begin(), client_signature.end(), '-'), |
| | | client_signature.end());*/ |
| | | int from_sw_version = ini.GetLongValue(productNamePtr, |
| | | const int from_sw_version = ini.GetLongValue(productNamePtr, |
| | | "from_sw_version", |
| | | FullLicenseInfo::UNUSED_SOFTWARE_VERSION); |
| | | int to_sw_version = ini.GetLongValue(productNamePtr, |
| | | const int to_sw_version = ini.GetLongValue(productNamePtr, |
| | | "to_sw_version", FullLicenseInfo::UNUSED_SOFTWARE_VERSION); |
| | | string extra_data = trim_copy( |
| | | ini.GetValue(productNamePtr, "extra_data", "")); |
| | |
| | | if (licenseLocation.licenseFileLocation != NULL |
| | | && licenseLocation.licenseFileLocation[0] != '\0') { |
| | | //hasFileLocation = true; |
| | | string varName(licenseLocation.licenseFileLocation); |
| | | vector<string> declared_positions = splitLicensePositions(varName); |
| | | const string varName(licenseLocation.licenseFileLocation); |
| | | const vector<string> declared_positions = splitLicensePositions(varName); |
| | | vector<string> existing_pos = filterExistingFiles(declared_positions); |
| | | if (existing_pos.size() > 0) { |
| | | if (existing_pos.size() > 0) { |
| | |
| | | bool licenseFileFoundWithEnvVariable = false; |
| | | if (licenseLocation.environmentVariableName != NULL |
| | | && licenseLocation.environmentVariableName[0] != '\0') { |
| | | string varName(licenseLocation.environmentVariableName); |
| | | const string varName(licenseLocation.environmentVariableName); |
| | | if (varName.length() > 0) { |
| | | //var name is passed in by the calling application. |
| | | char* env_var_value = getenv(varName.c_str()); |
| | | if (env_var_value != NULL && env_var_value[0] != '\0') { |
| | | vector<string> declared_positions = splitLicensePositions( |
| | | const vector<string> declared_positions = splitLicensePositions( |
| | | string(env_var_value)); |
| | | vector<string> existing_pos = filterExistingFiles( |
| | | declared_positions); |
| | |
| | | |
| | | EventRegistry LicenseReader::getLicenseDiskFiles(vector<string>& diskFiles) { |
| | | EventRegistry eventRegistry; |
| | | bool licenseFoundWithExplicitLocation = findLicenseWithExplicitLocation( |
| | | const bool licenseFoundWithExplicitLocation = findLicenseWithExplicitLocation( |
| | | diskFiles, eventRegistry); |
| | | bool foundNearModule = false; |
| | | if (licenseLocation.openFileNearModule) { |
| | | char fname[MAX_PATH] = { 0 }; |
| | | FUNCTION_RETURN fret = getModuleName(fname); |
| | | const FUNCTION_RETURN fret = getModuleName(fname); |
| | | if (fret == FUNC_RET_OK) { |
| | | string temptativeLicense = string(fname) + ".lic"; |
| | | const string temptativeLicense = string(fname) + ".lic"; |
| | | ifstream f(temptativeLicense.c_str()); |
| | | if (f.good()) { |
| | | foundNearModule = true; |
| | |
| | | LOG_WARN("Error determining module name."); |
| | | } |
| | | } |
| | | bool licenseFileFoundWithEnvVariable = findFileWithEnvironmentVariable( |
| | | const bool licenseFileFoundWithEnvVariable = findFileWithEnvironmentVariable( |
| | | diskFiles, eventRegistry); |
| | | |
| | | if (!foundNearModule && !licenseFoundWithExplicitLocation |
| | |
| | | void FullLicenseInfo::printAsIni(ostream & a_ostream) const { |
| | | CSimpleIniA ini; |
| | | string result; |
| | | string product = toupper_copy(trim_copy(this->product)); |
| | | const string product = toupper_copy(trim_copy(this->product)); |
| | | CSimpleIniA::StreamWriter sw(a_ostream); |
| | | ini.SetLongValue(product.c_str(), "license_version", |
| | | PROJECT_INT_VERSION); |
| | |
| | | } |
| | | |
| | | void EventRegistry::exportLastEvents(AuditEvent* auditEvents, int nlogs) { |
| | | int sizeToCopy = min(nlogs, (int) logs.size()); |
| | | const int sizeToCopy = min(nlogs, (int) logs.size()); |
| | | std::copy(logs.begin(), logs.begin() + sizeToCopy, auditEvents); |
| | | } |
| | | } |
| | |
| | | int year, month, day; |
| | | tm tm; |
| | | if (strlen(timeString) == 8) { |
| | | int nfield = sscanf(timeString, "%4d%2d%2d", &year, &month, &day); |
| | | const int nfield = sscanf(timeString, "%4d%2d%2d", &year, &month, &day); |
| | | if (nfield != 3) { |
| | | throw invalid_argument("Date not recognized"); |
| | | } |
| | | } else if (strlen(timeString) == 10) { |
| | | int nfield = sscanf(timeString, "%4d-%2d-%2d", &year, &month, &day); |
| | | const int nfield = sscanf(timeString, "%4d-%2d-%2d", &year, &month, &day); |
| | | if (nfield != 3) { |
| | | int nfield = sscanf(timeString, "%4d/%2d/%2d", &year, &month, &day); |
| | | const int nfield = sscanf(timeString, "%4d/%2d/%2d", &year, &month, &day); |
| | | if (nfield != 3) { |
| | | throw invalid_argument("Date not recognized"); |
| | | } |
| | |
| | | strncpy(logpath, folder, MAX_PATH); |
| | | strncat(logpath, "/open-license.log", MAX_PATH - strlen(logpath)); |
| | | #else |
| | | int plen = GetTempPath(MAX_PATH, logpath); |
| | | const int plen = GetTempPath(MAX_PATH, logpath); |
| | | if(plen == 0) { |
| | | fprintf(stderr, "Error getting temporary directory path"); |
| | | } |
| | |
| | | if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) { |
| | | /* If the 16 bits following the high surrogate are in the source buffer... */ |
| | | if (source < sourceEnd) { |
| | | UTF32 ch2 = *source; |
| | | const UTF32 ch2 = *source; |
| | | /* If it's a low surrogate, convert to UTF32. */ |
| | | if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) { |
| | | ch = ((ch - UNI_SUR_HIGH_START) << halfShift) |
| | |
| | | * This is not used here; it's just exported. |
| | | */ |
| | | Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd) { |
| | | int length = trailingBytesForUTF8[*source]+1; |
| | | const int length = trailingBytesForUTF8[*source]+1; |
| | | if (source+length > sourceEnd) { |
| | | return false; |
| | | } |
| | |
| | | UTF16* target = *targetStart; |
| | | while (source < sourceEnd) { |
| | | UTF32 ch = 0; |
| | | unsigned short extraBytesToRead = trailingBytesForUTF8[*source]; |
| | | const unsigned short extraBytesToRead = trailingBytesForUTF8[*source]; |
| | | if (source + extraBytesToRead >= sourceEnd) { |
| | | result = sourceExhausted; break; |
| | | } |
| | |
| | | UTF32* target = *targetStart; |
| | | while (source < sourceEnd) { |
| | | UTF32 ch = 0; |
| | | unsigned short extraBytesToRead = trailingBytesForUTF8[*source]; |
| | | const unsigned short extraBytesToRead = trailingBytesForUTF8[*source]; |
| | | if (source + extraBytesToRead >= sourceEnd) { |
| | | result = sourceExhausted; break; |
| | | } |
| | |
| | | FUNCTION_RETURN result = FUNC_RET_ERROR;
|
| | | char buffer[MAX_COMPUTERNAME_LENGTH + 1];
|
| | | int bufsize = MAX_COMPUTERNAME_LENGTH + 1;
|
| | | BOOL cmpName = GetComputerName(buffer, &bufsize);
|
| | | const BOOL cmpName = GetComputerName(buffer, &bufsize);
|
| | | if (cmpName) {
|
| | | strncpy(identifier, buffer, 6);
|
| | | result = FUNC_RET_OK;
|
| | |
| | | DWORD volSerial = 0;
|
| | | BOOL success;
|
| | | UINT driveType;
|
| | | DWORD dwSize = MAX_PATH;
|
| | | const DWORD dwSize = MAX_PATH;
|
| | | char szLogicalDrives[MAX_PATH] = { 0 };
|
| | | unsigned char buf[8] = "";
|
| | |
|
| | | FUNCTION_RETURN return_value;
|
| | | DWORD dwResult = GetLogicalDriveStrings(dwSize, szLogicalDrives);
|
| | | const DWORD dwResult = GetLogicalDriveStrings(dwSize, szLogicalDrives);
|
| | |
|
| | | if (dwResult > 0 && dwResult <= MAX_PATH) {
|
| | | return_value = FUNC_RET_OK;
|
| | |
| | |
|
| | | FUNCTION_RETURN getModuleName(char buffer[MAX_PATH]) {
|
| | | FUNCTION_RETURN result = FUNC_RET_OK;
|
| | | DWORD wres = GetModuleFileName(NULL, buffer, MAX_PATH);
|
| | | const DWORD wres = GetModuleFileName(NULL, buffer, MAX_PATH);
|
| | | if (wres == 0) {
|
| | | result = FUNC_RET_ERROR;
|
| | | }
|
| | |
| | | PcIdentifier concat_identifiers[2]; |
| | | char* b64_data = NULL; |
| | | int b64_size = 0; |
| | | size_t concatIdentifiersSize = sizeof(PcIdentifier) * 2; |
| | | const size_t concatIdentifiersSize = sizeof(PcIdentifier) * 2; |
| | | //concat_identifiers = (PcIdentifier *) malloc(concatIdentifiersSize); |
| | | memcpy(&concat_identifiers[0], identifier1, sizeof(PcIdentifier)); |
| | | memcpy(&concat_identifiers[1], identifier2, sizeof(PcIdentifier)); |
| | |
| | | const string CryptoHelperWindows::signString(const void* privateKey,
|
| | | size_t pklen, const string& license) const {
|
| | | BYTE *pbBuffer = (BYTE *) license.c_str();
|
| | | DWORD dwBufferLen = (DWORD)strlen((char *)pbBuffer);
|
| | | const DWORD dwBufferLen = (DWORD)strlen((char *)pbBuffer);
|
| | | HCRYPTHASH hHash;
|
| | |
|
| | | HCRYPTKEY hKey;
|
| | |
| | | fprintf(fp, "#define PUBLIC_KEY { \\\n"); |
| | | fprintf(fp, "%s", pbPublicKey.c_str()); |
| | | fprintf(fp, "}\n\n"); |
| | | int random = rand() % 1000; |
| | | const int random = rand() % 1000; |
| | | fprintf(fp, "#define SHARED_RANDOM %d;\n", random); |
| | | fprintf(fp, "#endif\n"); |
| | | fclose(fp); |
| | |
| | | printf("********************************************\n"); |
| | | |
| | | } |
| | | string private_fname = string(argv[1]); |
| | | string public_fname(argv[2]); |
| | | const string private_fname = string(argv[1]); |
| | | const string public_fname(argv[2]); |
| | | |
| | | if (file_exists(private_fname) || file_exists(public_fname)) { |
| | | printf("Key files exist, skipping key generation. Do 'make clean' to generate new keys.\n"); |
| | |
| | | void LicenseGenerator::generateAndOutputLicenses(const po::variables_map& vm, |
| | | ostream& outputFile) { |
| | | vector<FullLicenseInfo> licenseInfo = parseLicenseInfo(vm); |
| | | unique_ptr<CryptoHelper> helper = CryptoHelper::getInstance(); |
| | | const unique_ptr<CryptoHelper> helper = CryptoHelper::getInstance(); |
| | | const char pkey[] = PRIVATE_KEY; |
| | | size_t len = sizeof(pkey); |
| | | const size_t len = sizeof(pkey); |
| | | for (auto it = licenseInfo.begin(); it != licenseInfo.end(); ++it) { |
| | | const string license = it->printForSign(); |
| | | string signature = helper->signString((const void *)pkey,len,license); |
| | | const string signature = helper->signString((const void *)pkey,len,license); |
| | | it->license_signature = signature; |
| | | it->printAsIni(outputFile); |
| | | } |
| | |
| | | licenseLocation.openFileNearModule = false; |
| | | licenseLocation.licenseFileLocation = licLocation.c_str(); |
| | | licenseLocation.environmentVariableName = ""; |
| | | EVENT_TYPE result = acquire_license("TEST", licenseLocation, &license); |
| | | const EVENT_TYPE result = acquire_license("TEST", licenseLocation, &license); |
| | | BOOST_CHECK_EQUAL(result, LICENSE_OK); |
| | | BOOST_CHECK_EQUAL(license.has_expiry, true); |
| | | BOOST_CHECK_EQUAL(license.linked_to_pc, false); |
| | |
| | | licenseLocation.openFileNearModule = false; |
| | | licenseLocation.licenseFileLocation = licLocation.c_str(); |
| | | licenseLocation.environmentVariableName = ""; |
| | | EVENT_TYPE result = acquire_license("TEST", licenseLocation, &license); |
| | | const EVENT_TYPE result = acquire_license("TEST", licenseLocation, &license); |
| | | BOOST_CHECK_EQUAL(result, PRODUCT_EXPIRED); |
| | | BOOST_CHECK_EQUAL(license.has_expiry, true); |
| | | BOOST_CHECK_EQUAL(license.linked_to_pc, false); |
| | |
| | | using namespace std; |
| | | |
| | | void generate_license(const string& fname, const vector<string>& other_args) { |
| | | int argc = 4+other_args.size(); |
| | | const int argc = 4+other_args.size(); |
| | | const char** argv = new const char*[argc + 1]; |
| | | unsigned int i=0; |
| | | argv[i++] = "lic-generator"; |
| | |
| | | argv[i++] = "-o"; |
| | | argv[i++] = fname.c_str(); |
| | | argv[i++] = "TEST"; |
| | | int retCode = LicenseGenerator::generateLicense(argc, argv); |
| | | const int retCode = LicenseGenerator::generateLicense(argc, argv); |
| | | delete[] (argv); |
| | | BOOST_CHECK_EQUAL(retCode, 0); |
| | | BOOST_ASSERT(fs::exists(fname)); |
| | | CSimpleIniA ini; |
| | | SI_Error rc = ini.LoadFile(fname.c_str()); |
| | | const SI_Error rc = ini.LoadFile(fname.c_str()); |
| | | BOOST_CHECK_GE(rc,0); |
| | | int sectionSize = ini.GetSectionSize("TEST"); |
| | | const int sectionSize = ini.GetSectionSize("TEST"); |
| | | BOOST_CHECK_GT(sectionSize,0); |
| | | } |
| | |
| | | |
| | | BOOST_AUTO_TEST_CASE( standard_lic_file ) { |
| | | const string licLocation(PROJECT_TEST_TEMP_DIR "/standard_license.lic"); |
| | | vector<string> extraArgs; |
| | | const vector<string> extraArgs; |
| | | generate_license(licLocation, extraArgs); |
| | | /* */ |
| | | LicenseInfo license; |
| | |
| | | licenseLocation.openFileNearModule=false; |
| | | licenseLocation.licenseFileLocation = licLocation.c_str(); |
| | | licenseLocation.environmentVariableName = ""; |
| | | EVENT_TYPE result = acquire_license("TEST", |
| | | const EVENT_TYPE result = acquire_license("TEST", |
| | | licenseLocation, & license); |
| | | BOOST_CHECK_EQUAL(result, LICENSE_OK); |
| | | BOOST_CHECK_EQUAL(license.has_expiry, false); |
| | |
| | | const string licLocation(PROJECT_TEST_TEMP_DIR "/volid_license.lic"); |
| | | PcSignature identifier_out; |
| | | |
| | | IDENTIFICATION_STRATEGY strategy = IDENTIFICATION_STRATEGY::ETHERNET; |
| | | const IDENTIFICATION_STRATEGY strategy = IDENTIFICATION_STRATEGY::ETHERNET; |
| | | BOOST_TEST_CHECKPOINT("Before generate"); |
| | | FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out, |
| | | const FUNCTION_RETURN generate_ok = generate_user_pc_signature(identifier_out, |
| | | strategy); |
| | | BOOST_TEST_CHECKPOINT("After generate signature"); |
| | | BOOST_ASSERT(generate_ok == FUNCTION_RETURN::FUNC_RET_OK); |
| | |
| | | licenseLocation.openFileNearModule = false; |
| | | licenseLocation.licenseFileLocation = licLocation.c_str(); |
| | | licenseLocation.environmentVariableName = ""; |
| | | EVENT_TYPE result = acquire_license("TEST", licenseLocation, &license); |
| | | const EVENT_TYPE result = acquire_license("TEST", licenseLocation, &license); |
| | | BOOST_CHECK_EQUAL(result, LICENSE_OK); |
| | | BOOST_CHECK_EQUAL(license.has_expiry, false); |
| | | BOOST_CHECK_EQUAL(license.linked_to_pc, true); |
| | |
| | | const LicenseLocation location = { licLocation, NULL, false }; |
| | | LicenseReader licenseReader(location); |
| | | vector<FullLicenseInfo> licenseInfos; |
| | | EventRegistry registry = licenseReader.readLicenses("PrODUCT", |
| | | const EventRegistry registry = licenseReader.readLicenses("PrODUCT", |
| | | licenseInfos); |
| | | BOOST_CHECK(registry.isGood()); |
| | | BOOST_CHECK_EQUAL(1, licenseInfos.size()); |
| | |
| | | const LicenseLocation location = { licLocation, NULL, false }; |
| | | LicenseReader licenseReader(location); |
| | | vector<FullLicenseInfo> licenseInfos; |
| | | EventRegistry registry = licenseReader.readLicenses("PRODUCT-NOT", |
| | | const EventRegistry registry = licenseReader.readLicenses("PRODUCT-NOT", |
| | | licenseInfos); |
| | | BOOST_CHECK(!registry.isGood()); |
| | | BOOST_CHECK_EQUAL(0, licenseInfos.size()); |
| | |
| | | const LicenseLocation location = { licLocation, NULL, false }; |
| | | LicenseReader licenseReader(location); |
| | | vector<FullLicenseInfo> licenseInfos; |
| | | EventRegistry registry = licenseReader.readLicenses("PRODUCT", |
| | | const EventRegistry registry = licenseReader.readLicenses("PRODUCT", |
| | | licenseInfos); |
| | | BOOST_CHECK(!registry.isGood()); |
| | | BOOST_CHECK_EQUAL(0, licenseInfos.size()); |
| | |
| | | const LicenseLocation location = { NULL, envName, false }; |
| | | LicenseReader licenseReader(location); |
| | | vector<FullLicenseInfo> licenseInfos; |
| | | EventRegistry registry = licenseReader.readLicenses("PRODUCT", |
| | | const EventRegistry registry = licenseReader.readLicenses("PRODUCT", |
| | | licenseInfos); |
| | | BOOST_CHECK(!registry.isGood()); |
| | | BOOST_CHECK_EQUAL(0, licenseInfos.size()); |
| | |
| | | const LicenseLocation location = { NULL, "LIC_VAR", false }; |
| | | LicenseReader licenseReader(location); |
| | | vector<FullLicenseInfo> licenseInfos; |
| | | EventRegistry registry = licenseReader.readLicenses("PrODUCT", |
| | | const EventRegistry registry = licenseReader.readLicenses("PrODUCT", |
| | | licenseInfos); |
| | | BOOST_CHECK(registry.isGood()); |
| | | BOOST_CHECK_EQUAL(1, licenseInfos.size()); |
| | |
| | | using namespace std; |
| | | |
| | | void generate_license(const string& prod_name, const string& fname) { |
| | | int argc = 4; |
| | | const int argc = 4; |
| | | const char** argv = new const char*[argc + 1]; |
| | | argv[0] = "lic-generator"; |
| | | argv[1] = "-o"; |
| | | argv[2] = fname.c_str(); |
| | | argv[3] = "test"; |
| | | int retCode = LicenseGenerator::generateLicense(argc, argv); |
| | | const int retCode = LicenseGenerator::generateLicense(argc, argv); |
| | | delete[] (argv); |
| | | BOOST_CHECK_EQUAL(retCode, 0); |
| | | BOOST_ASSERT(fs::exists(fname)); |
| | | CSimpleIniA ini; |
| | | SI_Error rc = ini.LoadFile(fname.c_str()); |
| | | const SI_Error rc = ini.LoadFile(fname.c_str()); |
| | | BOOST_CHECK_GE(rc,0); |
| | | int sectionSize = ini.GetSectionSize(prod_name.c_str()); |
| | | const int sectionSize = ini.GetSectionSize(prod_name.c_str()); |
| | | BOOST_CHECK_GT(sectionSize,0); |
| | | } |
| | | |