Coverage Report - org.owasp.dependencycheck.agent.DependencyCheckScanAgent
 
Classes in this File Line Coverage Branch Coverage Complexity
DependencyCheckScanAgent
0%
0/240
0%
0/110
1.857
 
 1  
 /*
 2  
  * This file is part of dependency-check-core.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  *
 16  
  * Copyright (c) 2014 Steve Springett. All Rights Reserved.
 17  
  */
 18  
 package org.owasp.dependencycheck.agent;
 19  
 
 20  
 import java.io.File;
 21  
 import java.io.IOException;
 22  
 import java.util.List;
 23  
 import java.util.logging.Level;
 24  
 import java.util.logging.Logger;
 25  
 import org.owasp.dependencycheck.Engine;
 26  
 import org.owasp.dependencycheck.data.nvdcve.CveDB;
 27  
 import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
 28  
 import org.owasp.dependencycheck.data.nvdcve.DatabaseProperties;
 29  
 import org.owasp.dependencycheck.dependency.Dependency;
 30  
 import org.owasp.dependencycheck.dependency.Identifier;
 31  
 import org.owasp.dependencycheck.dependency.Vulnerability;
 32  
 import org.owasp.dependencycheck.exception.ScanAgentException;
 33  
 import org.owasp.dependencycheck.reporting.ReportGenerator;
 34  
 import org.owasp.dependencycheck.utils.Settings;
 35  
 
 36  
 /**
 37  
  * This class provides a way to easily conduct a scan solely based on existing evidence metadata rather than collecting
 38  
  * evidence from the files themselves. This class is based on the Ant task and Maven plugin with the exception that it
 39  
  * takes a list of dependencies that can be programmatically added from data in a spreadsheet, database or some other
 40  
  * datasource and conduct a scan based on this pre-defined evidence.
 41  
  *
 42  
  * <h2>Example:</h2>
 43  
  * <pre>
 44  
  * List<Dependency> dependencies = new ArrayList<Dependency>();
 45  
  * Dependency dependency = new Dependency(new File(FileUtils.getBitBucket()));
 46  
  * dependency.getProductEvidence().addEvidence("my-datasource", "name", "Jetty", Confidence.HIGH);
 47  
  * dependency.getVersionEvidence().addEvidence("my-datasource", "version", "5.1.10", Confidence.HIGH);
 48  
  * dependency.getVendorEvidence().addEvidence("my-datasource", "vendor", "mortbay", Confidence.HIGH);
 49  
  * dependencies.add(dependency);
 50  
  *
 51  
  * DependencyCheckScanAgent scan = new DependencyCheckScanAgent();
 52  
  * scan.setDependencies(dependencies);
 53  
  * scan.setReportFormat(ReportGenerator.Format.ALL);
 54  
  * scan.setReportOutputDirectory(System.getProperty("user.home"));
 55  
  * scan.execute();
 56  
  * </pre>
 57  
  *
 58  
  * @author Steve Springett <steve.springett@owasp.org>
 59  
  */
 60  
 @SuppressWarnings("unused")
 61  0
 public class DependencyCheckScanAgent {
 62  
 
 63  
     /**
 64  
      * System specific new line character.
 65  
      */
 66  0
     private static final String NEW_LINE = System.getProperty("line.separator", "\n").intern();
 67  
     /**
 68  
      * Logger for use throughout the class.
 69  
      */
 70  0
     private static final Logger LOGGER = Logger.getLogger(DependencyCheckScanAgent.class.getName());
 71  
     /**
 72  
      * The application name for the report.
 73  
      */
 74  0
     private String applicationName = "Dependency-Check";
 75  
 
 76  
     /**
 77  
      * Get the value of applicationName.
 78  
      *
 79  
      * @return the value of applicationName
 80  
      */
 81  
     public String getApplicationName() {
 82  0
         return applicationName;
 83  
     }
 84  
 
 85  
     /**
 86  
      * Set the value of applicationName.
 87  
      *
 88  
      * @param applicationName new value of applicationName
 89  
      */
 90  
     public void setApplicationName(String applicationName) {
 91  0
         this.applicationName = applicationName;
 92  0
     }
 93  
 
 94  
     /**
 95  
      * The pre-determined dependencies to scan
 96  
      */
 97  
     private List<Dependency> dependencies;
 98  
 
 99  
     /**
 100  
      * Returns a list of pre-determined dependencies.
 101  
      *
 102  
      * @return returns a list of dependencies
 103  
      */
 104  
     public List<Dependency> getDependencies() {
 105  0
         return dependencies;
 106  
     }
 107  
 
 108  
     /**
 109  
      * Sets the list of dependencies to scan.
 110  
      *
 111  
      * @param dependencies new value of dependencies
 112  
      */
 113  
     public void setDependencies(List<Dependency> dependencies) {
 114  0
         this.dependencies = dependencies;
 115  0
     }
 116  
 
 117  
     /**
 118  
      * The location of the data directory that contains
 119  
      */
 120  0
     private String dataDirectory = null;
 121  
 
 122  
     /**
 123  
      * Get the value of dataDirectory.
 124  
      *
 125  
      * @return the value of dataDirectory
 126  
      */
 127  
     public String getDataDirectory() {
 128  0
         return dataDirectory;
 129  
     }
 130  
 
 131  
     /**
 132  
      * Set the value of dataDirectory.
 133  
      *
 134  
      * @param dataDirectory new value of dataDirectory
 135  
      */
 136  
     public void setDataDirectory(String dataDirectory) {
 137  0
         this.dataDirectory = dataDirectory;
 138  0
     }
 139  
 
 140  
     /**
 141  
      * Specifies the destination directory for the generated Dependency-Check report.
 142  
      */
 143  
     private String reportOutputDirectory;
 144  
 
 145  
     /**
 146  
      * Get the value of reportOutputDirectory.
 147  
      *
 148  
      * @return the value of reportOutputDirectory
 149  
      */
 150  
     public String getReportOutputDirectory() {
 151  0
         return reportOutputDirectory;
 152  
     }
 153  
 
 154  
     /**
 155  
      * Set the value of reportOutputDirectory.
 156  
      *
 157  
      * @param reportOutputDirectory new value of reportOutputDirectory
 158  
      */
 159  
     public void setReportOutputDirectory(String reportOutputDirectory) {
 160  0
         this.reportOutputDirectory = reportOutputDirectory;
 161  0
     }
 162  
 
 163  
     /**
 164  
      * Specifies if the build should be failed if a CVSS score above a specified level is identified. The default is 11
 165  
      * which means since the CVSS scores are 0-10, by default the build will never fail and the CVSS score is set to 11.
 166  
      * The valid range for the fail build on CVSS is 0 to 11, where anything above 10 will not cause the build to fail.
 167  
      */
 168  0
     private float failBuildOnCVSS = 11;
 169  
 
 170  
     /**
 171  
      * Get the value of failBuildOnCVSS.
 172  
      *
 173  
      * @return the value of failBuildOnCVSS
 174  
      */
 175  
     public float getFailBuildOnCVSS() {
 176  0
         return failBuildOnCVSS;
 177  
     }
 178  
 
 179  
     /**
 180  
      * Set the value of failBuildOnCVSS.
 181  
      *
 182  
      * @param failBuildOnCVSS new value of failBuildOnCVSS
 183  
      */
 184  
     public void setFailBuildOnCVSS(float failBuildOnCVSS) {
 185  0
         this.failBuildOnCVSS = failBuildOnCVSS;
 186  0
     }
 187  
 
 188  
     /**
 189  
      * Sets whether auto-updating of the NVD CVE/CPE data is enabled. It is not recommended that this be turned to
 190  
      * false. Default is true.
 191  
      */
 192  0
     private boolean autoUpdate = true;
 193  
 
 194  
     /**
 195  
      * Get the value of autoUpdate.
 196  
      *
 197  
      * @return the value of autoUpdate
 198  
      */
 199  
     public boolean isAutoUpdate() {
 200  0
         return autoUpdate;
 201  
     }
 202  
 
 203  
     /**
 204  
      * Set the value of autoUpdate.
 205  
      *
 206  
      * @param autoUpdate new value of autoUpdate
 207  
      */
 208  
     public void setAutoUpdate(boolean autoUpdate) {
 209  0
         this.autoUpdate = autoUpdate;
 210  0
     }
 211  
 
 212  
     /**
 213  
      * The report format to be generated (HTML, XML, VULN, ALL). This configuration option has no affect if using this
 214  
      * within the Site plugin unless the externalReport is set to true. Default is HTML.
 215  
      */
 216  0
     private ReportGenerator.Format reportFormat = ReportGenerator.Format.HTML;
 217  
 
 218  
     /**
 219  
      * Get the value of reportFormat.
 220  
      *
 221  
      * @return the value of reportFormat
 222  
      */
 223  
     public ReportGenerator.Format getReportFormat() {
 224  0
         return reportFormat;
 225  
     }
 226  
 
 227  
     /**
 228  
      * Set the value of reportFormat.
 229  
      *
 230  
      * @param reportFormat new value of reportFormat
 231  
      */
 232  
     public void setReportFormat(ReportGenerator.Format reportFormat) {
 233  0
         this.reportFormat = reportFormat;
 234  0
     }
 235  
 
 236  
     /**
 237  
      * The Proxy Server.
 238  
      */
 239  
     private String proxyServer;
 240  
 
 241  
     /**
 242  
      * Get the value of proxyServer.
 243  
      *
 244  
      * @return the value of proxyServer
 245  
      */
 246  
     public String getProxyServer() {
 247  0
         return proxyServer;
 248  
     }
 249  
 
 250  
     /**
 251  
      * Set the value of proxyServer.
 252  
      *
 253  
      * @param proxyServer new value of proxyServer
 254  
      */
 255  
     public void setProxyServer(String proxyServer) {
 256  0
         this.proxyServer = proxyServer;
 257  0
     }
 258  
 
 259  
     /**
 260  
      * Get the value of proxyServer.
 261  
      *
 262  
      * @return the value of proxyServer
 263  
      * @deprecated use {@link org.owasp.dependencycheck.agent.DependencyCheckScanAgent#getProxyServer()} instead
 264  
      */
 265  
     @Deprecated
 266  
     public String getProxyUrl() {
 267  0
         return proxyServer;
 268  
     }
 269  
 
 270  
     /**
 271  
      * Set the value of proxyServer.
 272  
      *
 273  
      * @param proxyUrl new value of proxyServer
 274  
      * @deprecated use {@link org.owasp.dependencycheck.agent.DependencyCheckScanAgent#setProxyServer(java.lang.String)
 275  
      * } instead
 276  
      */
 277  
     @Deprecated
 278  
     public void setProxyUrl(String proxyUrl) {
 279  0
         this.proxyServer = proxyUrl;
 280  0
     }
 281  
 
 282  
     /**
 283  
      * The Proxy Port.
 284  
      */
 285  
     private String proxyPort;
 286  
 
 287  
     /**
 288  
      * Get the value of proxyPort.
 289  
      *
 290  
      * @return the value of proxyPort
 291  
      */
 292  
     public String getProxyPort() {
 293  0
         return proxyPort;
 294  
     }
 295  
 
 296  
     /**
 297  
      * Set the value of proxyPort.
 298  
      *
 299  
      * @param proxyPort new value of proxyPort
 300  
      */
 301  
     public void setProxyPort(String proxyPort) {
 302  0
         this.proxyPort = proxyPort;
 303  0
     }
 304  
 
 305  
     /**
 306  
      * The Proxy username.
 307  
      */
 308  
     private String proxyUsername;
 309  
 
 310  
     /**
 311  
      * Get the value of proxyUsername.
 312  
      *
 313  
      * @return the value of proxyUsername
 314  
      */
 315  
     public String getProxyUsername() {
 316  0
         return proxyUsername;
 317  
     }
 318  
 
 319  
     /**
 320  
      * Set the value of proxyUsername.
 321  
      *
 322  
      * @param proxyUsername new value of proxyUsername
 323  
      */
 324  
     public void setProxyUsername(String proxyUsername) {
 325  0
         this.proxyUsername = proxyUsername;
 326  0
     }
 327  
 
 328  
     /**
 329  
      * The Proxy password.
 330  
      */
 331  
     private String proxyPassword;
 332  
 
 333  
     /**
 334  
      * Get the value of proxyPassword.
 335  
      *
 336  
      * @return the value of proxyPassword
 337  
      */
 338  
     public String getProxyPassword() {
 339  0
         return proxyPassword;
 340  
     }
 341  
 
 342  
     /**
 343  
      * Set the value of proxyPassword.
 344  
      *
 345  
      * @param proxyPassword new value of proxyPassword
 346  
      */
 347  
     public void setProxyPassword(String proxyPassword) {
 348  0
         this.proxyPassword = proxyPassword;
 349  0
     }
 350  
 
 351  
     /**
 352  
      * The Connection Timeout.
 353  
      */
 354  
     private String connectionTimeout;
 355  
 
 356  
     /**
 357  
      * Get the value of connectionTimeout.
 358  
      *
 359  
      * @return the value of connectionTimeout
 360  
      */
 361  
     public String getConnectionTimeout() {
 362  0
         return connectionTimeout;
 363  
     }
 364  
 
 365  
     /**
 366  
      * Set the value of connectionTimeout.
 367  
      *
 368  
      * @param connectionTimeout new value of connectionTimeout
 369  
      */
 370  
     public void setConnectionTimeout(String connectionTimeout) {
 371  0
         this.connectionTimeout = connectionTimeout;
 372  0
     }
 373  
 
 374  
     /**
 375  
      * The file path used for verbose logging.
 376  
      */
 377  0
     private String logFile = null;
 378  
 
 379  
     /**
 380  
      * Get the value of logFile.
 381  
      *
 382  
      * @return the value of logFile
 383  
      */
 384  
     public String getLogFile() {
 385  0
         return logFile;
 386  
     }
 387  
 
 388  
     /**
 389  
      * Set the value of logFile.
 390  
      *
 391  
      * @param logFile new value of logFile
 392  
      */
 393  
     public void setLogFile(String logFile) {
 394  0
         this.logFile = logFile;
 395  0
     }
 396  
 
 397  
     /**
 398  
      * The path to the suppression file.
 399  
      */
 400  
     private String suppressionFile;
 401  
 
 402  
     /**
 403  
      * Get the value of suppressionFile.
 404  
      *
 405  
      * @return the value of suppressionFile
 406  
      */
 407  
     public String getSuppressionFile() {
 408  0
         return suppressionFile;
 409  
     }
 410  
 
 411  
     /**
 412  
      * Set the value of suppressionFile.
 413  
      *
 414  
      * @param suppressionFile new value of suppressionFile
 415  
      */
 416  
     public void setSuppressionFile(String suppressionFile) {
 417  0
         this.suppressionFile = suppressionFile;
 418  0
     }
 419  
 
 420  
     /**
 421  
      * flag indicating whether or not to show a summary of findings.
 422  
      */
 423  0
     private boolean showSummary = true;
 424  
 
 425  
     /**
 426  
      * Get the value of showSummary.
 427  
      *
 428  
      * @return the value of showSummary
 429  
      */
 430  
     public boolean isShowSummary() {
 431  0
         return showSummary;
 432  
     }
 433  
 
 434  
     /**
 435  
      * Set the value of showSummary.
 436  
      *
 437  
      * @param showSummary new value of showSummary
 438  
      */
 439  
     public void setShowSummary(boolean showSummary) {
 440  0
         this.showSummary = showSummary;
 441  0
     }
 442  
 
 443  
     /**
 444  
      * Whether or not the Maven Central analyzer is enabled.
 445  
      */
 446  0
     private boolean centralAnalyzerEnabled = true;
 447  
 
 448  
     /**
 449  
      * Get the value of centralAnalyzerEnabled.
 450  
      *
 451  
      * @return the value of centralAnalyzerEnabled
 452  
      */
 453  
     public boolean isCentralAnalyzerEnabled() {
 454  0
         return centralAnalyzerEnabled;
 455  
     }
 456  
 
 457  
     /**
 458  
      * Set the value of centralAnalyzerEnabled.
 459  
      *
 460  
      * @param centralAnalyzerEnabled new value of centralAnalyzerEnabled
 461  
      */
 462  
     public void setCentralAnalyzerEnabled(boolean centralAnalyzerEnabled) {
 463  0
         this.centralAnalyzerEnabled = centralAnalyzerEnabled;
 464  0
     }
 465  
 
 466  
     /**
 467  
      * The URL of Maven Central.
 468  
      */
 469  
     private String centralUrl;
 470  
 
 471  
     /**
 472  
      * Get the value of centralUrl.
 473  
      *
 474  
      * @return the value of centralUrl
 475  
      */
 476  
     public String getCentralUrl() {
 477  0
         return centralUrl;
 478  
     }
 479  
 
 480  
     /**
 481  
      * Set the value of centralUrl.
 482  
      *
 483  
      * @param centralUrl new value of centralUrl
 484  
      */
 485  
     public void setCentralUrl(String centralUrl) {
 486  0
         this.centralUrl = centralUrl;
 487  0
     }
 488  
 
 489  
     /**
 490  
      * Whether or not the nexus analyzer is enabled.
 491  
      */
 492  0
     private boolean nexusAnalyzerEnabled = true;
 493  
 
 494  
     /**
 495  
      * Get the value of nexusAnalyzerEnabled.
 496  
      *
 497  
      * @return the value of nexusAnalyzerEnabled
 498  
      */
 499  
     public boolean isNexusAnalyzerEnabled() {
 500  0
         return nexusAnalyzerEnabled;
 501  
     }
 502  
 
 503  
     /**
 504  
      * Set the value of nexusAnalyzerEnabled.
 505  
      *
 506  
      * @param nexusAnalyzerEnabled new value of nexusAnalyzerEnabled
 507  
      */
 508  
     public void setNexusAnalyzerEnabled(boolean nexusAnalyzerEnabled) {
 509  0
         this.nexusAnalyzerEnabled = nexusAnalyzerEnabled;
 510  0
     }
 511  
 
 512  
     /**
 513  
      * The URL of the Nexus server.
 514  
      */
 515  
     private String nexusUrl;
 516  
 
 517  
     /**
 518  
      * Get the value of nexusUrl.
 519  
      *
 520  
      * @return the value of nexusUrl
 521  
      */
 522  
     public String getNexusUrl() {
 523  0
         return nexusUrl;
 524  
     }
 525  
 
 526  
     /**
 527  
      * Set the value of nexusUrl.
 528  
      *
 529  
      * @param nexusUrl new value of nexusUrl
 530  
      */
 531  
     public void setNexusUrl(String nexusUrl) {
 532  0
         this.nexusUrl = nexusUrl;
 533  0
     }
 534  
 
 535  
     /**
 536  
      * Whether or not the defined proxy should be used when connecting to Nexus.
 537  
      */
 538  0
     private boolean nexusUsesProxy = true;
 539  
 
 540  
     /**
 541  
      * Get the value of nexusUsesProxy.
 542  
      *
 543  
      * @return the value of nexusUsesProxy
 544  
      */
 545  
     public boolean isNexusUsesProxy() {
 546  0
         return nexusUsesProxy;
 547  
     }
 548  
 
 549  
     /**
 550  
      * Set the value of nexusUsesProxy.
 551  
      *
 552  
      * @param nexusUsesProxy new value of nexusUsesProxy
 553  
      */
 554  
     public void setNexusUsesProxy(boolean nexusUsesProxy) {
 555  0
         this.nexusUsesProxy = nexusUsesProxy;
 556  0
     }
 557  
 
 558  
     /**
 559  
      * The database driver name; such as org.h2.Driver.
 560  
      */
 561  
     private String databaseDriverName;
 562  
 
 563  
     /**
 564  
      * Get the value of databaseDriverName.
 565  
      *
 566  
      * @return the value of databaseDriverName
 567  
      */
 568  
     public String getDatabaseDriverName() {
 569  0
         return databaseDriverName;
 570  
     }
 571  
 
 572  
     /**
 573  
      * Set the value of databaseDriverName.
 574  
      *
 575  
      * @param databaseDriverName new value of databaseDriverName
 576  
      */
 577  
     public void setDatabaseDriverName(String databaseDriverName) {
 578  0
         this.databaseDriverName = databaseDriverName;
 579  0
     }
 580  
 
 581  
     /**
 582  
      * The path to the database driver JAR file if it is not on the class path.
 583  
      */
 584  
     private String databaseDriverPath;
 585  
 
 586  
     /**
 587  
      * Get the value of databaseDriverPath.
 588  
      *
 589  
      * @return the value of databaseDriverPath
 590  
      */
 591  
     public String getDatabaseDriverPath() {
 592  0
         return databaseDriverPath;
 593  
     }
 594  
 
 595  
     /**
 596  
      * Set the value of databaseDriverPath.
 597  
      *
 598  
      * @param databaseDriverPath new value of databaseDriverPath
 599  
      */
 600  
     public void setDatabaseDriverPath(String databaseDriverPath) {
 601  0
         this.databaseDriverPath = databaseDriverPath;
 602  0
     }
 603  
 
 604  
     /**
 605  
      * The database connection string.
 606  
      */
 607  
     private String connectionString;
 608  
 
 609  
     /**
 610  
      * Get the value of connectionString.
 611  
      *
 612  
      * @return the value of connectionString
 613  
      */
 614  
     public String getConnectionString() {
 615  0
         return connectionString;
 616  
     }
 617  
 
 618  
     /**
 619  
      * Set the value of connectionString.
 620  
      *
 621  
      * @param connectionString new value of connectionString
 622  
      */
 623  
     public void setConnectionString(String connectionString) {
 624  0
         this.connectionString = connectionString;
 625  0
     }
 626  
 
 627  
     /**
 628  
      * The user name for connecting to the database.
 629  
      */
 630  
     private String databaseUser;
 631  
 
 632  
     /**
 633  
      * Get the value of databaseUser.
 634  
      *
 635  
      * @return the value of databaseUser
 636  
      */
 637  
     public String getDatabaseUser() {
 638  0
         return databaseUser;
 639  
     }
 640  
 
 641  
     /**
 642  
      * Set the value of databaseUser.
 643  
      *
 644  
      * @param databaseUser new value of databaseUser
 645  
      */
 646  
     public void setDatabaseUser(String databaseUser) {
 647  0
         this.databaseUser = databaseUser;
 648  0
     }
 649  
 
 650  
     /**
 651  
      * The password to use when connecting to the database.
 652  
      */
 653  
     private String databasePassword;
 654  
 
 655  
     /**
 656  
      * Get the value of databasePassword.
 657  
      *
 658  
      * @return the value of databasePassword
 659  
      */
 660  
     public String getDatabasePassword() {
 661  0
         return databasePassword;
 662  
     }
 663  
 
 664  
     /**
 665  
      * Set the value of databasePassword.
 666  
      *
 667  
      * @param databasePassword new value of databasePassword
 668  
      */
 669  
     public void setDatabasePassword(String databasePassword) {
 670  0
         this.databasePassword = databasePassword;
 671  0
     }
 672  
 
 673  
     /**
 674  
      * Additional ZIP File extensions to add analyze. This should be a comma-separated list of file extensions to treat
 675  
      * like ZIP files.
 676  
      */
 677  
     private String zipExtensions;
 678  
 
 679  
     /**
 680  
      * Get the value of zipExtensions.
 681  
      *
 682  
      * @return the value of zipExtensions
 683  
      */
 684  
     public String getZipExtensions() {
 685  0
         return zipExtensions;
 686  
     }
 687  
 
 688  
     /**
 689  
      * Set the value of zipExtensions.
 690  
      *
 691  
      * @param zipExtensions new value of zipExtensions
 692  
      */
 693  
     public void setZipExtensions(String zipExtensions) {
 694  0
         this.zipExtensions = zipExtensions;
 695  0
     }
 696  
 
 697  
     /**
 698  
      * The url for the modified NVD CVE (1.2 schema).
 699  
      */
 700  
     private String cveUrl12Modified;
 701  
 
 702  
     /**
 703  
      * Get the value of cveUrl12Modified.
 704  
      *
 705  
      * @return the value of cveUrl12Modified
 706  
      */
 707  
     public String getCveUrl12Modified() {
 708  0
         return cveUrl12Modified;
 709  
     }
 710  
 
 711  
     /**
 712  
      * Set the value of cveUrl12Modified.
 713  
      *
 714  
      * @param cveUrl12Modified new value of cveUrl12Modified
 715  
      */
 716  
     public void setCveUrl12Modified(String cveUrl12Modified) {
 717  0
         this.cveUrl12Modified = cveUrl12Modified;
 718  0
     }
 719  
 
 720  
     /**
 721  
      * The url for the modified NVD CVE (2.0 schema).
 722  
      */
 723  
     private String cveUrl20Modified;
 724  
 
 725  
     /**
 726  
      * Get the value of cveUrl20Modified.
 727  
      *
 728  
      * @return the value of cveUrl20Modified
 729  
      */
 730  
     public String getCveUrl20Modified() {
 731  0
         return cveUrl20Modified;
 732  
     }
 733  
 
 734  
     /**
 735  
      * Set the value of cveUrl20Modified.
 736  
      *
 737  
      * @param cveUrl20Modified new value of cveUrl20Modified
 738  
      */
 739  
     public void setCveUrl20Modified(String cveUrl20Modified) {
 740  0
         this.cveUrl20Modified = cveUrl20Modified;
 741  0
     }
 742  
 
 743  
     /**
 744  
      * Base Data Mirror URL for CVE 1.2.
 745  
      */
 746  
     private String cveUrl12Base;
 747  
 
 748  
     /**
 749  
      * Get the value of cveUrl12Base.
 750  
      *
 751  
      * @return the value of cveUrl12Base
 752  
      */
 753  
     public String getCveUrl12Base() {
 754  0
         return cveUrl12Base;
 755  
     }
 756  
 
 757  
     /**
 758  
      * Set the value of cveUrl12Base.
 759  
      *
 760  
      * @param cveUrl12Base new value of cveUrl12Base
 761  
      */
 762  
     public void setCveUrl12Base(String cveUrl12Base) {
 763  0
         this.cveUrl12Base = cveUrl12Base;
 764  0
     }
 765  
 
 766  
     /**
 767  
      * Data Mirror URL for CVE 2.0.
 768  
      */
 769  
     private String cveUrl20Base;
 770  
 
 771  
     /**
 772  
      * Get the value of cveUrl20Base.
 773  
      *
 774  
      * @return the value of cveUrl20Base
 775  
      */
 776  
     public String getCveUrl20Base() {
 777  0
         return cveUrl20Base;
 778  
     }
 779  
 
 780  
     /**
 781  
      * Set the value of cveUrl20Base.
 782  
      *
 783  
      * @param cveUrl20Base new value of cveUrl20Base
 784  
      */
 785  
     public void setCveUrl20Base(String cveUrl20Base) {
 786  0
         this.cveUrl20Base = cveUrl20Base;
 787  0
     }
 788  
 
 789  
     /**
 790  
      * The path to Mono for .NET assembly analysis on non-windows systems.
 791  
      */
 792  
     private String pathToMono;
 793  
 
 794  
     /**
 795  
      * Get the value of pathToMono.
 796  
      *
 797  
      * @return the value of pathToMono
 798  
      */
 799  
     public String getPathToMono() {
 800  0
         return pathToMono;
 801  
     }
 802  
 
 803  
     /**
 804  
      * Set the value of pathToMono.
 805  
      *
 806  
      * @param pathToMono new value of pathToMono
 807  
      */
 808  
     public void setPathToMono(String pathToMono) {
 809  0
         this.pathToMono = pathToMono;
 810  0
     }
 811  
 
 812  
     /**
 813  
      * Executes the Dependency-Check on the dependent libraries.
 814  
      *
 815  
      * @return the Engine used to scan the dependencies.
 816  
      * @throws org.owasp.dependencycheck.data.nvdcve.DatabaseException thrown if there is an exception connecting to the
 817  
      * database
 818  
      */
 819  
     private Engine executeDependencyCheck() throws DatabaseException {
 820  0
         populateSettings();
 821  0
         Engine engine = null;
 822  0
         engine = new Engine();
 823  0
         engine.setDependencies(this.dependencies);
 824  0
         engine.analyzeDependencies();
 825  0
         return engine;
 826  
     }
 827  
 
 828  
     /**
 829  
      * Generates the reports for a given dependency-check engine.
 830  
      *
 831  
      * @param engine a dependency-check engine
 832  
      * @param outDirectory the directory to write the reports to
 833  
      */
 834  
     private void generateExternalReports(Engine engine, File outDirectory) {
 835  0
         DatabaseProperties prop = null;
 836  0
         CveDB cve = null;
 837  
         try {
 838  0
             cve = new CveDB();
 839  0
             cve.open();
 840  0
             prop = cve.getDatabaseProperties();
 841  0
         } catch (DatabaseException ex) {
 842  0
             LOGGER.log(Level.FINE, "Unable to retrieve DB Properties", ex);
 843  
         } finally {
 844  0
             if (cve != null) {
 845  0
                 cve.close();
 846  
             }
 847  
         }
 848  0
         final ReportGenerator r = new ReportGenerator(this.applicationName, engine.getDependencies(), engine.getAnalyzers(), prop);
 849  
         try {
 850  0
             r.generateReports(outDirectory.getCanonicalPath(), this.reportFormat.name());
 851  0
         } catch (IOException ex) {
 852  0
             LOGGER.log(Level.SEVERE,
 853  
                     "Unexpected exception occurred during analysis; please see the verbose error log for more details.");
 854  0
             LOGGER.log(Level.FINE, null, ex);
 855  0
         } catch (Throwable ex) {
 856  0
             LOGGER.log(Level.SEVERE,
 857  
                     "Unexpected exception occurred during analysis; please see the verbose error log for more details.");
 858  0
             LOGGER.log(Level.FINE, null, ex);
 859  0
         }
 860  0
     }
 861  
 
 862  
     /**
 863  
      * Takes the properties supplied and updates the dependency-check settings. Additionally, this sets the system
 864  
      * properties required to change the proxy server, port, and connection timeout.
 865  
      */
 866  
     private void populateSettings() {
 867  0
         Settings.initialize();
 868  0
         if (dataDirectory != null) {
 869  0
             Settings.setString(Settings.KEYS.DATA_DIRECTORY, dataDirectory);
 870  
         } else {
 871  0
             final File jarPath = new File(DependencyCheckScanAgent.class.getProtectionDomain().getCodeSource().getLocation().getPath());
 872  0
             final File base = jarPath.getParentFile();
 873  0
             final String sub = Settings.getString(Settings.KEYS.DATA_DIRECTORY);
 874  0
             final File dataDir = new File(base, sub);
 875  0
             Settings.setString(Settings.KEYS.DATA_DIRECTORY, dataDir.getAbsolutePath());
 876  
         }
 877  
 
 878  0
         Settings.setBoolean(Settings.KEYS.AUTO_UPDATE, autoUpdate);
 879  
 
 880  0
         if (proxyServer != null && !proxyServer.isEmpty()) {
 881  0
             Settings.setString(Settings.KEYS.PROXY_SERVER, proxyServer);
 882  
         }
 883  0
         if (proxyPort != null && !proxyPort.isEmpty()) {
 884  0
             Settings.setString(Settings.KEYS.PROXY_PORT, proxyPort);
 885  
         }
 886  0
         if (proxyUsername != null && !proxyUsername.isEmpty()) {
 887  0
             Settings.setString(Settings.KEYS.PROXY_USERNAME, proxyUsername);
 888  
         }
 889  0
         if (proxyPassword != null && !proxyPassword.isEmpty()) {
 890  0
             Settings.setString(Settings.KEYS.PROXY_PASSWORD, proxyPassword);
 891  
         }
 892  0
         if (connectionTimeout != null && !connectionTimeout.isEmpty()) {
 893  0
             Settings.setString(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout);
 894  
         }
 895  0
         if (suppressionFile != null && !suppressionFile.isEmpty()) {
 896  0
             Settings.setString(Settings.KEYS.SUPPRESSION_FILE, suppressionFile);
 897  
         }
 898  0
         Settings.setBoolean(Settings.KEYS.ANALYZER_CENTRAL_ENABLED, centralAnalyzerEnabled);
 899  0
         if (centralUrl != null && !centralUrl.isEmpty()) {
 900  0
             Settings.setString(Settings.KEYS.ANALYZER_CENTRAL_URL, centralUrl);
 901  
         }
 902  0
         Settings.setBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED, nexusAnalyzerEnabled);
 903  0
         if (nexusUrl != null && !nexusUrl.isEmpty()) {
 904  0
             Settings.setString(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl);
 905  
         }
 906  0
         Settings.setBoolean(Settings.KEYS.ANALYZER_NEXUS_PROXY, nexusUsesProxy);
 907  0
         if (databaseDriverName != null && !databaseDriverName.isEmpty()) {
 908  0
             Settings.setString(Settings.KEYS.DB_DRIVER_NAME, databaseDriverName);
 909  
         }
 910  0
         if (databaseDriverPath != null && !databaseDriverPath.isEmpty()) {
 911  0
             Settings.setString(Settings.KEYS.DB_DRIVER_PATH, databaseDriverPath);
 912  
         }
 913  0
         if (connectionString != null && !connectionString.isEmpty()) {
 914  0
             Settings.setString(Settings.KEYS.DB_CONNECTION_STRING, connectionString);
 915  
         }
 916  0
         if (databaseUser != null && !databaseUser.isEmpty()) {
 917  0
             Settings.setString(Settings.KEYS.DB_USER, databaseUser);
 918  
         }
 919  0
         if (databasePassword != null && !databasePassword.isEmpty()) {
 920  0
             Settings.setString(Settings.KEYS.DB_PASSWORD, databasePassword);
 921  
         }
 922  0
         if (zipExtensions != null && !zipExtensions.isEmpty()) {
 923  0
             Settings.setString(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS, zipExtensions);
 924  
         }
 925  0
         if (cveUrl12Modified != null && !cveUrl12Modified.isEmpty()) {
 926  0
             Settings.setString(Settings.KEYS.CVE_MODIFIED_12_URL, cveUrl12Modified);
 927  
         }
 928  0
         if (cveUrl20Modified != null && !cveUrl20Modified.isEmpty()) {
 929  0
             Settings.setString(Settings.KEYS.CVE_MODIFIED_20_URL, cveUrl20Modified);
 930  
         }
 931  0
         if (cveUrl12Base != null && !cveUrl12Base.isEmpty()) {
 932  0
             Settings.setString(Settings.KEYS.CVE_SCHEMA_1_2, cveUrl12Base);
 933  
         }
 934  0
         if (cveUrl20Base != null && !cveUrl20Base.isEmpty()) {
 935  0
             Settings.setString(Settings.KEYS.CVE_SCHEMA_2_0, cveUrl20Base);
 936  
         }
 937  0
         if (pathToMono != null && !pathToMono.isEmpty()) {
 938  0
             Settings.setString(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, pathToMono);
 939  
         }
 940  0
     }
 941  
 
 942  
     /**
 943  
      * Executes the dependency-check and generates the report.
 944  
      *
 945  
      * @throws org.owasp.dependencycheck.exception.ScanAgentException thrown if there is an exception executing the
 946  
      * scan.
 947  
      */
 948  
     public void execute() throws ScanAgentException {
 949  0
         Engine engine = null;
 950  
         try {
 951  0
             engine = executeDependencyCheck();
 952  0
             generateExternalReports(engine, new File(this.reportOutputDirectory));
 953  0
             if (this.showSummary) {
 954  0
                 showSummary(engine.getDependencies());
 955  
             }
 956  0
             if (this.failBuildOnCVSS <= 10) {
 957  0
                 checkForFailure(engine.getDependencies());
 958  
             }
 959  0
         } catch (DatabaseException ex) {
 960  0
             LOGGER.log(Level.SEVERE,
 961  
                     "Unable to connect to the dependency-check database; analysis has stopped");
 962  0
             LOGGER.log(Level.FINE, "", ex);
 963  
         } finally {
 964  0
             Settings.cleanup(true);
 965  0
             if (engine != null) {
 966  0
                 engine.cleanup();
 967  
             }
 968  
         }
 969  0
     }
 970  
 
 971  
     /**
 972  
      * Checks to see if a vulnerability has been identified with a CVSS score that is above the threshold set in the
 973  
      * configuration.
 974  
      *
 975  
      * @param dependencies the list of dependency objects
 976  
      * @throws org.owasp.dependencycheck.exception.ScanAgentException thrown if there is an exception executing the
 977  
      * scan.
 978  
      */
 979  
     private void checkForFailure(List<Dependency> dependencies) throws ScanAgentException {
 980  0
         final StringBuilder ids = new StringBuilder();
 981  0
         for (Dependency d : dependencies) {
 982  0
             boolean addName = true;
 983  0
             for (Vulnerability v : d.getVulnerabilities()) {
 984  0
                 if (v.getCvssScore() >= failBuildOnCVSS) {
 985  0
                     if (addName) {
 986  0
                         addName = false;
 987  0
                         ids.append(NEW_LINE).append(d.getFileName()).append(": ");
 988  0
                         ids.append(v.getName());
 989  
                     } else {
 990  0
                         ids.append(", ").append(v.getName());
 991  
                     }
 992  
                 }
 993  0
             }
 994  0
         }
 995  0
         if (ids.length() > 0) {
 996  0
             final String msg = String.format("%n%nDependency-Check Failure:%n"
 997  
                     + "One or more dependencies were identified with vulnerabilities that have a CVSS score greater then '%.1f': %s%n"
 998  
                     + "See the dependency-check report for more details.%n%n", failBuildOnCVSS, ids.toString());
 999  
 
 1000  0
             throw new ScanAgentException(msg);
 1001  
         }
 1002  0
     }
 1003  
 
 1004  
     /**
 1005  
      * Generates a warning message listing a summary of dependencies and their associated CPE and CVE entries.
 1006  
      *
 1007  
      * @param dependencies a list of dependency objects
 1008  
      */
 1009  
     private void showSummary(List<Dependency> dependencies) {
 1010  0
         final StringBuilder summary = new StringBuilder();
 1011  0
         for (Dependency d : dependencies) {
 1012  0
             boolean firstEntry = true;
 1013  0
             final StringBuilder ids = new StringBuilder();
 1014  0
             for (Vulnerability v : d.getVulnerabilities()) {
 1015  0
                 if (firstEntry) {
 1016  0
                     firstEntry = false;
 1017  
                 } else {
 1018  0
                     ids.append(", ");
 1019  
                 }
 1020  0
                 ids.append(v.getName());
 1021  0
             }
 1022  0
             if (ids.length() > 0) {
 1023  0
                 summary.append(d.getFileName()).append(" (");
 1024  0
                 firstEntry = true;
 1025  0
                 for (Identifier id : d.getIdentifiers()) {
 1026  0
                     if (firstEntry) {
 1027  0
                         firstEntry = false;
 1028  
                     } else {
 1029  0
                         summary.append(", ");
 1030  
                     }
 1031  0
                     summary.append(id.getValue());
 1032  0
                 }
 1033  0
                 summary.append(") : ").append(ids).append(NEW_LINE);
 1034  
             }
 1035  0
         }
 1036  0
         if (summary.length() > 0) {
 1037  0
             final String msg = String.format("%n%n"
 1038  
                     + "One or more dependencies were identified with known vulnerabilities:%n%n%s"
 1039  
                     + "%n%nSee the dependency-check report for more details.%n%n", summary.toString());
 1040  0
             LOGGER.log(Level.WARNING, msg);
 1041  
         }
 1042  0
     }
 1043  
 
 1044  
 }