| | |
| | | er.addEvent(LICENSE_CORRUPTED, SVRT_ERROR); |
| | | } |
| | | if (has_expiry) { |
| | | const time_t now = time(NULL); |
| | | const time_t now = time(nullptr); |
| | | if (expires_on() < now) { |
| | | er.addEvent(PRODUCT_EXPIRED, SVRT_ERROR, ""); |
| | | } |
| | |
| | | } |
| | | |
| | | void FullLicenseInfo::toLicenseInfo(LicenseInfo* license) const { |
| | | if (license != NULL) { |
| | | if (license != nullptr) { |
| | | strncpy(license->proprietary_data, extra_data.c_str(), |
| | | PROPRIETARY_DATA_SIZE); |
| | | |
| | |
| | | strncpy(license->expiry_date, to_date.c_str(), 11); |
| | | const double secs = difftime( |
| | | seconds_from_epoch(to_date.c_str()), |
| | | time(NULL)); |
| | | time(nullptr)); |
| | | license->days_left = round(secs / (60 * 60 * 24)); |
| | | } |
| | | } |
| | |
| | | * application_data = xxxxxxxxx (optional string 16) |
| | | */ |
| | | const char * license_signature = ini.GetValue(productNamePtr, |
| | | "license_signature", NULL); |
| | | const long license_version = ini.GetLongValue(productNamePtr, |
| | | "license_signature", nullptr); |
| | | long license_version = ini.GetLongValue(productNamePtr, |
| | | "license_version", -1); |
| | | if (license_signature != NULL && license_version > 0) { |
| | | if (license_signature != nullptr && license_version > 0) { |
| | | const string from_date = trim_copy( |
| | | ini.GetValue(productNamePtr, "from_date", |
| | | FullLicenseInfo::UNUSED_TIME)); |
| | |
| | | EventRegistry& eventRegistry) { |
| | | //bool hasFileLocation = false; |
| | | bool licenseFoundWithExplicitLocation = false; |
| | | if (licenseLocation.licenseFileLocation != NULL |
| | | if (licenseLocation.licenseFileLocation != nullptr |
| | | && licenseLocation.licenseFileLocation[0] != '\0') { |
| | | //hasFileLocation = true; |
| | | const string varName(licenseLocation.licenseFileLocation); |
| | |
| | | bool LicenseReader::findFileWithEnvironmentVariable(vector<string>& diskFiles, |
| | | EventRegistry& eventRegistry) { |
| | | bool licenseFileFoundWithEnvVariable = false; |
| | | if (licenseLocation.environmentVariableName != NULL |
| | | if (licenseLocation.environmentVariableName != nullptr |
| | | && licenseLocation.environmentVariableName[0] != '\0') { |
| | | 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') { |
| | | if (env_var_value != nullptr && env_var_value[0] != '\0') { |
| | | const vector<string> declared_positions = splitLicensePositions( |
| | | string(env_var_value)); |
| | | vector<string> existing_pos = filterExistingFiles( |
| | |
| | | } |
| | | |
| | | AuditEvent const * EventRegistry::getLastFailure() const { |
| | | const AuditEvent* result = NULL; |
| | | const AuditEvent* result = nullptr; |
| | | if (logs.size() == 0) { |
| | | return result; |
| | | } |
| | |
| | | |
| | | static void mergeLicenses(vector<license::FullLicenseInfo> licenses, |
| | | LicenseInfo* license) { |
| | | if (license != NULL) { |
| | | if (license != nullptr) { |
| | | time_t curLicense_exp = 0; |
| | | for (auto it = licenses.begin(); it != licenses.end(); it++) { |
| | | //choose the license that expires later... |
| | |
| | | } else { |
| | | result = er.getLastFailure()->event_type; |
| | | } |
| | | if (license != NULL) { |
| | | if (license != nullptr) { |
| | | er.exportLastEvents(license->status, 5); |
| | | } |
| | | return result; |
| | |
| | | HRESULT hr = S_OK;
|
| | | DWORD dwErrCode;
|
| | | DWORD dwBlobLen;
|
| | | BYTE *pbKeyBlob = NULL;
|
| | | BYTE *pbKeyBlob = nullptr;
|
| | | stringstream ss;
|
| | | // If the handle to key container is NULL, fail.
|
| | | if (m_hCryptKey == NULL)
|
| | |
| | | // blob.
|
| | | if (!CryptExportKey(m_hCryptKey,
|
| | | NULL, PUBLICKEYBLOB, 0,
|
| | | NULL, &dwBlobLen)) {
|
| | | nullptr, &dwBlobLen)) {
|
| | | dwErrCode = GetLastError();
|
| | | throw logic_error(
|
| | | string("Error calculating size of public key ")
|
| | | + to_string(static_cast<long long>(dwErrCode)));
|
| | | }
|
| | | // Allocate memory for the pbKeyBlob.
|
| | | if ((pbKeyBlob = new BYTE[dwBlobLen]) == NULL) {
|
| | | if ((pbKeyBlob = new BYTE[dwBlobLen]) == nullptr) {
|
| | | throw logic_error(string("Out of memory exporting public key "));
|
| | | }
|
| | | // Do the actual exporting into the key BLOB.
|
| | |
| | | // blob.
|
| | | if (!CryptExportKey(m_hCryptKey,
|
| | | NULL, PRIVATEKEYBLOB, 0,
|
| | | NULL, &dwBlobLen)) {
|
| | | nullptr, &dwBlobLen)) {
|
| | | dwErrCode = GetLastError();
|
| | | throw logic_error(
|
| | | string("Error calculating size of private key ")
|
| | | + to_string(static_cast<long long>(dwErrCode)));
|
| | | }
|
| | | // Allocate memory for the pbKeyBlob.
|
| | | if ((pbKeyBlob = new BYTE[dwBlobLen]) == NULL) {
|
| | | if ((pbKeyBlob = new BYTE[dwBlobLen]) == nullptr) {
|
| | | throw logic_error(string("Out of memory exporting private key "));
|
| | | }
|
| | |
|
| | |
| | | // Determine the size of the signature and allocate memory.
|
| | |
|
| | | dwSigLen = 0;
|
| | | if (CryptSignHash(hHash, AT_SIGNATURE, NULL, 0, NULL, &dwSigLen)) {
|
| | | if (CryptSignHash(hHash, AT_SIGNATURE, nullptr, 0, nullptr, &dwSigLen)) {
|
| | | printf("Signature length %d found.\n", dwSigLen);
|
| | | } else {
|
| | | throw logic_error(string("Error during CryptSignHash."));
|
| | |
| | | // Sign the hash object.
|
| | |
|
| | | if (CryptSignHash(hHash, AT_SIGNATURE,
|
| | | NULL, 0, pbSignature, &dwSigLen)) {
|
| | | nullptr, 0, pbSignature, &dwSigLen)) {
|
| | | printf("pbSignature is the signature length. %d\n", dwSigLen);
|
| | | } else {
|
| | | throw logic_error(string("Error during CryptSignHash."));
|
| | |
| | | CryptDestroyKey(hKey);
|
| | |
|
| | | CryptBinaryToString(pbSignature, dwSigLen,
|
| | | CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, NULL, &strLen);
|
| | | CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, nullptr, &strLen);
|
| | | vector<char> buffer(strLen);
|
| | | CryptBinaryToString(pbSignature, dwSigLen,
|
| | | CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, &buffer[0], &strLen);
|
| | |
| | | |
| | | void write_pubkey_file(const string& public_fname, const string& pbPublicKey) { |
| | | FILE* fp = fopen(public_fname.c_str(), "w"); |
| | | if (fp == NULL) { |
| | | if (fp == nullptr) { |
| | | throw ios_base::failure(string("can't create :") + public_fname); |
| | | } |
| | | fprintf(fp, "//file generated by bootstrap.cpp, do not edit.\n\n"); |
| | |
| | | |
| | | void write_privkey_file(const string& private_fname, const string& privateKey) { |
| | | FILE* fp = fopen(private_fname.c_str(), "w"); |
| | | if (fp == NULL) { |
| | | if (fp == nullptr) { |
| | | throw ios_base::failure(string("can't create :") + private_fname); |
| | | } |
| | | fprintf(fp, "//file generated by bootstrap.cpp, do not edit.\n\n"); |
| | |
| | | try { |
| | | end_date = normalize_date(dt_end); |
| | | char curdate[20]; |
| | | time_t curtime = time(NULL); |
| | | time_t curtime = time(nullptr); |
| | | strftime(curdate, 20, "%Y-%m-%d", localtime(&curtime)); |
| | | begin_date.assign(curdate); |
| | | } catch (const invalid_argument &e) { |
| | |
| | | BOOST_AUTO_TEST_CASE( read_single_file ) { |
| | | const char * licLocation = |
| | | PROJECT_TEST_SRC_DIR "/library/test_reader.ini"; |
| | | const LicenseLocation location = { licLocation, NULL, false }; |
| | | const LicenseLocation location = { licLocation, nullptr, false }; |
| | | LicenseReader licenseReader(location); |
| | | vector<FullLicenseInfo> licenseInfos; |
| | | const EventRegistry registry = licenseReader.readLicenses("PrODUCT", |
| | |
| | | BOOST_AUTO_TEST_CASE( product_not_licensed ) { |
| | | const char * licLocation = |
| | | PROJECT_TEST_SRC_DIR "/library/test_reader.ini"; |
| | | const LicenseLocation location = { licLocation, NULL, false }; |
| | | const LicenseLocation location = { licLocation, nullptr, false }; |
| | | LicenseReader licenseReader(location); |
| | | vector<FullLicenseInfo> licenseInfos; |
| | | const EventRegistry registry = licenseReader.readLicenses("PRODUCT-NOT", |
| | |
| | | BOOST_AUTO_TEST_CASE( file_not_found ) { |
| | | const char * licLocation = PROJECT_TEST_SRC_DIR "/library/not_found.ini"; |
| | | //const char * envName = "MYVAR"; |
| | | const LicenseLocation location = { licLocation, NULL, false }; |
| | | const LicenseLocation location = { licLocation, nullptr, false }; |
| | | LicenseReader licenseReader(location); |
| | | vector<FullLicenseInfo> licenseInfos; |
| | | const EventRegistry registry = licenseReader.readLicenses("PRODUCT", |
| | |
| | | |
| | | BOOST_AUTO_TEST_CASE( env_var_not_defined ) { |
| | | const char * envName = "MYVAR"; |
| | | const LicenseLocation location = { NULL, envName, false }; |
| | | const LicenseLocation location = {nullptr, envName, false }; |
| | | LicenseReader licenseReader(location); |
| | | vector<FullLicenseInfo> licenseInfos; |
| | | const EventRegistry registry = licenseReader.readLicenses("PRODUCT", |
| | |
| | | char str[MAX_PATH]; |
| | | strcpy(str,"LIC_VAR=" PROJECT_TEST_SRC_DIR "/library/test_reader.ini"); |
| | | putenv(str); |
| | | const LicenseLocation location = { NULL, "LIC_VAR", false }; |
| | | const LicenseLocation location = {nullptr, "LIC_VAR", false }; |
| | | LicenseReader licenseReader(location); |
| | | vector<FullLicenseInfo> licenseInfos; |
| | | const EventRegistry registry = licenseReader.readLicenses("PrODUCT", |