Example #1
0
        private bool CheckIfActivated()
        {
            try
            {
                if (!KeyHelper.MatchCurrentHardwareId(HWID_))
                {
                    log.Error("HWID changed");
                    return(false);
                }
                KeyValidator keyVal = new KeyValidator(Tmpl_);

                keyVal.SetKey(LicenseKey_);

                keyVal.SetValidationData("Email", Email_); // the key will not be valid if you set a different user name than the one you have set at key generation
                LicensingClient licensingClient = new LicensingClient(Tmpl_, LicenseKey_, keyVal.QueryValidationData(null), HWID_, ActivationKey_);
                if (licensingClient.IsLicenseValid())
                {
                    byte[] featureSet = keyVal.QueryKeyData("FeatureSet");
                    featureSet.ToString();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception E)
            {
                log.Error("Program is not activated", E);
                return(false);
            }
        }
Example #2
0
        public void ActivationTask(String email, String key)
        {
            string       activationStatusStr = "";
            KeyValidator keyVal = null;

            try
            {
                // validate the generated key. This sequence of code is also used in the actual product to validate the entered license key
                keyVal = new KeyValidator(Tmpl_);
                keyVal.SetKey(key);
            }
            catch (Exception ex)
            {
                OnActivation(false, "Key is incorrect");
                log.Error("Key validation failed " + ex.Message);
                return;
            }

            try
            {
                keyVal.SetValidationData("Email", email); // the key will not be valid if you set a different user name than the one you have set at key generation


                LicensingClient licensingClient = new LicensingClient("https://activation.identamaster.com:444",
                                                                      Tmpl_,
                                                                      key,
                                                                      keyVal.QueryValidationData(null), CurrentHWID_,
                                                                      PRODUCT_ID);

                licensingClient.AcquireLicense();

                LicenseKey_    = key;
                Email_         = email;
                ActivationKey_ = licensingClient.ActivationKey;
                HWID_          = CurrentHWID_;
                // save keys
                SaveKeys();

                if (!licensingClient.IsLicenseValid())
                {
                    switch (licensingClient.LicenseStatus)
                    {
                    case LICENSE_STATUS.InvalidActivationKey:
                        activationStatusStr = "invalid activation key";
                        break;

                    case LICENSE_STATUS.InvalidHardwareId:
                        activationStatusStr = "invalid hardware id";
                        break;

                    case LICENSE_STATUS.Expired:
                    {
                        // the license expiration date returned by LicenseExpirationDate property is only valid if IsLicenseValid() returns true,
                        // or if IsLicenseValid() returns false and LicenseStatus returns LicenseStatus.Expired
                        DateTime expDate = licensingClient.LicenseExpirationDate;
                        activationStatusStr = "license expired (expiration date: " + expDate.Month + "/" + expDate.Day + "/" + expDate.Year + ")";
                    }
                    break;

                    default:
                        activationStatusStr = "unknown";
                        break;
                    }
                    OnActivation(false, activationStatusStr);
                }
                else
                {
                    State = STATE.ACTIVATED;
                    OnActivation(true, "");
                    return;
                }
            }
            catch (System.Net.WebException ex)
            {
                switch (ex.Status)
                {
                case System.Net.WebExceptionStatus.ConnectFailure:
                    OnActivation(false, "Couldn't access activation server");
                    log.Error("Could not connect to server " + ex.Message);
                    break;

                case System.Net.WebExceptionStatus.ProtocolError:
                    OnActivation(false, "Server didn't validate this key");
                    log.Error("Key validation failed " + ex.Message);
                    break;

                default:
                    OnActivation(false, "Network error");
                    log.Error("Unknown network error " + ex.Message);
                    break;
                }
                return;
            }
            catch (Exception ex)
            {
                OnActivation(false, "Failed");
                log.Error("Key validation failed " + ex.Message);
                return;
            }
        }