Пример #1
0
        private void ValidateTabPage1DomainKey()
        {
            string certSignFile  = Path.Combine(tbPath.Text, tbOpenSSLCertCreationFile.Text);
            string domainKeyPath = Path.Combine(tbPath.Text, tbDomainKey.Text);

            picDomainKeyStatus.Image = null;
            lblDomainKeyStatus.Text  = null;
            if (File.Exists(domainKeyPath) && File.Exists(certSignFile))
            {
                picDomainKeyStatus.Image   = ResourceStream.GetImage(ResourceStream.Ok);
                lblDomainKeyStatus.Text    = $"Domain key '{domainKeyPath}' available";
                btnCreateDomainKey.Enabled = false;

                // Print the key in the box
                if (string.IsNullOrWhiteSpace(tbCertSigningRequestContents.Text))
                {
                    tbCertSigningRequestContents.Text = GetCertificateSigningRequest(domainKeyPath, certSignFile);
                }
            }
            else
            {
                tbCertSigningRequestContents.Text = string.Empty;
                picDomainKeyStatus.Image          = ResourceStream.GetImage(ResourceStream.Warning);
                if (!File.Exists(certSignFile))
                {
                    lblDomainKeyStatus.Text    = $"No OpenSSL certificate creation file available (openssl.cnf)";
                    btnCreateDomainKey.Enabled = false;
                }
                else if (!File.Exists(domainKeyPath))
                {
                    lblDomainKeyStatus.Text    = $"No Domain key has been created yet";
                    btnCreateDomainKey.Enabled = true;
                }
            }
        }
Пример #2
0
        private void ValidateTabPage3()
        {
            var    rootDir   = tbPath.Text;
            string prefix    = Path.GetFileName(rootDir);
            string certFile  = Path.Combine(rootDir, prefix + "_cert.crt");
            string chainFile = Path.Combine(rootDir, prefix + "_chain.crt");


            picCertificateFileStatus.Image = null;
            lblCertificateFileStatus.Text  = null;
            if (File.Exists(certFile) && File.Exists(chainFile))
            {
                picCertificateFileStatus.Image = ResourceStream.GetImage(ResourceStream.Ok);
                lblCertificateFileStatus.Text  = $"Chain and Cert files both available at '{rootDir}'";
            }
            else
            {
                picAccountKeyStatus.Image = ResourceStream.GetImage(ResourceStream.Warning);
                if (!File.Exists(certFile))
                {
                    lblAccountKeyStatus.Text = $"Cert file '{certFile}' could not be found. Re-create files.";
                }
                else
                {
                    lblAccountKeyStatus.Text = $"Chain file '{chainFile}' could not be found. Re-create files.";
                }
            }
        }
Пример #3
0
        private void btnCreateCertificateFiles_Click(object sender, EventArgs e)
        {
            try
            {
                var    rootDir   = tbPath.Text;
                string prefix    = Path.GetFileName(rootDir);
                string certFile  = Path.Combine(rootDir, prefix + "_cert.crt");
                string chainFile = Path.Combine(rootDir, prefix + "_chain.crt");

                CreateFileWithContents(certFile, tbCertSigned.Text.Trim());
                CreateFileWithContents(chainFile, tbCertIntermediate.Text.Trim() + Environment.NewLine + tbCertRoot.Text.Trim());

                Process.Start(rootDir);

                ValidateTabPage3();

                ShowBalloonTip("Certification files created. Congratulations!",
                               btnCreateCertificateFiles,
                               1000);
            }
            catch (Exception ex)
            {
                picCertificateFileStatus.Image = ResourceStream.GetImage(ResourceStream.Error);
                lblCertificateFileStatus.Text  = ex.Message;
            }
        }
Пример #4
0
        private void ValidateTabPage1AccountKey()
        {
            string accountKeyPath = Path.Combine(tbPath.Text, tbAccountKey.Text);

            picAccountKeyStatus.Image = null;
            lblAccountKeyStatus.Text  = null;
            if (File.Exists(accountKeyPath))
            {
                picAccountKeyStatus.Image   = ResourceStream.GetImage(ResourceStream.Ok);
                lblAccountKeyStatus.Text    = $"Account key '{accountKeyPath}' available";
                btnCreateAccountKey.Enabled = false;

                // Print the key in the box
                if (string.IsNullOrWhiteSpace(tbAccountKeyContents.Text))
                {
                    tbAccountKeyContents.Text = GetKeyFileContents(accountKeyPath);
                }
            }
            else
            {
                picAccountKeyStatus.Image   = ResourceStream.GetImage(ResourceStream.Warning);
                lblAccountKeyStatus.Text    = $"No Account key has been created yet";
                btnCreateAccountKey.Enabled = true;
                tbAccountKeyContents.Text   = string.Empty;
            }
        }
