Ejemplo n.º 1
0
        public BitChatService(BitChatProfile profile, Certificate[] trustedRootCertificates, SecureChannelCryptoOptionFlags supportedCryptoOptions, InvalidCertificateEvent invalidCertEventHandler)
        {
            //verify root certs
            foreach (Certificate trustedCert in trustedRootCertificates)
                trustedCert.Verify(trustedRootCertificates);

            //verify profile cert
            profile.LocalCertificateStore.Certificate.Verify(trustedRootCertificates);

            _invalidCertEventHandler = invalidCertEventHandler;

            _manager = new InternalBitChatService(this, profile, trustedRootCertificates, supportedCryptoOptions);

            foreach (BitChatProfile.BitChatInfo bitChatInfo in profile.BitChatInfoList)
            {
                if (bitChatInfo.Type == BitChatNetworkType.PrivateChat)
                    _bitChats.Add(_manager.CreateBitChat(new MailAddress(bitChatInfo.NetworkNameOrPeerEmailAddress), bitChatInfo.SharedSecret, bitChatInfo.NetworkID, bitChatInfo.PeerCertificateList, bitChatInfo.SharedFileList, bitChatInfo.TrackerURIs));
                else
                    _bitChats.Add(_manager.CreateBitChat(bitChatInfo.NetworkNameOrPeerEmailAddress, bitChatInfo.SharedSecret, bitChatInfo.NetworkID, bitChatInfo.PeerCertificateList, bitChatInfo.SharedFileList, bitChatInfo.TrackerURIs));
            }

            //check profile cert revocation
            ThreadPool.QueueUserWorkItem(CheckCertificateRevocationAsync, new Certificate[] { profile.LocalCertificateStore.Certificate });

            //check trusted root cert revocation
            ThreadPool.QueueUserWorkItem(CheckCertificateRevocationAsync, trustedRootCertificates);
        }
Ejemplo 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);
        }
Ejemplo n.º 3
0
        public BitChatService(BitChatProfile profile, Certificate[] trustedRootCertificates, SecureChannelCryptoOptionFlags supportedCryptoOptions, InvalidCertificateEvent invalidCertEventHandler)
        {
            //verify root certs
            foreach (Certificate trustedCert in trustedRootCertificates)
            {
                trustedCert.Verify(trustedRootCertificates);
            }

            //verify profile cert
            profile.LocalCertificateStore.Certificate.Verify(trustedRootCertificates);

            _invalidCertEventHandler = invalidCertEventHandler;

            _manager = new InternalBitChatService(this, profile, trustedRootCertificates, supportedCryptoOptions);

            foreach (BitChatProfile.BitChatInfo bitChatInfo in profile.BitChatInfoList)
            {
                if (bitChatInfo.Type == BitChatNetworkType.PrivateChat)
                {
                    _bitChats.Add(_manager.CreateBitChat(new MailAddress(bitChatInfo.NetworkNameOrPeerEmailAddress), bitChatInfo.SharedSecret, bitChatInfo.NetworkID, bitChatInfo.PeerCertificateList, bitChatInfo.SharedFileList, bitChatInfo.TrackerURIs));
                }
                else
                {
                    _bitChats.Add(_manager.CreateBitChat(bitChatInfo.NetworkNameOrPeerEmailAddress, bitChatInfo.SharedSecret, bitChatInfo.NetworkID, bitChatInfo.PeerCertificateList, bitChatInfo.SharedFileList, bitChatInfo.TrackerURIs));
                }
            }

            //check profile cert revocation
            ThreadPool.QueueUserWorkItem(CheckCertificateRevocationAsync, new Certificate[] { profile.LocalCertificateStore.Certificate });

            //check trusted root cert revocation
            ThreadPool.QueueUserWorkItem(CheckCertificateRevocationAsync, trustedRootCertificates);
        }
Ejemplo 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();
                }
            }
        }
Ejemplo n.º 5
0
        public frmRegister(string localAppData, BitChatProfile profile, string profileFilePath, bool reissue)
        {
            _localAppData = localAppData;
            _profile = profile;
            _profileFilePath = profileFilePath;

            InitializeComponent();

            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;
            }
        }
Ejemplo n.º 6
0
            int _reNegotiateAfterSeconds = 3600;      //1hr

            #endregion

            #region constructor

            public InternalBitChatService(BitChatService service, BitChatProfile profile, Certificate[] trustedRootCertificates, SecureChannelCryptoOptionFlags supportedCryptoOptions)
            {
                _service = service;
                _profile = profile;
                _trustedRootCertificates = trustedRootCertificates;
                _supportedCryptoOptions  = supportedCryptoOptions;

                _connectionManager = new ConnectionManager(_profile.LocalEP, ChannelRequest);

                LocalPeerDiscovery.StartListener(41733);
                _localDiscovery = new LocalPeerDiscovery(_connectionManager.LocalEP.Port);
                _localDiscovery.PeerDiscovered += _localDiscovery_PeerDiscovered;

                _profile.LocalEP = _connectionManager.LocalEP;
            }
