public async Task <AggregationStatus> Get()
        {
            string rankingApiUrl      = _configuration.GetValue <string>("API_GATEWAY_RANKING_API_URL");
            var    getUserEntries     = _client.GetStringAsync(rankingApiUrl);
            string licensingStatusUrl = _configuration.GetValue <string>("API_GATEWAY_LICENSING_STATUS_URL");
            var    getLicenseStatus   = _client.GetStringAsync(licensingStatusUrl);

            UserEntry[] userEntries = new UserEntry[] { };
            try
            {
                userEntries = JsonSerializer.Deserialize <UserEntry[]>(await getUserEntries);
            }
            catch (TaskCanceledException)
            {
            }
            LicenseStatus licenseStatus = null;

            try
            {
                licenseStatus = JsonSerializer.Deserialize <LicenseStatus>(await getLicenseStatus);
            }
            catch (TaskCanceledException)
            {
            }
            var aggregationStatus = new AggregationStatus()
            {
                UserEntries   = userEntries,
                LicenseStatus = licenseStatus,
            };

            return(aggregationStatus);
        }
        public static MyLicense ReadLicense(out LicenseStatus licStatus, out string validationMsg)
        {
            byte[] certPublicKeyData;

            Assembly assembly = Assembly.GetExecutingAssembly();

            using (MemoryStream memoryStream = new MemoryStream())
            {
                assembly.GetManifestResourceStream("ScanHelper.LicenseVerify.cer")?.CopyTo(memoryStream);

                certPublicKeyData = memoryStream.ToArray();
            }

            if (File.Exists("license.lic"))
            {
                MyLicense license = (MyLicense)ReadLicense(typeof(MyLicense), File.ReadAllText("license.lic"), certPublicKeyData, out licStatus, out validationMsg);

                return(license);
            }

            licStatus     = LicenseStatus.Undefined;
            validationMsg = "Brak pliku licencji!";

            return(null);
        }
예제 #3
0
            public override LicenseStatus DoExtraValidation(bool is_mobile_uid_input, out string validationMsg)
            {
                LicenseStatus _licStatus = LicenseStatus.UNDEFINED;

                validationMsg = string.Empty;

                switch (this.Type)
                {
                case LicenseTypes.Single:
                    //For Single License, check whether UID is matched

                    if (this.UID == GenerateUID(this.AppName, is_mobile_uid_input ? this.UserMobile : null))
                    {
                        _licStatus = LicenseStatus.VALID;
                    }
                    else
                    {
                        validationMsg = "The license is NOT for this copy!";
                        _licStatus    = LicenseStatus.INVALID;
                    }
                    break;

                case LicenseTypes.Volume:
                    //No UID checking for Volume License
                    _licStatus = LicenseStatus.VALID;
                    break;

                default:
                    validationMsg = "Invalid license";
                    _licStatus    = LicenseStatus.INVALID;
                    break;
                }

                return(_licStatus);
            }
예제 #4
0
        public override LicenseStatus DoExtraValidation(out string validationMsg)
        {
            LicenseStatus _licStatus = LicenseStatus.UNDEFINED;

            validationMsg = string.Empty;

            switch (this.Type)
            {
            case LicenseTypes.Single:
                //For Single License, check whether UID is matched
                if (this.UID == LicenseHandler.GenerateUID(this.AppName))
                {
                    _licStatus = LicenseStatus.VALID;
                }
                else
                {
                    validationMsg = "¡La licencia no es para esta copia!";
                    _licStatus    = LicenseStatus.INVALID;
                }
                break;

            case LicenseTypes.Volume:
                //No UID checking for Volume License
                _licStatus = LicenseStatus.VALID;
                break;

            default:
                validationMsg = "Licencia Invalida";
                _licStatus    = LicenseStatus.INVALID;
                break;
            }

            return(_licStatus);
        }
