Пример #1
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="l"></param>
        public TheLicense(TheLicense l)
        {
            LicenseId      = l.LicenseId;
            Description    = l.Description;
            LicenseVersion = l.LicenseVersion;
            SkuId          = l.SkuId;
            if (l.PluginLicenses != null)
            {
                PluginLicenses = new ThePluginLicense[l.PluginLicenses.Length];
                {
                    int licIndex = 0;

                    foreach (var pluginLicense in l.PluginLicenses)
                    {
                        PluginLicenses[licIndex] = new ThePluginLicense
                        {
                            PlugInId    = pluginLicense.PlugInId,
                            DeviceTypes = pluginLicense.DeviceTypes.ToArray(),
                            AllowGlobalThingEntitlements = pluginLicense.AllowGlobalThingEntitlements,
                        };
                        licIndex++;
                    }
                }
            }
            Expiration             = l.Expiration;
            ActivationKeyValidator = l.ActivationKeyValidator;

            if (l.Parameters != null)
            {
                Parameters = new TheLicenseParameter[l.Parameters.Length];

                int paramIndex = 0;
                foreach (var parameter in l.Parameters)
                {
                    Parameters[paramIndex] = new TheLicenseParameter {
                        Name = parameter.Name, Value = parameter.Value
                    };
                    paramIndex++;
                }
            }

            if (l.Properties != null)
            {
                Properties = new TheLicenseProperty[l.Properties.Length];
                int propertyIndex = 0;
                foreach (var property in l.Properties)
                {
                    Properties[propertyIndex] = new TheLicenseProperty {
                        Name = property.Name, Value = property.Value
                    };
                    propertyIndex++;
                }
            }

            if (l.Signatures != null)
            {
                Signatures = l.Signatures.ToArray();
            }
        }
Пример #2
0
        internal string GetCanonicalLicense()
        {
            TheLicense tempLicense = new TheLicense(this);

            // Bug in original License constructor did not copy the Description field, so it was not included in the signature. Only shipped license was this one (P08 Project, OPC Client)
            //CODE-REVIEW: Is this still necessary?
            if (tempLicense.LicenseId == new Guid("6a78a4cb-1d9b-4a53-a41b-c57497085026"))
            {
                tempLicense.Description = null;
            }
            tempLicense.Signatures = new string[0];
            return(CU.SerializeObjectToJSONString(tempLicense));
        }
Пример #3
0
        public TheActivatedLicense(TheActivatedLicense al)
        {
            ActivationKeyHash       = al.ActivationKeyHash;
            ActivationKeyExpiration = al.ActivationKeyExpiration;
            License             = new TheLicense(al.License);
            ActivatedParameters = new TheLicenseParameter[al.ActivatedParameters.Length];
            int index = 0;

            foreach (var parameter in al.ActivatedParameters)
            {
                ActivatedParameters[index] = new TheLicenseParameter {
                    Name = parameter.Name, Value = parameter.Value
                };
                index++;
            }
            IsExpiredAndRemoved = al.IsExpiredAndRemoved;
        }
        public static string[] ValidateActivationkey(ICDESecrets mySecrets, string activationKeyString, Guid deviceId, List <TheLicense> allLicenses, out List <TheLicenseActivationInformation> activatedLicenses, out DateTimeOffset expirationDate)
        {
            expirationDate    = DateTimeOffset.MinValue;
            activatedLicenses = null;

            string signingKey = mySecrets.GetActivationKeySignatureKey();

            var normalizedKey = activationKeyString.Trim().Replace("-", "").ToUpper().Replace('O', '0').Replace('U', 'V').Replace('I', 'J').Replace('L', 'J');

            if (normalizedKey.Length != 36)
            {
                return(new string[] { "Invalid activation key: not the proper length", String.Format("{0}", activationKeyString) });
            }

            byte[] activationKey = TheActivationUtils.Base32Decode(normalizedKey);
            if (activationKey == null || activationKey.Length != 23 || activationKey[22] != 15)
            {
                return(new string[] { "Invalid activation key: failed to decode.", String.Format("{0}", activationKeyString) });
            }
            string activationKeyHash = Convert.ToBase64String((SHA1.Create().ComputeHash(activationKey)));

            byte[] signature = new byte[8];
            activationKey.Take(8).ToArray().CopyTo(signature, 0);

            int expirationInDays = (activationKey[8] + (activationKey[9] << 8));

            if (expirationInDays < 0)
            {
                return(new string[] { "Invalid activation key: invalid expiration date.", String.Format("{0}. Expiration: {1}", activationKeyString, expirationInDays) });
            }
            expirationDate = new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc) + new TimeSpan(expirationInDays, 0, 0, 0);
            if (expirationDate < DateTime.Now)
            {
                return(new string[] { "Invalid activation key: key expired.", String.Format("{0}. Expiration: {1}", activationKeyString, expirationDate.ToString()) });
            }

            ActivationFlags flags = (ActivationFlags)activationKey[10];

            if ((flags & ActivationFlags.RequireOnline) != 0)
            {
                return(new string[] { "Invalid activation key: online activation required but not supported in this cdeEngine version.", String.Format("{0}", activationKeyString) });
            }
            byte licenseCount = activationKey[12];

            if (licenseCount > MaxLicensesInActivationKey)
            {
                return(new string[] { "Invalid activation key: too many licenses specified.", String.Format("{0}. License Count: {1}", activationKeyString, licenseCount) });
            }
            if (licenseCount == 0)
            {
                return(new string[] { "Invalid activation key: no licenses specified.", String.Format("{0}. License Count: {1}", activationKeyString, 0) });
            }
            if (licenseCount > allLicenses.Count)
            {
                return(new string[] { "Unable to apply activation key: some licenses not available on the system.", String.Format("{0}. License Count in key: {1}. Total valid licenses on system: {2}", activationKeyString, licenseCount, allLicenses.Count) });
            }

            byte[] parameters  = new byte[TheActivationUtils.MaxLicenseParameters];
            int    paramOffset = 13;

            for (int j = 0; j < TheActivationUtils.MaxLicenseParameters; j++)
            {
                parameters[j] = activationKey[paramOffset];
                paramOffset++;
            }

            int[]        candidateIndices = new int[licenseCount];
            TheLicense[] candidates       = new TheLicense[licenseCount];
            bool         done             = false;

            do
            {
                bool validCombination = true;
                for (int i = 0; i < licenseCount; i++)
                {
                    candidates[i] = allLicenses[candidateIndices[i]];
                    if (i > 0 && String.CompareOrdinal(candidates[i].LicenseId.ToString(), candidates[i - 1].LicenseId.ToString()) <= 0)
                    {
                        validCombination = false;
                        break;
                    }
                }

                if (validCombination && TheActivationUtils.GenerateLicenseSignature(deviceId, signingKey, (uint)expirationInDays, candidates.ToArray(), parameters, flags, out byte[] candidateSignature))