//=============================================================================
        private void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            if (m_VM == null)
            {
                return;
            }

            if (m_VM.License == null)
            {
                return;
            }

            // Try to get create license via license server.
            // For test only.
            if (false)
            {
                WebClient webClient = new WebClient();
                webClient.QueryString.Add(LicenseServerData.PARAM_USERNAME, m_VM.License.Username);
                webClient.QueryString.Add(LicenseServerData.PARAM_PASSWORD, m_VM.License.Password);
                webClient.QueryString.Add(LicenseServerData.PARAM_ETHERNET_ADDRESS, m_VM.License.EthernetAddress);
                webClient.QueryString.Add(LicenseServerData.PARAM_GUID, m_VM.License.GUID);
                webClient.QueryString.Add(LicenseServerData.PARAM_PLATFORM_ID, m_VM.License.PlatformID);
                webClient.QueryString.Add(LicenseServerData.PARAM_WINVER_MAJOR, m_VM.License.WindowsVersionMajor);
                webClient.QueryString.Add(LicenseServerData.PARAM_WINVER_MINOR, m_VM.License.WindowsVersionMinor);
                webClient.QueryString.Add(LicenseServerData.PARAM_EXCEL_VERSION, m_VM.License.ExcelVersion);

                webClient.DownloadFile(LicenseServerData.LICENSE_GENERATOR_SERVER_URI, "D:\\LicenseTest.lic");
            }

            string strPath = System.IO.Path.Combine(m_VM.LicenseFileDirectory.Trim(), m_VM.LicenseFileName.Trim());
            string strError;
            bool   bError = !LicenseUtilities.sCreateLicense(m_VM.License, strPath, out strError);

            if (bError)
            {
                m_VM.DoesStatusContainsError = true;
                m_VM.Status = strError;
            }
            else
            {
                m_VM.DoesStatusContainsError = false;
                m_VM.Status = "File successfully created.";
            }
        }
        /// <summary>
        /// Gets the computer ID.
        /// </summary>
        /// <returns>
        /// A string identifying the computer
        /// </returns>
        /// <remarks>
        /// This id is included in the authenticated license and checked when the license
        /// is validated.   This prevents a license being authenticated on one machine and
        /// then copied to another.
        /// </remarks>
        public override string GetComputerID()
        {
            var computerId = this.GenerateKey("id.dat");

            return(LicenseUtilities.ToBase32(computerId.ToByteArray()));
        }
