예제 #1
0
        public static void SendMessageOnGroup(APIServer server, GroupRepository groupRepository)
        {
            Console.WriteLine("Enter the group on which you want to send messages:");
            var    groupName   = Console.ReadLine();
            string pubKeyFile  = groupName + "PublicKey.txt";
            string privKeyFile = groupName + "PrivateKey.txt";
            Group  group       = server.GetGroupByName(groupName);

            if (pubKeyFile != null && privKeyFile != null)
            {
                var groupCreator           = GetGroupCreator(server, pubKeyFile, privKeyFile);
                ParticipantMessage message = new ParticipantMessage();
                Console.WriteLine("Enter the message you want to send:");
                message.Message = Console.ReadLine();
                Console.WriteLine("Enter your nickname:");
                var nickname = Console.ReadLine();

                ClientParticipant clientParticipant = new ClientParticipant(server, groupRepository);
                var blindparticipant = groupCreator.GetBlindParticipantByNickname(group.Id, nickname);
                VerifiedParticipant verifiedParticipant = new VerifiedParticipant
                {
                    PublicKey = blindparticipant.PublicKey,
                    Signature = blindparticipant.Signature
                };
                message.BlindParticipant = blindparticipant.Id.ToString();

                clientParticipant.AddMessage(group.Id, message, verifiedParticipant);
                Console.WriteLine("Participant verified");
                Console.WriteLine("Message sent");
            }
            else
            {
                Console.WriteLine("Group creator Keys were not saved to file, please go to step 1");
            }
        }
예제 #2
0
        static public void SaveBlindParticipant(APIServer server, GroupRepository groupRepository)
        {
            Console.WriteLine("Enter the group for which you want to register participants:");
            var groupName = Console.ReadLine();

            Console.WriteLine("Enter participant email address that you want to be saved as blind participant:");
            var participantEmail = Console.ReadLine();
            var group            = server.GetGroupByName(groupName);

            var        factor      = File.ReadAllText("BlindFactor.txt");
            BigInteger blindFactor = new BigInteger(factor);

            var fileToRead = (participantEmail.Substring(0, participantEmail.IndexOf("@")) + "PublicKey.txt").ToString();
            RsaKeyParameters  participantPublicKey = (RsaKeyParameters)RsaKeyUtils.GetDeserializedKPublicKey(File.ReadAllText(fileToRead));
            GroupRegistration groupRegistration    = new GroupRegistration(group, new ContentBlinder(group.RsaPublicKey, blindFactor), participantPublicKey);

            ClientParticipant   clientParticipant   = new ClientParticipant(server, groupRepository);
            VerifiedParticipant verifiedParticipant = clientParticipant.CheckVerifiedEntity(group, participantEmail, groupRegistration);

            clientParticipant.AddClientCertificate(verifiedParticipant, group, participantEmail);
            Console.WriteLine("Enter nickname:");
            var nickname = Console.ReadLine();

            clientParticipant.AddBlindParticipant(group.Id, verifiedParticipant, nickname);

            Console.WriteLine();
            Console.WriteLine("Participant was saved as a blind participant to the group");
        }
예제 #3
0
        public void SaveClientCertificate(VerifiedParticipant verifiedParticipant, Guid groupId, string email)
        {
            var participant = context.Participants.FirstOrDefault(p => p.GroupId == groupId && p.Email == email);

            if (participant != null)
            {
                participant.EmailIsConfirmed = true;
            }
            context.Participants.Update(participant);
            context.SaveChanges();
        }
예제 #4
0
        public void SaveMessage(VerifiedParticipant participant, ParticipantMessage message)
        {
            var blindParticipant    = context.BlindParticipants.FirstOrDefault(p => p.PublicKey == participant.PublicKey && p.Signature == participant.Signature);
            var conversationMessage = new ConversationMessage
            {
                GroupId = blindParticipant.GroupId,
                Message = message.BlindParticipant + "-" + message.Message
            };

            context.ConversationMessages.Add(conversationMessage);
            context.SaveChanges();
        }
예제 #5
0
        public List <VerifiedParticipant> GetBlindParticipants(Guid groupId)
        {
            List <VerifiedParticipant> list = new List <VerifiedParticipant>();
            VerifiedParticipant        verifiedParticipant = new VerifiedParticipant();
            var blindparticipants = context.BlindParticipants.Where(b => b.GroupId == groupId).ToList();

            foreach (var blindparticipant in blindparticipants)
            {
                verifiedParticipant.PublicKey = blindparticipant.PublicKey;
                verifiedParticipant.Signature = blindparticipant.Signature;
                list.Add(verifiedParticipant);
            }
            return(list);
        }
예제 #6
0
        public void AddMessage(Guid groupId, ParticipantMessage message, VerifiedParticipant participant)
        {
            var groupDetails = groupRepository.GetGroup(groupId);

            var groupPubKey = File.ReadAllText(groupDetails.Name + "PublicKey.txt");
            var rsaPubKey   = RsaKeyUtils.GetDeserializedKPublicKey(groupPubKey);

            SignedEntity signedEntity = new SignedEntity(FromBase64String(participant.PublicKey), FromBase64String(participant.Signature));

            bool isVerified = signatureVerifier.Verify(signedEntity, rsaPubKey);

            if (isVerified)
            {
                groupRepository.SaveMessage(participant, message);
            }
        }
        public VerifiedParticipant CheckVerifiedEntity(Group group, string email, GroupRegistration groupRegistration)
        {
            var signedMessage = server.GetSignedMessage(group.Id, email);

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

            VerifiedParticipant verifiedParticipant = new VerifiedParticipant();

            verifiedParticipant.PublicKey = RsaKeyUtils.GetSerializedPublicKey(groupRegistration.PublicKey);
            verifiedParticipant.Signature = GetSignature(groupRegistration, signedMessage);


            return(verifiedParticipant);
        }
 public void AddBlindParticipant(Guid groupId, VerifiedParticipant verifiedParticipant, string nickname)
 {
     server.AddNewBlindParticipant(groupId, verifiedParticipant.PublicKey, verifiedParticipant.Signature, nickname);
 }
 public void AddMessage(Guid groupId, ParticipantMessage message, VerifiedParticipant participant)
 {
     server.AddMessage(groupId, message, participant);
 }
 public void AddClientCertificate(VerifiedParticipant verifiedParticipant, Group group, string email)
 {
     groupRepository.SaveClientCertificate(verifiedParticipant, group.Id, email);
 }