static int Download(DownloadOptions options)
        {
            _logger.LogDebug($"Entering {LoggingHelper.GetMyMethodName()} with scan options {options}");
            var declareConfigRepository = new DeclareConfigurationRepository(options.JsonFileLocation);

            _downloaderLogic.PrepareDownloadFolder(options.Target);

            if (!_downloaderLogic.AnyArtifactoryProvidersConfigured(declareConfigRepository.Apps()))
            {
                return(1);
            }

            var artifactoryPaths = _downloaderLogic.GetArtifactoryPaths(declareConfigRepository.Apps());

            foreach (var artifactoryPath in artifactoryPaths)
            {
                _logger.LogInformation($"Starting download for {artifactoryPath}");
                _commandRunner.RunJFrogTask(new ArtifactoryCommand
                {
                    ArtifactoryApiKey     = _artifactoryApiKey,
                    ArtifactorySourcePath = CleanseHelper.Cleanse(artifactoryPath),
                    ArtifactoryUrl        = _artifactoryUrl,
                    DownloadFolder        = CleanseHelper.Cleanse(options.Target)
                }.ReturnCommand());
                _logger.LogInformation($"Download complete for {artifactoryPath}");
            }

            _logger.LogDebug($"Exiting {LoggingHelper.GetMyMethodName()} with value {1}");
            return(1);
        }
Exemple #2
0
        static int Configure(ConfigureOptions options)
        {
            _logger.LogDebug($"Entering {LoggingHelper.GetMyMethodName()} with scan options {options}");
            var _localizationRepository = LoggingHelper.GetLocalizationRepository(options.Language);

            _logger.LogInformation(_localizationRepository.GetText("INFO00001", options.ToString()));

            var declareConfigRepository = new DeclareConfigurationRepository(options.JsonFileLocation);

            foreach (var app in declareConfigRepository.Apps())
            {
                _logger.LogInformation($"Starting build for {app.application_name}");

                _dscLogic.MakeItSoPolicy(app, app.policy);

                if (!_dscLogic.MakeItSoApp(app))
                {
                    return(0);
                }

                _dscLogic.MakeItSoTeam(app);
                foreach (var user in app.users)
                {
                    user.teams = app.application_name;
                    _dscLogic.MakeItSoUser(user, app);
                }
                _dscLogic.MakeItSoMitigations(app);
                _dscLogic.MakeItSoSandboxes(app);
                _logger.LogInformation($"build complete for {app.application_name}");
            }

            _logger.LogDebug($"Exiting {LoggingHelper.GetMyMethodName()} with value {1}");
            return(1);
        }
Exemple #3
0
        static int Evaluate(EvaluateOptions options)
        {
            _logger.LogDebug("Evaluating the applications in the configuration file.");
            var _localizationRepository = LoggingHelper.GetLocalizationRepository(options.Language);

            _logger.LogInformation(_localizationRepository.GetText("INFO00001", options.ToString()));

            var declareConfigRepository = new DeclareConfigurationRepository(options.JsonFileLocation);

            foreach (var app in declareConfigRepository.Apps())
            {
                _logger.LogInformation($"Starting evaluation for {app.application_name}");
                _dscLogic.GetLatestStatus(app);

                if (String.IsNullOrWhiteSpace(app.policy_schedule))
                {
                    _logger.LogWarning($"There is no policy schedule configured for {app.application_name}");
                }
                else
                {
                    _dscLogic.IsScanDueFromSchedule(app);
                }

                _logger.LogInformation($"Evaluation complete for {app.application_name}");
            }

            _logger.LogDebug($"Exiting {LoggingHelper.GetMyMethodName()} with value {1}");
            return(1);
        }
