예제 #1
0
 private void SignOperationTo()
 {
     try
     {
         var operation     = DetermineOpearation();
         var operationAsn1 = Asn1Formatter.SetCommandAsn1((int)Cmd.sign);
         handler.Send(operationAsn1);
         data = handler.Recieve();
         if (Encoding.ASCII.GetString(Asn1Formatter.GetCertAsn1(data)) == "ESTABLISHED")
         {
             int certIndex = (int)CerificatesBox.Invoke(new Func <int>(() => CerificatesBox.SelectedIndex));
             handler.Send(crypter.Sign(Encoding.ASCII.GetBytes(textBox1.Text), certIndex));
         }
         else
         {
             throw new Exception("Error while send");
         }
     }
     catch (NullReferenceException ne)
     {
         var errorCode = Asn1Formatter.SetCommandAsn1((int)Cmd.error);
         handler.Send(errorCode);
         MessageBox.Show(ne.Message);
         Console.WriteLine(ne.Message);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
예제 #2
0
        private void GetCertsFromServer(object sender, EventArgs e)
        {
            var asn1Cmd = Asn1Formatter.SetCommandAsn1((int)Cmd.certs);

            int.TryParse(textBox3.Text, out int port);
            handler = new ClientSocket(textBox2.Text, port);
            handler.Init();
            handler.Send(asn1Cmd);
            data = handler.Recieve();
            BERelement certsNames = BERelement.DecodePacket(data);

            CerificatesBox.DataSource = null;
            CerificatesBox.Items.Clear();
            foreach (var cert in certsNames.Items)
            {
                CerificatesBox.Items.Add(Encoding.ASCII.GetString(cert.Value));
            }
            CerificatesBox.SelectedIndex = 0;
        }