Example #1
0
        private void ShowScanData(ref CxWSQueryVulnerabilityData[] scanData, ref long scanId, CxWebServiceClient client)
        {
            // Get url to scanned project result
            string savedFileName = string.Format("report{0}", Guid.NewGuid());
            long   id            = 0;
            CxWSResponseScanStatus scanStatus = client.ServiceClient.GetStatusOfSingleScan(_scan.LoginResult.SessionId, _scan.RunScanResult.ScanId);
            string ScanTaskId = scanStatus.ScanId.ToString();//after scan is finished the server replaces the scan id with task scan id

            scanData = PerspectiveHelper.GetScanResultsPaths(ScanTaskId, ref scanId);
            id       = scanId;
            LoginData.BindProject bindProject = _scan.LoginResult.AuthenticationData.BindedProjects.Find(project => project.BindedProjectId == CommonData.ProjectId &&
                                                                                                         project.ProjectName == CommonData.ProjectName &&
                                                                                                         project.RootPath == CommonData.ProjectRootPath);

            if (bindProject == null) // scaned for the first time
            {
                bindProject             = new LoginData.BindProject();
                bindProject.ProjectName = CommonData.ProjectName;
                bindProject.RootPath    = CommonData.ProjectRootPath;
                bindProject.IsBound     = true;
                _scan.LoginResult.AuthenticationData.BindedProjects.Add(bindProject);
            }
            if (!CommonData.IsProjectBound) // its new project
            {
                bindProject.BindedProjectId = scanStatus.ProjectId;
                CommonData.ProjectId        = scanStatus.ProjectId;
                CommonData.IsProjectPublic  = scanStatus.IsPublic;
                bindProject.IsPublic        = scanStatus.IsPublic;
                bindProject.IsBound         = true;
            }
            bindProject.SelectedScanId = id;
            bindProject.ScanReports    = new List <ScanReportInfo>();
            LoginHelper.Save(_scan.LoginResult.AuthenticationData);


            BackgroundWorkerHelper bgWork = new BackgroundWorkerHelper(delegate
            {
                CommonData.SelectedScanId = id;
                String path = PerspectiveHelper.GetScanXML(id);
                ScanReportInfo scanReportInfo         = new ScanReportInfo();
                scanReportInfo.Path                   = path;
                scanReportInfo.Id                     = id;
                LoginData.BindProject projectToUpdate = _scan.LoginResult.AuthenticationData.BindedProjects.Find(delegate(LoginData.BindProject bp)
                {
                    return(bp.BindedProjectId == CommonData.ProjectId);
                }
                                                                                                                 );

                projectToUpdate.ScanReports = new List <ScanReportInfo>();
                projectToUpdate.ScanReports.Add(scanReportInfo);

                LoginHelper.Save(_scan.LoginResult.AuthenticationData);
            });

            bgWork.DoWork();
        }
        /// <summary>
        /// Ask user to open perspective now
        /// </summary>
        /// <param name="login">user auth data</param>
        /// <returns></returns>
        internal static bool IsOpenNow(LoginData login)
        {
            OpenPercspectiveDialog dlg = new OpenPercspectiveDialog();
            DialogResult           r   = dlg.ShowDialog();

            if (dlg.RememberDecision)
            {
                login.IsOpenPerspective = (r == DialogResult.OK) ? CxViewerAction.Entities.Enum.SimpleDecision.Yes : Entities.Enum.SimpleDecision.No;
                LoginHelper.Save(login);
            }

            return(r == DialogResult.Yes);
        }
        static void BindSelectedProject(LoginResult loginResult, Entities.Project project)
        {
            CxWSResponseProjectsDisplayData cxWSResponseProjectsDisplayData = null;
            // show bind project form
            CxWebServiceClient client = null;
            bool isThrewError         = false;
            BackgroundWorkerHelper bg = new BackgroundWorkerHelper(delegate
            {
                try
                {
                    client = new CxWebServiceClient(loginResult.AuthenticationData);
                }
                catch (Exception e)
                {
                    Logger.Create().Error(e.ToString());
                    System.Windows.Forms.MessageBox.Show(e.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK);
                    isThrewError = true;
                    return;
                }

                if (client == null)
                {
                    System.Windows.Forms.MessageBox.Show("Cannot connect to server", "Error", System.Windows.Forms.MessageBoxButtons.OK);
                    isThrewError = true;
                    return;
                }
                cxWSResponseProjectsDisplayData = client.ServiceClient.GetProjectsDisplayData(loginResult.SessionId);
            }, loginResult.AuthenticationData.ReconnectInterval * 1000, loginResult.AuthenticationData.ReconnectCount);

            //Show wait dialog and perform server request in different thread to safe UI responsibility
            if (!bg.DoWork(RETRIEVE_RESULTS_LOADING_TEXT))
            {
                return;
            }

            if (cxWSResponseProjectsDisplayData == null || !cxWSResponseProjectsDisplayData.IsSuccesfull || isThrewError)
            {
                return;
            }

            var bindProjectEntity = new BindProjectEntity {
                CxProjectsDisplayData = cxWSResponseProjectsDisplayData
            };

            #region show Select Project window

            //            if (projectID < 0)
            //            {
            if (_dispatcher == null)
            {
                _dispatcher = ServiceLocators.ServiceLocator.GetDispatcher();
            }

            if (_dispatcher != null)
            {
                _dispatcher.Dispatch(bindProjectEntity);
            }


            if (bindProjectEntity.CommandResult == System.Windows.Forms.DialogResult.Cancel)
            {
                _canceled = true;
                return;
            }
            //            }

            #endregion

            long selectedProjectId = 0;
            if (client != null && ((bindProjectEntity.SelectedProject != null && bindProjectEntity.CommandResult == System.Windows.Forms.DialogResult.OK)))
            {
                Logger.Create().Info("Loading project id: " + bindProjectEntity.SelectedProject.projectID);
                bg.DoWorkFunc = delegate(object obj)
                {
                    selectedProjectId = bindProjectEntity.SelectedProject.projectID;
                    if (loginResult.AuthenticationData.BindedProjects == null)
                    {
                        loginResult.AuthenticationData.BindedProjects = new List <LoginData.BindProject>();
                    }

                    LoginData.BindProject bindProject = loginResult.AuthenticationData.BindedProjects.Find(delegate(LoginData.BindProject bp)
                    {
                        return(bp.ProjectName == project.ProjectName && bp.RootPath == project.RootPath);
                    }
                                                                                                           );
                    bool isNewProject = true;
                    if (bindProject != null)
                    {
                        bindProject.BindedProjectId = selectedProjectId;
                        bindProject.ScanReports     = new List <ScanReportInfo>();
                        bindProject.IsBound         = true;
                        bindProject.SelectedScanId  = 0;
                        bindProject.IsPublic        = bindProjectEntity.isPublic;
                        isNewProject = false;
                    }
                    else
                    {
                        bindProject = new LoginData.BindProject()
                        {
                            BindedProjectId = selectedProjectId,
                            RootPath        = project.RootPath,
                            ProjectName     = project.ProjectName,
                            ScanReports     = new List <ScanReportInfo>(),
                            IsPublic        = bindProjectEntity.isPublic,
                            IsBound         = true,
                        };
                        isNewProject = true;
                    }


                    CxWSResponseScansDisplayData cxWSResponseScansDisplayData = PerspectiveHelper.GetScansDisplayData(selectedProjectId);
                    if (cxWSResponseScansDisplayData.ScanList.Length == 0)
                    {
                        // show error about 0 scan list
                        System.Windows.Forms.MessageBox.Show("The chosen project doesn't contain scans", "Error", System.Windows.Forms.MessageBoxButtons.OK);
                        isThrewError = true;
                        return;
                    }

                    foreach (ScanDisplayData item in cxWSResponseScansDisplayData.ScanList)
                    {
                        // Add relation to scanned project and scan report
                        ScanReportInfo scanReportInfo = new ScanReportInfo {
                            Id = item.ScanID
                        };
                        string minutes = item.QueuedDateTime.Minute.ToString().Length > 1 ? item.QueuedDateTime.Minute.ToString() : "0" + item.QueuedDateTime.Minute;

                        scanReportInfo.Name = string.Format("{0}/{1}/{2} {3}:{4}", item.QueuedDateTime.Month,
                                                            item.QueuedDateTime.Day,
                                                            item.QueuedDateTime.Year,
                                                            item.QueuedDateTime.Hour,
                                                            minutes);

                        bindProject.AddScanReport(scanReportInfo);
                    }

                    if (bindProject.ScanReports.Count > 0)
                    {
                        CommonData.SelectedScanId  = bindProject.ScanReports[0].Id;
                        bindProject.SelectedScanId = CommonData.SelectedScanId;
                    }

                    if (isNewProject)
                    {
                        loginResult.AuthenticationData.BindedProjects.Add(bindProject);
                    }
                };
                bool bCancel = !bg.DoWork("Downloading project data...");

                if (!bCancel && !isThrewError)
                {
                    CommonData.ProjectId = selectedProjectId;
                    LoginHelper.Save(loginResult.AuthenticationData);
                }
            }
        }
