示例#1
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");
        }
        static void Main(string[] args)
        {
            //Asta va fi inlocuit cu un API call
            SignatureVerifier  signatureVerifier = new SignatureVerifier();
            RNGRandomGenerator rngGenerator      = new RNGRandomGenerator();
            EmailSender        emailSender       = new EmailSender();
            BlindChatDbContext context           = new BlindChatDbContext();
            GroupRepository    groupRepository   = new GroupRepository(context);
            APIServer          server            = new APIServer(groupRepository, emailSender, rngGenerator, signatureVerifier);

            //Set participants
            List <Participant> unconfirmedParticipants = server.GetParticipantsToConfirm("Loazarii");

            foreach (var participant in unconfirmedParticipants)
            {
                int    invitationCode = participant.InvitationCode;
                Guid   groupId        = (Guid)participant.GroupId;
                string email          = participant.Email;
                Group  group          = server.GetGroup(participant.InvitationCode);

                ClientParticipant clientParticipant = new ClientParticipant(server, groupRepository);
                var groupPublicKey = clientParticipant.GetGroupDetails(invitationCode);

                //Generate certificate
                CertificateGenerator generator = new CertificateGenerator();
                var participantKeys            = generator.GenerateCertificate("C=RO,O=Qubiz", TimeSpan.FromDays(1), "certParticipant.pfx", "Test.123");

                //Serialize
                var privateSerializedKey = RsaKeyUtils.GetSerializedPrivateKey(participantKeys.Private);
                var publicSerializedKey  = RsaKeyUtils.GetSerializedPublicKey(participantKeys.Public);

                //Concatenante serialized key
                var content = RsaKeyUtils.Combine(publicSerializedKey, privateSerializedKey);

                //Generate blind content
                ContentBlinder contentBlinder    = new ContentBlinder((RsaKeyParameters)groupPublicKey, "Loazarii");
                var            blindedContent    = contentBlinder.GetBlindedContent(content);
                var            groupRegistration = clientParticipant.GetGroupRegistration(invitationCode, (RsaKeyParameters)participantKeys.Public);

                //Save blindedCertificate
                clientParticipant.RegisterBlindCertificate(invitationCode, groupRegistration);

                //Send for sign DONE

                //Get blindSignature
                var blindMessage = server.GetSignedMessage(groupId, email);
                var signature    = Convert.FromBase64CharArray(blindMessage.Signature.ToCharArray(), 0, blindMessage.Signature.Length);

                //Unblind signature
                var unblindedSignature = contentBlinder.GetUnblindedSignature(signature);

                //Verify
                var verifiedParticipant = clientParticipant.CheckVerifiedEntity(group, participant.Email, groupRegistration);
                clientParticipant.AddClientCertificate(verifiedParticipant, group, email);
                ParticipantMessage message = new ParticipantMessage();
                message.Message = "Andreiu, ce nevoie faci?";
                clientParticipant.AddMessage(groupId, message, verifiedParticipant);
            }

            Console.ReadKey();
        }