Ejemplo n.º 3
0
        private void CheckLicense()
        {
            const int TRIAL_DAYS = 30;

            const string LICENSE_PARAMETERS =
                @"<AuthenticatedLicenseParameters>
	              <EncryptedLicenseParameters>
	                <ProductName>LaJust Power Meter</ProductName>
	                <RSAKeyValue>
	                  <Modulus>n66mRwUlIE5rGPYLtrCrdDR1yGuOZbyALMEKvO6X2fIqWkTgVtaCKHVnjzxVG1JSOlngHuCtoOypeuL0pNKyxj4/0TGny7mYS5Eas2J0NnDEH2P75FsVzGQ7ESNyns/uXEmtCgzVCtfktW3X7bNQgi3ycb1ZCwJVjVaoQGiuUyM=</Modulus>
	                  <Exponent>AQAB</Exponent>
	                </RSAKeyValue>
	                <DesignSignature>X0XJLQFa08k1f6BD9Zte2OyJyW/mk0dro0EYPN9nDM5egOzn1ljCBBGWdPEZmPHz++G7w1uNvTMI/KcIlgUTa/oTJAbd/kOXbDIDliZX1NAPkxtgAdhxiZL/TL3rx9faMdWg78C4jucprOmTCHHAjz1xHtBRoOWbQhV3jT9LhX0=</DesignSignature>
	                <RuntimeSignature>L5hUaIqMKt3xY0jOl8oKcoPnDzLfuZIV5/gHKJt/cqrm6ufnfmynGjNiL24nt2Lqczt+P3HeUSIxnikJJtJ+bRI5d6ljiRuP2vB1yu73gEAU1cF24HKz3v+xMsYmRBdVvuShKCvpLB2JFAjZE9HejFr73p+pCIlsZyZjAn2H930=</RuntimeSignature>
	                <KeyStrength>7</KeyStrength>
	                <ChecksumProductInfo>True</ChecksumProductInfo>
	                <TextEncoding>Base32</TextEncoding>
	                <ShortSerialNo>False</ShortSerialNo>
	              </EncryptedLicenseParameters>
	              <AuthenticationServerURL>http://authsvc.lajust.net/LicenseService/AuthenticationService.asmx</AuthenticationServerURL>
	              <ServerRSAKeyValue>
	                <Modulus>zpt4gdTSKUZTSpbfEL02AJKqNbfeJZ79Xe6Z76dCzX+ntPQL+lusGJ1TUbGpY6SPdLHc++8Dvnl5F+8mT2nBhBNUYtVCohE3GrQin1B/zi42PUvgy/lx4jbW1GfG2blYYqwgp/TOXciQo+aHcuhgpX8w+1azd6zD/gb/yo8asPc=</Modulus>
	                <Exponent>AQAB</Exponent>
	              </ServerRSAKeyValue>
	            </AuthenticatedLicenseParameters>"    ;

            // Check for machine names checksums that do not require license files
            // We don't put the actual machine name in the code for security reasons
            switch (LicenseUtilities.Checksum(Environment.MachineName.ToUpper()))
            {
            case "766":     // "LAJUST-MSI" MSI 2200AE All In One Machine
            case "754":     // "LAJUST-PC"  Dell Studio One All In One Machine
                return;
            }

            // The license file, the directory will automatically get created if required
            string licenseFile = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\LaJust\LaJustPowerMeter.lic";

            // Check if there is a valid license for the application
            MyAuthenticatedLicenseProvider licenseProvider = new MyAuthenticatedLicenseProvider();
            AuthenticatedLicense           license         = licenseProvider.GetLicense(LICENSE_PARAMETERS, licenseFile, true);

            // Allow forcing of the license dialog using command line option
            if (Environment.CommandLine.ToUpper().Contains("/LICENSE"))
            {
                MyAuthenticatedLicenseInstallForm licenseForm = new MyAuthenticatedLicenseInstallForm();
                license = licenseForm.ShowDialog(Solution.Product, licenseFile, license);
            }

            // If there is no installed license then display the evaluation dialog until
            // the user installs a license or selects Exit or Continue
            EvaluationMonitor evaluationMonitor = new IsolatedStorageEvaluationMonitor(LicenseUtilities.Checksum(Solution.Version), false, false);
            EvaluationDialog  evaluationDialog  = new EvaluationDialog(evaluationMonitor, Solution.Product)
            {
                TrialDays = TRIAL_DAYS, ExtendedTrialDays = TRIAL_DAYS
            };

            while (license == null || license.Status != AuthenticatedLicenseStatus.Valid)
            {
                EvaluationDialogResult dialogResult = evaluationDialog.ShowDialog();
                if (dialogResult == EvaluationDialogResult.Exit)
                {
                    Environment.Exit(0);
                }
                else if (dialogResult == EvaluationDialogResult.Continue)
                {
                    break; // exit the loop
                }
                else if (dialogResult == EvaluationDialogResult.InstallLicense)
                {
                    MyAuthenticatedLicenseInstallForm licenseForm = new MyAuthenticatedLicenseInstallForm();
                    license = licenseForm.ShowDialog(Solution.Product, licenseFile, license);
                }
            }

            // Reset the evaluation monitor if there is a currently valid license, this allows
            // for another 30 days trial if something should happen to the license
            if (license != null && license.Status == AuthenticatedLicenseStatus.Valid)
            {
                evaluationMonitor.Reset(true);
            }
        }