Example #4
0
        private RunScanResult RunScan(BackgroundWorkerHelper bg, CxWebServiceClient client, ConfigurationResult configuration, byte[] zippedProject)
        {
            RunScanResult runScanResult = null;

            bg.DoWorkFunc = delegate(object obj)
            {
                ProjectSettings projectSettings = new ProjectSettings();
                projectSettings.AssociatedGroupID   = _scan.UploadSettings.Team.ToString();
                projectSettings.PresetID            = _scan.UploadSettings.Preset;
                projectSettings.ProjectName         = _scan.UploadSettings.ProjectName;
                projectSettings.ScanConfigurationID = configuration.FirstConfigurationKey;
                LocalCodeContainer localCodeContainer = new LocalCodeContainer();
                localCodeContainer.FileName   = "zipCxViewer";
                localCodeContainer.ZippedFile = zippedProject;
                try
                {
                    CxWSResponseRunID cxWSResponseRunID;
                    if (_scan.IsIncremental)
                    {
                        cxWSResponseRunID = client.ServiceClient.RunIncrementalScan(
                            _scan.LoginResult.SessionId,
                            projectSettings,
                            localCodeContainer
                            , _scan.UploadSettings.IsPublic, _scan.IsPublic
                            );
                    }
                    else
                    {
                        cxWSResponseRunID = client.ServiceClient.CreateAndRunProject(
                            _scan.LoginResult.SessionId,
                            projectSettings,
                            localCodeContainer
                            , _scan.UploadSettings.IsPublic, _scan.IsPublic
                            );
                    }


                    runScanResult = new RunScanResult();
                    runScanResult.IsSuccesfull = cxWSResponseRunID.IsSuccesfull;
                    runScanResult.ScanId       = cxWSResponseRunID.RunId;//Server actually returns the scanId which is a long number (and not the runID)
                    _scan.LoginResult.AuthenticationData.UnboundRunID = cxWSResponseRunID.RunId;
                    runScanResult.ProjectId = cxWSResponseRunID.ProjectID;
                    _scan.RunScanResult     = runScanResult;
                    if (!cxWSResponseRunID.IsSuccesfull)
                    {
                        TopMostMessageBox.Show(string.Format("Scan Error: {0}", cxWSResponseRunID.ErrorMessage), "Scanning Error", MessageBoxButtons.OK);
                    }
                    else
                    {
                        LoginHelper.Save(_scan.LoginResult.AuthenticationData);
                    }
                }
                catch (Exception err)
                {
                    Logger.Create().Error(err.ToString());

                    TopMostMessageBox.Show(string.Format("Scan Error: {0}", err.Message), "Scanning Error", MessageBoxButtons.OK);
                }
            };

            if (!bg.DoWork("Upload project zipped source for scanning..."))
            {
                return(null);
            }

            return(runScanResult);
        }
