Exemplo n.º 1
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.º 2
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 });
            }
        }