Пример #5
0
        private void btnOpenSSLExecute_Click(object sender, EventArgs e)
        {
            try
            {
                string tmpPath = Path.Combine(tbPath.Text, "tmp");

                // Create a clean dir
                if (Directory.Exists(tmpPath))
                {
                    Directory.Delete(tmpPath, true);
                }

                Directory.CreateDirectory(tmpPath);

                string accountKey  = Path.Combine(tbPath.Text, tbAccountKey.Text);
                string openSSLPath = tbOpenSSLPath.Text;

                // Create batch file with contents
                string rawCommand = tbOpenSSLData.Text;
                string winCommand = rawCommand.Replace(@"PRIV_KEY=./account.key; echo -n ", @"echo|set /p=").Replace("openssl", "\"" + openSSLPath + "\"").Replace("$PRIV_KEY", "\"" + accountKey + "\"");

                var batFileFullPath = Path.Combine(tmpPath, "run.bat");
                CreateFileWithContents(batFileFullPath, winCommand);

                string rawResults = RunExternalExe(batFileFullPath);

                // If the command is first
                var idx = rawResults.IndexOf(accountKey);
                if (idx != -1)
                {
                    rawResults = rawResults.Substring(idx + accountKey.Length + 1).Trim();
                }

                string winResults = "(stdin)= " + rawResults.Replace(Environment.NewLine, "");

                tbOpenSSLResults.Text = winResults;
                Clipboard.SetText(winResults);

                // Clear out the other boxes so nothing gets confused
                tbFileContents.Text   = string.Empty;
                tbFileServerPath.Text = string.Empty;

                picOpenSSLExecStatus.Image = ResourceStream.GetImage(ResourceStream.Ok);
                lblOpenSSLExecStatus.Text  = "Success";

                ShowBalloonTip("Signature created and copied to clipboard",
                               btnOpenSSLExecute,
                               1000);
            }
            catch (Exception ex)
            {
                picOpenSSLExecStatus.Image = ResourceStream.GetImage(ResourceStream.Error);
                lblOpenSSLExecStatus.Text  = "Error " + ex.Message;
            }
        }
Пример #6
0
        private void btnCreateVerificationFile_Click(object sender, EventArgs e)
        {
            try
            {
                string tmpPath = Path.Combine(tbPath.Text, "files");

                // Create a clean dir, if not able to delete then simply continue
                try
                {
                    if (Directory.Exists(tmpPath))
                    {
                        Directory.Delete(tmpPath, true);
                    }
                }
                catch
                {
                    MessageBox.Show(this, "Could not prepare 'files' directory. \nMake sure you close all windows previously opened by \nthis operation then try again.\nPath: " + tmpPath);
                    return;
                }

                Directory.CreateDirectory(tmpPath);

                string rawUrl = tbFileServerPath.Text;
                Uri    url    = new Uri(rawUrl, UriKind.Absolute);

                string fullFilePath = Path.Combine(tmpPath, url.AbsolutePath.TrimStart('/').Replace('/', '\\'));
                Directory.CreateDirectory(Path.GetDirectoryName(fullFilePath));

                CreateFileWithContents(fullFilePath, tbFileContents.Text);

                Process.Start(tmpPath);

                picVerificationFileStatus.Image = ResourceStream.GetImage(ResourceStream.Ok);
                lblVerificationFileStatus.Text  = "Success";

                ShowBalloonTip("Verification file created",
                               btnCreateVerificationFile,
                               1000);
            }
            catch (Exception ex)
            {
                picVerificationFileStatus.Image = ResourceStream.GetImage(ResourceStream.Error);
                lblVerificationFileStatus.Text  = ex.Message;
            }
        }