Ejemplo n.º 7
0
        internal BitChat(IBitChatManager manager, BitChatProfile profile, BitChatNetwork network, BitChatProfile.SharedFileInfo[] sharedFileInfoList, Uri[] trackerURIs)
        {
            _manager = manager;
            _profile = profile;
            _network = network;
            _network.VirtualPeerAdded += _network_VirtualPeerAdded;
            _network.VirtualPeerHasRevokedCertificate  += _network_VirtualPeerHasRevokedCertificate;
            _network.VirtualPeerSecureChannelException += _network_VirtualPeerSecureChannelException;

            foreach (BitChatNetwork.VirtualPeer virtualPeer in _network.GetVirtualPeerList())
            {
                Peer peer = new Peer(virtualPeer, this);

                if (peer.IsSelf)
                {
                    _selfPeer = peer;
                }

                _peers.Add(peer);
            }

            foreach (BitChatProfile.SharedFileInfo info in sharedFileInfoList)
            {
                try
                {
                    _sharedFiles.Add(info.FileMetaData.FileID, SharedFile.LoadFile(info, this, _syncCxt));
                }
                catch
                { }
            }

            //start tracking
            _manager.StartLocalTracking(_network.NetworkID);
            StartTracking(trackerURIs);

            //start noop timer
            _NOOPTimer = new Timer(NOOPTimerCallback, null, NOOP_PACKET_TIME_SECONDS, Timeout.Infinite);

            //start network update timer
            _updateNetworkStatusTimer  = new Timer(UpdateNetworkStatusCallback, null, NETWORK_STATUS_TIMER_INTERVAL, Timeout.Infinite);
            _reCheckNetworkStatusTimer = new Timer(ReCheckNetworkStatusCallback, null, Timeout.Infinite, Timeout.Infinite);
        }
Ejemplo n.º 8
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();
            }
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
0
        internal BitChat(IBitChatManager manager, BitChatProfile profile, BitChatNetwork network, BitChatProfile.SharedFileInfo[] sharedFileInfoList, Uri[] trackerURIs)
        {
            _manager = manager;
            _profile = profile;
            _network = network;
            _network.VirtualPeerAdded += _network_VirtualPeerAdded;
            _network.VirtualPeerHasRevokedCertificate += _network_VirtualPeerHasRevokedCertificate;
            _network.VirtualPeerSecureChannelException += _network_VirtualPeerSecureChannelException;

            foreach (BitChatNetwork.VirtualPeer virtualPeer in _network.GetVirtualPeerList())
            {
                Peer peer = new Peer(virtualPeer, this);

                if (peer.IsSelf)
                    _selfPeer = peer;

                _peers.Add(peer);
            }

            foreach (BitChatProfile.SharedFileInfo info in sharedFileInfoList)
            {
                try
                {
                    _sharedFiles.Add(info.FileMetaData.FileID, SharedFile.LoadFile(info, this, _syncCxt));
                }
                catch
                { }
            }

            //start tracking
            _manager.StartLocalTracking(_network.NetworkID);
            StartTracking(trackerURIs);

            //start noop timer
            _NOOPTimer = new Timer(NOOPTimerCallback, null, NOOP_PACKET_TIME_SECONDS, Timeout.Infinite);

            //start network update timer
            _updateNetworkStatusTimer = new Timer(UpdateNetworkStatusCallback, null, NETWORK_STATUS_TIMER_INTERVAL, Timeout.Infinite);
            _reCheckNetworkStatusTimer = new Timer(ReCheckNetworkStatusCallback, null, Timeout.Infinite, Timeout.Infinite);
        }
Ejemplo n.º 11
0
 public void UpdateProfile(BitChatProfile.BitChatInfo[] bitChatInfoList)
 {
     _profile.UpdateBitChatInfo(bitChatInfoList);
 }
Ejemplo n.º 12
0
            public BitChat CreateBitChat(string networkName, string sharedSecret, BinaryID networkID, Certificate[] knownPeerCerts, BitChatProfile.SharedFileInfo[] sharedFileInfoList, Uri[] trackerURIs)
            {
                BitChatNetwork network = new BitChatNetwork(networkName, sharedSecret, networkID, knownPeerCerts, this, this);

                lock (_networks)
                {
                    _networks.Add(network.NetworkID, network);
                }

                if (trackerURIs == null)
                    trackerURIs = _profile.TrackerURIs;

                return new BitChat(this, _profile, network, sharedFileInfoList, trackerURIs);
            }
Ejemplo 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 });
            }
        }
Ejemplo n.º 14
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;
                }
            }
        }
Ejemplo n.º 15
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();
                }
            }
        }
Ejemplo n.º 16
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;
            }
        }
Ejemplo n.º 17
0
            public InternalBitChatService(BitChatService service, BitChatProfile profile, Certificate[] trustedRootCertificates, SecureChannelCryptoOptionFlags supportedCryptoOptions)
            {
                _service = service;
                _profile = profile;
                _trustedRootCertificates = trustedRootCertificates;
                _supportedCryptoOptions = supportedCryptoOptions;

                _connectionManager = new ConnectionManager(_profile.LocalEP, ChannelRequest);

                LocalPeerDiscovery.StartListener(41733);
                _localDiscovery = new LocalPeerDiscovery(_connectionManager.LocalEP.Port);
                _localDiscovery.PeerDiscovered += _localDiscovery_PeerDiscovered;

                _profile.LocalEP = _connectionManager.LocalEP;
            }