private void ButtonAddCertificate_Click(object sender, System.EventArgs e) { bool passed = false; bool displayPassword = true; System.String ImprtKeyPassword = ""; if (this._show_credentials) { this.DialogAddCertificate.Title = "Select Credentials File to Import"; if (this.DialogAddCertificate.ShowDialog(this) == DialogResult.OK) { String ext = this.DialogAddCertificate.FileName.Substring(this.DialogAddCertificate.FileName.LastIndexOf(".")); if ((ext == ".cer")) { throw new System.ApplicationException("Not a valid credential to import"); } while (!passed) { try { this._cred_handling.ImportCredentialFromOtherFile(this.DialogAddCertificate.FileName, ImprtKeyPassword); passed = true; displayPassword = false; } catch (Exception excep) { if (excep.GetType().FullName == "Wrappers.Exceptions.PasswordExpection") { passed = false; PassWordForm passWordForm = new PassWordForm(this._session, displayPassword); displayPassword = false; DialogResult res = passWordForm.ShowDialog(); if (res != DialogResult.OK) { passed = true; displayPassword = false; } else /* when result is ok */ { ImprtKeyPassword = passWordForm.passWordEntered; } } else { MessageBox.Show(excep.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); passed = true; } // MessageBox.Show(excep.Message); } } // Touch. this.DataGridCertificates.DataSource = null; _ExceptionText = ""; _KeysInformation = ConvertToKeyInformationArrayList(_cred_handling.Credentials); DataGridCertificates.DataSource = _KeysInformation; Debug.Assert(_ExceptionText.Length == 0, "Following errors occured while filling datagrid:\n\n" + _ExceptionText); this.ButtonRemoveCertificate.Enabled = true; this.file_changed = true; } } else { this.DialogAddCertificate.Title = "Select Certificate File to Import"; if (this.DialogAddCertificate.ShowDialog(this) == DialogResult.OK) { try { String ext = this.DialogAddCertificate.FileName.Substring(this.DialogAddCertificate.FileName.LastIndexOf(".")); if (ext == ".pfx") { throw new System.ApplicationException("Not a valid certificate file "); } this._cert_handling.ImportCertificateFromOtherFile(this.DialogAddCertificate.FileName, ""); } catch (Exception Message) { MessageBox.Show(Message.Message); } // Touch. this.DataGridCertificates.DataSource = null; _ExceptionText = ""; _KeysInformation = ConvertToKeyInformationArrayList(_cert_handling.Certificates); DataGridCertificates.DataSource = _KeysInformation; Debug.Assert(_ExceptionText.Length == 0, "Following errors occured while filling datagrid:\n\n" + _ExceptionText); this.ButtonRemoveCertificate.Enabled = true; this.file_changed = true; } } }
private void ButtonAddCertificate_Click(object sender, System.EventArgs e) { bool passed = false; bool displayPassword = true; System.String ImprtKeyPassword = ""; if (this._show_credentials) { this.DialogAddCertificate.Title = "Select Credentials File to Import"; if (this.DialogAddCertificate.ShowDialog (this) == DialogResult.OK) { String ext = this.DialogAddCertificate.FileName.Substring(this.DialogAddCertificate.FileName.LastIndexOf(".")); if ((ext == ".cer")) throw new System.ApplicationException("Not a valid credential to import"); while (!passed) { try { this._cred_handling.ImportCredentialFromOtherFile(this.DialogAddCertificate.FileName, ImprtKeyPassword); passed = true; displayPassword = false; } catch (Exception excep) { if (excep.GetType().FullName == "Wrappers.Exceptions.PasswordExpection") { passed = false; PassWordForm passWordForm = new PassWordForm( this._session, displayPassword); displayPassword = false; DialogResult res = passWordForm.ShowDialog(); if ( res != DialogResult.OK) { passed = true; displayPassword = false; } else /* when result is ok */ { ImprtKeyPassword = passWordForm.passWordEntered; } } else { MessageBox.Show(excep.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); passed = true; } // MessageBox.Show(excep.Message); } } // Touch. this.DataGridCertificates.DataSource = null; _ExceptionText = ""; _KeysInformation = ConvertToKeyInformationArrayList(_cred_handling.Credentials); DataGridCertificates.DataSource = _KeysInformation; Debug.Assert(_ExceptionText.Length == 0, "Following errors occured while filling datagrid:\n\n" + _ExceptionText); this.ButtonRemoveCertificate.Enabled = true; this.file_changed = true; } } else { this.DialogAddCertificate.Title = "Select Certificate File to Import"; if (this.DialogAddCertificate.ShowDialog (this) == DialogResult.OK) { try { String ext = this.DialogAddCertificate.FileName.Substring(this.DialogAddCertificate.FileName.LastIndexOf(".")); if (ext == ".pfx") throw new System.ApplicationException("Not a valid certificate file "); this._cert_handling.ImportCertificateFromOtherFile (this.DialogAddCertificate.FileName, ""); } catch (Exception Message) { MessageBox.Show(Message.Message); } // Touch. this.DataGridCertificates.DataSource = null; _ExceptionText = ""; _KeysInformation = ConvertToKeyInformationArrayList(_cert_handling.Certificates); DataGridCertificates.DataSource = _KeysInformation; Debug.Assert(_ExceptionText.Length == 0, "Following errors occured while filling datagrid:\n\n" + _ExceptionText); this.ButtonRemoveCertificate.Enabled = true; this.file_changed = true; } } }
private void ButtonViewCredentials_Click(object sender, System.EventArgs e) { bool passed = false; bool displayPassword = true; DialogResult result = DialogResult.None; (GetSelectedSessionNew().Implementation as Dvtk.Sessions.ISecure).SecuritySettings.TlsPassword = "******"; while(!passed) { try { CredentialsCertificatesForm cred_cert_form = null; cred_cert_form = new CredentialsCertificatesForm (GetSelectedSessionNew(), true); result = cred_cert_form.ShowDialog(); passed = true; displayPassword = false; } catch (Exception theException) { if (theException.GetType().FullName == "Wrappers.Exceptions.PasswordExpection") { passed = false; PassWordForm passWordForm = new PassWordForm(GetSelectedSessionNew(), displayPassword); displayPassword = false; if (passWordForm.ShowDialog()!= DialogResult.OK) { passed = true; displayPassword = false; } } else { MessageBox.Show(theException.Message ,"Warning", MessageBoxButtons.OK,MessageBoxIcon.Warning); passed = true; } } } if (result == DialogResult.OK) { (GetSelectedSessionNew().Implementation as Dvtk.Sessions.ISecure).SecuritySettings.TlsPassword = "******"; SessionChange theSessionChange = new SessionChange(GetSelectedSessionNew(), SessionChange.SessionChangeSubTypEnum.OTHER); Notify(theSessionChange); } }
/// <summary> /// This method performs the validation of a media direcetory /// </summary> /// <param name="MediaDirectoryInfo"></param> public void Execute(DirectoryInfo MediaDirectoryInfo) { _ISMediaDirectoryValidation = true; string errorTextFromIsFileInUse; DvtkApplicationLayer.Session session = GetSession(); session.IsExecute = true; if (!Directory.Exists(session.ResultsRootDirectory)) { MessageBox.Show("The results directory specified for this session is not valid.\nExecution is cancelled.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); session.IsExecute = false; } else if (IsFileInUse(GetSelectedTag(), out errorTextFromIsFileInUse)) { string firstPartWarningText = ""; if (GetSelectedTag() is Script) { firstPartWarningText = "Unable to execute script.\n\n"; } else if (GetSelectedTag() is Emulator) { firstPartWarningText = "Unable to execute emulator.\n\n"; } MessageBox.Show(firstPartWarningText + errorTextFromIsFileInUse + "\n\n(hint: change the session ID to obtain a different results file name)", "Warning"); } else { _TagThatIsBeingExecuted = GetSelectedTag(); /* if session is an emulator session or a script session . * Since media session do not require any connection to have * secured connection*/ if ((_TagThatIsBeingExecuted is DvtkApplicationLayer.Emulator) || (_TagThatIsBeingExecuted is DvtkApplicationLayer.DicomScript)) { bool bDisplayPwdMsg = false; bool bPwdMsg = true; int certIndex = 0; int credIndex = 0; Dvtk.Sessions.ISecuritySettings theISecuritySettings = null; theISecuritySettings = (GetSelectedSessionNew().Implementation as Dvtk.Sessions.ISecure).SecuritySettings; /* If the session selected has security settings enabled */ if (theISecuritySettings.SecureSocketsEnabled == true) { certIndex = theISecuritySettings.CertificateFileName.LastIndexOf("\\"); credIndex = theISecuritySettings.CredentialsFileName.LastIndexOf("\\"); /* if Certificate file name not specified */ if ((certIndex + 1) == theISecuritySettings.CertificateFileName.Length) { MessageBox.Show("Session cannot be executed as the certificate name is not specified "); _TagThatIsBeingExecuted = null; bDisplayPwdMsg = true; } /* if Certificate file donot exist */ else if (!File.Exists(theISecuritySettings.CertificateFileName)) { MessageBox.Show("Certificate File does not exist "); _TagThatIsBeingExecuted = null; bDisplayPwdMsg = true; } /* if Credential file name not specified */ else if ((credIndex + 1) == theISecuritySettings.CredentialsFileName.Length) { MessageBox.Show("Session can not be executed as the credential name is not specified "); _TagThatIsBeingExecuted = null; bDisplayPwdMsg = true; } /* If credential file donot exist */ else if (!File.Exists(theISecuritySettings.CredentialsFileName)) { MessageBox.Show("Credential File do not exist "); _TagThatIsBeingExecuted = null; bDisplayPwdMsg = true; } (GetSelectedSessionNew().Implementation as Dvtk.Sessions.ISecure).SecuritySettings.TlsPassword = "******"; while (!bDisplayPwdMsg) { try { (GetSelectedSessionNew().Implementation as Dvtk.Sessions.ISecure).CreateSecurityCredentialHandler(); bDisplayPwdMsg = true; (GetSelectedSessionNew().Implementation as Dvtk.Sessions.ISecure).DisposeSecurityCredentialHandler(); } catch (Exception theException) { if (theException.GetType().FullName == "Wrappers.Exceptions.PasswordExpection") { bDisplayPwdMsg = false; PassWordForm passWordForm = new PassWordForm(GetSelectedSessionNew(), bPwdMsg); bPwdMsg = false; if (passWordForm.ShowDialog() != DialogResult.OK) { bDisplayPwdMsg = true; bPwdMsg = false; _TagThatIsBeingExecuted = null; } } else { MessageBox.Show(theException.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); bDisplayPwdMsg = true; _TagThatIsBeingExecuted = null; } } } } } if (_TagThatIsBeingExecuted != null) { // Update the UI. StartExecution theStartExecution = new StartExecution(GetSelectedUserNode()); Notify(theStartExecution); // If this is a script file tag, start execution of the script. if (_TagThatIsBeingExecuted is Script) { ExecuteSelectedScript(); } // If this is a emulator tag, start execution of the correct emulator. if (_TagThatIsBeingExecuted is Emulator) { ExecuteSelectedEmulator(); } // If this is a media session tag, start execution of the media validator. if (_TagThatIsBeingExecuted is DvtkApplicationLayer.MediaSession) { ExecuteMediaDirectoryValidation(MediaDirectoryInfo); } else { session.IsExecute = false; // Update the UI. EndExecution theEndExecution = new EndExecution(GetSelectedTag()); Notify(theEndExecution); } } } }