コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            regConf conf = new regConf();
            string  sid  = WindowsIdentity.GetCurrent().User.Value;

            cpRegFile rf = new cpRegFile("input.reg");

            bool res = rf.importRegFile();

            if (!res)
            {
                MessageBox.Show("error importing");
            }

            cpContainers tmpcontainers = new cpContainers($@"{conf.getParam("baseKey", "")}\{sid}\{conf.getParam("cpKeys", "")}", $@"{appdatapath}\cpKey.list");

            listBox1.Items.Clear();

            List <string> toinstall = tmpcontainers.compareList();

            if (toinstall.Count > 0)
            {
                foreach (string item in toinstall)
                {
                    if (tmpcontainers.instCert(item))
                    {
                        listBox1.Items.Add(item);
                    }
                }
            }
        }
コード例 #2
0
        public bool instCert(string cpcName)
        {
            bool    res  = false;
            regConf conf = new regConf();
            string  sid  = WindowsIdentity.GetCurrent().User.Value;

            using (Process psCspt = new Process())
            {
                psCspt.StartInfo.FileName = conf.getParam("pathCsptest", "");
                string rArgs = $"-property -cinstall -container \"{cpcName}\"";

                psCspt.StartInfo.Arguments   = rArgs;
                psCspt.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                psCspt.Start();
                psCspt.WaitForExit();

                if (psCspt.ExitCode == 0)
                {
                    res = true;
                }
                else
                {
                    res = false;
                }
            }

            return(res);
        }
コード例 #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;

            if (!Directory.Exists(appdatapath))
            {
                Directory.CreateDirectory(appdatapath);
            }

            regConf conf = new regConf();

            log.writeLog($"Cpci2 agent started.\r\n");
            log.writeLog($"Checking configuration...\r\n");
            try
            {
                string sid = WindowsIdentity.GetCurrent().User.Value;
                toolStripStatusLabel1.Text = $"firstRun: {conf.getParam("firstRun", "")}";
                toolStripStatusLabel2.Text = $"SID: {sid}";
                timer1.Interval            = conf.getParam("timerInterval", 999);
                toolStripStatusLabel3.Text = $"timerInterval: {timer1.Interval}";
                log.writeLog($"\t {toolStripStatusLabel1.Text}\r\n");
                log.writeLog($"\t {toolStripStatusLabel2.Text}\r\n");
                log.writeLog($"\t timerInterval: {timer1.Interval}\r\n");
                log.writeLog($"\t baseKey: {conf.getParam("baseKey", "")}\r\n");
                log.writeLog($"\t cpKeys: {conf.getParam("cpKeys", "")}\r\n");
                log.writeLog($"\t pathCSPTest: {conf.getParam("pathCSPTest", "")}\r\n");
                label1.Text = $@"{Environment.GetEnvironmentVariable("APPDATA")}\dln\cpci2\cpci2.log";
            }
            catch (Exception ex)
            {
                log.writeLog(FormatErrorStr("Error while checking configuration!\r\n Details:\r\n", ex));
            }
            timer1.Start();
        }
コード例 #4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            string  inputpath = $@"{appdatapath}\input.reg";
            bool    res       = false;
            regConf conf      = new regConf();
            string  sid       = WindowsIdentity.GetCurrent().User.Value;

            timer1.Stop();

            if (File.Exists(inputpath))
            {
                log.writeLog($"{inputpath} found.\r\n");
                cpRegFile rf = new cpRegFile(inputpath);
                log.writeLog($"Trying to import {inputpath}\r\n");
                try
                {
                    res = rf.importRegFile();
                    if (res)
                    {
                        log.writeLog($"{inputpath} successfully imported.\r\n");
                    }
                    else
                    {
                        log.writeLog($"Unknown error while importing {inputpath}!\r\n");
                    }
                }
                catch (Exception ex)
                {
                    log.writeLog(FormatErrorStr($"Error while importing {inputpath}!\r\n Details:\r\n", ex));
                }
            }

            cpContainers cont = new cpContainers($@"{conf.getParam("baseKey", "")}\{sid}\{conf.getParam("cpKeys", "")}", $@"{appdatapath}\cpKey.list");

            try
            {
                List <string> toinstall = cont.compareList();
                List <string> installed = new List <string>();
                if (toinstall.Count > 0)
                {
                    foreach (string item in toinstall)
                    {
                        try
                        {
                            log.writeLog($"Trying to install certificate from {item} container...\r\n");
                            if (cont.instCert(item))
                            {
                                installed.Add(item);
                                log.writeLog($"OK Certificate from {item} container installed successfully!\r\n");
                            }
                            else
                            {
                                log.writeLog($"ERROR while installing certificate {item}! No certificate in key containers?\r\n");
                                log.writeLog($"Try to run {conf.getParam("pathCSPTest", "")} {item} for details.\r\n");
                            }
                        }
                        catch (Exception ex)
                        {
                            log.writeLog(FormatErrorStr($"ERROR while installing certificate {item}!\r\n Details:\r\n", ex));
                        }
                    }

                    if (installed.Count > 0)
                    {
                        try
                        {
                            File.WriteAllLines($@"{appdatapath}\lasttimeinstalled.txt", installed.ToArray());
                        }
                        catch
                        {
                            //
                        }

                        notifyIcon1.BalloonTipTitle = "ЭЦП Установлены!";
                        notifyIcon1.BalloonTipText  = $"Количество установленных ЭЦП: {installed.Count}\r\n Нажмите для просмотра списка.";
                        notifyIcon1.ShowBalloonTip(900 * 1000);
                    }
                }
            }
            catch (Exception ex)
            {
                log.writeLog(FormatErrorStr($"Error while comparing containers list!\r\n Details:\r\n", ex));
            }

            timer1.Start();
        }