Exemple #1
0
        private void ProcessLicense()
        {
            try
            {
                byte[] dataBytes = Convert.FromBase64String(LicenseInfo.ActivationInfo);
                byte[] signBytes = Convert.FromBase64String(LicenseInfo.Signature);

                if (_cryptoService.VerifyData(dataBytes, new SHA1CryptoServiceProvider(), signBytes))
                {
                    int infoLength = 94;

                    // ProductID (2) + ProductFeatures (2) + TrialDays (2) + GeneratedDate (8) + ClientID (12) + UsernameHash (20) + CompanyHash(20) + UserEmailHash(20) + ActivatedDate (8)  = 94

                    byte[] hash = new byte[dataBytes.Length - infoLength];
                    Buffer.BlockCopy(dataBytes, infoLength, hash, 0, hash.Length);

                    if (_identifierService.Match(hash))
                    {
                        ProductID              = BitConverter.ToInt16(dataBytes, 0);
                        ProductFeatures        = BitConverter.ToInt16(dataBytes, 2);
                        TrialDays              = BitConverter.ToInt16(dataBytes, 4);
                        ProductKeyCreationDate = new DateTime(BitConverter.ToInt64(dataBytes, 6));

                        ClientID = Encoding.Unicode.GetString(dataBytes, 14, 12);

                        UsernameHash  = Encoding.ASCII.GetString(dataBytes, 26, 20);
                        CompanyHash   = Encoding.ASCII.GetString(dataBytes, 46, 20);
                        UserEmailHash = Encoding.ASCII.GetString(dataBytes, 66, 20);

                        ActivationDate = new DateTime(BitConverter.ToInt64(dataBytes, 86));

                        _userInfoProvider.Refresh();
                        if (Hash(_userInfoProvider.Company) == CompanyHash &&
                            Hash(_userInfoProvider.Username) == UsernameHash &&
                            Hash(_userInfoProvider.Email) == UserEmailHash)
                        {
                            if (TrialDays == 0)
                            {
                                Status        = LicenseStatus.Licensed;
                                StatusReason  = string.Empty;
                                TrialDaysLeft = int.MaxValue;
                            }
                            else
                            {
                                // Modif tekigo : évite en partie les changements de date
                                if (DateTimeOffset.Now.Date < ActivationDate.Date)
                                {
                                    Status       = LicenseStatus.Invalid;
                                    StatusReason = "Failed.";
                                }

                                TrialDaysLeft = (TrialDays - (DateTimeOffset.Now.Date - ActivationDate.Date).Days);
                                if (TrialDaysLeft > 0)
                                {
                                    Status       = LicenseStatus.TrialVersion;
                                    StatusReason = string.Format("{0} days left.", TrialDaysLeft);
                                }
                                else
                                {
                                    Status       = LicenseStatus.Expired;
                                    StatusReason = string.Format("License expired {0} days ago.", -TrialDaysLeft);
                                }
                            }
                        }
                        else
                        {
                            Status       = LicenseStatus.Invalid;
                            StatusReason = string.Format(@"User information invalid.
Company: Value: '{0}', Value Hash: {1}, LicenseHash: {2}
Username: Value: '{3}', Value Hash: {4}, LicenseHash: {5}
Email: Value: '{6}', Value Hash: {7}, LicenseHash: {8}",
                                                         _userInfoProvider.Company, Hash(_userInfoProvider.Company), CompanyHash,
                                                         _userInfoProvider.Username, Hash(_userInfoProvider.Username), UsernameHash,
                                                         _userInfoProvider.Email, Hash(_userInfoProvider.Email), UserEmailHash
                                                         );
                        }
                    }
                    else
                    {
                        Status       = LicenseStatus.MachineHashMismatch;
                        StatusReason = "Machine and product info hash mismatch.";
                    }
                }
                else
                {
                    Status       = LicenseStatus.Invalid;
                    StatusReason = "Failed verifying signature.";
                }
            }
            catch (Exception ex)
            {
                Status       = LicenseStatus.Invalid;
                StatusReason = ex.Message;
            }
        }
