private JObject ProcessSignIn(JObject param) { JObject result = null; LogUtil.Default.Log("SignIn Request: " + param.ToString()); using (CeremonySQL ceremonySQL = new CeremonySQL()) { User user = ceremonySQL.SignInUser(param); if (user != null) { result = BuildResponse(false, "SignIn Successed."); JObject ret = new JObject(); ret["name"] = user.Name; ret["country"] = user.Country; ret["order"] = user.Order; ret["total"] = ceremonySQL.reconnect().GetUserIndex(); ret["selected_index"] = ceremonySQL.reconnect().GetSelectedUserIndex(); result = BuildResponse(true, "", ret); } else { result = BuildResponse(false, "SignIn Failed."); } } LogUtil.Default.Log("SignIn Response: " + result.ToString()); return(result); }
public void StartTimeInterval(int interval = PARTICIPANT_INTERVAL) { LogUtil.Default.Log("Interval: " + interval); StopTimeInterval(); Application.Current.Dispatcher.Invoke(delegate { RefreshView(); }); using (CeremonySQL ceremonySQL = new CeremonySQL()) { if (ceremonySQL.GetCeremonyStatus() != CeremonyStatus.CEREMONY_STATUS_STARTED) { return; } if (ceremonySQL.reconnect().GetUserIndex() == ceremonySQL.reconnect().GetSelectedUserIndex()) { return; } } dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(interval / 3600, (interval % 3600) / 60, interval % 60); dispatcherTimer.Start(); Settings.Default.SendEmailToSelectedUser(); }
private JObject ProcessCompleteCeremony(JObject param) { try { string pubkey = param["pubkey"].AsString(); int nSegmentNumber = int.Parse(param["SegmentNumber"].AsString()); using (CeremonySQL ceremonySQL = new CeremonySQL()) { User user = ceremonySQL.GetUserByPubkey(pubkey); if (user == null) { return(BuildResponse(false, "This user does not exist.")); } if (VerifyConstraint(user.Order, nSegmentNumber - ceremonySQL.reconnect().GetSegmentNumber()) == false) { return(BuildResponse(false, "VERIFY=false")); } if (!ceremonySQL.reconnect().ToNextUser() /*CeremonySQL.Default.CompleteCeremony()*/) { LogUtil.Default.Log("Next User in database failed."); return(BuildResponse(false, "Server internal error.")); } if (!ceremonySQL.reconnect().UpdateSegmentNumber(nSegmentNumber)) { LogUtil.Default.Log("Update Seg number failed."); return(BuildResponse(false, "Server internal error.")); } if (nSegmentNumber == Window.nTotalSegments) { if (!ceremonySQL.reconnect().CompleteCeremony()) { LogUtil.Default.Log("Complete ceremony in database failed."); return(BuildResponse(false, "Server internal error.")); } Task.Run(() => { GenerateKeyFromConstraints(); }); } } Application.Current.Dispatcher.Invoke(delegate { Window.StartTimeInterval(); }); LogUtil.Default.Log("Complete ceremony successed."); return(BuildResponse(true)); } catch (Exception ex) { return(BuildResponse(false)); } }
private JObject ProcessSignUp(JObject param) { JObject result = null; LogUtil.Default.Log("SignUp Request: " + param.ToString()); using (CeremonySQL ceremonySQL = new CeremonySQL()) { if (ceremonySQL.GetCeremonyStatus() == CeremonyStatus.CEREMONY_STATUS_WAITING) { if (ceremonySQL.reconnect().SignUpUser(param)) { result = BuildResponse(true); System.Windows.Application.Current.Dispatcher.Invoke(delegate { Window.RefreshView(); }); } else { result = BuildResponse(false, "Sign up failed."); } } else { result = BuildResponse(false, "Ceremony already has been started."); } } LogUtil.Default.Log("SignUp Response: " + result.ToString()); return(result); }
private JObject ProcessGetInfo(JObject param) { JObject ret = new JObject(); using (CeremonySQL ceremonySQL = new CeremonySQL()) { User selectedUser = ceremonySQL.GetSelectedUser(); User user = ceremonySQL.reconnect().GetUserByPubkey(param["pubkey"].AsString()); ret["total_participants"] = ceremonySQL.reconnect().GetUserIndex(); ret["selected_participants"] = (selectedUser == null ? 0 : selectedUser.Order); ret["ceremony_status"] = ceremonySQL.reconnect().GetCeremonyStatus(); ret["my_status"] = ((int)user.Status); ret["segment_number"] = ceremonySQL.reconnect().GetSegmentNumber(); } JObject result = BuildResponse(true, "", ret); LogUtil.Default.Log(ret.ToString()); return(result); }
public MainWindow() { LogUtil.Default.Log("Ceremony Server Started..."); InitializeComponent(); StartRPCService(); //check ceremony status and if the ceremony is started, start timeinterval. using (CeremonySQL ceremonySQL = new CeremonySQL()) { ceremonySQL.GetLastParticipantTime(); int selectedUserIndex = ceremonySQL.reconnect().GetSelectedUserIndex(); int userIndex = ceremonySQL.reconnect().GetUserIndex(); var lastParticipantTime = ceremonySQL.reconnect().GetLastParticipantTime(); if (ceremonySQL.reconnect().GetCeremonyStatus() == CeremonyStatus.CEREMONY_STATUS_STARTED) { if (selectedUserIndex != userIndex) { DateTime now = DateTime.Now; if (DateTimeUtil.Default.GetTimeStamp(DateTime.Now) - lastParticipantTime > PARTICIPANT_INTERVAL) { Settings.Default.SendEmailToSelectedUser((int)MailType.MAIL_TYPE_TIMEOUT); ceremonySQL.reconnect().TimeOutUser(); StartTimeInterval(); } else { StartTimeInterval(PARTICIPANT_INTERVAL - (int)(DateTimeUtil.Default.GetTimeStamp(DateTime.Now) - lastParticipantTime)); } } } } RefreshView(); }
public bool StartCeremony() { using (CeremonySQL ceremonySQL = new CeremonySQL()) { if (ceremonySQL.GetCeremonyStatus() != CeremonyStatus.CEREMONY_STATUS_WAITING) { return(false); } if (!ceremonySQL.reconnect().StartCeremony()) { return(false); } } return(true); }
public void RefreshView() { using (CeremonySQL ceremonySQL = new CeremonySQL()) { TxtParticipantCnt.Text = "Total Participants : " + ceremonySQL.GetUserIndex(); TxtSelectedUserIndex.Text = "Index : " + ceremonySQL.reconnect().GetSelectedUserIndex(); User user = ceremonySQL.reconnect().GetSelectedUser(); TxtSelectedUserName.Text = "Name : " + (user == null ? "" : user.Name); TxtSelectedUserEmail.Text = "Email : " + (user == null ? "" : user.Email); TxtSelectedUserAddress.Text = "Address : " + (user == null ? "" : user.Address); TxtSelectedUserCountry.Text = "Country : " + (user == null ? "" : user.Country); TxtSuccessedCnt.Text = "Successed Participants : " + ceremonySQL.reconnect().GetParticipantCntByStatus(UserStatus.USER_STATUS_SUCCESSED); TxtTimeoutCnt.Text = "Timeout Participants : " + ceremonySQL.reconnect().GetParticipantCntByStatus(UserStatus.USER_STATUS_TIMEOUT); string strStatus = ""; switch (ceremonySQL.reconnect().GetCeremonyStatus()) { case CeremonyStatus.CEREMONY_STATUS_WAITING: strStatus = "WAITING"; break; case CeremonyStatus.CEREMONY_STATUS_STARTED: strStatus = "STARTED"; break; case CeremonyStatus.CEREMONY_STATUS_COMPLETED: strStatus = "COMPLETED"; break; } TxtCeremonyStatus.Text = "Ceremony Status : " + strStatus; if (ceremonySQL.reconnect().GetCeremonyStatus() == CeremonyStatus.CEREMONY_STATUS_WAITING) { BtnStart.IsEnabled = true; } else { BtnStart.IsEnabled = false; } } }
public bool SendEmailToSelectedUser(int mailType = (int)MailType.MAIL_TYPE_START) { try { LogUtil.Default.Log("Sending email to selected user..."); using (CeremonySQL ceremonySQL = new CeremonySQL()) { User user = ceremonySQL.GetSelectedUser(); if (user == null) { throw new Exception("No User Selected."); } SmtpClient smtpClient = new SmtpClient("quras.io"); smtpClient.Port = 587; smtpClient.UseDefaultCredentials = false; smtpClient.Credentials = new NetworkCredential("email", "password"); smtpClient.EnableSsl = true; String body = ""; // Set email body if (mailType == (int)MailType.MAIL_TYPE_START) { body = "Hi " + user.Name + "!\n\n" + (ceremonySQL.reconnect().GetSelectedUserIndex() == 1 ? "" : "Now " + (ceremonySQL.reconnect().GetSelectedUserIndex() - 1) + " people have participated to the Quras Trusted Setup.\n") + "It is your turn to participate to the Quras Trusted Setup.\n\n" + "You can participate as followings.\n" + "Step 1. Sign In.\n" + "1) Enter your email address and password.\n" + "2) Press \"Sign In\" button to sign in.\n" + "Step 2.Generate Seed Key\n" + "1) Wait for your turn. Actually, you can check your turn and ceremony status in the client screen.\n" + "2) When it is your turn, enter Seed Text and press \"Create Sead\" button. (You can reset your seed text by pressing \"Reset\" button)\n" + "3) Check the created hex seed and press \"Generate\" button. You can see the status updated.\n\n" + "And if you don't participate to the Quras Trusted Setup in 90 mins, you will be timeout.\n\n" + "Thanks.\n" + "Best Regard."; } else if (mailType == (int)MailType.MAIL_TYPE_TIMEOUT) { body = "Hi " + user.Name + "!\n\n" + "You have not participated to the ceremony in 90 mins, So you have been timeout.\n\n" + "Thanks.\n" + "Best Regard."; } smtpClient.Send("*****@*****.**", user.Email, "Quras Trusted Setup", body); } LogUtil.Default.Log("Email has been sent to selected user."); return(true); } catch (Exception ex) { LogUtil.Default.Log("Sending email to selected user Failed."); LogUtil.Default.Log(ex.ToString()); return(false); } }