Esempio n. 1
0
        private bool CompleteWhisperHandshake(Conversation conversation, Participant participant, byte[] keyBlob)
        {
            var conv = seriousBusiness.FindConversation(conversation);

            if (conv == null)
            {
                return(false);
            }

            var p = conv.FindParticipant(participant);

            if (p == null)
            {
                return(false);
            }

            if (p.dh == null)
            {
                if (!InitiateWhisperHandshake(conversation, participant))
                {
                    return(false);
                }
            }

            p.DeriveKey(keyBlob);

            string info = $"Your key: {Ascii85.Encode(p.GetPublicKey())}\r\nTheir key: {Ascii85.Encode(keyBlob)}";

            Application.Current.Dispatcher.Invoke(() => { FindOrCreateWhisperWindow(conversation, participant, info).Show(); });

            return(true);
        }
Esempio n. 2
0
        public string SendWhisper(Conversation conversation, Participant participant, string text)
        {
            var conv = seriousBusiness.FindConversation(conversation);

            if (conv == null)
            {
                return(null);
            }

            var p = conv.FindParticipant(participant);

            if (p == null)
            {
                return(null);
            }

            if (p.dh == null)
            {
                return(null);
            }

            if (p.derivedKey == null)
            {
                return(null);
            }

            var bytes = Encoding.UTF8.GetBytes(text);

            byte[] cipherText;
            using (Aes aes = new AesCryptoServiceProvider())
            {
                aes.Key = p.derivedKey;
                byte[] iv = aes.IV;

                if (iv.Length != 16)
                {
                    throw new Exception("Expecting 256-bit iv");
                }

                using (var cipherTextStream = new MemoryStream())
                {
                    cipherTextStream.Write(iv, 0, iv.Length);

                    using (CryptoStream cs = new CryptoStream(cipherTextStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(bytes, 0, bytes.Length);
                        cs.Close();
                        cipherText = cipherTextStream.ToArray();
                    }
                }
            }

            string whisperText = whisperPrefix + Ascii85.Encode(cipherText);

            SendWhisperData(conv.conversation, whisperText);

            return(whisperText);
        }
Esempio n. 3
0
        public bool HandleWhisper(Conversation conversation, Participant participant, string text)
        {
            if (text.StartsWith(whisperHandshakePrefix) && text.StartsWith(whisperHandshakePrefix + "<~"))
            {
                return(CompleteWhisperHandshake(conversation, participant, Ascii85.Decode(text.Substring(whisperHandshakePrefix.Length))));
            }
            else if (text.StartsWith(whisperPrefix) && text.StartsWith(whisperPrefix + "<~"))
            {
                return(ExtractWhisper(conversation, participant, Ascii85.Decode(text.Substring(whisperHandshakePrefix.Length)), text));
            }

            return(false);
        }
Esempio n. 4
0
        private void SendWhisperHandshake(Conversation conversation, byte[] data)
        {
            var handshakeText = whisperHandshakePrefix + Ascii85.Encode(data);

            bool sendAsRtf = false;

            if (sendAsRtf)
            {
                seriousBusiness.DoSendMessage(conversation, ShhWrap(handshakeText), InstantMessageContentType.RichText);
            }
            else
            {
                seriousBusiness.DoSendMessage(conversation, handshakeText, InstantMessageContentType.PlainText);
            }
        }