NAP
licenseservice.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local Includes
8 #include "publickey.h"
9 
10  // External Includes
11 #include <nap/service.h>
12 #include <nap/datetime.h>
13 #include <signingscheme.h>
14 
15 namespace nap
16 {
17  // Forward Declares
18  class LicenseService;
19 
25  {
26  RTTI_ENABLE(ServiceConfiguration)
27  public:
28  std::string mDirectory = "{PROJECT_DIR}/license";
29  virtual rtti::TypeInfo getServiceType() const override { return RTTI_OF(LicenseService); }
30  };
31 
32 
36  struct NAPAPI LicenseInformation
37  {
38  std::string mName;
39  std::string mMail;
40  std::string mApp;
41  std::string mTag;
42  std::string mID;
43  bool mExpires = false;
45 
49  bool canExpire() const { return mExpires; }
50 
56  bool expired();
57  };
58 
59 
82  class NAPAPI LicenseService : public Service
83  {
84  RTTI_ENABLE(Service)
85  public:
89  LicenseService(ServiceConfiguration* configuration);
90 
105  bool getMachineID(std::string& id, nap::utility::ErrorState& error);
106 
128  bool validateLicense(const nap::PublicKey& publicKey, LicenseInformation& outInformation, utility::ErrorState& error);
129 
151  bool validateLicense(const std::string& publicKey, LicenseInformation& outInformation, utility::ErrorState& error);
152 
175  bool validateLicense(const nap::PublicKey& publicKey, nap::ESigningScheme signingScheme, LicenseInformation& outInformation, utility::ErrorState& error);
176 
199  bool validateLicense(const std::string& publicKey, nap::ESigningScheme signingScheme, LicenseInformation& outInformation, utility::ErrorState& error);
200 
205  bool hasLicense() const { return !mLicense.empty(); }
206 
210  const std::string& getLicense() const { return mLicense; }
211 
216  bool hasKey() const { return !mSignature.empty(); }
217 
221  const std::string& getKey() const { return mSignature; }
222 
223  protected:
231  virtual bool init(utility::ErrorState& error) override;
232 
233  private:
234  std::string mLicense;
235  std::string mSignature;
236  std::string mDirectory;
237  };
238 }
nap::LicenseInformation::canExpire
bool canExpire() const
Definition: licenseservice.h:49
nap::LicenseInformation::mMail
std::string mMail
Extracted user mail.
Definition: licenseservice.h:39
nap::LicenseConfiguration
Definition: licenseservice.h:24
nap::LicenseService::hasLicense
bool hasLicense() const
Definition: licenseservice.h:205
nap::LicenseInformation::mTag
std::string mTag
Extracted additional license information.
Definition: licenseservice.h:41
nap::LicenseInformation::mName
std::string mName
Extracted user name.
Definition: licenseservice.h:38
nap::LicenseInformation::mTime
DateTime mTime
License expiry date as system timestamp.
Definition: licenseservice.h:44
nap::PublicKey
Definition: publickey.h:13
nap::DateTime
Definition: datetime.h:173
nap::utility::ErrorState
Definition: errorstate.h:19
nap::LicenseService
Definition: licenseservice.h:82
nap::ServiceConfiguration
Definition: service.h:28
nap::LicenseInformation::mID
std::string mID
Extracted machine id.
Definition: licenseservice.h:42
nap::Service
Definition: templateservice.h:8
nap::LicenseService::hasKey
bool hasKey() const
Definition: licenseservice.h:216
nap::LicenseService::getKey
const std::string & getKey() const
Definition: licenseservice.h:221
nap::LicenseInformation
Definition: licenseservice.h:36
nap
Definition: templateapp.h:17
nap::LicenseInformation::mApp
std::string mApp
Extracted application signature.
Definition: licenseservice.h:40
nap::rtti::TypeInfo
rttr::type TypeInfo
Definition: typeinfo.h:140
nap::LicenseConfiguration::getServiceType
virtual rtti::TypeInfo getServiceType() const override
Definition: licenseservice.h:29
nap::LicenseService::getLicense
const std::string & getLicense() const
Definition: licenseservice.h:210
nap::ESigningScheme
ESigningScheme
Definition: signingscheme.h:14