Exemplo n.º 1
0
        private void frmRegisterNow_Click(object sender, EventArgs e)
        {
            this.Hide();

            using (frmRegister frm = new frmRegister(_localAppData))
            {
                DialogResult result = frm.ShowDialog(this);

                switch (result)
                {
                case System.Windows.Forms.DialogResult.OK:
                    _profile         = frm.Profile;
                    _profileFilePath = frm.ProfileFilePath;

                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                    break;

                case System.Windows.Forms.DialogResult.Ignore:
                    this.Show();
                    break;

                default:
                    this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                    this.Close();
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public frmMain(BitChatProfile profile, string profileFilePath, string cmdLine)
        {
            InitializeComponent();

            _profile         = profile;
            _profileFilePath = profileFilePath;

            SecureChannelCryptoOptionFlags cryptoOptions;

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
                if (Environment.OSVersion.Version.Major > 5)
                {
                    cryptoOptions = SecureChannelCryptoOptionFlags.ECDHE256_RSA_WITH_AES256_CBC_HMAC_SHA256 | SecureChannelCryptoOptionFlags.DHE2048_RSA_WITH_AES256_CBC_HMAC_SHA256;
                }
                else
                {
                    cryptoOptions = SecureChannelCryptoOptionFlags.DHE2048_RSA_WITH_AES256_CBC_HMAC_SHA256;
                }
                break;

            default:
                cryptoOptions = SecureChannelCryptoOptionFlags.DHE2048_RSA_WITH_AES256_CBC_HMAC_SHA256;
                break;
            }

            //start bitchat service
            _service = new BitChatService(profile, Program.TRUSTED_CERTIFICATES, cryptoOptions, InvalidCertificateEvent);
        }
Exemplo n.º 3
0
        private void btnReIssueProfile_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Reissuing a profile certificate will allow you register again with the same email address and change your information in the profile certificate while keeping all your profile settings intact.\r\n\r\nAre you sure you want to reissue the selected profile?\r\n\r\nWARNING! This will revoke the previously issued profile certificate however, your settings will remain intact.", "Reissue Profile Certificate?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.Yes)
            {
                this.Hide();

                _profileFilePath = Path.Combine(_localAppData, (lstProfiles.SelectedItem as string) + ".profile");

                using (frmPassword frm = new frmPassword(_profileFilePath))
                {
                    if (frm.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                    {
                        _profile = frm.Profile;

                        using (frmRegister frmReg = new frmRegister(_localAppData, _profile, _profileFilePath, true))
                        {
                            if (frmReg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                            {
                                _profile         = frmReg.Profile;
                                _profileFilePath = frmReg.ProfileFilePath;

                                string profileName = Path.GetFileNameWithoutExtension(_profileFilePath);
                                lstProfiles.SelectedItem = profileName;
                            }
                        }
                    }
                }

                this.Show();
            }
        }
Exemplo n.º 4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                using (FileStream fS = new FileStream(_profileFilePath, FileMode.Open, FileAccess.Read))
                {
                    _profile = new BitChatProfile(fS, txtPassword.Text);
                }

                DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            catch
            {
                try
                {
                    using (FileStream fS = new FileStream(_profileFilePath + ".bak", FileMode.Open, FileAccess.Read))
                    {
                        _profile = new BitChatProfile(fS, txtPassword.Text);
                    }

                    DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
                catch
                {
                    MessageBox.Show("Invalid password or file data tampered. Please try again.", "Invalid Password!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    txtPassword.Text = "";
                    txtPassword.Focus();
                }
            }
        }
        public frmSettings(BitChatProfile profile)
        {
            InitializeComponent();

            txtDownloadFolder.Text    = profile.DownloadFolder;
            btnBrowseDLFolder.Enabled = !profile.IsPortableApp;

            foreach (Uri tracker in profile.TrackerURIs)
            {
                txtTrackers.Text += tracker.AbsoluteUri + "\r\n";
            }

            txtPort.Text                         = profile.LocalPort.ToString();
            chkUseCRL.Checked                    = profile.CheckCertificateRevocationList;
            chkAllowInvitations.Checked          = profile.AllowInboundInvitations;
            chkAllowOnlyLocalInvitations.Enabled = chkAllowInvitations.Checked;
            chkAllowOnlyLocalInvitations.Checked = profile.AllowOnlyLocalInboundInvitations;
            chkUPnP.Checked                      = profile.EnableUPnP;

            if (profile.Proxy == null)
            {
                cmbProxy.SelectedIndex = 0;
            }
            else
            {
                cmbProxy.SelectedIndex = (int)profile.Proxy.Type;
            }

            btnCheckProxy.Enabled   = (cmbProxy.SelectedIndex != 0);
            txtProxyAddress.Text    = profile.ProxyAddress;
            txtProxyPort.Text       = profile.ProxyPort.ToString();
            txtProxyAddress.Enabled = btnCheckProxy.Enabled;
            txtProxyPort.Enabled    = btnCheckProxy.Enabled;
            chkProxyAuth.Enabled    = btnCheckProxy.Enabled;

            if ((cmbProxy.SelectedIndex == 2) && (profile.ProxyPort == 9150) && (profile.ProxyAddress == "127.0.0.1"))
            {
                cmbProxy.SelectedIndex = 3;
            }

            if (profile.ProxyCredentials == null)
            {
                chkProxyAuth.Checked = false;
            }
            else
            {
                chkProxyAuth.Checked = true;
                txtProxyUser.Text    = profile.ProxyCredentials.UserName;
                txtProxyPass.Text    = profile.ProxyCredentials.Password;
            }

            txtProxyUser.Enabled = chkProxyAuth.Enabled && chkProxyAuth.Checked;
            txtProxyPass.Enabled = chkProxyAuth.Enabled && chkProxyAuth.Checked;
        }
Exemplo n.º 6
0
        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 });
            }
        }
