Ejemplo n.º 1
0
        /// <summary>
        /// Activates the license by contacting the Cryptlex servers. It
        /// validates the key and returns with encrypted and digitally signed token
        /// which it stores and uses to activate your application.
        ///
        /// This function should be executed at the time of registration, ideally on
        /// a button click.
        /// </summary>
        /// <returns>LA_OK, LA_EXPIRED, LA_SUSPENDED, LA_FAIL</returns>
        public int ActivateLicense()
        {
            if (String.IsNullOrEmpty(this._productId))
            {
                throw new LexActivatorException(LexStatusCodes.LA_E_PRODUCT_ID);
            }
            if (String.IsNullOrEmpty(this._rsaPublicKey))
            {
                throw new LexActivatorException(LexStatusCodes.LA_E_RSA_PUBLIC_KEY);
            }

            _licenseKey = LexDataStore.GetValue(this._productId, LexConstants.KEY_LICENSE_KEY);
            if (String.IsNullOrEmpty(_licenseKey))
            {
                throw new LexActivatorException(LexStatusCodes.LA_E_LICENSE_KEY);
            }

            _activationPayload = new ActivationPayload();
            var meterAttributes = new List <ActivationMeterAttribute>();
            int status          = LexActivationService.ActivateFromServer(_productId, _licenseKey, _rsaPublicKey, _activationPayload, meterAttributes);

            if (LexValidator.ValidateSuccessCode(status))
            {
                StartTimer(_activationPayload.ServerSyncInterval, _activationPayload.ServerSyncInterval);
                return(status);
            }
            throw new LexActivatorException(status);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// It verifies whether your app is genuinely activated or not. The verification is
        /// done locally by verifying the cryptographic digital signature fetched at the time of activation.
        ///
        /// This is just an auxiliary function which you may use in some specific cases, when you
        /// want to skip the server sync.
        ///
        /// NOTE: You may want to set grace period to 0 to ignore grace period.
        /// </summary>
        /// <returns>LA_OK, LA_EXPIRED, LA_SUSPENDED, LA_GRACE_PERIOD_OVER, LA_FAIL</returns>
        private int IsLicenseValid()
        {
            if (String.IsNullOrEmpty(this._productId))
            {
                return(LexStatusCodes.LA_E_PRODUCT_ID);
            }
            if (!LexValidator.ValidateSystemTime(this._productId))
            {
                return(LexStatusCodes.LA_E_TIME_MODIFIED);
            }
            _licenseKey = LexDataStore.GetValue(this._productId, LexConstants.KEY_LICENSE_KEY);
            if (!LexValidator.ValidateLicenseKey(_licenseKey))
            {
                return(LexStatusCodes.LA_E_LICENSE_KEY);
            }
            string jwt = LexDataStore.GetValue(_productId, LexConstants.KEY_ACTIVATION_JWT);

            if (String.IsNullOrEmpty(jwt))
            {
                return(LexStatusCodes.LA_FAIL);
            }
            if (_activationPayload != null && _activationPayload.IsValid)
            {
                return(LexValidator.ValidateActivationStatus(_productId, _activationPayload));
            }
            _activationPayload = new ActivationPayload();
            return(LexValidator.ValidateActivation(jwt, _rsaPublicKey, _licenseKey, _productId, _activationPayload));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the license key used for activation.
        /// </summary>
        /// <returns>Returns the license key.</returns>
        public string GetLicenseKey()
        {
            if (String.IsNullOrEmpty(this._productId))
            {
                throw new LexActivatorException(LexStatusCodes.LA_E_PRODUCT_ID);
            }
            string licenseKey = LexDataStore.GetValue(this._productId, LexConstants.KEY_LICENSE_KEY);

            if (String.IsNullOrEmpty(licenseKey))
            {
                throw new LexActivatorException(LexStatusCodes.LA_E_LICENSE_KEY);
            }
            return(licenseKey);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Sets the license key required to activate the license.
 /// </summary>
 /// <param name="licenseKey">a valid license key</param>
 public void SetLicenseKey(string licenseKey)
 {
     if (String.IsNullOrEmpty(this._productId))
     {
         throw new LexActivatorException(LexStatusCodes.LA_E_PRODUCT_ID);
     }
     if (String.IsNullOrEmpty(this._rsaPublicKey))
     {
         throw new LexActivatorException(LexStatusCodes.LA_E_RSA_PUBLIC_KEY);
     }
     if (!LexValidator.ValidateLicenseKey(licenseKey))
     {
         throw new LexActivatorException(LexStatusCodes.LA_E_LICENSE_KEY);
     }
     this._licenseKey = licenseKey;
     LexDataStore.SaveValue(this._productId, LexConstants.KEY_LICENSE_KEY, licenseKey);
 }