Exemple #4
0
        public void GetArtifactoryPaths()
        {
            var repo             = new DeclareConfigurationRepository(complete_configuration_file);
            var artifactoryPaths = _downloaderLogic.GetArtifactoryPaths(repo.Apps());

            Assert.AreEqual(5, artifactoryPaths.Length);
            Assert.IsTrue(artifactoryPaths.Any(x => x.Equals("mvn-public-local/org/owasp/encoder/encoder/1.1/encoder-1.1.jar")));
            Assert.IsTrue(artifactoryPaths.Any(x => x.Equals("mvn-public-local/org/owasp/encoder/encoder/1.1.1/encoder-1.1.1.jar")));
            Assert.IsTrue(artifactoryPaths.Any(x => x.Equals("mvn-public-local/org/owasp/encoder/encoder/1.2/encoder-1.2.jar")));
            Assert.IsTrue(artifactoryPaths.Any(x => x.Equals("mvn-public-local/org/owasp/encoder/encoder/1.2.2/encoder-1.2.2.jar")));
            Assert.IsTrue(artifactoryPaths.Any(x => x.Equals("mvn-public-local/org/owasp/encoder/encoder/1.2.3/encoder-1.2.3.jar")));
        }
Exemple #5
0
        static int Scan(ScanOptions options)
        {
            _logger.LogDebug($"Entering {LoggingHelper.GetMyMethodName()} with scan options {options}");
            var _localizationRepository = LoggingHelper.GetLocalizationRepository(options.Language);

            _logger.LogInformation(_localizationRepository.GetText("INFO00001", options.ToString()));

            var declareConfigRepository = new DeclareConfigurationRepository(options.JsonFileLocation);

            foreach (var app in declareConfigRepository.Apps())
            {
                bool scheduled = false;

                if (String.IsNullOrWhiteSpace(app.policy_schedule))
                {
                    _logger.LogWarning(_localizationRepository.GetText("WARN00002", app.application_name));
                }
                else
                {
                    scheduled = _dscLogic.IsScanDueFromSchedule(app);
                }

                if (scheduled || options.IgnoreSchedule)
                {
                    _logger.LogWarning(_localizationRepository.GetText("INFO00007", app.application_name));
                    _logger.LogWarning(_localizationRepository.GetText("INFO00008", app.application_name));
                    foreach (var file in app.upload.Select(x => x.location))
                    {
                        _logger.LogInformation($"{file}");
                    }

                    _logger.LogWarning(_localizationRepository.GetText("INFO00009", app.application_name));
                    foreach (var module in app.modules.Select(x => $"module_name={x.module_name},entry_point={x.entry_point}"))
                    {
                        _logger.LogInformation($"{module}");
                    }

                    _dscLogic.MakeItSoScan(app, app.upload.ToArray(), app.modules.ToArray());
                }
            }

            _logger.LogDebug($"Exiting {LoggingHelper.GetMyMethodName()} with value {1}");
            return(1);
        }
Exemple #6
0
        static int Delete(DeleteOptions options)
        {
            _logger.LogDebug($"Entering {LoggingHelper.GetMyMethodName()} with scan options {options}");
            var _localizationRepository = LoggingHelper.GetLocalizationRepository(options.Language);

            _logger.LogInformation(_localizationRepository.GetText("INFO00001", options.ToString()));

            var declareConfigRepository = new DeclareConfigurationRepository(options.JsonFileLocation);

            foreach (var app in declareConfigRepository.Apps())
            {
                _logger.LogInformation($"Tearing down {app.application_name}");
                _dscLogic.TearDownProfile(app);
                _logger.LogInformation($"Tear down complete for {app.application_name}");
            }

            _logger.LogDebug($"Exiting {LoggingHelper.GetMyMethodName()} with value {1}");
            return(1);
        }
Exemple #7
0
        static int MitigationTemplates(MitigationOptions options)
        {
            _logger.LogDebug($"Entering {LoggingHelper.GetMyMethodName()} with scan options {options}");
            var _localizationRepository = LoggingHelper.GetLocalizationRepository(options.Language);

            _logger.LogInformation(_localizationRepository.GetText("INFO00001", options.ToString()));

            var declareConfigRepository = new DeclareConfigurationRepository(options.JsonFileLocation);

            foreach (var app in declareConfigRepository.Apps())
            {
                _logger.LogInformation($"Generating mitigations templates for {app.application_name}");
                _dscLogic.MakeMitigationTemplates(app, options.PolicyOnly);
                _logger.LogInformation($"Generated mitigations templates for {app.application_name}");
            }

            _logger.LogDebug($"Exiting {LoggingHelper.GetMyMethodName()} with value {1}");
            return(1);
        }