Exemplo n.º 7
0
        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;
            }
        }
Exemplo n.º 8
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            _profileFilePath = Path.Combine(_localAppData, (lstProfiles.SelectedItem as string) + ".profile");

            using (frmPassword frm = new frmPassword(_profileFilePath))
            {
                if (frm.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    _profile = frm.Profile;

                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
            }
        }
Exemplo n.º 9
0
        private void frmProfileManager_Load(object sender, EventArgs e)
        {
            if (_firstRunComplete)
            {
                return;
            }

            _firstRunComplete = true;

            switch (lstProfiles.Items.Count)
            {
            case 0:
                using (frmWelcome frm = new frmWelcome(_isPortableApp, _profileFolder))
                {
                    DialogResult result = frm.ShowDialog(this);

                    switch (result)
                    {
                    case System.Windows.Forms.DialogResult.OK:
                        _profile         = frm.Profile;
                        _profileFilePath = frm.ProfileFilePath;

                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                        this.Close();
                        break;

                    case System.Windows.Forms.DialogResult.Ignore:
                        btnImportProfile_Click(null, null);
                        break;

                    default:
                        this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                        this.Close();
                        break;
                    }
                }
                break;

            case 1:
                _profileFilePath = Path.Combine(_profileFolder, (lstProfiles.Items[0] as string) + ".profile");

                Start();
                break;

            default:
                break;
            }
        }
Exemplo n.º 10
0
        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;
            }
        }
Exemplo n.º 11
0
        public frmChatProperties(BitChat chat, BitChatProfile profile)
        {
            InitializeComponent();

            _chat    = chat;
            _profile = profile;

            this.Text = _chat.NetworkDisplayName + " - Properties";

            chkLANChat.Checked         = !_chat.EnableTracking;
            chkLANChat.CheckedChanged += chkLANChat_CheckedChanged;

            txtNetwork.Text = chat.NetworkName;

            if (chat.NetworkName == null)
            {
                txtSecret.ReadOnly = true;
            }

            txtSecret.Text = _chat.SharedSecret;

            if (_chat.NetworkType == BitChatCore.Network.BitChatNetworkType.PrivateChat)
            {
                label1.Text = "Peer's Email Address";
            }

            ListViewItem dhtItem = lstTrackerInfo.Items.Add("DHT");

            dhtItem.SubItems.Add("");
            dhtItem.SubItems.Add("");
            dhtItem.SubItems.Add("");

            foreach (TrackerClient tracker in _chat.GetTrackers())
            {
                ListViewItem item = lstTrackerInfo.Items.Add(tracker.TrackerUri.AbsoluteUri);
                item.Tag = tracker;

                item.SubItems.Add("");
                item.SubItems.Add("");
                item.SubItems.Add("");
            }

            _timer          = new Timer();
            _timer.Interval = 1000;
            _timer.Tick    += timer_Tick;
            _timer.Start();
        }
