Skip to content

Commit 8d45773

Browse files
committed
Add NotExpiredValidators
1 parent e3460c6 commit 8d45773

File tree

6 files changed

+131
-4
lines changed

6 files changed

+131
-4
lines changed

include/cryptolens/Configuration_Unix.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "validators/AndValidator.hpp"
88
#include "validators/CorrectKeyValidator.hpp"
99
#include "validators/CorrectProductValidator.hpp"
10+
#include "validators/NotExpiredValidator_ctime.hpp"
1011
#include "validators/OnValidMachineValidator.hpp"
1112

1213
namespace cryptolens_io {
@@ -24,16 +25,34 @@ struct Configuration_Unix {
2425
using ActivateValidator = AndValidator_<Env, CorrectKeyValidator_<Env>
2526
, AndValidator_<Env, CorrectProductValidator_<Env>
2627
, AndValidator_<Env, OnValidMachineValidator_<Env>
28+
, NotExpiredValidator_ctime_<Env>
2729
>>>;
2830
};
2931

32+
template<typename MachineCodeComputer_>
33+
struct Configuration_Unix_IgnoreExpires {
34+
using ResponseParser = ResponseParser_ArduinoJson5;
35+
using RequestHandler = RequestHandler_curl;
36+
using SignatureVerifier = SignatureVerifier_OpenSSL;
37+
using MachineCodeComputer = MachineCodeComputer_;
38+
39+
template<typename Env>
40+
using ActivateValidator = AndValidator_<Env, CorrectKeyValidator_<Env>
41+
, AndValidator_<Env, CorrectProductValidator_<Env>
42+
, OnValidMachineValidator_<Env>
43+
>>;
44+
};
45+
3046
} // namespace v20190401
3147

3248
namespace latest {
3349

3450
template<typename MachineCodeComputer_>
3551
using Configuration_Unix = ::cryptolens_io::v20190401::Configuration_Unix<MachineCodeComputer_>;
3652

53+
template<typename MachineCodeComputer_>
54+
using Configuration_Unix_IgnoreExpires = ::cryptolens_io::v20190401::Configuration_Unix_IgnoreExpires<MachineCodeComputer_>;
55+
3756
} // namespace latest
3857

3958
} // namespace cryptolens_io

include/cryptolens/Configuration_Windows.hpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "validators/AndValidator.hpp"
88
#include "validators/CorrectKeyValidator.hpp"
99
#include "validators/CorrectProductValidator.hpp"
10+
#include "validators/NotExpiredValidator_kernel32.hpp"
1011
#include "validators/OnValidMachineValidator.hpp"
1112

1213
namespace cryptolens_io {
@@ -22,9 +23,24 @@ struct Configuration_Windows {
2223

2324
template<typename Env>
2425
using ActivateValidator = AndValidator_<Env, CorrectKeyValidator_<Env>
25-
, AndValidator_<Env, CorrectProductValidator_<Env>
26-
, AndValidator_<Env, OnValidMachineValidator_<Env>
27-
>>>;
26+
, AndValidator_<Env, CorrectProductValidator_<Env>
27+
, AndValidator_<Env, OnValidMachineValidator_<Env>
28+
, NotExpiredValidator_kernel32_<Env>
29+
>>>;
30+
};
31+
32+
template<typename MachineCodeComputer_>
33+
struct Configuration_Windows_IgnoreExpires {
34+
using ResponseParser = ResponseParser_ArduinoJson5;
35+
using RequestHandler = RequestHandler_WinHTTP;
36+
using SignatureVerifier = SignatureVerifier_CryptoAPI;
37+
using MachineCodeComputer = MachineCodeComputer_;
38+
39+
template<typename Env>
40+
using ActivateValidator = AndValidator_<Env, CorrectKeyValidator_<Env>
41+
, AndValidator_<Env, CorrectProductValidator_<Env>
42+
, OnValidMachineValidator_<Env>
43+
>>;
2844
};
2945

3046
} // namespace v20190401
@@ -34,6 +50,9 @@ namespace latest {
3450
template<typename MachineCodeComputer_>
3551
using Configuration_Windows = ::cryptolens_io::v20190401::Configuration_Windows<MachineCodeComputer_>;
3652

53+
template<typename MachineCodeComputer_>
54+
using Configuration_Windows_IgnoreExpires = ::cryptolens_io::v20190401::Configuration_Windows_IgnoreExpires<MachineCodeComputer_>;
55+
3756
} // namespace latest
3857

