예제 #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 });
            }
        }
예제 #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 });
            }
        }
예제 #3
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 });
            }
        }
예제 #4
0
 public bool IsSignatureValid(Certificate signingCert, string hashAlgo)
 {
     return(AsymmetricCryptoKey.Verify(new MemoryStream(_publicKey, false), _signature, hashAlgo, signingCert));
 }
예제 #5
0
 public KeyExchange(byte[] publicKey, AsymmetricCryptoKey privateKey, string hashAlgo)
 {
     _publicKey = publicKey;
     _signature = privateKey.Sign(new MemoryStream(_publicKey, false), hashAlgo);
 }
예제 #6
0
 public SecureChannelHandshakeKeyExchange(byte[] publicKey, AsymmetricCryptoKey privateKey, string hashAlgo)
     : base(SecureChannelCode.None)
 {
     _publicKey = publicKey;
     _signature = privateKey.Sign(new MemoryStream(_publicKey, false), hashAlgo);
 }
예제 #7
0
 public KeyExchange(string publicKeyXML, AsymmetricCryptoKey privateKey, string hashAlgo)
 {
     _publicKeyXML = publicKeyXML;
     _signature    = privateKey.Sign(new MemoryStream(Encoding.UTF8.GetBytes(_publicKeyXML), false), hashAlgo);
 }
 public KeyExchange(string publicKeyXML, AsymmetricCryptoKey privateKey, string hashAlgo)
 {
     _publicKeyXML = publicKeyXML;
     _signature = privateKey.Sign(new MemoryStream(Encoding.UTF8.GetBytes(_publicKeyXML), false), hashAlgo);
 }