Exemple #8
0
        static int Test(TestOptions options)
        {
            _logger.LogDebug($"Entering {LoggingHelper.GetMyMethodName()} with scan options {options}");
            var _localizationRepository = LoggingHelper.GetLocalizationRepository(options.Language);

            _logger.LogInformation(_localizationRepository.GetText("INFO00001", options.ToString()));
            var declareConfigRepository = new DeclareConfigurationRepository(options.JsonFileLocation);

            foreach (var app in declareConfigRepository.Apps())
            {
                _logger.LogInformation(_localizationRepository.GetText("INFO00002", app.application_name));
                bool doesScanConfirm;
                if (options.LastScan)
                {
                    _logger.LogInformation(_localizationRepository.GetText("INFO00003"));
                    doesScanConfirm = _dscLogic.ConformToPreviousScan(app, app.modules.ToArray());
                }
                else
                {
                    _logger.LogInformation(_localizationRepository.GetText("INFO00004"));
                    doesScanConfirm = _dscLogic.ConformConfiguration(app,
                                                                     app.upload.ToArray(),
                                                                     app.modules.ToArray(), true);
                }

                if (doesScanConfirm)
                {
                    _logger.LogInformation(_localizationRepository.GetText("INFO00005", app.application_name));
                }
                else
                {
                    _logger.LogWarning(_localizationRepository.GetText("WARN00001", app.application_name));
                }
            }

            _logger.LogInformation(_localizationRepository.GetText("INFO00006"));
            _logger.LogDebug($"Exiting {LoggingHelper.GetMyMethodName()} with value {1}");
            return(1);
        }
Exemple #9
0
        public void RunJFrogTask_ShouldDownloadAllFilesInConfig()
        {
            var repo             = new DeclareConfigurationRepository(complete_configuration_file);
            var artifactoryPaths = _downloaderLogic.GetArtifactoryPaths(repo.Apps());

            foreach (var artifactoryPath in artifactoryPaths)
            {
                _commandRunner.RunJFrogTask(new ArtifactoryCommand
                {
                    ArtifactoryApiKey     = _artifactoryApiKey,
                    ArtifactorySourcePath = CleanseHelper.Cleanse(artifactoryPath),
                    ArtifactoryUrl        = _artifactoryUrl,
                    DownloadFolder        = CleanseHelper.Cleanse(_downloadFolder)
                }.ReturnCommand());
            }

            Assert.IsTrue(File.Exists($"{_downloadFolder}\\org\\owasp\\encoder\\encoder\\1.1\\encoder-1.1.jar"));
            Assert.IsTrue(File.Exists($"{_downloadFolder}\\org\\owasp\\encoder\\encoder\\1.1.1\\encoder-1.1.1.jar"));
            Assert.IsTrue(File.Exists($"{_downloadFolder}\\org\\owasp\\encoder\\encoder\\1.2\\encoder-1.2.jar"));
            Assert.IsTrue(File.Exists($"{_downloadFolder}\\org\\owasp\\encoder\\encoder\\1.2.2\\encoder-1.2.2.jar"));
            Assert.IsTrue(File.Exists($"{_downloadFolder}\\org\\owasp\\encoder\\encoder\\1.2.3\\encoder-1.2.3.jar"));
        }
Exemple #10
0
        public void AnyArtifactoryProvidersConfigured_ShouldReturnFalseForIncompleteConfig()
        {
            var repo = new DeclareConfigurationRepository(incomplete_configuration_file);

            Assert.IsFalse(_downloaderLogic.AnyArtifactoryProvidersConfigured(repo.Apps()));
        }