1010
1111#pragma comment(lib, "bcrypt.lib")
1212
13-
14- class LicenseManager final // Not finished yet
13+ class LicenseManager final
1514{
1615public:
1716 LicenseManager (std::string LicenseServerEndpoint, bool bAllowOfflineProductUsage, std::string LicenseFileName)
@@ -21,46 +20,62 @@ class LicenseManager final //Not finished yet
2120
2221 ~LicenseManager ()
2322 {
24- if (RSAPubKeyPinned != nullptr )
25- delete[] RSAPubKeyPinned ;
23+ if (DEFAULT_PUB_KEY_X != nullptr )
24+ delete[] DEFAULT_PUB_KEY_X ;
2625
27- if (PINNED_PUB_KEY_X != nullptr )
28- delete[] PINNED_PUB_KEY_X ;
26+ if (DEFAULT_PUB_KEY_Y != nullptr )
27+ delete[] DEFAULT_PUB_KEY_Y ;
2928
30- if (PINNED_PUB_KEY_Y != nullptr )
31- delete[] PINNED_PUB_KEY_Y ;
32- }
29+ if (PublicKeyX != nullptr )
30+ delete[] PublicKeyX;
3331
34- bool SendLicenseInfo (__in const bool bUsingEncryption);
32+ if (PublicKeyY != nullptr )
33+ delete[] PublicKeyY;
34+ }
3535
36- static bool Sha256_CNG (const void * data, size_t len, std::vector<uint8_t >& out32);
37- static bool DerEcdsaToP1363 (const uint8_t * der, size_t derLen, uint8_t out64[64 ]);
36+ bool SendLicenseInfo (__in const bool bUsingEncryption, __in const std::string& machine_id, __in const std::string& software_version, __out std::string& leaseId);
3837
39- BCRYPT_KEY_HANDLE import_es256_pubkey (__in std::vector<uint8_t >& x, __in std::vector<uint8_t >& y);
4038 bool VerifyLicenseJWT_ES256 (__in const std::string& token);
4139
42- const uint8_t * GetPubX () const { return PINNED_PUB_KEY_X ; }
43- const uint8_t * GetPubY () const { return PINNED_PUB_KEY_Y ; }
40+ void SetPubXY (__in const uint8_t * arrX, __in const uint8_t * arrY)
41+ {
42+ if (this ->PublicKeyX == nullptr )
43+ this ->PublicKeyX = new uint8_t [32 ]{ 0 };
44+
45+ if (this ->PublicKeyY == nullptr )
46+ this ->PublicKeyY = new uint8_t [32 ]{ 0 };
47+
48+ for (int i = 0 ; i < 32 ; i++)
49+ {
50+ this ->PublicKeyX [i] = arrX[i];
51+ this ->PublicKeyY [i] = arrY[i];
52+ }
53+ }
54+
55+ const uint8_t * GetPubX () const { if (this ->PublicKeyX == nullptr ) return DEFAULT_PUB_KEY_X ; else return this ->PublicKeyX ; }
56+ const uint8_t * GetPubY () const { if (this ->PublicKeyY == nullptr ) return DEFAULT_PUB_KEY_Y ; else return this ->PublicKeyY ; }
4457
4558 bool IsOfflineUsageAllowed () const { return bAllowOfflineProductUsage; }
4659
60+ void SetLicenseToken (__in const std::string& jwtToken) { this ->LicenseToken = jwtToken; }
61+
4762private:
4863
49- char * RSAPubKeyPinned = nullptr ;
50-
51- std::string LicenseKey;
52- std::vector<uint8_t > LicenseSignature; // grabbed from file or registry or w/e
64+ std::string LicenseToken;
5365 std::string LicenseFileName;
54-
5566 std::string LicenseServerEndpoint;
56-
5767 bool bAllowOfflineProductUsage = false ;
5868
59- std::vector<uint8_t > LoadPublicKeyContents (const std::string& pubKeyText);
60- BCRYPT_KEY_HANDLE LoadRSAPublicKey (const std::vector<uint8_t > derData);
61- bool VerifySignature (BCRYPT_KEY_HANDLE hKey, const std::vector<uint8_t >& licenseData, const std::vector<uint8_t >& signature);
69+ static bool Sha256_CNG (__in const void * data, __in const size_t len, __out std::vector<uint8_t >& out32);
70+ static bool DerEcdsaToP1363 (__in const uint8_t * der, __in const size_t derLen, __out uint8_t out64[64 ]);
71+
72+ BCRYPT_KEY_HANDLE import_es256_pubkey (__in std::vector<uint8_t >& x, __in std::vector<uint8_t >& y);
73+
74+ uint8_t * PublicKeyX = nullptr ; // 32 length byte array
75+ uint8_t * PublicKeyY = nullptr ; // 32 length byte array
6276
63- // pinned public key -> replace with your public key X/Y from dump_xy.py (we originally generate an ECDSA keypair with openssl, then make a license.jwt file which embeds license details)
64- const uint8_t * PINNED_PUB_KEY_X = new uint8_t [32 ] { 0x0e ,0x8a ,0x31 ,0x1e ,0x93 ,0x8d ,0xc5 ,0x14 ,0x8e ,0xb7 ,0x9c ,0xb1 ,0x70 ,0xd9 ,0xca ,0x35 ,0x3a ,0x44 ,0x9b ,0xb9 ,0xe1 ,0x65 ,0xa0 ,0xc3 ,0xfb ,0xc6 ,0xb8 ,0x73 ,0x2b ,0xd8 ,0xcd ,0xc8 };
65- const uint8_t * PINNED_PUB_KEY_Y = new uint8_t [32 ] { 0xfe ,0x24 ,0xf5 ,0x84 ,0xeb ,0x0e ,0x20 ,0x39 ,0xd3 ,0x66 ,0xbe ,0x76 ,0x14 ,0x3c ,0xdb ,0xc0 ,0xc1 ,0x97 ,0xca ,0x96 ,0x83 ,0x55 ,0x99 ,0x0f ,0xc1 ,0x18 ,0x5b ,0x1d ,0x7d ,0x94 ,0x48 ,0x67 };
77+ // pinned DEFAULT public key -> replace with your public key X/Y from running `python dump_xy.py` (we originally generate an ES256 keypair with openssl, then make a license.jwt file which embeds license details)
78+ // If you're just using default license from github, use the fixed key below, otherwise if you use your own license/keys use `SetPublicXY(your_x, your_y)`
79+ const uint8_t * DEFAULT_PUB_KEY_X = new uint8_t [32 ] { 0x0e ,0x8a ,0x31 ,0x1e ,0x93 ,0x8d ,0xc5 ,0x14 ,0x8e ,0xb7 ,0x9c ,0xb1 ,0x70 ,0xd9 ,0xca ,0x35 ,0x3a ,0x44 ,0x9b ,0xb9 ,0xe1 ,0x65 ,0xa0 ,0xc3 ,0xfb ,0xc6 ,0xb8 ,0x73 ,0x2b ,0xd8 ,0xcd ,0xc8 };
80+ const uint8_t * DEFAULT_PUB_KEY_Y = new uint8_t [32 ] { 0xfe ,0x24 ,0xf5 ,0x84 ,0xeb ,0x0e ,0x20 ,0x39 ,0xd3 ,0x66 ,0xbe ,0x76 ,0x14 ,0x3c ,0xdb ,0xc0 ,0xc1 ,0x97 ,0xca ,0x96 ,0x83 ,0x55 ,0x99 ,0x0f ,0xc1 ,0x18 ,0x5b ,0x1d ,0x7d ,0x94 ,0x48 ,0x67 };
6681};
0 commit comments