public static ProjectScanStatuses EditRemark(long resultId, long pathId, string remark)
        {
            LoginData     loginData     = LoginHelper.LoadSaved();
            OidcLoginData oidcLoginData = OidcLoginData.GetOidcLoginDataInstance();
            LoginResult   loginResult   = new LoginResult();
            bool          cancelPressed = false;

            if (oidcLoginData.AccessToken == null)
            {
                //Execute login
                loginResult = LoginHelper.DoLoginWithoutForm(out cancelPressed, false);
                if (!loginResult.IsSuccesfull)
                {
                    loginResult = LoginHelper.DoLogin(out cancelPressed);
                }

                if (loginResult.IsSuccesfull)
                {
                    return(EditRemark(loginResult, resultId, pathId, remark));
                }
                else if (!cancelPressed)
                {
                    TopMostMessageBox.Show("Unable to connect to server or user creadentials are invalid. Please verify data", "Log in problem");
                    return(ProjectScanStatuses.Error);
                }
            }
            else
            {
                loginResult.AuthenticationData = loginData;
                loginResult.IsSuccesfull       = true;
            }

            return(ProjectScanStatuses.CanceledByUser);
        }
Esempio n. 2
0
        internal static ProjectScanStatuses BindProject(Entities.Project project)
        {
            Logger.Create().Debug("BindProjectByType in");
            ProjectScanStatuses status = ProjectScanStatuses.CanceledByUser;

            try
            {
                status = LoginAndBindSelectedProject(project);
                if (status == ProjectScanStatuses.Success)
                {
                    ShowResultLogic showResultLogic = new ShowResultLogic();
                    showResultLogic.Act();

                    status = ProjectScanStatuses.Success;
                }
                else if (status == ProjectScanStatuses.CanceledByUser)
                {
                    //Do nothing...
                }
                else
                {
                    TopMostMessageBox.Show("Unable to retrieve results.", "Error", System.Windows.Forms.MessageBoxButtons.OK);
                }

                CommonActionsInstance.getInstance().ClearScanProgressView();

                CommonActionsInstance.getInstance().CloseScanProgressView();
            }
            catch (Exception err)
            {
                Logger.Create().Error(err);
            }
            return(status);
        }
 internal static void ShowLoginErrorMessage(LoginResult loginResult)
 {
     if (loginResult.LoginResultType == LoginResultType.UnknownServerName)
     {
         TopMostMessageBox.Show(Constants.ERR_UNKNOWN_SERVER, "Verify authority", MessageBoxButtons.OK);
     }
     else
     {
         TopMostMessageBox.Show(Constants.ERR_UNKNOWN_USER_PASSWORD, "Verify authority", MessageBoxButtons.OK);
     }
 }
Esempio n. 4
0
        private bool SetScanPrivacy()
        {
            bool         isPublic = false;
            DialogResult result   = TopMostMessageBox.Show("Make scan results visible to other users", "Results visibility", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                isPublic = true;
            }

            return(isPublic);
        }
Esempio n. 5
0
        private byte[] ZipProject(Scan scan, Project project, BackgroundWorkerHelper bg)
        {
            byte[] zippedProject = null;
            bg.DoWorkFunc = delegate(object obj)
            {
                string error = string.Empty;
                zippedProject = ZipHelper.Compress(project, scan.LoginResult.AuthenticationData.ExcludeFileExt, scan.LoginResult.AuthenticationData.ExcludeFolder, scan.LoginResult.AuthenticationData.MaxZipFileSize * 1048576, out error);
                if (zippedProject == null)
                {
                    TopMostMessageBox.Show(string.Format("Zip Error: {0}", error), "Zip Error", MessageBoxButtons.OK);
                }
            }; //Convert mb to byte
            bg.DoWork("Zip project before sending...");

            return(zippedProject);
        }
