/// <summary> /// Event handler for OK button click event /// </summary> private void btnOk_Click(object sender, System.EventArgs e) { // Check for passphrase /* If passphrase is valid try setting the passphrase. * if successful try storing on local place * if success close dialog. * else show dialog again.. * */ System.Resources.ResourceManager resManager = new System.Resources.ResourceManager(typeof(Connecting)); if (this.Passphrase.Text == this.RetypePassphrase.Text) { string publicKey = null; string ragent = null; if (this.RecoveryAgentCombo.SelectedItem != null && (string)this.RecoveryAgentCombo.SelectedItem != TrayApp.Properties.Resources.serverDefaultRA) { // Show the certificate..... byte[] CertificateObj = this.simws.GetRACertificateOnClient(this.DomainID, (string)this.RecoveryAgentCombo.SelectedItem); System.Security.Cryptography.X509Certificates.X509Certificate cert = new System.Security.Cryptography.X509Certificates.X509Certificate(CertificateObj); // MyMessageBox mmb = new MyMessageBox( "Verify Certificate", "Verify Certificate", cert.ToString(true), MyMessageBoxButtons.YesNo, MyMessageBoxIcon.Question, MyMessageBoxDefaultButton.Button2 ); MyMessageBox mmb = new MyMessageBox(string.Format(resManager.GetString("verifyCert"), (string)this.RecoveryAgentCombo.SelectedItem), resManager.GetString("verifyCertTitle"), cert.ToString(true), MyMessageBoxButtons.YesNo, MyMessageBoxIcon.Question, MyMessageBoxDefaultButton.Button2); DialogResult messageDialogResult = mmb.ShowDialog(); mmb.Dispose(); mmb.Close(); if (messageDialogResult != DialogResult.Yes) { return; } else { ragent = (string)this.RecoveryAgentCombo.SelectedItem; publicKey = Convert.ToBase64String(cert.GetPublicKey()); } //return; } /*else // If recovery agent is not selected... * { * MyMessageBox mmb = new MyMessageBox( resManager.GetString("NoCertWarning"), resManager.GetString("NoCertTitle"), "", MyMessageBoxButtons.YesNo, MyMessageBoxIcon.Question, MyMessageBoxDefaultButton.Button2); * DialogResult messageDialogResult = mmb.ShowDialog(); * mmb.Dispose(); * mmb.Close(); * if( messageDialogResult != DialogResult.Yes ) * return; * }*/ else { ragent = "DEFAULT"; DomainInformation domainInfo = (DomainInformation)this.simws.GetDomainInformation(this.DomainID); string memberUID = domainInfo.MemberUserID; try { publicKey = this.ifws.GetDefaultServerPublicKey(this.DomainID, memberUID); } catch (Exception) { Novell.iFolderCom.MyMessageBox mmb = new MyMessageBox(Resource.GetString("PassStoreErr") /*"Unable to set the passphrase"*/, resourceManager.GetString("$this.Text") /*"Error setting the passphrase"*/, "" /*Resource.GetString("TryAgain")*//*"Please try again"*/, MyMessageBoxButtons.OK, MyMessageBoxIcon.Error); mmb.ShowDialog(); mmb.Dispose(); return; } } Status passPhraseStatus = null; try { passPhraseStatus = simws.SetPassPhrase(DomainID, this.Passphrase.Text, ragent, publicKey); } catch (Exception ex) { //MessageBox.Show("Unable to set Passphrase. "+ ex.Message); MessageBox.Show(Resource.GetString("IsPassphraseSetException") + ex.Message); } if (passPhraseStatus.statusCode == StatusCodes.Success) { // Validating Passphrase //passPhraseStatus = simws.ValidatePassPhrase( DomainID, PadString(this.Passphrase.Text, 16)); //if(passPhraseStatus.statusCode != StatusCodes.Success) // MessageBox.Show("Passphrase not validated"); simws.StorePassPhrase(DomainID, this.Passphrase.Text, CredentialType.Basic, this.savePassphrase.Checked); //string passphr = simws.GetPassPhrase(DomainID); //MessageBox.Show("Passphrase is set & stored", passphr, MessageBoxButtons.OK); //this.status= simws.IsPassPhraseSet(DomainID); //if( status == true) status = true; Novell.iFolderCom.MyMessageBox mmb = new MyMessageBox(Resource.GetString("SetPassphraseSuccess") /*"Successfully set the passphrase"*/, resourceManager.GetString("$this.Text"), "", MyMessageBoxButtons.OK, MyMessageBoxIcon.Information); mmb.ShowDialog(); mmb.Dispose(); this.Dispose(); this.Close(); } else { // Unable to set the passphrase status = false; Novell.iFolderCom.MyMessageBox mmb = new MyMessageBox(Resource.GetString("PassStoreErr") /*"Unable to set the passphrase"*/, resourceManager.GetString("$this.Text") /*"Error setting the passphrase"*/, "" /*Resource.GetString("TryAgain")*//*"Please try again"*/, MyMessageBoxButtons.OK, MyMessageBoxIcon.Error); mmb.ShowDialog(); mmb.Dispose(); } } else { status = false; } }
private static bool SetPassPhrase( EnterPassPhraseDialog epd, string DomainID, string publicKey, SimiasWebService simws ) { bool status; Status passPhraseStatus = null; if(epd.RecoveryAgent != null && epd.RecoveryAgent != Util.GS("Server_Default")) passPhraseStatus = simws.SetPassPhrase( DomainID, epd.PassPhrase, epd.RecoveryAgent, publicKey); else passPhraseStatus = simws.SetPassPhrase( DomainID, epd.PassPhrase, "DEFAULT", publicKey); if(passPhraseStatus.statusCode == StatusCodes.Success) { status = true; simws.StorePassPhrase( DomainID, epd.PassPhrase, CredentialType.Basic, epd.ShouldSavePassPhrase); } else { status = false; iFolderMsgDialog dialog = new iFolderMsgDialog( null, iFolderMsgDialog.DialogType.Error, iFolderMsgDialog.ButtonSet.None, Util.GS("Error setting the PassPhrase"), Util.GS("Unable to set the passphrase"), Util.GS("Please try again")); dialog.Run(); dialog.Hide(); dialog.Destroy(); dialog = null; } return status; }
///<summary> /// Display enter passphrase dialog ///</summary> ///<param name="DomainID">ID of the domain</param> ///<param name="simws">Reference to simias web service</param> ///<returns>Status else false</returns> private static bool ShowEnterPassPhraseDialog(string DomainID, SimiasWebService simws) { bool status = false; int result; EnterPassPhraseDialog epd = new EnterPassPhraseDialog(DomainID, simws); try { do { result = epd.Run(); epd.Hide(); if (result == (int)ResponseType.Cancel || result == (int)ResponseType.DeleteEvent) { break; } if (epd.PassPhrase != epd.RetypedPassPhrase) { Console.WriteLine("PassPhrases do not match"); // show an error message iFolderMsgDialog dialog = new iFolderMsgDialog( null, iFolderMsgDialog.DialogType.Error, iFolderMsgDialog.ButtonSet.None, Util.GS("PassPhrase mismatch"), Util.GS("The PassPhrase and retyped Passphrase are not same"), Util.GS("Enter the passphrase again")); dialog.Run(); dialog.Hide(); dialog.Destroy(); dialog = null; } else { break; } }while(result != (int)ResponseType.Cancel); if (result == (int)ResponseType.Cancel || result == (int)ResponseType.DeleteEvent) { status = false; simws.StorePassPhrase(DomainID, "", CredentialType.None, false); } else if (epd.PassPhrase == epd.RetypedPassPhrase) { // Check the recovery agent string publicKey = ""; Status passPhraseStatus = simws.SetPassPhrase(DomainID, epd.PassPhrase, epd.RecoveryAgent, publicKey); if (passPhraseStatus.statusCode == StatusCodes.Success) { status = true; simws.StorePassPhrase(DomainID, epd.PassPhrase, CredentialType.Basic, epd.ShouldSavePassPhrase); } else { // error setting the passphrase status = false; iFolderMsgDialog dialog = new iFolderMsgDialog( null, iFolderMsgDialog.DialogType.Error, iFolderMsgDialog.ButtonSet.None, Util.GS("Error setting the Passphrase"), Util.GS("Unable to set the passphrase"), Util.GS("Try again")); dialog.Run(); dialog.Hide(); dialog.Destroy(); dialog = null; } } } catch (Exception ex) { iFolderMsgDialog dialog = new iFolderMsgDialog( null, iFolderMsgDialog.DialogType.Error, iFolderMsgDialog.ButtonSet.None, Util.GS("Unable to set the passphrase"), Util.GS(ex.Message), Util.GS("Please enter the passphrase again")); dialog.Run(); dialog.Hide(); dialog.Destroy(); dialog = null; return(false); } return(status); }