Example #5
0
        private RunScanResult RunBoundedProjectScan(Scan scan, BackgroundWorkerHelper bg, CxWebServiceClient client, byte[] zippedProject)
        {
            RunScanResult runScanResult = null;

            bg.DoWorkFunc = delegate(object obj)
            {
                ProjectSettings projectSettings = new ProjectSettings();
                projectSettings.projectID = CommonData.ProjectId;
                LocalCodeContainer localCodeContainer = new LocalCodeContainer();
                localCodeContainer.FileName   = "zipCxViewer";
                localCodeContainer.ZippedFile = zippedProject;
                try
                {
                    CxWSResponseRunID cxWSResponseRunID;

                    if (_scan.IsIncremental)
                    {
                        cxWSResponseRunID = client.ServiceClient.RunIncrementalScan(
                            scan.LoginResult.SessionId,
                            projectSettings,
                            localCodeContainer
                            , CommonData.IsProjectPublic,
                            scan.IsPublic
                            );
                    }
                    else
                    {
                        cxWSResponseRunID = client.ServiceClient.RunScanAndAddToProject(
                            scan.LoginResult.SessionId,
                            projectSettings,
                            localCodeContainer
                            , CommonData.IsProjectPublic,
                            scan.IsPublic
                            );
                    }

                    runScanResult = new RunScanResult();                  // RunScanResult.FromXml(scanZipedSource);
                    runScanResult.IsSuccesfull = cxWSResponseRunID.IsSuccesfull;
                    runScanResult.ScanId       = cxWSResponseRunID.RunId; //Server actually returns the scanId which is a long number (and not the runID)
                    scan.LoginResult.AuthenticationData.UnboundRunID = cxWSResponseRunID.RunId;
                    CommonData.ProjectId = cxWSResponseRunID.ProjectID;
                    _scan.RunScanResult  = runScanResult;
                    if (!cxWSResponseRunID.IsSuccesfull)
                    {
                        TopMostMessageBox.Show(string.Format("Scan Error: {0}", cxWSResponseRunID.ErrorMessage), "Scanning Error", MessageBoxButtons.OK);
                    }
                    else
                    {
                        LoginHelper.Save(scan.LoginResult.AuthenticationData);
                    }
                }
                catch (Exception err)
                {
                    Logger.Create().Error(err.ToString());
                    TopMostMessageBox.Show(string.Format("Scan Error: {0}", err.Message), "Scanning Error", MessageBoxButtons.OK);
                }
            };
            if (!bg.DoWork("Upload project zipped source for scanning..."))
            {
                return(null);
            }

            return(runScanResult);
        }
        /// <summary>
        /// Execute 'Previous Result' command
        /// </summary>
        public static void DoPrevResult()
        {
            Logger.Create().Debug("DoPrevResult in");
            // Get logged user credentials and project relation data
            LoginData login = Helpers.LoginHelper.Load(0);

            CxWSQueryVulnerabilityData[] perspective = null;
            login.IsOpenPerspective = Entities.Enum.SimpleDecision.Yes;

            LoginData.BindProject bindProject = login.BindedProjects.Find(delegate(LoginData.BindProject bp)
            {
                return(bp.BindedProjectId == CommonData.ProjectId &&
                       bp.ProjectName == CommonData.ProjectName &&
                       bp.RootPath == CommonData.ProjectRootPath);
            }
                                                                          );

            if (bindProject != null && bindProject.ScanReports != null && bindProject.ScanReports.Count > 0)
            {
                ScanReportInfo tmp = bindProject.ScanReports.Find(delegate(ScanReportInfo sri)
                {
                    return(sri.Id == CommonData.SelectedScanId);
                }
                                                                  );
                if (tmp == null || tmp.Id == 0)
                {
                    tmp = bindProject.ScanReports[0];
                    CommonData.SelectedScanId = tmp.Id;
                }

                perspective = GetScanResultsPath(tmp.Id);
                bindProject.SelectedScanId = tmp.Id;
                if (!string.IsNullOrEmpty(tmp.Path))
                {
                    StorageHelper.Delete(tmp.Path);
                }

                BackgroundWorkerHelper bgWork = new BackgroundWorkerHelper(delegate
                {
                    tmp.Path = PerspectiveHelper.GetScanXML(CommonData.SelectedScanId);

                    LoginHelper.Save(login);
                });

                bgWork.DoWork();



                Dictionary <string, long> list = new Dictionary <string, long>();
                foreach (ScanReportInfo item in bindProject.ScanReports)
                {
                    if (!list.ContainsKey(item.Name))
                    {
                        list.Add(item.Name, item.Id);
                    }
                }
                CommonActionsInstance.getInstance().ReportPersepectiveView.SetScanList(list, tmp.Id);

                if (perspective != null)
                {
                    ShowStored(perspective, login, tmp.Id);
                }
            }
        }