Пример #7
0
        private void btnCreateDomainKey_Click(object sender, EventArgs e)
        {
            try
            {
                string tmpPath = Path.Combine(tbPath.Text, "tmp");

                // Create a clean dir
                if (!Directory.Exists(tmpPath))
                {
                    Directory.CreateDirectory(tmpPath);
                }

                string domainKey    = Path.Combine(tbPath.Text, tbDomainKey.Text);
                string certSignFile = Path.Combine(tbPath.Text, tbOpenSSLCertCreationFile.Text);
                string openSSLPath  = tbOpenSSLPath.Text;


                var batFileFullPath = Path.Combine(tmpPath, "run.bat");
                // Create batch file with contents
                string winCommand = "\"" + openSSLPath + "\" genrsa 4096 > \"" + domainKey + "\"";
                CreateFileWithContents(batFileFullPath, winCommand);
                RunExternalExe(batFileFullPath);

                string rawCertData = GetCertificateSigningRequest(domainKey, certSignFile);
                tbCertSigningRequestContents.Text = rawCertData;
                Clipboard.SetText(rawCertData);

                ValidateTabPage1DomainKey();

                ShowBalloonTip("Domain key created and copied to clipboard",
                               btnCreateDomainKey,
                               1000);
            }
            catch (Exception ex)
            {
                picDomainKeyStatus.Image = ResourceStream.GetImage(ResourceStream.Error);
                lblDomainKeyStatus.Text  = ex.Message;
            }
        }
Пример #8
0
        private void btnCreateAccountKey_Click(object sender, EventArgs e)
        {
            try
            {
                string tmpPath = Path.Combine(tbPath.Text, "tmp");

                // Create a clean dir
                if (!Directory.Exists(tmpPath))
                {
                    Directory.CreateDirectory(tmpPath);
                }

                string accountKey  = Path.Combine(tbPath.Text, tbAccountKey.Text);
                string openSSLPath = tbOpenSSLPath.Text;


                var batFileFullPath = Path.Combine(tmpPath, "run.bat");
                // Create batch file with contents
                string winCommand = "\"" + openSSLPath + "\" genrsa 4096 > \"" + accountKey + "\"";
                CreateFileWithContents(batFileFullPath, winCommand);
                RunExternalExe(batFileFullPath);

                string rawKeyData = GetKeyFileContents(accountKey);

                tbAccountKeyContents.Text = rawKeyData;
                Clipboard.SetText(rawKeyData);

                ValidateTabPage1AccountKey();

                ShowBalloonTip("Account key created and copied to clipboard",
                               btnCreateAccountKey,
                               1000);
            }
            catch (Exception ex)
            {
                picAccountKeyStatus.Image = ResourceStream.GetImage(ResourceStream.Error);
                lblAccountKeyStatus.Text  = ex.Message;
            }
        }
Пример #9
0
        private void ValidateSetupTab()
        {
            // Load values from settings if nothing is set
            if (string.IsNullOrWhiteSpace(tbOpenSSLPath.Text))
            {
                tbOpenSSLPath.Text = Settings.Default.OpenSSLPath;
            }
            if (string.IsNullOrWhiteSpace(tbPath.Text))
            {
                tbPath.Text = Settings.Default.LastWorkingPath;
            }

            var openSSLPathExists = File.Exists(tbOpenSSLPath.Text);
            var workingPathExists = Directory.Exists(tbPath.Text);

            picOKOpenSSL.Image                 = openSSLPathExists ? ResourceStream.GetImage(ResourceStream.Ok) : ResourceStream.GetImage(ResourceStream.Error);
            picOKWorkingPath.Image             = workingPathExists ? ResourceStream.GetImage(ResourceStream.Ok) : ResourceStream.GetImage(ResourceStream.Error);
            picOKCertificateCreationFile.Image = File.Exists(Path.Combine(tbPath.Text, tbOpenSSLCertCreationFile.Text)) ? ResourceStream.GetImage(ResourceStream.Ok) : ResourceStream.GetImage(ResourceStream.Error);

            picOKAccountKey.Image = !string.IsNullOrWhiteSpace(tbAccountKey.Text) ? ResourceStream.GetImage(ResourceStream.Ok) : ResourceStream.GetImage(ResourceStream.Error);
            picOKDomainKey.Image  = !string.IsNullOrWhiteSpace(tbDomainKey.Text) ? ResourceStream.GetImage(ResourceStream.Ok) : ResourceStream.GetImage(ResourceStream.Error);

            // Save settings for next use
            if (openSSLPathExists)
            {
                Settings.Default.OpenSSLPath = tbOpenSSLPath.Text;
            }
            if (workingPathExists)
            {
                Settings.Default.LastWorkingPath = tbPath.Text;
            }

            if (openSSLPathExists || workingPathExists)
            {
                Settings.Default.Save();
            }
        }