Beispiel #1
0
        private void TrustContact()
        {
            int recepientId = TextEncoder.ReadInt(stream);

            using (Context context = new Context(config))
            {
                var key = context.UsersKeys
                          .Where(u => u.RecepientId == recepientId)
                          .Where(u => u.SenderId == user.UserId)
                          .SingleOrDefault();
                if (key != null)
                {
                    key.Trusted = true;
                }
                else
                {
                    Log("Receiving new key.");
                    key = new UsersKeys()
                    {
                        RecepientId     = recepientId,
                        SenderId        = user.UserId,
                        EncryptedAesKey = BinaryEncoder.ReceiveBytes(stream),
                        Trusted         = true
                    };
                    context.Add(key);
                }
                context.SaveChanges();
            }
            Log("Trust contact done.");
        }
Beispiel #2
0
        private void TrustContact()
        {
            int recepientId = BinaryEncoder.ReadInt(stream);

            using (Context context = new Context(config))
            {
                var key = context.UsersKeys
                          .Where(u => u.RecepientId == recepientId)
                          .Where(u => u.SenderId == connectionInfo.UserId)
                          .SingleOrDefault();
                if (BinaryEncoder.ReadInt(stream) == 0)
                {
                    Log("No new key will be received.");
                    key.Trusted = true;
                }
                else
                {
                    Log("Receiving new key.");
                    var aesKey = BinaryEncoder.ReceiveBytes(stream);
                    if (key != null)
                    {
                        Log("Updating denied!");
                        //key.AesKey = aesKey;
                        key.Trusted = true;
                    }
                    else
                    {
                        key = new UsersKeys()
                        {
                            RecepientId = recepientId,
                            SenderId    = connectionInfo.UserId,
                            AesKey      = aesKey,
                            Trusted     = true
                        };
                        context.Add(key);
                    }
                }
                context.SaveChanges();
            }
            Log("Trust contact done.");
        }