Ejemplo n.º 4
0
        //=============================================================================
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // Apply application theme from TXT file
            var assembly     = Assembly.GetExecutingAssembly();
            var resourceName = "RackDrawingApp.Resources.ApplicationTheme.txt";

            //
            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                ColorTheme appTheme = ColorTheme.ReadFromStream(stream);

                // apply theme
                if (appTheme != null)
                {
                    CurrentTheme.CurrentColorTheme = appTheme;
                }
            }

            // Application should be closed after 24 hours run.
            AppCloseTimer.Initialize(AppShutdown);

            bool bShowLoginWindows = true;

            // If some arguments are passed, then try to get login, password and license path.
            if (e.Args.Count() > 0)
            {
                string strLogin          = string.Empty;
                string strPassword       = string.Empty;
                string strLicensePath    = string.Empty;
                string strCutomerName    = string.Empty;
                string strEnqNo          = string.Empty;
                string strContactNo      = string.Empty;
                string strEmailID        = string.Empty;
                string strBillingAddress = string.Empty;
                string strSiteAddress    = string.Empty;
                string strDrawingPath    = string.Empty;
                //
                foreach (string strArg in e.Args)
                {
                    if (string.IsNullOrEmpty(strArg))
                    {
                        continue;
                    }

                    if (strArg.StartsWith(ARG_LOGIN))
                    {
                        strLogin = strArg.Replace(ARG_LOGIN, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_PASSWORD))
                    {
                        strPassword = strArg.Replace(ARG_PASSWORD, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_LICENSE))
                    {
                        strLicensePath = strArg.Replace(ARG_LICENSE, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_CUSTOMER_NAME))
                    {
                        strCutomerName = strArg.Replace(ARG_CUSTOMER_NAME, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_ENQ_NO))
                    {
                        strEnqNo = strArg.Replace(ARG_ENQ_NO, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_CONTACT_NO))
                    {
                        strContactNo = strArg.Replace(ARG_CONTACT_NO, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_EMAIL_ID))
                    {
                        strEmailID = strArg.Replace(ARG_EMAIL_ID, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_BILLING_ADDRESS))
                    {
                        strBillingAddress = strArg.Replace(ARG_BILLING_ADDRESS, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_SITE_ADDRESS))
                    {
                        strSiteAddress = strArg.Replace(ARG_SITE_ADDRESS, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_DRAWING_PATH))
                    {
                        strDrawingPath = strArg.Replace(ARG_DRAWING_PATH, string.Empty);
                    }
                }

                UserInfo.Login                  = strLogin;
                UserInfo.CustomerName           = strCutomerName;
                UserInfo.EnqNo                  = strEnqNo;
                UserInfo.CustomerContactNo      = strContactNo;
                UserInfo.CustomerEmailID        = strEmailID;
                UserInfo.CustomerBillingAddress = strBillingAddress;
                UserInfo.CustomerSiteAddress    = strSiteAddress;
                UserInfo.DrawingPath            = strDrawingPath;
                if (!string.IsNullOrEmpty(strLicensePath))
                {
                    string strError;
                    int    iRes = LicenseUtilities.IsValidLicense(strLicensePath, strLogin, strPassword, out strError);
                    if (iRes >= 0)
                    {
                        bShowLoginWindows = false;
                    }
                }
            }

            if (bShowLoginWindows)
            {
                LoginWindow loginWnd = new LoginWindow();
                loginWnd.Show();
            }
            else
            {
                StartupWindow startupWnd = new StartupWindow();
                if (!string.IsNullOrEmpty(UserInfo.DrawingPath))
                {
                    startupWnd.StartOldApp();
                }
                else
                {
                    startupWnd.Show();
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // WARNING!!!
            // Application should have administrator rights otherwise "listener.Start();" throws an exception.
            try
            {
                HttpListener listener = new HttpListener();
                listener.Prefixes.Add(LicenseServerData.LICENSE_GENERATOR_SERVER_URI);
                listener.Start();
                Console.WriteLine("Waiting for connections...");

                long connectionsCount = 0;
                while (true)
                {
                    ++connectionsCount;

                    HttpListenerContext  context  = listener.GetContext();
                    HttpListenerRequest  request  = context.Request;
                    HttpListenerResponse response = context.Response;

                    // Display request and parse parameters.
                    Console.WriteLine("\nConnection #{0}\nQuery: {1}", connectionsCount, request.Url);
                    string strUsername     = string.Empty;
                    string strPassword     = string.Empty;
                    string strEthAddr      = string.Empty;
                    string strGUID         = string.Empty;
                    string strEndDate      = string.Empty;
                    string strPlatformID   = string.Empty;
                    string strWinMajor     = string.Empty;
                    string strWinMinor     = string.Empty;
                    string strExcelVersion = string.Empty;
                    string strPath         = string.Empty;
                    foreach (var queryKey in context.Request.QueryString.Keys)
                    {
                        if (queryKey == null)
                        {
                            continue;
                        }

                        string strQueryKey = queryKey.ToString();
                        if (string.IsNullOrEmpty(strQueryKey))
                        {
                            continue;
                        }

                        object queryValue    = context.Request.QueryString[strQueryKey];
                        string strQueryValue = string.Empty;
                        if (queryValue != null)
                        {
                            strQueryValue = queryValue.ToString();
                        }

                        Console.WriteLine("{0} = {1}", strQueryKey, strQueryValue);

                        if (strQueryKey == LicenseServerData.PARAM_USERNAME)
                        {
                            strUsername = strQueryValue;
                        }
                        else if (strQueryKey == LicenseServerData.PARAM_PASSWORD)
                        {
                            strPassword = strQueryValue;
                        }
                        else if (strQueryKey == LicenseServerData.PARAM_ETHERNET_ADDRESS)
                        {
                            strEthAddr = strQueryValue;
                        }
                        else if (strQueryKey == LicenseServerData.PARAM_GUID)
                        {
                            strGUID = strQueryValue;
                        }
                        else if (strQueryKey == LicenseServerData.PARAM_END_DATE)
                        {
                            strEndDate = strQueryValue;
                        }
                        else if (strQueryKey == LicenseServerData.PARAM_PLATFORM_ID)
                        {
                            strPlatformID = strQueryValue;
                        }
                        else if (strQueryKey == LicenseServerData.PARAM_WINVER_MAJOR)
                        {
                            strWinMajor = strQueryValue;
                        }
                        else if (strQueryKey == LicenseServerData.PARAM_WINVER_MINOR)
                        {
                            strWinMinor = strQueryValue;
                        }
                        else if (strQueryKey == LicenseServerData.PARAM_EXCEL_VERSION)
                        {
                            strExcelVersion = strQueryValue;
                        }
                    }

                    // Try to create license.
                    LicenseData licenseData = new LicenseData();
                    licenseData.Username        = strUsername;
                    licenseData.Password        = strPassword;
                    licenseData.EthernetAddress = strEthAddr;
                    licenseData.GUID            = strGUID;
                    //
                    if (string.IsNullOrEmpty(strEndDate))
                    {
                        licenseData.IncludeDate = false;
                    }
                    else
                    {
                        licenseData.IncludeDate = true;
                        try
                        {
                            licenseData.CanRunTill = Convert.ToDateTime(strEndDate);
                        }
                        catch (Exception ex)
                        {
                            response.StatusCode        = (int)HttpStatusCode.BadRequest;
                            response.StatusDescription = "Incorrect parameters.";
                            response.OutputStream.Close();

                            Console.WriteLine("ERROR, cant parse \"end_date\" parameter: " + ex.Message);
                            continue;
                        }
                    }
                    //
                    licenseData.PlatformID          = strPlatformID;
                    licenseData.WindowsVersionMajor = strWinMajor;
                    licenseData.WindowsVersionMinor = strWinMinor;
                    licenseData.ExcelVersion        = strExcelVersion;

                    // Try to create license file in the assembly directory.
                    string assemblyFolder  = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    string licenseFilePath = assemblyFolder + "\\RackDrawingAppLicense.lic";
                    string strError;
                    bool   bError = !LicenseUtilities.sCreateLicense(licenseData, licenseFilePath, out strError);

                    // Send license file in response.
                    if (!bError)
                    {
                        using (FileStream fs = File.OpenRead(licenseFilePath))
                        {
                            string filename = Path.GetFileName(licenseFilePath);
                            //response is HttpListenerContext.Response...
                            response.ContentLength64 = fs.Length;
                            response.SendChunked     = false;
                            response.ContentType     = System.Net.Mime.MediaTypeNames.Application.Octet;
                            response.AddHeader("Content-disposition", "attachment; filename=" + filename);

                            byte[] buffer = new byte[64 * 1024];
                            int    read;
                            using (BinaryWriter bw = new BinaryWriter(response.OutputStream))
                            {
                                while ((read = fs.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    bw.Write(buffer, 0, read);
                                    bw.Flush();                                     //seems to have no effect
                                }

                                bw.Close();
                            }

                            response.StatusCode        = (int)HttpStatusCode.OK;
                            response.StatusDescription = "OK";
                            response.OutputStream.Close();
                        }

                        Console.WriteLine("SUCCESS. License file was sent.");
                    }
                    else
                    {
                        response.StatusCode        = (int)HttpStatusCode.BadRequest;
                        response.StatusDescription = "Incorrect parameters.";
                        response.OutputStream.Close();

                        Console.WriteLine("ERROR. " + strError);
                    }

                    File.Delete(licenseFilePath);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
                Console.WriteLine("Press any key...");
                Console.ReadKey();
            }
        }
Ejemplo n.º 6
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // Apply application theme from TXT file
            var assembly     = Assembly.GetExecutingAssembly();
            var resourceName = "RackDrawingApp_LicenseGenerator.Resources.ApplicationTheme.txt";

            //
            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                ColorTheme appTheme = ColorTheme.ReadFromStream(stream);

                // apply theme
                if (appTheme != null)
                {
                    CurrentTheme.CurrentColorTheme = appTheme;
                }
            }

            // If arguments are empty then display window.
            // Otherwise try to parse arguments.
            if (e.Args.Count() == 0)
            {
                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
            }
            else
            {
                string strUsername     = string.Empty;
                string strPassword     = string.Empty;
                string strEthAddr      = string.Empty;
                string strGUID         = string.Empty;
                string strEndDate      = string.Empty;
                string strPlatformID   = string.Empty;
                string strWinMajor     = string.Empty;
                string strWinMinor     = string.Empty;
                string strExcelVersion = string.Empty;
                string strPath         = string.Empty;
                //
                foreach (string strArg in e.Args)
                {
                    if (string.IsNullOrEmpty(strArg))
                    {
                        continue;
                    }

                    if (strArg.StartsWith(ARG_USERNAME))
                    {
                        strUsername = strArg.Replace(ARG_USERNAME, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_PASSWORD))
                    {
                        strPassword = strArg.Replace(ARG_PASSWORD, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_ETHERNET_ADDRESS))
                    {
                        strEthAddr = strArg.Replace(ARG_ETHERNET_ADDRESS, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_GUID))
                    {
                        strGUID = strArg.Replace(ARG_GUID, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_END_DATE))
                    {
                        strGUID = strArg.Replace(ARG_END_DATE, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_PLATFORM_ID))
                    {
                        strPlatformID = strArg.Replace(ARG_PLATFORM_ID, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_WINVER_MAJOR))
                    {
                        strWinMajor = strArg.Replace(ARG_WINVER_MAJOR, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_WINVER_MINOR))
                    {
                        strWinMinor = strArg.Replace(ARG_WINVER_MINOR, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_EXCEL_VERSION))
                    {
                        strExcelVersion = strArg.Replace(ARG_EXCEL_VERSION, string.Empty);
                    }
                    else if (strArg.StartsWith(ARG_PATH))
                    {
                        strPath = strArg.Replace(ARG_PATH, string.Empty);
                    }
                }

                LicenseData licenseData = new LicenseData();
                licenseData.Username        = strUsername;
                licenseData.Password        = strPassword;
                licenseData.EthernetAddress = strEthAddr;
                licenseData.GUID            = strGUID;
                //
                if (string.IsNullOrEmpty(strEndDate))
                {
                    licenseData.IncludeDate = false;
                }
                else
                {
                    licenseData.IncludeDate = true;
                    try
                    {
                        licenseData.CanRunTill = Convert.ToDateTime(strEndDate);
                    }
                    catch
                    {
                        return;
                    }
                }
                //
                licenseData.PlatformID          = strPlatformID;
                licenseData.WindowsVersionMajor = strWinMajor;
                licenseData.WindowsVersionMinor = strWinMinor;
                licenseData.ExcelVersion        = strExcelVersion;

                string strError;
                LicenseUtilities.sCreateLicense(licenseData, strPath, out strError);
                return;
            }
        }
        //=============================================================================
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            if (m_VM == null)
            {
                return;
            }

            string strLicenseFilePath = string.Empty;

            if (m_VM.ConnectToServer)
            {
                try
                {
                    // Try to connect to the login server.
                    using (WebClient webClient = new WebClient())
                    {
                        webClient.QueryString.Add(LoginServerData.PARAM_USERNAME, m_VM.UserName);
                        webClient.QueryString.Add(LoginServerData.PARAM_PASSWORD, _PasswordBox.Password.ToString());

                        // Try to create license file in the assembly directory.
                        string assemblyFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                        strLicenseFilePath = assemblyFolder + "\\RackDrawingAppLicense.lic";

                        //
                        webClient.DownloadFile(LoginServerData.LOGIN_SERVER_URI, strLicenseFilePath);
                    }
                }
                catch (Exception exception)
                {
                    m_VM.Error = exception.Message;
                    return;
                }
            }
            else
            {
                strLicenseFilePath = m_VM.LicenseFilePath;
            }

            if (string.IsNullOrEmpty(strLicenseFilePath))
            {
                if (m_VM.ConnectToServer)
                {
                    m_VM.Error = "An error occurred while downloading the license file";
                }
                else
                {
                    m_VM.Error = "License file is not selected.";
                }
                return;
            }

            if (!File.Exists(strLicenseFilePath))
            {
                if (m_VM.ConnectToServer)
                {
                    m_VM.Error = "An error occurred while downloading the license file";
                }
                else
                {
                    m_VM.Error = "License file doesnt exists.";
                }
                return;
            }

            string strError;
            int    iRes = LicenseUtilities.IsValidLicense(strLicenseFilePath, m_VM.UserName, _PasswordBox.Password.ToString(), out strError);

            if (iRes >= 0)
            {
                UserInfo.Login = m_VM.UserName;

                StartupWindow startupWnd = new StartupWindow();
                if (!string.IsNullOrEmpty(UserInfo.DrawingPath))
                {
                    startupWnd.StartOldApp();
                }
                else
                {
                    startupWnd.Show();
                }
                this.Close();
            }
            else
            {
                m_VM.Error = strError;
            }
        }