Exemplo n.º 1
0
        public AcceptKeyDialog(Network network, ReceivedKeyEventArgs args)
            : base(null, "AcceptKeyDialog")
        {
            var publicKey = new PublicKey(args.Key.Info, args.Key.Key);
            keyTextView.Buffer.Text = publicKey.ToArmoredString();
            string nodeID = FileFind.Common.SHA512Str(publicKey.Key);
            nodeIdLabel.Text = nodeID;

            if (args.Node != null)  {
                if (nodeID.ToUpper() != args.Node.NodeID.ToUpper()) {
                    throw new Exception ("The key recieved does not match this user!");
                }
                nicknameLabel.Text = args.Node.NickName;
            } else if (args.Connection != null) {
                var conn = args.Connection;

                connectionLabel.Text = String.Format("{0} ({1})", conn.RemoteAddress, conn.Incoming ? "Incoming" : "Outgoing");
                nicknameLabel.Text = args.Key.Info;

                connectionLabel.Show();
                connectionTitleLabel.Show();
            } else {
                nicknameLabel.Text = args.Key.Info;
            }

            denyKeyButtonLabel.Text = String.Format ("Deny Key ({0})", secondsLeft);
        }
Exemplo n.º 2
0
 private void on_saveKeyButton_clicked(object o, EventArgs args)
 {
     FileSelector selector = new FileSelector("Save Public Key...", FileChooserAction.Save);
     selector.TransientFor = dialog;
     selector.CurrentName = nicknameEntry.Text + ".mpk";
     if (selector.Run() == (int)ResponseType.Ok) {
         string publicKey = new PublicKey(nicknameEntry.Text, provider.ToXmlString(false)).ToArmoredString();
         File.WriteAllText(selector.Filename, publicKey);
     }
     selector.Destroy();
 }
Exemplo n.º 3
0
 private void on_copyKeyButton_clicked(object o, EventArgs args)
 {
     string publicKey = new PublicKey(nicknameEntry.Text, provider.ToXmlString(false)).ToArmoredString();
     Gtk.Clipboard.GetForDisplay(Gdk.Display.Default, Gdk.Atom.Intern("CLIPBOARD", true)).Text = publicKey;
     Gui.ShowMessageDialog("The clipboard has been set.", dialog);
 }
Exemplo n.º 4
0
 public TrustedNodeInfo(PublicKey key)
 {
     this.Identifier = key.Nickname;
     this.PublicKey = key;
 }
Exemplo n.º 5
0
 public void AddPublicKey(PublicKey key)
 {
     TrustedNodeInfo info = new TrustedNodeInfo(key);
     this.trustedNodes.Add(info.NodeID, info);
     if (nodes.ContainsKey(info.NodeID)) {
         Node node = nodes[info.NodeID];
         if (!node.FinishedKeyExchange) {
             node.CreateNewSessionKey();
         }
     }
     Core.Settings.SyncNetworkInfo();
 }
Exemplo n.º 6
0
        public static PublicKey Parse(string armoredText)
        {
            PublicKey result = new PublicKey();
            var headers = new Dictionary<string, string>();
            string line = null;
            string crc = null;
            StringBuilder data = new StringBuilder();
            ParseState state = ParseState.Start;
            using (var reader = new StringReader(armoredText)) {
                while ((line = reader.ReadLine()) != null) {
                    line = line.Trim();
                    switch (state) {
                    case ParseState.Start:
                        if (line != BEGIN_LINE)
                            goto done;
                        state = ParseState.Header;
                        break;
                    case ParseState.Header:
                        if (line == String.Empty)
                            state = ParseState.Body;
                        else {
                            int i = line.IndexOf(": ");
                            if (i <= 0)
                                goto done;
                            string name = line.Substring(0, i).Trim();
                            string val = line.Substring(i + 2).Trim();
                            headers.Add(name, val);
                        }
                        break;
                    case ParseState.Body:
                        var match = Regex.Match(line, "^=(....)$");
                        if (match.Success) {
                            crc = match.Groups[1].Captures[0].Value;
                            state = ParseState.End;
                        } else if (line == END_LINE) {
                            state = ParseState.End;
                        } else {
                            data.Append(line);
                        }
                        break;
                    case ParseState.End:
                        goto done;
                    }
                }
            }
            done:

            if (state != ParseState.End)
                throw new Exception(String.Format("Malformed/missing {0}", Enum.GetName(typeof(ParseState), state).ToLower()));

            if (String.IsNullOrEmpty(crc))
                throw new Exception("Missing checksum");

            byte[] dataBytes = null;
            string dataString = null;
            try {
                dataBytes = Convert.FromBase64String(data.ToString());
                dataString = Encoding.UTF8.GetString(dataBytes);
                dataBytes = Encoding.UTF8.GetBytes(dataString);
            } catch (Exception) {
                throw new Exception("Invalid key data");
            }

            byte[] expectedHash = null;
            byte[] actualHash = null;
            try {
                expectedHash = Convert.FromBase64String(crc);
                actualHash = s_CRC24.ComputeHash(dataBytes);
            } catch (Exception) {
                throw new Exception("Invalid checksum");
            }

            if (!expectedHash.SequenceEqual(actualHash))
                throw new Exception("Checksum does not match");

            if (headers.ContainsKey("Nickname"))
                result.Nickname = headers["Nickname"];

            result.Key = dataString;

            return result;
        }