3958
} // namespace cryptolens_io

include/cryptolens/basic_Error.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ constexpr int PRODUCT_NOT_FOUND = 5;
7070
constexpr int KEY_NOT_FOUND = 6;
7171
constexpr int KEY_BLOCKED = 7;
7272
constexpr int DEVICE_LIMIT_REACHED = 8;
73+
constexpr int KEY_EXPIRED = 9;
7374

7475
} // namespace Main
7576

include/cryptolens/validators/CorrectKeyValidator.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "../api.hpp"
44
#include "../basic_Error.hpp"
5-
#include "../LicenseKeyInformation.hpp"
65

76
namespace cryptolens_io {
87

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <ctime>
4+
5+
#include "../api.hpp"
6+
#include "../basic_Error.hpp"
7+
8+
namespace cryptolens_io {
9+
10+
namespace v20190401 {
11+
12+
template<typename Env>
13+
class NotExpiredValidator_ctime_ {
14+
public:
15+
NotExpiredValidator_ctime_(basic_Error & e) {}
16+
17+
void validate(basic_Error & e, Env & env) {
18+
std::uint64_t expires = env.get_license_key_information().get_expires();
19+
20+
auto current = std::time(NULL);
21+
if (current < 0 || expires < (std::uint64_t)current) {
22+
using namespace errors;
23+
e.set(api::main(), Subsystem::Main, Main::KEY_EXPIRED);
24+
}
25+
}
26+
27+
private:
28+
};
29+
30+
} // namespace v20190401
31+
32+
namespace latest {
33+
34+
template<typename Env>
35+
using NotExpiredValidator_ctime_ = ::cryptolens_io::v20190401::NotExpiredValidator_ctime_<Env>;
36+
37+
} // namespace latest
38+
39+
} // namespace cryptolens_io
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma once
2+
3+
#include "../imports/windows/Windows.h"
4+
5+
#include "../api.hpp"
6+
#include "../basic_Error.hpp"
7+
8+
namespace cryptolens_io {
9+
10+
namespace v20190401 {
11+
12+
template<typename Env>
13+
class NotExpiredValidator_kernel32_ {
14+
public:
15+
NotExpiredValidator_kernel32_(basic_Error & e) {}
16+
17+
void validate(basic_Error & e, Env & env) {
18+
std::uint64_t expires = env.get_license_key_information().get_expires();
19+
20+
if (expires < get_current_()) {
21+
using namespace errors;
22+
e.set(api::main(), Subsystem::Main, Main::KEY_EXPIRED);
23+
}
24+
}
25+
26+
private:
27+
std::uint64_t get_current_() {
28+
FILETIME ft;
29+
GetSystemTimeAsFileTime(&ft);
30+
31+
constexpr std::uint64_t EPOCH = 0x019DB1DED53E8000;
32+
constexpr std::uint64_t TICKS_PER_SECOND = 10000000;
33+
34+
std::uint64_t tlow = ft.dwLowDateTime;
35+
std::uint64_t thigh = ft.dwHighDateTime;
36+
std::uint64_t t = thigh << 32 | tlow;
37+
return (t - EPOCH) / TICKS_PER_SECOND;
38+
}
39+
};
40+
41+
} // namespace v20190401
42+
43+
namespace latest {
44+
45+
template<typename Env>
46+
using NotExpiredValidator_kernel32_ = ::cryptolens_io::v20190401::NotExpiredValidator_kernel32_<Env>;
47+
48+
} // namespace latest
49+
50+
} // namespace cryptolens_io

0 commit comments

Comments
 (0)