예제 #5
0
        private bool ValidateLicense()
        {
            if (string.IsNullOrWhiteSpace(License))
            {
                MessageBox.Show("Please input license", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            //Check the activation string
            LicenseStatus _licStatus = LicenseStatus.UNDEFINED;
            string        _msg       = string.Empty;
            LicenseEntity _lic       = LicenseHandler.ParseLicenseFromBASE64String(LicenseObjectType, License.Trim(), _certPubicKeyData, out _licStatus, out _msg);

            switch (_licStatus)
            {
            case LicenseStatus.VALID:
                MessageBox.Show(_msg, "License is valid", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(true);

            case LicenseStatus.CRACKED:
            case LicenseStatus.INVALID:
            case LicenseStatus.UNDEFINED:
                MessageBox.Show(_msg, "License is INVALID", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return(false);

            default:
                return(false);
            }
        }
예제 #6
0
        /// <summary>
        /// Checks the response of the REST API.
        /// </summary>
        /// <param name="resp">The response.</param>
        public static void CheckAPIResponse(HttpWebResponse resp)
        {
            if (!_isActivated)
            {
                return;
            }

            var kst = KeyStatus.Unchecked;

            try { kst = (KeyStatus)int.Parse(resp.Headers["X-License"]); } catch { }

            if (kst != KeyStatus.Valid && kst != KeyStatus.Unchecked)
            {
                _isActivated   = false;
                _licenseHash   = null;
                _licenseStatus = LicenseStatus.KeyStatusError;

                try
                {
                    using (var fs = File.OpenWrite(Path.Combine(AppDataPath, ".license")))
                    {
                        fs.Position = 0;
                        fs.WriteByte((byte)((int)kst + 200));
                        fs.Flush(true);
                    }
                }
                catch { }
            }
        }
예제 #7
0
        public static void InitLicense()
        {
            MemoryStream mem = new MemoryStream();

            Assembly.GetExecutingAssembly().GetManifestResourceStream("PrivateWin10.LicenseVerify.cer").CopyTo(mem);
            byte[] certPubicKeyData = mem.ToArray();

            string        msg    = string.Empty;
            LicenseStatus status = LicenseStatus.UNDEFINED;

            if (File.Exists("license.lic"))
            {
                lic = (MyLicense)LicenseHandler.ParseLicenseFromBASE64String(typeof(MyLicense), File.ReadAllText("license.lic"), certPubicKeyData, out status, out msg);
            }
            else
            {
                msg = "Your copy of this application is not activated";
            }
            if (lic == null)
            {
                lic = new MyLicense(); // we always want this object
            }
            lic.LicenseStatus = status;
            if (status != LicenseStatus.VALID && msg.Length == 0)
            {
                msg = "Your license file is invalid or broken";
            }

            if (status == LicenseStatus.INVALID || status == LicenseStatus.CRACKED)
            {
                MessageBox.Show(msg, App.mName, MessageBoxButton.OK, MessageBoxImage.Error);
            }

            Console.WriteLine(msg);
        }
예제 #8
0
 public DebugViewModel(HttpRequestBase request, ISettings settings, LicenseStatus status, List<string> logs, IpLocatonResult loc)
 {
     Request = request;
     Settings = settings;
     MailDllStatus = status;
     Logs = logs;
     Location=loc;
 }
예제 #9
0
        public bool EditionIsValidLicense_DependentOnLincenseStatus(LicenseStatus ls)
        {
            var edition = new Edition();

            edition.LicenseStatus = ls;

            return(edition.IsLicenseValid);
        }
예제 #10
0
 public void Update(string ip, string hwid, string key)
 {
     IP         = ip;
     HWID       = hwid;
     Key        = key;
     ModifyDate = DateTime.UtcNow;
     Status     = LicenseStatus.Updated;
 }
예제 #11
0
 private License(LicenseStatus status, string activationCode, DateTime lastUsed, DateTime expires, bool allowCustomMarkers)
 {
     Status = status;
     ActivationCode = activationCode;
     LastUsed = lastUsed;
     Expires = expires;
     AllowCustomMarkers = allowCustomMarkers;
 }
예제 #12
0
 public void Canceled()
 {
     if (Status == LicenseStatus.Canceled)
     {
         throw new DomainException("license_error", "License already canceled.");
     }
     ModifyDate = DateTime.UtcNow;
     Status     = LicenseStatus.Canceled;
 }
예제 #13
0
        public LicenseStatus Check(LicenseRegistration registration)
        {
            var status = new LicenseStatus();

            status.IsLicensed = GetIsLicensed(registration);
            status.IsTrial    = status.IsLicensed || GetIsTrial(registration);

            return(status);
        }
예제 #14
0
 public License(Guid id, Guid customerId, string ip, string hwid, string key) : base(id)
 {
     CustomerId = customerId;
     IP         = ip;
     HWID       = hwid;
     Key        = key;
     CreatedAt  = DateTime.UtcNow;
     Status     = LicenseStatus.Created;
 }
예제 #15
0
        public static string GetDescription(this LicenseStatus value)
        {
            FieldInfo field = value.GetType().GetField(value.ToString());

            DescriptionAttribute attribute
                = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute))
                  as DescriptionAttribute;

            return(attribute == null?value.ToString() : attribute.Description);
        }
예제 #16
0
        public void Active()
        {
            if (Status == LicenseStatus.Active)
            {
                throw new DomainException("license_error", "License already active.");
            }

            ModifyDate = DateTime.UtcNow;
            Status     = LicenseStatus.Active;
        }
예제 #17
0
        public static LicenseEntity ParseLicenseFromBASE64String(Type licenseObjType, string licenseString, string certPubKeyFilePath, out LicenseStatus licStatus, out string validationMsg)
        {
            validationMsg = string.Empty;
            licStatus = LicenseStatus.UNDEFINED;

            if (string.IsNullOrWhiteSpace(licenseString))
            {
                licStatus = LicenseStatus.CRACKED;
                return null;
            }

            string _licXML = string.Empty;
            LicenseEntity _lic = null;

            try
            {
                //Get RSA key from certificate
                X509Certificate2 cert = new X509Certificate2(certPubKeyFilePath);
                RSACryptoServiceProvider rsaKey = (RSACryptoServiceProvider)cert.PublicKey.Key;

                XmlDocument xmlDoc = new XmlDocument();

                // Load an XML file into the XmlDocument object.
                xmlDoc.PreserveWhitespace = true;
                xmlDoc.LoadXml(Encoding.UTF8.GetString(Convert.FromBase64String(licenseString)));

                // Verify the signature of the signed XML.            
                if (VerifyXml(xmlDoc, rsaKey))
                {
                    XmlNodeList nodeList = xmlDoc.GetElementsByTagName("Signature");
                    xmlDoc.DocumentElement.RemoveChild(nodeList[0]);

                    _licXML = xmlDoc.OuterXml;

                    //Deserialize license
                    XmlSerializer _serializer = new XmlSerializer(typeof(LicenseEntity), new Type[] { licenseObjType });
                    using (StringReader _reader = new StringReader(_licXML))
                    {
                        _lic = (LicenseEntity)_serializer.Deserialize(_reader);
                    }

                    licStatus = _lic.DoExtraValidation(out validationMsg);
                }
                else
                {
                    licStatus = LicenseStatus.INVALID;
                }
            }
            catch
            {
                licStatus = LicenseStatus.CRACKED;
            }

            return _lic;
        }
예제 #18
0
파일: FormMain.cs 프로젝트: j1rjacob/TMFftp
        private void CheckLicense()
        {
            //Initialize variables with default values
            MyLicense     _lic    = null;
            string        _msg    = string.Empty;
            LicenseStatus _status = LicenseStatus.UNDEFINED;

            //Read public key from assembly
            Assembly _assembly = Assembly.GetExecutingAssembly();

            using (MemoryStream _mem = new MemoryStream())
            {
                _assembly.GetManifestResourceStream("TMF_ftp.LicenseVerify.cer").CopyTo(_mem);
                _certPubicKeyData = _mem.ToArray();
            }

            //Check if the XML license file exists
            if (File.Exists("license.lic"))
            {
                _lic = (MyLicense)LicenseHandler.ParseLicenseFromBASE64String(
                    typeof(MyLicense),
                    File.ReadAllText("license.lic"),
                    _certPubicKeyData,
                    out _status,
                    out _msg);
            }
            else
            {
                _status = LicenseStatus.INVALID;
                _msg    = "This application is not activated";
            }

            switch (_status)
            {
            case LicenseStatus.VALID:
                //TODO: If license is valid, you can do extra checking here
                //TODO: E.g., check license expiry date if you have added expiry date property to your license entity
                //TODO: Also, you can set feature switch here based on the different properties you added to your license entity

                return;

            default:

                MessageBox.Show(_msg, "TMF ftp", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                using (frmActivation frm = new frmActivation())
                {
                    frm.CertificatePublicKeyData = _certPubicKeyData;
                    frm.ShowDialog();

                    Application.Exit();
                }
                break;
            }
        }
예제 #19
0
        internal void LogLicenseStatus(LicenseStatus licenseStatus, ILog logger, License license)
        {
            switch (licenseStatus)
            {
            case LicenseStatus.Valid:
                break;

            case LicenseStatus.ValidWithExpiredUpgradeProtection:
                logger.Warn("Upgrade protection expired. In order for us to continue to provide you with support and new versions of the Particular Service Platform, please extend your upgrade protection by visiting http://go.particular.net/upgrade-protection-expired");
                break;

            case LicenseStatus.ValidWithExpiringTrial:
                logger.WarnFormat("Trial license expiring {0}. To continue using the Particular Service Platform, please extend your trial or purchase a license by visiting http://go.particular.net/trial-expiring", GetRemainingDaysString(license.GetDaysUntilLicenseExpires()));
                break;

            case LicenseStatus.ValidWithExpiringSubscription:
                logger.WarnFormat("Platform license expiring {0}. To continue using the Particular Service Platform, please extend your license by visiting http://go.particular.net/license-expiring", GetRemainingDaysString(license.GetDaysUntilLicenseExpires()));
                break;

            case LicenseStatus.ValidWithExpiringUpgradeProtection:
                logger.WarnFormat("Upgrade protection expiring {0}. In order for us to continue to provide you with support and new versions of the Particular Service Platform, please extend your upgrade protection by visiting http://go.particular.net/upgrade-protection-expiring", GetRemainingDaysString(license.GetDaysUntilUpgradeProtectionExpires()));
                break;

            case LicenseStatus.InvalidDueToExpiredTrial:
                logger.Error("Trial license expired. To continue using the Particular Service Platform, please extend your trial or purchase a license by visiting http://go.particular.net/trial-expired");
                break;

            case LicenseStatus.InvalidDueToExpiredSubscription:
                logger.Error("Platform license expired. To continue using the Particular Service Platform, please extend your license by visiting http://go.particular.net/license-expired");
                break;

            case LicenseStatus.InvalidDueToExpiredUpgradeProtection:
                logger.Error("Upgrade protection expired. In order for us to continue to provide you with support and new versions of the Particular Service Platform, please extend your upgrade protection by visiting http://go.particular.net/upgrade-protection-expired");
                break;
            }

            string GetRemainingDaysString(int?remainingDays)
            {
                switch (remainingDays)
                {
                case null:
                    return("soon");

                case 0:
                    return("today");

                case 1:
                    return("in 1 day");

                default:
                    return($"in {remainingDays} days");
                }
            }
        }
예제 #20
0
        public void TestMinimumHostLicenseValue()
        {
            Mock <Host> saHost = ObjectFactory.BuiltObject <Host>(ObjectBuilderType.ClearwaterHost, id);

            SetupMockHostWithExpiry(saHost, new DateTime(2015, 10, 25));

            using (LicenseStatus ls = new LicenseStatus(saHost.Object))
            {
                Assert.True(ls.ExpiryDate.HasValue, "Expiry date doesn't have a value");
                Assert.That(ls.ExpiryDate.Value.ToShortDateString(),
                            Is.EqualTo(new DateTime(2015, 10, 25).ToShortDateString()), "Expiry dates");
            }
        }
        public void SetStatus(LicenseStatus licenseStatus)
        {
            _appLicenseStatus = licenseStatus;

            if (_appLicenseStatus == LicenseStatus.Active)
            {
                enabled = false;
            }
            else
            {
                enabled = true;
                AssignRenderTexture();
            }
        }
예제 #22
0
        private bool CheckLicense()
        {
            //Initialize variables with default values
            MagentixLicense _lic = null;

            byte[]        _certPubicKeyData;
            string        _msg    = string.Empty;
            LicenseStatus _status = LicenseStatus.UNDEFINED;

            //Read public key from assembly
            Assembly _assembly = Assembly.GetExecutingAssembly();

            using (MemoryStream _mem = new MemoryStream())
            {
                Stream stream = _assembly.GetManifestResourceStream("Magentix.Presentation.LicenseVerify.cer");
                stream.CopyTo(_mem);

                _certPubicKeyData = _mem.ToArray();
            }

            //Check if the XML license file exists
            if (File.Exists("license.lic"))
            {
                _lic = (MagentixLicense)LicenseHandler.ParseLicenseFromBASE64String(
                    typeof(MagentixLicense),
                    File.ReadAllText("license.lic"),
                    _certPubicKeyData,
                    out _status,
                    out _msg);
                if (_lic.TrialVersion == true && _lic.TrialDate < DateTime.Now)
                {
                    MessageBox.Show("Your trial version is expired. Please buy full version.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return(false);
                }
            }
            else
            {
                _status = LicenseStatus.INVALID;
                _msg    = "Your copy of this application is not activated";
            }

            switch (_status)
            {
            case LicenseStatus.VALID:
                return(true);

            default:
                return(false);
            }
        }
예제 #23
0
        /// <summary>
        /// Returns a string similar to "x days", "x minutes", "x hours", "x months"
        /// where x is the time till the host's license expires/needs reactivating.
        /// </summary>
        /// <param name="timeTillExpire"></param>
        /// <param name="capAtTenYears">Set to true will return Messages.UNLIMITED for timespans over 3653 days</param>
        /// <returns></returns>
        public static string GetLicenseTimeLeftString(TimeSpan timeTillExpire, bool capAtTenYears)
        {
            if (timeTillExpire.Ticks < 0)
            {
                return("");
            }

            if (capAtTenYears && LicenseStatus.IsInfinite(timeTillExpire))
            {
                return(Messages.UNLIMITED);
            }

            return(timeTillExpire.FuzzyTime());
        }
예제 #24
0
        private void checkLicense()
        {
            //Initialize variables with default values
            GITLicense.GITLicense _lic = null;
            string        _msg         = string.Empty;
            LicenseStatus _status      = LicenseStatus.UNDEFINED;

            //Read public key from assembly
            Assembly _assembly = Assembly.GetExecutingAssembly();

            using (MemoryStream _mem = new MemoryStream())
            {
                _assembly.GetManifestResourceStream("Betburger.License.LicenseVerify.cer").CopyTo(_mem);

                _certPubicKeyData = _mem.ToArray();
            }

            //Check if the XML license file exists
            if (File.Exists("license.lic"))
            {
                _lic = (GITLicense.GITLicense)LicenseHandler.ParseLicenseFromBASE64String(
                    typeof(GITLicense.GITLicense),
                    File.ReadAllText("license.lic"),
                    _certPubicKeyData,
                    out _status,
                    out _msg);
            }
            else
            {
                _status = LicenseStatus.INVALID;
                _msg    = "Your copy of this application is not activated";
            }

            switch (_status)
            {
            case LicenseStatus.VALID:
                return;

            default:
                MessageBox.Show(_msg, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                using (frmActivation frm = new frmActivation())
                {
                    frm.CertificatePublicKeyData = _certPubicKeyData;
                    frm.ShowDialog();
                    Application.Exit();
                }
                break;
            }
        }
예제 #25
0
파일: App.xaml.cs 프로젝트: vlad1000/priv10
        public static void InitLicense()
        {
            MemoryStream mem = new MemoryStream();

            Assembly.GetExecutingAssembly().GetManifestResourceStream("PrivateWin10.LicenseVerify.cer").CopyTo(mem);
            byte[] certPubicKeyData = mem.ToArray();

            string        msg    = string.Empty;
            LicenseStatus status = LicenseStatus.UNDEFINED;

            if (File.Exists("license.lic"))
            {
                lic = (MyLicense)LicenseHandler.ParseLicenseFromBASE64String(typeof(MyLicense), File.ReadAllText(App.appPath + @"\license.lic"), certPubicKeyData, out status, out msg);
            }
            else
            {
                msg = "Your copy of this application is not activated";
            }
            if (lic == null)
            {
                lic = new MyLicense(); // we always want this object
            }
            lic.LicenseStatus = status;
            if (status != LicenseStatus.VALID && msg.Length == 0)
            {
                msg = "Your license file is invalid or broken";
            }

            if (status == LicenseStatus.INVALID || status == LicenseStatus.CRACKED)
            {
                MessageBox.Show(msg, App.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }

            Console.WriteLine(msg);

            if (status != LicenseStatus.VALID)
            {
                string use = App.GetConfig("Startup", "Usage", "");
                if (use.Equals("business", StringComparison.OrdinalIgnoreCase) || use.Equals("commertial", StringComparison.OrdinalIgnoreCase))
                {
                    lic.CommercialUse = true;

                    if (IsEvaluationExpired())
                    {
                        MessageBox.Show("The commercial evaluation period of PrivateWin10 has expired, please purchase an appropriate license.", string.Empty, MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
            }
        }
예제 #26
0
        private void btnActivate_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtActivationCode.Text))
            {
                MessageBox.Show("Please input license", "MagentixPOS", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            //Check the activation string
            LicenseStatus _licStatus = LicenseStatus.UNDEFINED;
            string        _msg       = string.Empty;

            byte[]   CertificatePublicKeyData;
            Assembly _assembly = Assembly.GetExecutingAssembly();

            using (MemoryStream _mem = new MemoryStream())
            {
                Stream stream = _assembly.GetManifestResourceStream("Magentix.Presentation.LicenseVerify.cer");
                stream.CopyTo(_mem);

                CertificatePublicKeyData = _mem.ToArray();
            }
            MagentixLicense _lic = (MagentixLicense)LicenseHandler.ParseLicenseFromBASE64String(typeof(MagentixLicense), txtActivationCode.Text.Trim(), CertificatePublicKeyData, out _licStatus, out _msg);

            switch (_licStatus)
            {
            case LicenseStatus.VALID:
                if (_lic.TrialVersion == true && _lic.TrialDate < DateTime.Now)
                {
                    MessageBox.Show("This key is expired. Please buy full version key.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    txtActivationCode.Select(0, txtActivationCode.Text.Length);
                    txtActivationCode.Focus();
                    return;
                }
                File.WriteAllText("license.lic", txtActivationCode.Text);
                this.DialogResult = true;
                return;

            case LicenseStatus.CRACKED:
            case LicenseStatus.INVALID:
            case LicenseStatus.UNDEFINED:
                MessageBox.Show("License is INVALID", "MagentixPOS", MessageBoxButton.OK, MessageBoxImage.Error);
                return;

            default:
                return;
            }
        }
예제 #27
0
    public override LicenseStatus DoExtraValidation(out string validationMsg)
    {
        LicenseStatus _licStatus = LicenseStatus.UNDEFINED;

        validationMsg = string.Empty;

        switch (this.Type)
        {
        case LicenseTypes.Single:
            //For Single License, check whether UID is matched
            if (this.UID == LicenseHandler.GenerateUID(this.AppName))
            {
                _licStatus = LicenseStatus.VALID;
            }
            else
            {
                validationMsg = "The license is NOT for this copy!";
                _licStatus    = LicenseStatus.INVALID;
            }
            break;

        case LicenseTypes.Volume:
            //No UID checking for Volume License
            _licStatus = LicenseStatus.VALID;
            break;

        default:
            validationMsg = "Invalid license";
            _licStatus    = LicenseStatus.INVALID;
            break;
        }

        if (_licStatus == LicenseStatus.VALID)
        {
            if (WasVoided())
            {
                validationMsg = "This license number has been voided!";
                _licStatus    = LicenseStatus.INVALID;
            }
            else if (HasExpired())
            {
                validationMsg = "This license has expired!";
                _licStatus    = LicenseStatus.INVALID;
            }
        }

        return(_licStatus);
    }
예제 #28
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="LicenseT">LicenseT must inherite : LicenseEntity . see examples</typeparam>
        /// <param name="_assembly">Assembly.GetExecutingAssembly()</param>
        /// <param name="app_name">e.g. "hesabdari"</param>
        /// <param name="license_cer_full_file_name">e.g "LicenseVerify.cer" file must be Embedded Resource Build Action and Do not copy to output directory</param>
        /// <param name="license_key"> get it from a file or db. send null if license file or license column not exist </param>
        /// <returns></returns>
        public bool CheckLicense <LicenseT>(Assembly _assembly, string license_cer_full_file_name, string license_key) where LicenseT : LicenseEntity
        {
            LicenseInfo = "";
            //Initialize variables with default values
            LicenseT      _lic    = null;
            string        _msg    = string.Empty;
            LicenseStatus _status = LicenseStatus.UNDEFINED;

            //Read public key from assembly
            CertificatePublicKeyData = GetPubicKeyData(_assembly, license_cer_full_file_name);


            //Check if the XML license file exists
            if (!string.IsNullOrWhiteSpace(license_key))
            {
                _lic = (LicenseT)ParseLicenseFromBASE64String(
                    typeof(LicenseT),
                    license_key,
                    out _status,
                    out _msg);
            }
            else
            {
                _status = LicenseStatus.INVALID;
                _msg    = "Your copy of this application is not activated";
            }

            switch (_status)
            {
            case LicenseStatus.VALID:

                //TODO: If license is valid, you can do extra checking here
                //TODO: E.g., check license expiry date if you have added expiry date property to your license entity
                //TODO: Also, you can set feature switch here based on the different properties you added to your license entity

                //Here for demo, just show the license information and RETURN without additional checking
                LicenseInfo = ShowLicenseInfo(_lic, "");

                return(true);

            default:
                //for the other status of license file, show the warning message
                //and also popup the activation form for user to activate your application
                MessageBox.Show(_msg, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
        }
예제 #29
0
        public void MinimumPoolLicenseValueOnSlave()
        {
            Mock <Pool>         pool   = ObjectFactory.BuiltObject <Pool>(ObjectBuilderType.PoolOfTwoClearwaterHosts, id);
            List <Mock <Host> > hosts  = ObjectManager.GeneratedXenObjectsMocks <Host>(id);
            Mock <Host>         master = hosts.FirstOrDefault(h => h.Object.opaque_ref.Contains("master"));

            SetupMockHostWithExpiry(master, new DateTime(2013, 4, 1));
            Mock <Host> slave = hosts.FirstOrDefault(h => h.Object.opaque_ref.Contains("slave"));

            SetupMockHostWithExpiry(slave, new DateTime(2012, 1, 12));

            using (LicenseStatus ls = new LicenseStatus(pool.Object))
            {
                Assert.True(ls.ExpiryDate.HasValue, "Expiry date doesn't have a value");
                Assert.That(ls.ExpiryDate.Value.ToShortDateString(), Is.EqualTo(new DateTime(2012, 1, 12).ToShortDateString()), "Expiry dates");
            }
        }
예제 #30
0
        public void Initialize()
        {
            //Initialize variables with default values
            FinancialAnalysisLicense _lic = null;
            string        _msg            = string.Empty;
            LicenseStatus _status         = LicenseStatus.UNDEFINED;

            //Read public key from assembly
            Assembly _assembly = Assembly.GetExecutingAssembly();

            using (MemoryStream _mem = new MemoryStream())
            {
                _assembly.GetManifestResourceStream("FinancialAnalysis.Logic.LicenseVerify.cer").CopyTo(_mem);

                _certPubicKeyData = _mem.ToArray();
            }

            //Check if the XML license file exists
            if (File.Exists("license.lic"))
            {
                _lic = (FinancialAnalysisLicense)LicenseHandler.ParseLicenseFromBASE64String(
                    typeof(FinancialAnalysisLicense),
                    File.ReadAllText("license.lic"),
                    _certPubicKeyData,
                    out _status,
                    out _msg);
                Globals.ActiveLicense = _lic;
            }
            else
            {
                _status = LicenseStatus.INVALID;
                _msg    = "Your copy of this application is not activated";
            }

            if (_status == LicenseStatus.VALID)
            {
                //TODO: If license is valid, you can do extra checking here
                //TODO: E.g., check license  if you have added expiry date property to your license entity
                //TODO: Also, you can set feature switch here based on the different properties you added to your license entity

                //Here for demo, just show the license information and RETURN without additional checking
                //licInfo.ShowLicenseInfo(_lic);

                return;
            }
        }
예제 #31
0
        public DemoLicense.MyLicense GetLicense(byte[] certpublickeydata)
        {
            MyLicense     _lic    = null;
            string        _msg    = string.Empty;
            LicenseStatus _status = LicenseStatus.UNDEFINED;

            if (File.Exists("license.lic"))
            {
                _lic = (MyLicense)LicenseHandler.ParseLicenseFromBASE64String(
                    typeof(MyLicense),
                    File.ReadAllText("license.lic"),
                    certpublickeydata,
                    out _status,
                    out _msg);
            }

            return(_lic);
        }
        public bool ValidateLicense()
        {
            if (string.IsNullOrWhiteSpace(txtLicense.Text))
            {
                MessageBox.Show("Please input license", string.Empty, MessageBoxButton.OK, MessageBoxImage.Warning);
                return(false);
            }

            //Check the activation string
            LicenseStatus _licStatus = LicenseStatus.UNDEFINED;
            string        _msg       = string.Empty;

            try
            {
                LicenseEntity _lic = LicenseHandler.ParseLicenseFromBASE64String(LicenseObjectType, txtLicense.Text.Trim(), CertificatePublicKeyData, out _licStatus, out _msg);
                switch (_licStatus)
                {
                case LicenseStatus.VALID:
                    if (ShowMessageAfterValidation)
                    {
                        MessageBox.Show(_msg, "License is valid", MessageBoxButton.OK, MessageBoxImage.Information);
                    }

                    return(true);

                case LicenseStatus.CRACKED:
                case LicenseStatus.INVALID:
                case LicenseStatus.UNDEFINED:
                    if (ShowMessageAfterValidation)
                    {
                        MessageBox.Show(_msg, "License is INVALID", MessageBoxButton.OK, MessageBoxImage.Error);
                    }

                    return(false);

                default:
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #33
0
        internal static void EnsureHasAvailableBundleLicense()
        {
            if (ValidateCoreLicense)
            {
                bool flag;
                switch (FrameworkLicenseType)
                {
                case LicenseType.const_0:
                case LicenseType.UIOSP:
                case LicenseType.iOpenWorksSDK:
                    return;

                case LicenseType.AppStoreRuntime:
                {
                    IBundleInstallerService firstOrDefaultService = BundleRuntime.Instance.GetFirstOrDefaultService <IBundleInstallerService>();
                    flag = false;
                    using (IEnumerator <KeyValuePair <string, BundleData> > enumerator = firstOrDefaultService.BundleDatas.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            KeyValuePair <string, BundleData> current = enumerator.Current;
                            LicenseStatus licenseStatus = GetLicenseStatus(current.Value);
                            if ((licenseStatus != LicenseStatus.None) && (licenseStatus != LicenseStatus.Expried))
                            {
                                goto Label_007B;
                            }
                        }
                        break;
Label_007B:
                        flag = true;
                    }
                    break;
                }

                default:
                    LogAndThrow(new NotSupportedException("Not support framework license type."));
                    return;
                }
                if (!flag)
                {
                    LogAndThrow(new Exception("Framework starts fail, because no licensed bundle found."));
                }
            }
        }
        protected virtual void LicenseStatusChange(LicenseStatus oldObj, LicenseStatus newObj)
        {
            Action<LicenseStatusEventArg> handler = licenseChange;

            if (licenseChange != null)
            {
                LicenseStatusEventArg arg = new LicenseStatusEventArg();
                arg.oldStatus = oldObj;
                arg.NewStatus = newObj;
                _licenseStatus = newObj;
                handler(arg);
            }
        }
예제 #35
0
		public void method_3(LicenseStatus licenseStatus_3)
		{
			this.licenseStatus_1 = licenseStatus_3;
		}
예제 #36
0
		public void method_5(LicenseStatus licenseStatus_3)
		{
			this.licenseStatus_2 = licenseStatus_3;
		}
예제 #37
0
		public void method_1(LicenseStatus licenseStatus_3)
		{
			this.licenseStatus_0 = licenseStatus_3;
		}
예제 #38
0
        /// <summary>
        /// Initializes the license.
        /// </summary>
        public static void InitLicense()
        {
            _isActivated = false;
            _licenseHash = null;

            if (IsActivated != _isActivated)
            {
                Process.GetCurrentProcess().Kill();
            }

            if (IsOriginalAssembly.HasValue && !IsOriginalAssembly.Value)
            {
                _licenseStatus = LicenseStatus.Aborted;
                Log.Warn("License initialization aborted due to assembly tampering.");
                return;
            }

            var licfile = Path.Combine(AppDataPath, ".license");

            if (!File.Exists(licfile))
            {
                _licenseStatus = LicenseStatus.NotAvailable;
                Log.Debug("Licensing data not found.");
                return;
            }

            Log.Debug("Loading licensing information...");

            try
            {
                byte[] xkey, lic;

                using (var fs = File.OpenRead(licfile))
                using (var br = new BinaryReader(fs))
                {
                    var status = br.ReadByte();

                    if (status > 200)
                    {
                        _licenseStatus = LicenseStatus.KeyStatusError;
                        Log.Error("The license is cryptographically valid, but has been denied by the activation server. Your key was most likely revoked. Please contact [email protected] for more information.");
                        return;
                    }

                    _user = br.ReadString();
                    xkey = br.ReadBytes(br.Read7BitEncodedInt());
                    lic  = br.ReadBytes(br.Read7BitEncodedInt());
                }

                try
                {
                    xkey = ProtectedData.Unprotect(xkey, null, DataProtectionScope.LocalMachine);
                    lic  = ProtectedData.Unprotect(lic, null, DataProtectionScope.LocalMachine);
                    _key = Encoding.UTF8.GetString(xkey);
                }
                catch
                {
                    _licenseStatus = LicenseStatus.LicenseDecryptError;
                    Log.Error("The license is not for this computer or Windows machine keys were reset.");
                    return;
                }

                if (!VerifyKey(_user, _key))
                {
                    _licenseStatus = LicenseStatus.KeyCryptoError;
                    Log.Error("The key within the license is cryptographically invalid. If you have recently updated the software, the keying scheme might have been changed. If you did not receive an email containing a new key, please contact [email protected] for more information.");
                    return;
                }

                var mbdsn = string.Empty;

                try
                {
                    var mos = new ManagementObjectSearcher("select SerialNumber from Win32_BaseBoard").Get();

                    foreach (var mo in mos)
                    {
                        mbdsn = mo["SerialNumber"].ToString();
                        break;
                    }
                }
                catch { }

                var cpusn = string.Empty;

                try
                {
                    var mos = new ManagementObjectSearcher("select ProcessorId from Win32_Processor").Get();

                    foreach (var mo in mos)
                    {
                        cpusn = mo["ProcessorId"].ToString();
                        break;
                    }
                }
                catch { }

                var hddsn = string.Empty;

                try
                {
                    var mos = new ManagementObjectSearcher("select SerialNumber from Win32_DiskDrive where MediaType = \"Fixed hard disk media\"").Get();

                    foreach (var mo in mos)
                    {
                        hddsn = mo["SerialNumber"].ToString();
                        break;
                    }
                }
                catch { }

                var prtsn = string.Empty;

                try
                {
                    var mos = new ManagementObjectSearcher("select VolumeSerialNumber from Win32_LogicalDisk where DriveType = 3").Get();

                    foreach (var mo in mos)
                    {
                        prtsn = mo["VolumeSerialNumber"].ToString();
                        break;
                    }
                }
                catch { }

                var verify = Encoding.UTF8.GetBytes(_user + '\0' + _key + '\0' + mbdsn + '\0' + cpusn + '\0' + hddsn + '\0' + prtsn);

                using (var rsa = new RSACryptoServiceProvider(0))
                {
                    var dt = DateTime.Now;
                    rsa.ImportParameters(PublicKey);
                    _isActivated = rsa.VerifyData(verify, SHA512.Create(), lic);
                    Log.Trace("Signature verified in " + (DateTime.Now - dt).TotalSeconds + "s.");

                    if (_isActivated)
                    {
                        _licenseHash   = BitConverter.ToString(new HMACSHA384(SHA384.Create().ComputeHash(Encoding.UTF8.GetBytes(_user.ToLower().Trim())).Truncate(16)).ComputeHash(Encoding.UTF8.GetBytes(_key.Trim()))).ToLower().Replace("-", string.Empty);
                        _licenseStatus = LicenseStatus.Valid;
                        Log.Info("License validated for " + _user + ". Thank you for supporting the software!");
                    }
                    else
                    {
                        _licenseStatus = LicenseStatus.LicenseInvalid;
                        Log.Error("The license is not for this computer or hardware S/Ns have changed recently.");
                    }
                }
            }
            catch (Exception ex)
            {
                _licenseStatus = LicenseStatus.LicenseException;
                Log.Error("Exception occurred during license validation.", ex);
            }
        }
예제 #39
0
        /// <summary>
        /// Checks the response of the REST API.
        /// </summary>
        /// <param name="resp">The response.</param>
        public static void CheckAPIResponse(HttpWebResponse resp)
        {
            if (!_isActivated)
            {
                return;
            }

            var kst = KeyStatus.Unchecked;

            try { kst = (KeyStatus)int.Parse(resp.Headers["X-License"]); } catch { }

            if (kst != KeyStatus.Valid && kst != KeyStatus.Unchecked)
            {
                _isActivated   = false;
                _licenseHash   = null;
                _licenseStatus = LicenseStatus.KeyStatusError;

                try
                {
                    using (var fs = File.OpenWrite(Path.Combine(AppDataPath, ".license")))
                    {
                        fs.Position = 0;
                        fs.WriteByte((byte)((int)kst + 200));
                        fs.Flush(true);
                    }
                }
                catch { }
            }
        }