Exemplo n.º 12
0
        private void Start()
        {
            using (frmPassword frm = new frmPassword(_profileFilePath, _isPortableApp, _profileFolder))
            {
                switch (frm.ShowDialog(this))
                {
                case DialogResult.OK:
                    _profile = frm.Profile;

                    if (_profile.LocalCertificateStore.Certificate.Type == TechnitiumLibrary.Security.Cryptography.CertificateType.User)
                    {
                        //check for profile certificate expiry
                        double daysToExpire = (_profile.LocalCertificateStore.Certificate.ExpiresOnUTC - DateTime.UtcNow).TotalDays;

                        if (daysToExpire < 0.0)
                        {
                            //cert already expired

                            if (MessageBox.Show("Your profile certificate '" + _profile.LocalCertificateStore.Certificate.SerialNumber + "' issued to '" + _profile.LocalCertificateStore.Certificate.IssuedTo.EmailAddress.Address + "' has expired on " + _profile.LocalCertificateStore.Certificate.ExpiresOnUTC.ToString() + ".\r\n\r\nDo you want to reissue the certificate now?", "Profile Certificate Expired! Reissue Now?", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.Yes)
                            {
                                btnReIssueProfile_Click(null, null);
                            }

                            return;
                        }
                        else if (daysToExpire < 30.0)
                        {
                            //cert to expire in 30 days
                            if (MessageBox.Show("Your profile certificate '" + _profile.LocalCertificateStore.Certificate.SerialNumber + "' issued to '" + _profile.LocalCertificateStore.Certificate.IssuedTo.EmailAddress.Address + "' will expire in " + Convert.ToInt32(daysToExpire) + " days on " + _profile.LocalCertificateStore.Certificate.ExpiresOnUTC.ToString() + ".\r\n\r\nDo you want to reissue the certificate now?", "Profile Certificate About To Expire! Reissue Now?", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.Yes)
                            {
                                btnReIssueProfile_Click(null, null);
                                return;
                            }
                        }
                    }

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                    break;

                case DialogResult.Yes:
                    btnNewProfile_Click(null, null);
                    break;
                }
            }
        }
Exemplo n.º 13
0
        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 });
            }
        }
Exemplo n.º 14
0
        private void btnNewProfile_Click(object sender, EventArgs e)
        {
            this.Hide();

            using (frmRegister frm = new frmRegister(_localAppData))
            {
                if (frm.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    _profile         = frm.Profile;
                    _profileFilePath = frm.ProfileFilePath;

                    string profileName = Path.GetFileNameWithoutExtension(_profileFilePath);

                    lstProfiles.Items.Add(profileName);
                    lstProfiles.SelectedItem = profileName;
                }
            }

            this.Show();
        }
Exemplo n.º 15
0
        public frmSettings(BitChatService service)
        {
            InitializeComponent();

            _service = service;

            BitChatProfile profile = service.Profile;

            txtPort.Text           = profile.LocalEP.Port.ToString();
            txtDownloadFolder.Text = profile.DownloadFolder;
            chkUseCRL.Checked      = profile.CheckCertificateRevocationList;

            foreach (Uri tracker in profile.TrackerURIs)
            {
                txtTrackers.Text += tracker.AbsoluteUri + "\r\n";
            }

            _timer          = new Timer();
            _timer.Interval = 1000;
            _timer.Tick    += _timer_Tick;
            _timer.Start();
        }
Exemplo n.º 16
0
        public frmMain(BitChatProfile profile, string profileFilePath, string cmdLine)
        {
            InitializeComponent();

            _profile         = profile;
            _profileFilePath = profileFilePath;

            SecureChannelCryptoOptionFlags cryptoOptions;

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
                if (Environment.OSVersion.Version.Major > 5)
                {
                    cryptoOptions = SecureChannelCryptoOptionFlags.ECDHE256_RSA_WITH_AES256_CBC_HMAC_SHA256 | SecureChannelCryptoOptionFlags.DHE2048_RSA_WITH_AES256_CBC_HMAC_SHA256;
                }
                else
                {
                    cryptoOptions = SecureChannelCryptoOptionFlags.DHE2048_RSA_WITH_AES256_CBC_HMAC_SHA256;
                }

                break;

            default:
                cryptoOptions = SecureChannelCryptoOptionFlags.DHE2048_RSA_WITH_AES256_CBC_HMAC_SHA256;
                break;
            }

            //start bitchat client
            _node = new BitChatNode(profile, Program.TRUSTED_CERTIFICATES, cryptoOptions);

            _node.InvalidCertificateDetected += BitChatNode_InvalidCertificateDetected;
            _node.BitChatInvitationReceived  += BitChatNode_BitChatInvitationReceived;

            _node.Start();
        }