Exemple #2
0
        private void ProcessLicense()
        {
            try
            {
                byte[] dataBytes = Convert.FromBase64String(LicenseInfo.ActivationInfo);
                byte[] signBytes = Convert.FromBase64String(LicenseInfo.Signature);

                if (_cryptoService.VerifyData(dataBytes, new SHA1CryptoServiceProvider(), signBytes))
                {
                    int infoLength = 82;

                    // ProductID (2) + TrialDays (2) + NumberOfUsers (2) + GeneratedDate (8) + UsernameHash (20) + CompanyHash(20) + UserEmailHash(20) + ActivatedDate (8)  = 82

                    byte[] hash = new byte[dataBytes.Length - infoLength];
                    Buffer.BlockCopy(dataBytes, infoLength, hash, 0, hash.Length);

                    if (_identifierService.Match(hash))
                    {
                        ProductID              = BitConverter.ToInt16(dataBytes, 0);
                        TrialDays              = BitConverter.ToInt16(dataBytes, 2);
                        NumberOfUsers          = BitConverter.ToInt16(dataBytes, 4);
                        ProductKeyCreationDate = new DateTime(BitConverter.ToInt64(dataBytes, 6));

                        UsernameHash  = Encoding.ASCII.GetString(dataBytes, 14, 20);
                        CompanyHash   = Encoding.ASCII.GetString(dataBytes, 34, 20);
                        UserEmailHash = Encoding.ASCII.GetString(dataBytes, 54, 20);

                        ActivationDate = new DateTime(BitConverter.ToInt64(dataBytes, 74));

                        _userInfoProvider.Refresh();
                        if (Hash(_userInfoProvider.Company) == CompanyHash &&
                            Hash(_userInfoProvider.Username) == UsernameHash &&
                            Hash(_userInfoProvider.Email) == UserEmailHash)
                        {
                            if (TrialDays == 0)
                            {
                                Status        = WebLicenseStatus.Licensed;
                                StatusReason  = "Common_License_StatusReason_Licensed";
                                TrialDaysLeft = int.MaxValue;
                            }
                            else
                            {
                                if (DateTimeOffset.Now.Date < ActivationDate.Date)
                                {
                                    Status       = WebLicenseStatus.Invalid;
                                    StatusReason = "Common_License_StatusReason_DateChangeDetected";
                                }

                                TrialDaysLeft = (TrialDays - (DateTimeOffset.Now.Date - ActivationDate.Date).Days);
                                if (TrialDaysLeft > 0)
                                {
                                    Status             = WebLicenseStatus.TrialVersion;
                                    StatusReason       = "Common_License_StatusReason_Trial";
                                    StatusReasonParams = new object[] { TrialDaysLeft };
                                }
                                else
                                {
                                    Status             = WebLicenseStatus.Expired;
                                    StatusReason       = "Common_License_StatusReason_Expired";
                                    StatusReasonParams = new object[] { -TrialDaysLeft };
                                }

                                if (UsersPool.Count > NumberOfUsers)
                                {
                                    Status             = WebLicenseStatus.OverageOfUsers;
                                    StatusReason       = "Common_License_StatusReason_OverageOfUsers";
                                    StatusReasonParams = new object[] { UsersPool.Count, NumberOfUsers };
                                }
                            }
                        }
                        else
                        {
                            Status             = WebLicenseStatus.Invalid;
                            StatusReason       = "Common_License_StatusReason_InvalidUserInformation";
                            StatusReasonParams = new object[] {
                                _userInfoProvider.Company,
                                _userInfoProvider.Username,
                                _userInfoProvider.Email
                            };
                        }
                    }
                    else
                    {
                        Status       = WebLicenseStatus.MachineHashMismatch;
                        StatusReason = "Common_License_StatusReason_MachineHashMismatch";
                    }
                }
                else
                {
                    Status       = WebLicenseStatus.Invalid;
                    StatusReason = "Common_License_StatusReason_SignatureFailed";
                }
            }
            catch (Exception ex)
            {
                Status             = WebLicenseStatus.Invalid;
                StatusReason       = "Common_License_StatusReason_Exception";
                StatusReasonParams = new object[] { ex.Message };
            }
        }