예제 #1
0
        internal static bool validateLicenseFile(string licFile, ref LicenseTerms lic)
        {
            try
            {
                LicenseDTO license = null;
                if (File.Exists(licFile))
                {
                    license = LicenseDTO.FromString(File.ReadAllText(licFile));
                }
                else
                {
                    //TODO : file not exists
                }

                if (license != null)
                {
                    lic = ValidateLicense(license);
                    return(true);
                }
                else
                {
                    //TODO : "Invalid License File Not Supplied!"
                    return(false);
                }
            }
            catch (SecurityException se)
            {
                // display the reason for the license check failure:
                //TODO :
            }
            return(false);
        }
예제 #2
0
        private void btnGenerateLic_Click(object sender, EventArgs e)
        {
            saveFileDialog.CheckFileExists = false;
            saveFileDialog.FileName        = "SmartDataServiceFocas.lic";
            List <CNCData> cNCDataList = new List <CNCData>();

            foreach (var item in bindingSource1.DataSource as IEnumerable <CNCData> )
            {
                cNCDataList.Add(new CNCData {
                    IsOEM = item.IsOEM, CNCdata1 = item.CNCdata1, CNCdata2 = item.CNCdata2, CNCdata3 = item.CNCdata3
                });
            }

            LicenseTerms terms = new LicenseTerms
            {
                Customer         = txtCustomer.Text.Trim(),
                Plant            = txtPlant.Text.Trim(),
                Email            = txtEmail.Text.Trim(),
                LicType          = cmdLicType.SelectedItem.ToString(),
                StartDate        = dtpStartDate.Value.Date.ToString("yyyy-MM-dd"),
                ExpiresAt        = dtpExpiresAt.Value.Date.ToString("yyyy-MM-dd"),
                ComputerSerialNo = txtSerialNo.Text.Trim(),
                CNCData          = cNCDataList,
            };
            LicenseDTO licDto = LicenseServer.CreateLicense(terms);

            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                licDto.SaveLicenseStringFinal(saveFileDialog.FileName);
            }
        }
예제 #3
0
        internal static LicenseTerms ValidateLicense(LicenseDTO license)
        {
            RSACryptoServiceProvider rsa = Utility.GetPublicKeyFromAssemblyAtClient(Assembly.GetExecutingAssembly());

            byte[] dataToVerify = Convert.FromBase64String(license.LicenseTerms);
            byte[] signature    = Convert.FromBase64String(license.Signature);

            // verify that the license-terms match the signature data
            if (rsa.VerifyData(dataToVerify, new SHA1CryptoServiceProvider(), signature))
            {
                return(LicenseTerms.FromString(license.LicenseTerms));
            }
            else
            {
                return(null);
            }
        }