コード例 #1
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);
            }
        }
コード例 #2
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);
        }
コード例 #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);
            }
        }
コード例 #4
0
        //create the LicenseTerms object from GUI and call this function to create lic
        public static LicenseDTO CreateLicense(LicenseTerms terms)
        {
            //Get the rsa from snk file
            RSACryptoServiceProvider rsa = Utility.GetRSAFromSnkFileAtServer(@"SmartDataServiceFocas.snk");

            // get the byte-array of the licence terms:
            byte[] license = terms.GetLicenseData();

            // get the signature:
            byte[] signature = rsa.SignData(license, new SHA1CryptoServiceProvider());

            // now create the license object:
            return(new LicenseDTO()
            {
                LicenseTerms = Convert.ToBase64String(license),
                Signature = Convert.ToBase64String(signature)
            });

            // save the license file:
            //license.Save(licenseResourceFolder + "\\" + userName + ".lic");
        }
コード例 #5
0
        private void btnSelectLicenseFile_Click(object sender, EventArgs e)
        {
            var result = openFileDialog.ShowDialog(this);

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                txtLicFiletoRead.Text = openFileDialog.FileName;
                LicenseTerms terms = null;
                LicenseServer.validateLicenseFile(openFileDialog.FileName, ref terms);
                if (terms != null)
                {
                    txtCustomer.Text          = terms.Customer;
                    txtPlant.Text             = terms.Plant;
                    txtEmail.Text             = terms.Email;
                    cmdLicType.SelectedItem   = terms.LicType;
                    dtpStartDate.Text         = terms.StartDate;
                    dtpExpiresAt.Text         = terms.ExpiresAt;
                    txtSerialNo.Text          = terms.ComputerSerialNo;
                    bindingSource1.DataSource = terms.CNCData;
                }
            }
        }