Exemple #1
0
        /// <summary>
        /// Generate a license from the command line arguments.
        /// </summary>
        void GenerateLicense()
        {
            // A license requires the product.  This will extract the product id from the command line and attempt to find it in the table of products.
            Guid productId = Guid.Parse(this.commandLine[Parameter.Product]);

            DataSet.ProductRow productRow = DataModel.Product.FindByProductId(productId);

            // The email address is used as a unique identifier for the customer.
            String email      = this.commandLine[Parameter.Email];
            Guid   customerId = Guid.Empty;
            var    results    = from row in DataModel.Customer.AsEnumerable() where row.Email == email select row;

            DataSet.CustomerRow customerRow = results.FirstOrDefault();

            // If the customer doesn't exist yet, then create one from the command line parameters.
            if (customerRow == null)
            {
                // This will generate a new record from the command line arguments which likely have been provided by a daemon process in Outlook.
                customerRow              = DataModel.Customer.NewCustomerRow();
                customerRow.Address      = this.commandLine[Parameter.Address];
                customerRow.City         = this.commandLine[Parameter.City];
                customerRow.Country      = this.commandLine[Parameter.Country];
                customerRow.CustomerId   = Guid.NewGuid();
                customerRow.DateCreated  = DateTime.Now;
                customerRow.DateModified = DateTime.Now;
                customerRow.Email        = email;
                customerRow.FirstName    = this.commandLine[Parameter.FirstName];
                customerRow.LastName     = this.commandLine[Parameter.LastName];
                customerRow.Phone        = this.commandLine[Parameter.Phone];
                customerRow.PostalCode   = this.commandLine[Parameter.PostalCode];
                customerRow.Province     = this.commandLine[Parameter.Province];

                // Add the customer and update the database.
                DataModel.Customer.AddCustomerRow(customerRow);
                DataModel.CustomerTableAdapter.Update(DataModel.Customer);
            }

            // Create a perpetual license for development and runtime.
            Byte[] licenseTypeArray = new Byte[2];
            licenseTypeArray[0] = LicenseType.Perpetual;
            licenseTypeArray[1] = LicenseType.Perpetual;
            Int16 licenseType = BitConverter.ToInt16(licenseTypeArray, 0);

            // The effective date of this license is right now.
            DateTime dateCreated = DateTime.Now;

            // This will generate the license from the command line arguments parsed above and deposit it in a file also parsed from the command line.
            LicenseInfo licenseInfo = new LicenseInfo()
            {
                DateCreated = dateCreated,
                CustomerId  = customerRow.CustomerId,
                LicenseType = licenseType,
                ProductId   = productRow.ProductId
            };

            LicenseManager.GenerateLicense(licenseInfo, this.commandLine[Parameter.Output]);
        }
        void OnGenerateLicense(Object sender, RoutedEventArgs e)
        {
            Byte[] licenseTypeArray = new Byte[2];
            licenseTypeArray[0] = LicenseType.Evaluation3Month;
            licenseTypeArray[1] = LicenseType.Evaluation3Month;
            Int16 licenseType = BitConverter.ToInt16(licenseTypeArray, 0);

            DateTime dateCreated = DateTime.Now;

            LicenseInfo licenseInfo = new LicenseInfo()
            {
                DateCreated = dateCreated,
                CustomerId  = MainWindow.TeraqueCustomerId,
                LicenseType = licenseType,
                ProductId   = MainWindow.ExplorerChromeSuite
            };

            LicenseManager.GenerateLicense(licenseInfo, "../../license.lic");
        }
Exemple #3
0
        internal static void GenerateLicense(LicenseInfo licenseInfo, String fileName)
        {
            if (licenseInfo == null)
            {
                throw new ArgumentNullException("licenseInfo");
            }

            DataSet.ProductRow  productRow  = DataModel.Product.FindByProductId(licenseInfo.ProductId);
            DataSet.CustomerRow customerRow = DataModel.Customer.FindByCustomerId(licenseInfo.CustomerId);

            // Generate a new license.
            DataSet.LicenseRow licenseRow = DataModel.License.AddLicenseRow(
                licenseInfo.DateCreated,
                customerRow,
                Guid.NewGuid(),
                licenseInfo.LicenseType,
                productRow);
            DataModel.LicenseTableAdapter.Update(DataModel.License);

            // Generate the payload from the license type, the product id, the serial number and the current date.
            Byte[] licenseType       = BitConverter.GetBytes(licenseRow.LicenseType);
            Byte[] productIdArray    = licenseRow.ProductId.ToByteArray();
            Byte[] serialNumberArray = BitConverter.GetBytes(licenseRow.SerialNumber);
            Byte[] dateCreatedArray  = BitConverter.GetBytes(licenseRow.DateCreated.ToBinary());
            Byte[] payload           = new Byte[licenseType.Length + productIdArray.Length + serialNumberArray.Length + dateCreatedArray.Length];
            Array.Copy(licenseType, payload, licenseType.Length);
            Array.Copy(productIdArray, 0, payload, licenseType.Length, productIdArray.Length);
            Array.Copy(serialNumberArray, 0, payload, licenseType.Length + productIdArray.Length, serialNumberArray.Length);
            Array.Copy(dateCreatedArray, 0, payload, licenseType.Length + productIdArray.Length + serialNumberArray.Length, dateCreatedArray.Length);

            RSAParameters rsaParameters = new RSAParameters();

            rsaParameters.D        = LicenseManager.privateKeyD;
            rsaParameters.DP       = LicenseManager.privateKeyDp;
            rsaParameters.DQ       = LicenseManager.privateKeyDq;
            rsaParameters.Exponent = LicenseManager.publicKeyExponent;
            rsaParameters.InverseQ = LicenseManager.privateKeyInverseQ;
            rsaParameters.Modulus  = LicenseManager.publicKeyModulus;
            rsaParameters.P        = LicenseManager.privateKeyP;
            rsaParameters.Q        = LicenseManager.privateKeyQ;
            RSACryptoServiceProvider rsaCryptoServiceProvider = new RSACryptoServiceProvider();

            rsaCryptoServiceProvider.ImportParameters(rsaParameters);

            SHA1CryptoServiceProvider sha1CryptoServiceProvider = new SHA1CryptoServiceProvider();

            Byte[] signature     = rsaCryptoServiceProvider.SignData(payload, sha1CryptoServiceProvider);
            Byte[] signedPayload = new Byte[payload.Length + signature.Length];
            Array.Copy(payload, signedPayload, payload.Length);
            Array.Copy(signature, 0, signedPayload, payload.Length, signature.Length);

            Byte[] publicKey = new Byte[LicenseManager.publicKeyExponent.Length + LicenseManager.publicKeyModulus.Length];
            Array.Copy(LicenseManager.publicKeyExponent, publicKey, LicenseManager.publicKeyExponent.Length);
            Array.Copy(LicenseManager.publicKeyModulus, 0, publicKey, LicenseManager.publicKeyExponent.Length, LicenseManager.publicKeyModulus.Length);

            Byte[] licenseKey = new Byte[publicKey.Length + signedPayload.Length];
            Array.Copy(publicKey, licenseKey, publicKey.Length);
            Array.Copy(signedPayload, 0, licenseKey, publicKey.Length, signedPayload.Length);

            using (StreamWriter streamWriter = new StreamWriter(fileName))
                streamWriter.WriteLine(Convert.ToBase64String(licenseKey));
        }