private void RegisterAsync(CertificateProfile certProfile) { try { //register AsymmetricCryptoKey privateKey; if (rbImportRSA.Checked) { privateKey = AsymmetricCryptoKey.CreateUsing(_parameters); } else { privateKey = new AsymmetricCryptoKey(AsymmetricEncryptionAlgorithm.RSA, 4096); } Certificate selfSignedCert = new Certificate(CertificateType.RootCA, "", certProfile, CertificateCapability.SignCACertificate, DateTime.UtcNow, DateTime.UtcNow, AsymmetricEncryptionAlgorithm.RSA, privateKey.GetPublicKey()); selfSignedCert.SelfSign("SHA256", privateKey, null); if (_profile == null) { List <Uri> trackerURIs = new List <Uri>(); trackerURIs.AddRange(BitChatProfile.IPv4DefaultTrackerURIs); trackerURIs.AddRange(BitChatProfile.IPv6DefaultTrackerURIs); _profile = new BitChatProfile((new Random(DateTime.UtcNow.Millisecond)).Next(1024, 65535), Environment.GetFolderPath(Environment.SpecialFolder.Desktop), trackerURIs.ToArray(), _isPortableApp, _profileFolder); } if (_enableProxy) { _profile.ConfigureProxy(_proxyType, _proxyAddress, _proxyPort, _proxyCredentials); } _profile.Register(Program.SIGNUP_URI, new CertificateStore(selfSignedCert, privateKey)); _profile.SetPassword(SymmetricEncryptionAlgorithm.Rijndael, 256, txtProfilePassword.Text); _profileFilePath = Path.Combine(_profileFolder, _profile.LocalCertificateStore.Certificate.IssuedTo.Name + ".profile"); using (FileStream fS = new FileStream(_profileFilePath, FileMode.Create, FileAccess.ReadWrite)) { _profile.WriteTo(fS); } this.Invoke(new Action <object>(RegistrationSuccess), new object[] { null }); } catch (Exception ex) { this.Invoke(new Action <object>(RegistrationFail), new object[] { ex.Message }); } }
public frmRegister(BitChatProfile profile, string profileFilePath, bool isPortableApp, string profileFolder, bool reissue) { _profile = profile; _profileFilePath = profileFilePath; _isPortableApp = isPortableApp; _profileFolder = profileFolder; if (profile.Proxy != null) { _proxyType = profile.Proxy.Type; } _enableProxy = (_profile.Proxy != null); _proxyAddress = _profile.ProxyAddress; _proxyPort = _profile.ProxyPort; _proxyCredentials = _profile.ProxyCredentials; InitializeComponent(); chkEnableProxy.Checked = _enableProxy; this.chkEnableProxy.CheckedChanged += new System.EventHandler(this.chkEnableProxy_CheckedChanged); if (reissue) { CertificateProfile certProfile = _profile.LocalCertificateStore.Certificate.IssuedTo; txtName.Text = certProfile.Name; txtEmail.Text = certProfile.EmailAddress.Address; txtEmail.ReadOnly = true; if (certProfile.Website != null) { txtWebsite.Text = certProfile.Website.AbsoluteUri; } txtPhone.Text = certProfile.PhoneNumber; txtStreetAddress.Text = certProfile.StreetAddress; txtCity.Text = certProfile.City; txtState.Text = certProfile.State; txtCountry.Text = certProfile.Country; txtPostalCode.Text = certProfile.PostalCode; } else { lblRegisteredEmail.Text = _profile.LocalCertificateStore.Certificate.IssuedTo.EmailAddress.Address; pnlRegister.Visible = false; pnlDownloadCert.Visible = true; } }
public frmRegister(string localAppData, BitChatProfile profile, string profileFilePath, bool reissue) { _localAppData = localAppData; _profile = profile; _profileFilePath = profileFilePath; InitializeComponent(); this.Width = 700 + 56; this.Height = 450; pnlRegister.Left = 12 + 56; pnlRegister.Top = 12; pnlMessages.Left = 12 + 56; pnlMessages.Top = 12; pnlDownloadCert.Left = 12 + 56; pnlDownloadCert.Top = 12; if (reissue) { CertificateProfile certProfile = _profile.LocalCertificateStore.Certificate.IssuedTo; txtName.Text = certProfile.Name; txtEmail.Text = certProfile.EmailAddress.Address; txtEmail.ReadOnly = true; if (certProfile.Website != null) { txtWebsite.Text = certProfile.Website.AbsoluteUri; } txtPhone.Text = certProfile.PhoneNumber; txtStreetAddress.Text = certProfile.StreetAddress; txtCity.Text = certProfile.City; txtState.Text = certProfile.State; txtCountry.Text = certProfile.Country; txtPostalCode.Text = certProfile.PostalCode; } else { lblRegisteredEmail.Text = _profile.LocalCertificateStore.Certificate.IssuedTo.EmailAddress.Address; pnlRegister.Visible = false; pnlDownloadCert.Visible = true; } }
private void RegisterAsync(CertificateProfile profile) { try { //register AsymmetricCryptoKey privateKey; if (rbImportRSA.Checked) { privateKey = AsymmetricCryptoKey.CreateUsing(_parameters); } else { privateKey = new AsymmetricCryptoKey(AsymmetricEncryptionAlgorithm.RSA, 4096); } Certificate selfSignedCert = new Certificate(CertificateType.RootCA, "", profile, CertificateCapability.SignCACertificate, DateTime.UtcNow, DateTime.UtcNow, AsymmetricEncryptionAlgorithm.RSA, privateKey.GetPublicKey()); selfSignedCert.SelfSign("SHA256", privateKey, null); Registration.Register(Program.SIGNUP_URI, selfSignedCert); if (_profile == null) { _profile = new BitChatProfile(null, new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0), GetDownloadsPath(), BitChatProfile.DefaultTrackerURIs); } _profile.LocalCertificateStore = new CertificateStore(selfSignedCert, privateKey); _profile.SetPassword(SymmetricEncryptionAlgorithm.Rijndael, 256, txtProfilePassword.Text); _profileFilePath = Path.Combine(_localAppData, _profile.LocalCertificateStore.Certificate.IssuedTo.Name + ".profile"); using (FileStream fS = new FileStream(_profileFilePath, FileMode.Create, FileAccess.ReadWrite)) { _profile.WriteTo(fS); } this.Invoke(new Action <object>(RegistrationSuccess), new object[] { null }); } catch (Exception ex) { this.Invoke(new Action <object>(RegistrationFail), new object[] { ex.Message }); } }
private void btnRegister_Click(object sender, EventArgs e) { string name = null; MailAddress emailAddress = null; Uri website = null; string phoneNumber = null; string streetAddress = null; string city = null; string state = null; string country = null; string postalCode = null; #region validate form if (string.IsNullOrEmpty(txtName.Text)) { MessageBox.Show("Please enter a valid name.", "Name Missing!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtName.Focus(); return; } if (string.IsNullOrEmpty(txtEmail.Text)) { MessageBox.Show("Please enter a valid email address.", "Email Address Missing!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtEmail.Focus(); return; } else { try { emailAddress = new MailAddress(txtEmail.Text); } catch { MessageBox.Show("Please enter a valid email address.", "Invalid Email Address!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtEmail.Focus(); return; } } if (!string.IsNullOrEmpty(txtWebsite.Text)) { try { website = new Uri(txtWebsite.Text); } catch { MessageBox.Show("Please enter a valid web address. Example: http://example.com", "Invalid Web Address!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtWebsite.Focus(); return; } } if (string.IsNullOrEmpty(txtCountry.Text)) { MessageBox.Show("Please select a valid country name.", "Country Name Missing!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtCountry.Focus(); return; } if (string.IsNullOrEmpty(txtProfilePassword.Text)) { MessageBox.Show("Please enter a profile password.", "Profile Password Missing!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtProfilePassword.Focus(); return; } if (string.IsNullOrEmpty(txtConfirmPassword.Text)) { MessageBox.Show("Please confirm profile password.", "Confirm Password Missing!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtConfirmPassword.Focus(); return; } if (txtConfirmPassword.Text != txtProfilePassword.Text) { txtProfilePassword.Text = ""; txtConfirmPassword.Text = ""; MessageBox.Show("Profile password doesn't match with confirm profile password. Please enter both passwords again.", "Password Mismatch!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtProfilePassword.Focus(); return; } #endregion if (!string.IsNullOrEmpty(txtName.Text)) { name = txtName.Text; } if (!string.IsNullOrEmpty(txtPhone.Text)) { phoneNumber = txtPhone.Text; } if (!string.IsNullOrEmpty(txtStreetAddress.Text)) { streetAddress = txtStreetAddress.Text; } if (!string.IsNullOrEmpty(txtCity.Text)) { city = txtCity.Text; } if (!string.IsNullOrEmpty(txtState.Text)) { state = txtState.Text; } if (!string.IsNullOrEmpty(txtCountry.Text)) { country = txtCountry.Text; } if (!string.IsNullOrEmpty(txtPostalCode.Text)) { postalCode = txtPostalCode.Text; } CertificateProfile profile = new CertificateProfile(name, CertificateProfileType.Individual, emailAddress, website, phoneNumber, streetAddress, city, state, country, postalCode); pnlRegister.Visible = false; lblPanelTitle.Text = "Registering..."; if (rbImportRSA.Checked) { lblPanelMessage.Text = "Please wait while we register your profile certificate.\r\n\r\nRegistering on https://" + Program.SIGNUP_URI.Host + " ..."; } else { lblPanelMessage.Text = "Please wait while we generate your profile private key and register your profile certificate.\r\n\r\nRegistering on https://" + Program.SIGNUP_URI.Host + " ..."; } pnlMessages.Visible = true; Action <CertificateProfile> d = new Action <CertificateProfile>(RegisterAsync); d.BeginInvoke(profile, null, null); }
private void RegisterAsync(CertificateProfile profile) { try { //register AsymmetricCryptoKey privateKey; if (rbImportRSA.Checked) privateKey = AsymmetricCryptoKey.CreateUsing(_parameters); else privateKey = new AsymmetricCryptoKey(AsymmetricEncryptionAlgorithm.RSA, 4096); Certificate selfSignedCert = new Certificate(CertificateType.RootCA, "", profile, CertificateCapability.SignCACertificate, DateTime.UtcNow, DateTime.UtcNow, AsymmetricEncryptionAlgorithm.RSA, privateKey.GetPublicKey()); selfSignedCert.SelfSign("SHA256", privateKey, null); Registration.Register(Program.SIGNUP_URI, selfSignedCert); if (_profile == null) _profile = new BitChatProfile(null, new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0), GetDownloadsPath(), BitChatProfile.DefaultTrackerURIs); _profile.LocalCertificateStore = new CertificateStore(selfSignedCert, privateKey); _profile.SetPassword(SymmetricEncryptionAlgorithm.Rijndael, 256, txtProfilePassword.Text); _profileFilePath = Path.Combine(_localAppData, _profile.LocalCertificateStore.Certificate.IssuedTo.Name + ".profile"); using (FileStream fS = new FileStream(_profileFilePath, FileMode.Create, FileAccess.ReadWrite)) { _profile.WriteTo(fS); } this.Invoke(new Action<object>(RegistrationSuccess), new object[] { null }); } catch (Exception ex) { this.Invoke(new Action<object>(RegistrationFail), new object[] { ex.Message }); } }
private void btnRegister_Click(object sender, EventArgs e) { string name = null; MailAddress emailAddress = null; Uri website = null; string phoneNumber = null; string streetAddress = null; string city = null; string state = null; string country = null; string postalCode = null; #region validate form if (string.IsNullOrEmpty(txtName.Text)) { MessageBox.Show("Please enter a valid name.", "Name Missing!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtName.Focus(); return; } if (string.IsNullOrEmpty(txtEmail.Text)) { MessageBox.Show("Please enter a valid email address.", "Email Address Missing!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtEmail.Focus(); return; } else { try { emailAddress = new MailAddress(txtEmail.Text); } catch { MessageBox.Show("Please enter a valid email address.", "Invalid Email Address!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtEmail.Focus(); return; } } if (!string.IsNullOrEmpty(txtWebsite.Text)) { try { website = new Uri(txtWebsite.Text); } catch { MessageBox.Show("Please enter a valid web address. Example: http://example.com", "Invalid Web Address!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtWebsite.Focus(); return; } } if (string.IsNullOrEmpty(txtCountry.Text)) { MessageBox.Show("Please select a valid country name.", "Country Name Missing!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtCountry.Focus(); return; } if (string.IsNullOrEmpty(txtProfilePassword.Text)) { MessageBox.Show("Please enter a profile password.", "Profile Password Missing!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtProfilePassword.Focus(); return; } if (string.IsNullOrEmpty(txtConfirmPassword.Text)) { MessageBox.Show("Please confirm profile password.", "Confirm Password Missing!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtConfirmPassword.Focus(); return; } if (txtConfirmPassword.Text != txtProfilePassword.Text) { txtProfilePassword.Text = ""; txtConfirmPassword.Text = ""; MessageBox.Show("Profile password doesn't match with confirm profile password. Please enter both passwords again.", "Password Mismatch!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtProfilePassword.Focus(); return; } #endregion if (!string.IsNullOrEmpty(txtName.Text)) name = txtName.Text; if (!string.IsNullOrEmpty(txtPhone.Text)) phoneNumber = txtPhone.Text; if (!string.IsNullOrEmpty(txtStreetAddress.Text)) streetAddress = txtStreetAddress.Text; if (!string.IsNullOrEmpty(txtCity.Text)) city = txtCity.Text; if (!string.IsNullOrEmpty(txtState.Text)) state = txtState.Text; if (!string.IsNullOrEmpty(txtCountry.Text)) country = txtCountry.Text; if (!string.IsNullOrEmpty(txtPostalCode.Text)) postalCode = txtPostalCode.Text; CertificateProfile profile = new CertificateProfile(name, CertificateProfileType.Individual, emailAddress, website, phoneNumber, streetAddress, city, state, country, postalCode); pnlRegister.Visible = false; lblPanelTitle.Text = "Registering..."; if (rbImportRSA.Checked) lblPanelMessage.Text = "Please wait while we register your profile certificate.\r\n\r\nRegistering on https://" + Program.SIGNUP_URI.Host + " ..."; else lblPanelMessage.Text = "Please wait while we generate your profile private key and register your profile certificate.\r\n\r\nRegistering on https://" + Program.SIGNUP_URI.Host + " ..."; pnlMessages.Visible = true; Action<CertificateProfile> d = new Action<CertificateProfile>(RegisterAsync); d.BeginInvoke(profile, null, null); }