private void CreateProfile(string email, string password, ProtectedDataBlock privateKeyPem, byte[] publicKeyPem) { logger.Debug("Creating profile"); if (!pbData.CreateProfile(email, password)) { OnMessageRaised("Error while creating secure database"); } pbData.AddUserInfo(new DTO.UserInfo() { Email = email, RSAPrivateKey = privateKeyPem, PublicKey = publicKeyPem }); }
private void NextButtonClick(object element) { try { logger.Debug("Started account request and creating rsaKeys"); if (String.IsNullOrEmpty(email) || String.IsNullOrEmpty(masterPassword)) { // To - Do Change style of Dialog MessageBox.Show("Error retreiving account information"); return; } if (this.masterPassword != UserPassword) { // To - Do Change style of Dialog MessageBox.Show("Master password not matching"); return; } UserPassword = string.Empty; //Generate a public/private key pair /*RSA rsaBase = new RSA(); * rsaBase.GenerateKeys(1024, 65537, null, null); * string privateKeyPem = rsaBase.PrivateKeyAsPEM; * string publicKeyPem = rsaBase.PublicKeyAsPEM; * * logger.Debug("Call webAPI.RequestAccount"); * string publicKeyPem = rsaBase.PublicKeyAsPEM;*/ byte[] publicKeyPem = null; ProtectedDataBlock privateKeyPem = null; using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048)) { privateKeyPem = new ProtectedDataBlock(Encoding.UTF8.GetBytes(RSAKeyManagement.ExportPrivateKeyToPEM(rsa))); publicKeyPem = Encoding.UTF8.GetBytes(RSAKeyManagement.ExportPublicKeyToPEM(rsa)); } IPBWebAPI webAPI = resolver.GetInstanceOf <IPBWebAPI>(); dynamic accountResponse = webAPI.RequestAccount(new WEBApiJSON.AccountRequest() { email = email, language = "English", installation = pbData.InstallationUUID, public_key = Convert.ToBase64String(publicKeyPem) }); if (accountResponse == null) { // To - Do Change style of Dialog MessageBox.Show("Error in account registration"); return; } else { if (accountResponse.error != null) { //MessageBox.Show(accountResponse.error.details[0].ToString()); if (accountResponse.error.code == "400") { //try to register device dynamic deviceRegistrationResponse = webAPI.RegisterDevice(new WEBApiJSON.DeviceRegistrationRequest() { installation = pbData.InstallationUUID, nickname = Environment.MachineName, software_version = Assembly.GetExecutingAssembly().GetName().Version.ToString() }, email); if (deviceRegistrationResponse == null) { // To - Do Change style of Dialog MessageBox.Show("Error in device registration"); return; } else { if (deviceRegistrationResponse.error != null) { //MessageBox.Show(deviceRegistrationResponse.error.message.ToString()); if (deviceRegistrationResponse.error.code.ToString() == "403") { //send verification code for new device dynamic verificationRequestResponse = webAPI.RequestVerificationCode(email); Application.Current.Dispatcher.Invoke((Action) delegate { var verificationScreen = new VerificationRequired(resolver, email, masterPassword);// resolver.GetInstanceOf<VerificationRequired>(); Navigator.NavigationService.Navigate(verificationScreen); }); } return; } Application.Current.Dispatcher.Invoke((Action) delegate { Login login = resolver.GetInstanceOf <Login>(); login.EmailTextBox.Text = email; Navigator.NavigationService.Navigate(login); }); } } } } logger.Debug("Creating profile"); if (!pbData.CreateProfile(email, masterPassword)) { // To - Do Change style of Dialog MessageBox.Show("Error while creating secure database"); } pbData.AddUserInfo(new DTO.UserInfo() { Email = email, RSAPrivateKey = privateKeyPem, PublicKey = publicKeyPem }); logger.Debug("Performing initial sync"); PerformInitialSync(); SetDefaultSettings(pbData); inAppAnalyitics.Get <Events.AccountCreationFlow, AccountCreationFlowItem>().Log(new AccountCreationFlowItem(3, AccountCreationFlowSteps.ConfirmMP, string.Empty, MarketingActionType.Continue)); // Added dispatcher because background worker can't create new UI elements Application.Current.Dispatcher.Invoke((Action) delegate { var nextScreen = new SetupComplete(resolver);// resolver.GetInstanceOf<SetupComplete>(); Navigator.NavigationService.Navigate(nextScreen); }); } catch (Exception ex) { logger.Error(ex.Message); } }