Esempio n. 6
0
        static ProjectScanStatuses LoginAndBindSelectedProject(Entities.Project project)
        {
            OidcLoginData oidcLoginData = OidcLoginData.GetOidcLoginDataInstance();
            LoginData     loginData     = LoginHelper.LoadSaved();
            LoginResult   loginResult   = new LoginResult();
            bool          cancelPressed = false;

            if (oidcLoginData.AccessToken == null)
            {
                //Execute login
                loginResult = LoginHelper.DoLoginWithoutForm(out cancelPressed, false);
                if (!loginResult.IsSuccesfull)
                {
                    loginResult = LoginHelper.DoLogin(out cancelPressed);
                }
            }
            else
            {
                loginResult.AuthenticationData = loginData;
                loginResult.IsSuccesfull       = true;
            }

            if (loginResult.IsSuccesfull)
            {
                _canceled = false;
                BindSelectedProject(loginResult, project);
                if (!_canceled)
                {
                    return(ProjectScanStatuses.Success);
                }
                else
                {
                    return(ProjectScanStatuses.CanceledByUser);
                }
            }
            else if (!cancelPressed)
            {
                TopMostMessageBox.Show("Unable to connect to server.", "Log in problem");
                return(ProjectScanStatuses.Error);
            }

            return(ProjectScanStatuses.CanceledByUser);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        private StatusScanResult UpdateScanStatus(ref bool bCancel, bool backgroundMode, IScanView view, BackgroundWorkerHelper bg, CxWebServiceClient client, ref bool isIISStoped)
        {
            // Get current scan status
            CxWSResponseScanStatus cxWSResponseScanStatus = null;
            StatusScanResult       statusScan             = null;

            bg.DoWorkFunc = delegate(object obj)
            {
                cxWSResponseScanStatus         = client.ServiceClient.GetStatusOfSingleScan(_scan.LoginResult.SessionId, _scan.RunScanResult.ScanId);
                statusScan                     = new StatusScanResult();
                statusScan.CurrentStage        = cxWSResponseScanStatus.CurrentStage;
                statusScan.CurrentStagePercent = cxWSResponseScanStatus.CurrentStagePercent;
                statusScan.Details             = cxWSResponseScanStatus.StepDetails;
                statusScan.IsSuccesfull        = cxWSResponseScanStatus.IsSuccesfull;
                statusScan.QueuePosition       = cxWSResponseScanStatus.QueuePosition;
                statusScan.RunId               = cxWSResponseScanStatus.RunId;
                statusScan.RunStatus           = cxWSResponseScanStatus.CurrentStatus;
                statusScan.StageMessage        = cxWSResponseScanStatus.StageMessage;
                statusScan.StageName           = cxWSResponseScanStatus.StageName;
                statusScan.StepMessage         = cxWSResponseScanStatus.StepMessage;
                statusScan.TimeFinished        = cxWSResponseScanStatus.TimeFinished != null?cxWSResponseScanStatus.TimeFinished.ToString() : null;

                statusScan.TimeStarted = cxWSResponseScanStatus.TimeScheduled != null?cxWSResponseScanStatus.TimeScheduled.ToString() : null;

                statusScan.TotalPercent = cxWSResponseScanStatus.TotalPercent;
            };
            bCancel = !bg.DoWork(null);

            if (!BackgroundWorkerHelper.IsReloginInvoked)
            {
                isIISStoped = !_scan.LoginResult.AuthenticationData.SaveSastScan;
            }
            else
            {
                BackgroundWorkerHelper.IsReloginInvoked = false;
            }

            if (!bCancel && cxWSResponseScanStatus != null && !isIISStoped)
            {
                ScanProgress progress = new ScanProgress(
                    _scan.UploadSettings.ProjectName,
                    statusScan.RunStatus.ToString(),
                    statusScan.StageName,
                    statusScan.StepMessage,
                    statusScan.CurrentStagePercent,
                    0,
                    100,
                    statusScan.TotalPercent);

                if (!backgroundMode)
                {
                    view.Progress = progress;
                }
                try {
                    CommonActionsInstance.getInstance().ScanProgressView.Progress = progress;
                }
                catch (Exception ex) {
                    Logger.Create().Error(ex.ToString());
                }

                if (statusScan.RunStatus == CurrentStatusEnum.Failed)
                {
                    TopMostMessageBox.Show(statusScan.StageMessage, "Scan Error");
                    bCancel = true;
                }

                if (_scan.ScanView == null || _scan.ScanView.Visibility == false)
                {
                    var scanStatusBar = new ScanStatusBar(true, string.Format("Scaning project {0}: {1} {2}",
                                                                              _scan.UploadSettings.ProjectName,
                                                                              statusScan.StepMessage, statusScan.RunStatus), statusScan.TotalPercent, 100);

                    CommonActionsInstance.getInstance().UpdateScanProgress(scanStatusBar);
                }
            }
            return(statusScan);
        }
Esempio n. 10
0
        /// <summary>
        /// Execute scan
        /// </summary>
        /// <param name="project">Upload project folder</param>
        /// <param name="isIncremental"></param>
        /// <param name="scanData"></param>
        /// <param name="scanId"></param>
        /// <returns></returns>
        public ProjectScanStatuses DoScan(Project project, bool isIncremental, ref CxWSQueryVulnerabilityData[] scanData, ref long scanId)
        {
            if (_scan != null && _scan.InProcess)
            {
                return(ProjectScanStatuses.CanceledByUser);
            }
            LoginResult loginResult = new LoginResult();

            try
            {
                //Release old view data

                CommonActionsInstance.getInstance().ClearScanProgressView();

                LoginData     logindata     = LoginHelper.LoadSaved();
                OidcLoginData oidcLoginData = OidcLoginData.GetOidcLoginDataInstance();
                //Execute login
                if (oidcLoginData.AccessToken == null)
                {
                    loginResult = Login();
                    if (loginResult == null || loginResult.AuthenticationData == null)
                    {
                        LoginHelper.ShowLoginErrorMessage(loginResult);
                        return(ProjectScanStatuses.Error);
                    }
                }
                else
                {
                    loginResult.AuthenticationData = logindata;
                    loginResult.IsSuccesfull       = true;
                }

                if (_cancelPressed)
                {
                    return(ProjectScanStatuses.CanceledByUser);
                }

                if (loginResult.IsSuccesfull)
                {
                    _scan = new Scan(loginResult, onScanInBackground, onCancel, onDetails)
                    {
                        InProcess     = true,
                        DockView      = CommonActionsInstance.getInstance().ScanProgressView,
                        ScanProject   = project,
                        IsIncremental = isIncremental
                    };

                    //Execute setting upload project properties
                    _uploadSettings = GetUploadSettings(project, loginResult);

                    if (_uploadSettings == null || _cancelPressed)
                    {
                        return(ProjectScanStatuses.CanceledByUser);
                    }

                    if (_uploadSettings.IsUploading)
                    {
                        _scan.UploadSettings = _uploadSettings;

                        return(ExecuteScan(project, ref scanData, ref scanId));
                    }
                }
                else if (!_cancelPressed)
                {
                    TopMostMessageBox.Show("Unable to connect to server or user creadentials are invalid. Please verify data", "Log in problem");
                    return(ProjectScanStatuses.Error);
                }
            }
            finally
            {
                if (_scan != null)
                {
                    _scan.InProcess = false;
                }
            }

            return(ProjectScanStatuses.CanceledByUser);
        }