static public void InviteParticipants(BlindChatDbContext context, APIServer server) { Console.WriteLine("Enter the group for which you want to invite 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); List <string> emails = new List <string>(); Console.WriteLine("Enter participant email address:"); var participantEmail = Console.ReadLine(); //var participantEmail = "*****@*****.**"; emails.Add(participantEmail); Console.WriteLine(); var getGroup = context.Groups.FirstOrDefault(g => g.Name == groupName); var getConfirmationCode = context.ConfirmationCodes.FirstOrDefault(c => c.GroupId == getGroup.Id); int confirmatioCode = getConfirmationCode.Code; groupCreator.AddParticipantsToGroup(emails, confirmatioCode); Console.WriteLine("Participant was added to the group"); } else { Console.WriteLine("Group creator Keys were not saved to file, please go to step 1"); } }
static void Main(string[] args) { 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); CertificateGenerator generator = new CertificateGenerator(); int userInput = 0; do { userInput = DisplayMenu(); switch (userInput.ToString()) { case "1": CreateGroup(server, generator); break; case "2": InviteParticipants(context, server); break; case "3": RegisterParticipant(server, groupRepository, generator); break; case "4": SignCertificate(server); break; case "5": SaveBlindParticipant(server, groupRepository); break; case "6": SendMessageOnGroup(server, groupRepository); break; default: Console.WriteLine("Default case"); break; } } while (userInput != 7); }
public GroupRepository(BlindChatDbContext dbContext) { this.context = dbContext; }
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(); }