コード例 #1
0
        static public void CreateGroup(APIServer server, CertificateGenerator generator)
        {
            // Generate group Certificate
            var groupKeys = generator.GenerateCertificate("C=DE,O=Organiztion", TimeSpan.FromDays(1), "cert.pfx", "Test.123");

            Console.WriteLine("Group certificate was generated");

            BlindSigner  blindSigner  = new BlindSigner(groupKeys);
            GroupCreator groupCreator = new GroupCreator(server, blindSigner);

            Console.WriteLine("Create group");
            Console.WriteLine("Enter group name:");
            string groupName = Console.ReadLine();
            //string groupName = "Loazarii";
            Group group = new Group();

            group.Name = groupName;
            Console.WriteLine("Enter owner email:");
            string ownerEmail = Console.ReadLine();

            //string ownerEmail = "*****@*****.**";
            group.OwnerEmail   = ownerEmail;
            group.RsaPublicKey = (RsaKeyParameters)groupKeys.Public;
            groupCreator.RegisterGroup(group);
            Console.WriteLine("");

            //Write keys to file
            File.WriteAllText(group.Name + "PublicKey.txt", RsaKeyUtils.GetSerializedPublicKey((RsaKeyParameters)groupKeys.Public));
            File.WriteAllText(group.Name + "PrivateKey.txt", RsaKeyUtils.GetSerializedPrivateKey((RsaKeyParameters)groupKeys.Private));

            Console.WriteLine("You're group " + group.Name + " was registered!");
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        static public void RegisterParticipant(APIServer server, GroupRepository groupRepository, CertificateGenerator generator)
        {
            Console.WriteLine("Enter the group for which you want to register participants:");
            string groupName   = Console.ReadLine();
            string pubKeyFile  = groupName + "PublicKey.txt";
            string privKeyFile = groupName + "PrivateKey.txt";

            if (pubKeyFile != null && privKeyFile != null)
            {
                var groupCreator = GetGroupCreator(server, pubKeyFile, privKeyFile);
                Console.WriteLine();
                Console.WriteLine("Enter participant email to be confirmed:");
                var    participantEmail = Console.ReadLine();
                var    participant      = groupCreator.GetParticipantToConfirm(groupName, participantEmail);
                int    invitationCode   = participant.InvitationCode;
                Guid   groupId          = (Guid)participant.GroupId;
                string email            = participant.Email;
                Group  user_group       = groupCreator.GetGroup(participant.InvitationCode);

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

                //Generate certificate
                var participantKeys = generator.GenerateCertificate("C=RO,O=Qubiz", TimeSpan.FromDays(1), "certParticipant.pfx", "Test.123");
                Console.WriteLine("Client certificate was generated");

                //Write keys to file
                File.WriteAllText(participantEmail.Substring(0, participantEmail.IndexOf("@")) + "PublicKey.txt", RsaKeyUtils.GetSerializedPublicKey((RsaKeyParameters)participantKeys.Public));
                File.WriteAllText(participantEmail.Substring(0, participantEmail.IndexOf("@")) + "PrivateKey.txt", RsaKeyUtils.GetSerializedPrivateKey((RsaKeyParameters)participantKeys.Private));
                Console.WriteLine("Participant keys were saved to file");

                //Create GroupRegistration
                var groupRegistration = clientParticipant.GetGroupRegistration(invitationCode, (RsaKeyParameters)participantKeys.Public);
                Console.WriteLine("Blind factor was saved");

                //Save blindedCertificate
                clientParticipant.RegisterBlindCertificate(invitationCode, groupRegistration);
                Console.WriteLine("Blind certificate was saved");
            }
            else
            {
                Console.WriteLine("Group creator Keys were not saved to file, please go to step 1");
            }
        }