Exemplo n.º 17
0
        private void frmProfileManager_Load(object sender, EventArgs e)
        {
            if (_loaded)
            {
                return;
            }

            switch (lstProfiles.Items.Count)
            {
            case 0:
                using (frmWelcome frm = new frmWelcome(_localAppData))
                {
                    DialogResult result = frm.ShowDialog(this);

                    switch (result)
                    {
                    case System.Windows.Forms.DialogResult.OK:
                        _profile         = frm.Profile;
                        _profileFilePath = frm.ProfileFilePath;

                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                        this.Close();
                        break;

                    case System.Windows.Forms.DialogResult.Ignore:
                        btnImportProfile_Click(null, null);
                        break;

                    default:
                        this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                        this.Close();
                        break;
                    }
                }
                break;

            case 1:
                _profileFilePath = Path.Combine(_localAppData, (lstProfiles.Items[0] as string) + ".profile");

                using (frmPassword frm = new frmPassword(_profileFilePath))
                {
                    switch (frm.ShowDialog(this))
                    {
                    case System.Windows.Forms.DialogResult.OK:
                        _profile = frm.Profile;

                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                        this.Close();
                        break;

                    case System.Windows.Forms.DialogResult.Yes:
                        btnNewProfile_Click(null, null);
                        break;
                    }
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 18
0
        internal static SharedFile PrepareDownloadFile(SharedFileMetaData metaData, BitChat chat, BitChat.Peer seeder, BitChatProfile profile, SynchronizationContext syncCxt)
        {
            //check if file already exists
            lock (_sharedFiles)
            {
                SharedFile sharedFile;

                if (_sharedFiles.ContainsKey(metaData.FileID))
                {
                    sharedFile = _sharedFiles[metaData.FileID];
                }
                else
                {
                    sharedFile          = new SharedFile(null, metaData, new FileBlockState[metaData.BlockHash.Length], 0, syncCxt);
                    sharedFile._profile = profile;

                    _sharedFiles.Add(metaData.FileID, sharedFile);
                }

                sharedFile.AddChat(chat);
                sharedFile.AddSeeder(seeder);

                return(sharedFile);
            }
        }
Exemplo n.º 19
0
        public frmViewProfile(BitChatProfile profile, BitChat.Peer peer)
        {
            InitializeComponent();

            _profile = profile;
            _peer    = peer;

            CertificateProfile certProfile;

            byte[] profileImage = null;

            if (_peer == null)
            {
                certProfile  = _profile.LocalCertificateStore.Certificate.IssuedTo;
                profileImage = _profile.ProfileImage;
            }
            else
            {
                lnkView.Text = "View User Details";

                if (!_peer.IsSelf)
                {
                    labIcon.Cursor = Cursors.Default;
                    picIcon.Cursor = Cursors.Default;
                }

                certProfile = _peer.PeerCertificate.IssuedTo;

                if (_peer.IsOnline)
                {
                    profileImage = _peer.ProfileImage;
                }
            }

            //name
            if (certProfile.FieldExists(CertificateProfileFlags.Name))
            {
                string name = certProfile.Name;

                //name icon
                if (name.Length > 0)
                {
                    labIcon.Text = name.Substring(0, 1).ToUpper();

                    int x = name.LastIndexOf(" ", StringComparison.CurrentCultureIgnoreCase);
                    if (x > 0)
                    {
                        labIcon.Text += name.Substring(x + 1, 1).ToUpper();
                    }
                    else if (name.Length > 1)
                    {
                        labIcon.Text += name.Substring(1, 1).ToLower();
                    }
                }
                else
                {
                    labIcon.Text = "";
                }

                if ((_peer == null) || _peer.IsOnline)
                {
                    labIcon.BackColor = Color.FromArgb(102, 153, 255);
                }
                else
                {
                    labIcon.BackColor = Color.Gray;
                }

                labName.Text = name;
            }
            else
            {
                labIcon.Text      = "";
                labName.Text      = "{missing name}";
                labName.ForeColor = Color.Red;
            }

            //email
            if (certProfile.FieldExists(CertificateProfileFlags.EmailAddress))
            {
                labEmail.Text = certProfile.EmailAddress.Address;
            }
            else
            {
                labEmail.Text      = "{missing email address}";
                labEmail.ForeColor = Color.Red;
            }

            //location
            if (certProfile.FieldExists(CertificateProfileFlags.City | CertificateProfileFlags.State | CertificateProfileFlags.Country))
            {
                labLocation.Text = "";

                if (certProfile.FieldExists(CertificateProfileFlags.City))
                {
                    labLocation.Text = certProfile.City + ", ";
                }

                if (certProfile.FieldExists(CertificateProfileFlags.State))
                {
                    labLocation.Text += certProfile.State + ", ";
                }

                if (certProfile.FieldExists(CertificateProfileFlags.Country))
                {
                    labLocation.Text += certProfile.Country;
                }
            }
            else
            {
                labLocation.Text      = "{missing location}";
                labLocation.ForeColor = Color.Red;
            }

            //image icon
            if (profileImage != null)
            {
                using (MemoryStream mS = new MemoryStream(profileImage))
                {
                    _profileImage = Image.FromStream(mS);
                    picIcon.Image = _profileImage;
                }

                picIcon.Visible = true;
                labIcon.Visible = false;
            }
        }
Exemplo n.º 20
0
        internal static SharedFile PrepareDownloadFile(SharedFileMetaData metaData, BitChat chat, BitChat.Peer seeder, BitChatProfile profile, SynchronizationContext syncCxt)
        {
            //check if file already exists
            lock (_sharedFiles)
            {
                SharedFile sharedFile;

                if (_sharedFiles.ContainsKey(metaData.FileID))
                {
                    sharedFile = _sharedFiles[metaData.FileID];
                }
                else
                {
                    sharedFile = new SharedFile(null, metaData, new FileBlockState[metaData.BlockHash.Length], 0, syncCxt);
                    sharedFile._profile = profile;

                    _sharedFiles.Add(metaData.FileID, sharedFile);
                }

                sharedFile.AddChat(chat);
                sharedFile.AddSeeder(seeder);

                return sharedFile;
            }
        }
        public ConnectionManager(BitChatProfile profile)
        {
            IPEndPoint localEP;

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
                if (Environment.OSVersion.Version.Major < 6)
                {
                    //below vista
                    _tcpListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    localEP      = new IPEndPoint(IPAddress.Any, profile.LocalPort);
                }
                else
                {
                    //vista & above
                    _tcpListener = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
                    _tcpListener.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
                    localEP = new IPEndPoint(IPAddress.IPv6Any, profile.LocalPort);
                }
                break;

            case PlatformID.Unix:     //mono framework
                if (Socket.OSSupportsIPv6)
                {
                    _tcpListener = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
                    localEP      = new IPEndPoint(IPAddress.IPv6Any, profile.LocalPort);
                }
                else
                {
                    _tcpListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    localEP      = new IPEndPoint(IPAddress.Any, profile.LocalPort);
                }

                break;

            default:     //unknown
                _tcpListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                localEP      = new IPEndPoint(IPAddress.Any, profile.LocalPort);
                break;
            }

            try
            {
                _tcpListener.Bind(localEP);
                _tcpListener.Listen(10);
            }
            catch
            {
                localEP.Port = 0;

                _tcpListener.Bind(localEP);
                _tcpListener.Listen(10);
            }

            _profile = profile;

            _localPort   = (_tcpListener.LocalEndPoint as IPEndPoint).Port;
            _localPeerID = BinaryID.GenerateRandomID160();

            //start dht
            _dhtClient = new DhtClient(_localPort, this);
            _dhtClient.ProxyEnabled = (_profile.Proxy != null);
            _dhtClient.AddNode(profile.BootstrapDhtNodes);

            //setup dht seeding tracker
            _dhtSeedingTracker                  = new TrackerManager(_dhtSeedingNetworkID, _localPort, null, DHT_SEED_TRACKER_UPDATE_INTERVAL);
            _dhtSeedingTracker.Proxy            = _profile.Proxy;
            _dhtSeedingTracker.DiscoveredPeers += dhtSeedingTracker_DiscoveredPeers;
            _dhtSeedingTracker.StartTracking(profile.TrackerURIs);

            //start accepting connections
            _tcpListenerThread = new Thread(AcceptTcpConnectionAsync);
            _tcpListenerThread.IsBackground = true;
            _tcpListenerThread.Start(_tcpListener);

            //start upnp process
            _connectivityCheckTimer = new Timer(ConnectivityCheckTimerCallback, null, 1000, Timeout.Infinite);
        }
Exemplo n.º 22
0
 internal static SharedFile LoadFile(BitChatProfile.SharedFileInfo info, BitChat chat, SynchronizationContext syncCxt)
 {
     return LoadFile(info.FilePath, info.FileMetaData, info.BlockAvailable, info.IsPaused, chat, syncCxt);
 }