Coverage Report - org.owasp.dependencycheck.agent.DependencyCheckScanAgent
 
Classes in this File Line Coverage Branch Coverage Complexity
DependencyCheckScanAgent
0%
0/140
0%
0/114
1.879
 
 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  
         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  
         this.applicationName = applicationName;
 92  
     }
 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  
         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  
         this.dependencies = dependencies;
 115  
     }
 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  
         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  
         this.dataDirectory = dataDirectory;
 138  
     }
 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  
         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  
         this.reportOutputDirectory = reportOutputDirectory;
 161  
     }
 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  
         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  
         this.failBuildOnCVSS = failBuildOnCVSS;
 186  
     }
 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  
         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  
         this.autoUpdate = autoUpdate;
 210  
     }
 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  
         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  
         this.reportFormat = reportFormat;
 234  
     }
 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  
         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  
         this.proxyServer = proxyServer;
 257  
     }
 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  
         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  
         this.proxyServer = proxyUrl;
 280  
     }
 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  
         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  
         this.proxyPort = proxyPort;
 303  
     }
 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  
         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  
         this.proxyUsername = proxyUsername;
 326  
     }
 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  
         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  
         this.proxyPassword = proxyPassword;
 349  
     }
 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  
         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  
         this.connectionTimeout = connectionTimeout;
 372  
     }
 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  
         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  
         this.logFile = logFile;
 395  
     }
 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  
         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  
         this.suppressionFile = suppressionFile;
 418  
     }
 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  
         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  
         this.showSummary = showSummary;
 441  
     }
 442  
 
 443  
     /**
 444  
      * Whether or not the nexus analyzer is enabled.
 445  
      */
 446  0
     private boolean nexusAnalyzerEnabled = true;
 447  
 
 448  
     /**
 449  
      * Get the value of nexusAnalyzerEnabled.
 450  
      *
 451  
      * @return the value of nexusAnalyzerEnabled
 452  
      */
 453  
     public boolean isNexusAnalyzerEnabled() {
 454  
         return nexusAnalyzerEnabled;
 455  
     }
 456  
 
 457  
     /**
 458  
      * Set the value of nexusAnalyzerEnabled.
 459  
      *
 460  
      * @param nexusAnalyzerEnabled new value of nexusAnalyzerEnabled
 461  
      */
 462  
     public void setNexusAnalyzerEnabled(boolean nexusAnalyzerEnabled) {
 463  
         this.nexusAnalyzerEnabled = nexusAnalyzerEnabled;
 464  
     }
 465  
 
 466  
     /**
 467  
      * The URL of the Nexus server.
 468  
      */
 469  
     private String nexusUrl;
 470  
 
 471  
     /**
 472  
      * Get the value of nexusUrl.
 473  
      *
 474  
      * @return the value of nexusUrl
 475  
      */
 476  
     public String getNexusUrl() {
 477  
         return nexusUrl;
 478  
     }
 479  
 
 480  
     /**
 481  
      * Set the value of nexusUrl.
 482  
      *
 483  
      * @param nexusUrl new value of nexusUrl
 484  
      */
 485  
     public void setNexusUrl(String nexusUrl) {
 486  
         this.nexusUrl = nexusUrl;
 487  
     }
 488  
 
 489  
     /**
 490  
      * Whether or not the defined proxy should be used when connecting to Nexus.
 491  
      */
 492  0
     private boolean nexusUsesProxy = true;
 493  
 
 494  
     /**
 495  
      * Get the value of nexusUsesProxy.
 496  
      *
 497  
      * @return the value of nexusUsesProxy
 498  
      */
 499  
     public boolean isNexusUsesProxy() {
 500  
         return nexusUsesProxy;
 501  
     }
 502  
 
 503  
     /**
 504  
      * Set the value of nexusUsesProxy.
 505  
      *
 506  
      * @param nexusUsesProxy new value of nexusUsesProxy
 507  
      */
 508  
     public void setNexusUsesProxy(boolean nexusUsesProxy) {
 509  
         this.nexusUsesProxy = nexusUsesProxy;
 510  
     }
 511  
 
 512  
     /**
 513  
      * The database driver name; such as org.h2.Driver.
 514  
      */
 515  
     private String databaseDriverName;
 516  
 
 517  
     /**
 518  
      * Get the value of databaseDriverName.
 519  
      *
 520  
      * @return the value of databaseDriverName
 521  
      */
 522  
     public String getDatabaseDriverName() {
 523  
         return databaseDriverName;
 524  
     }
 525  
 
 526  
     /**
 527  
      * Set the value of databaseDriverName.
 528  
      *
 529  
      * @param databaseDriverName new value of databaseDriverName
 530  
      */
 531  
     public void setDatabaseDriverName(String databaseDriverName) {
 532  
         this.databaseDriverName = databaseDriverName;
 533  
     }
 534  
 
 535  
     /**
 536  
      * The path to the database driver JAR file if it is not on the class path.
 537  
      */
 538  
     private String databaseDriverPath;
 539  
 
 540  
     /**
 541  
      * Get the value of databaseDriverPath.
 542  
      *
 543  
      * @return the value of databaseDriverPath
 544  
      */
 545  
     public String getDatabaseDriverPath() {
 546  
         return databaseDriverPath;
 547  
     }
 548  
 
 549  
     /**
 550  
      * Set the value of databaseDriverPath.
 551  
      *
 552  
      * @param databaseDriverPath new value of databaseDriverPath
 553  
      */
 554  
     public void setDatabaseDriverPath(String databaseDriverPath) {
 555  
         this.databaseDriverPath = databaseDriverPath;
 556  
     }
 557  
 
 558  
     /**
 559  
      * The database connection string.
 560  
      */
 561  
     private String connectionString;
 562  
 
 563  
     /**
 564  
      * Get the value of connectionString.
 565  
      *
 566  
      * @return the value of connectionString
 567  
      */
 568  
     public String getConnectionString() {
 569  
         return connectionString;
 570  
     }
 571  
 
 572  
     /**
 573  
      * Set the value of connectionString.
 574  
      *
 575  
      * @param connectionString new value of connectionString
 576  
      */
 577  
     public void setConnectionString(String connectionString) {
 578  
         this.connectionString = connectionString;
 579  
     }
 580  
 
 581  
     /**
 582  
      * The user name for connecting to the database.
 583  
      */
 584  
     private String databaseUser;
 585  
 
 586  
     /**
 587  
      * Get the value of databaseUser.
 588  
      *
 589  
      * @return the value of databaseUser
 590  
      */
 591  
     public String getDatabaseUser() {
 592  
         return databaseUser;
 593  
     }
 594  
 
 595  
     /**
 596  
      * Set the value of databaseUser.
 597  
      *
 598  
      * @param databaseUser new value of databaseUser
 599  
      */
 600  
     public void setDatabaseUser(String databaseUser) {
 601  
         this.databaseUser = databaseUser;
 602  
     }
 603  
 
 604  
     /**
 605  
      * The password to use when connecting to the database.
 606  
      */
 607  
     private String databasePassword;
 608  
 
 609  
     /**
 610  
      * Get the value of databasePassword.
 611  
      *
 612  
      * @return the value of databasePassword
 613  
      */
 614  
     public String getDatabasePassword() {
 615  
         return databasePassword;
 616  
     }
 617  
 
 618  
     /**
 619  
      * Set the value of databasePassword.
 620  
      *
 621  
      * @param databasePassword new value of databasePassword
 622  
      */
 623  
     public void setDatabasePassword(String databasePassword) {
 624  
         this.databasePassword = databasePassword;
 625  
     }
 626  
 
 627  
     /**
 628  
      * Additional ZIP File extensions to add analyze. This should be a comma-separated list of file extensions to treat
 629  
      * like ZIP files.
 630  
      */
 631  
     private String zipExtensions;
 632  
 
 633  
     /**
 634  
      * Get the value of zipExtensions.
 635  
      *
 636  
      * @return the value of zipExtensions
 637  
      */
 638  
     public String getZipExtensions() {
 639  
         return zipExtensions;
 640  
     }
 641  
 
 642  
     /**
 643  
      * Set the value of zipExtensions.
 644  
      *
 645  
      * @param zipExtensions new value of zipExtensions
 646  
      */
 647  
     public void setZipExtensions(String zipExtensions) {
 648  
         this.zipExtensions = zipExtensions;
 649  
     }
 650  
 
 651  
     /**
 652  
      * The url for the modified NVD CVE (1.2 schema).
 653  
      */
 654  
     private String cveUrl12Modified;
 655  
 
 656  
     /**
 657  
      * Get the value of cveUrl12Modified.
 658  
      *
 659  
      * @return the value of cveUrl12Modified
 660  
      */
 661  
     public String getCveUrl12Modified() {
 662  
         return cveUrl12Modified;
 663  
     }
 664  
 
 665  
     /**
 666  
      * Set the value of cveUrl12Modified.
 667  
      *
 668  
      * @param cveUrl12Modified new value of cveUrl12Modified
 669  
      */
 670  
     public void setCveUrl12Modified(String cveUrl12Modified) {
 671  
         this.cveUrl12Modified = cveUrl12Modified;
 672  
     }
 673  
 
 674  
     /**
 675  
      * The url for the modified NVD CVE (2.0 schema).
 676  
      */
 677  
     private String cveUrl20Modified;
 678  
 
 679  
     /**
 680  
      * Get the value of cveUrl20Modified.
 681  
      *
 682  
      * @return the value of cveUrl20Modified
 683  
      */
 684  
     public String getCveUrl20Modified() {
 685  
         return cveUrl20Modified;
 686  
     }
 687  
 
 688  
     /**
 689  
      * Set the value of cveUrl20Modified.
 690  
      *
 691  
      * @param cveUrl20Modified new value of cveUrl20Modified
 692  
      */
 693  
     public void setCveUrl20Modified(String cveUrl20Modified) {
 694  
         this.cveUrl20Modified = cveUrl20Modified;
 695  
     }
 696  
 
 697  
     /**
 698  
      * Base Data Mirror URL for CVE 1.2.
 699  
      */
 700  
     private String cveUrl12Base;
 701  
 
 702  
     /**
 703  
      * Get the value of cveUrl12Base.
 704  
      *
 705  
      * @return the value of cveUrl12Base
 706  
      */
 707  
     public String getCveUrl12Base() {
 708  
         return cveUrl12Base;
 709  
     }
 710  
 
 711  
     /**
 712  
      * Set the value of cveUrl12Base.
 713  
      *
 714  
      * @param cveUrl12Base new value of cveUrl12Base
 715  
      */
 716  
     public void setCveUrl12Base(String cveUrl12Base) {
 717  
         this.cveUrl12Base = cveUrl12Base;
 718  
     }
 719  
 
 720  
     /**
 721  
      * Data Mirror URL for CVE 2.0.
 722  
      */
 723  
     private String cveUrl20Base;
 724  
 
 725  
     /**
 726  
      * Get the value of cveUrl20Base.
 727  
      *
 728  
      * @return the value of cveUrl20Base
 729  
      */
 730  
     public String getCveUrl20Base() {
 731  
         return cveUrl20Base;
 732  
     }
 733  
 
 734  
     /**
 735  
      * Set the value of cveUrl20Base.
 736  
      *
 737  
      * @param cveUrl20Base new value of cveUrl20Base
 738  
      */
 739  
     public void setCveUrl20Base(String cveUrl20Base) {
 740  
         this.cveUrl20Base = cveUrl20Base;
 741  
     }
 742  
 
 743  
     /**
 744  
      * The path to Mono for .NET assembly analysis on non-windows systems.
 745  
      */
 746  
     private String pathToMono;
 747  
 
 748  
     /**
 749  
      * Get the value of pathToMono.
 750  
      *
 751  
      * @return the value of pathToMono
 752  
      */
 753  
     public String getPathToMono() {
 754  
         return pathToMono;
 755  
     }
 756  
 
 757  
     /**
 758  
      * Set the value of pathToMono.
 759  
      *
 760  
      * @param pathToMono new value of pathToMono
 761  
      */
 762  
     public void setPathToMono(String pathToMono) {
 763  
         this.pathToMono = pathToMono;
 764  
     }
 765  
 
 766  
     /**
 767  
      * Executes the Dependency-Check on the dependent libraries.
 768  
      *
 769  
      * @return the Engine used to scan the dependencies.
 770  
      * @throws org.owasp.dependencycheck.data.nvdcve.DatabaseException thrown if there is an exception connecting to the
 771  
      * database
 772  
      */
 773  
     private Engine executeDependencyCheck() throws DatabaseException {
 774  0
         populateSettings();
 775  0
         Engine engine = null;
 776  0
         engine = new Engine();
 777  0
         engine.setDependencies(this.dependencies);
 778  0
         engine.analyzeDependencies();
 779  0
         return engine;
 780  
     }
 781  
 
 782  
     /**
 783  
      * Generates the reports for a given dependency-check engine.
 784  
      *
 785  
      * @param engine a dependency-check engine
 786  
      * @param outDirectory the directory to write the reports to
 787  
      */
 788  
     private void generateExternalReports(Engine engine, File outDirectory) {
 789  0
         DatabaseProperties prop = null;
 790  0
         CveDB cve = null;
 791  
         try {
 792  0
             cve = new CveDB();
 793  0
             cve.open();
 794  0
             prop = cve.getDatabaseProperties();
 795  0
         } catch (DatabaseException ex) {
 796  0
             LOGGER.log(Level.FINE, "Unable to retrieve DB Properties", ex);
 797  
         } finally {
 798  0
             if (cve != null) {
 799  0
                 cve.close();
 800  
             }
 801  
         }
 802  0
         final ReportGenerator r = new ReportGenerator(this.applicationName, engine.getDependencies(), engine.getAnalyzers(), prop);
 803  
         try {
 804  0
             r.generateReports(outDirectory.getCanonicalPath(), this.reportFormat.name());
 805  0
         } catch (IOException ex) {
 806  0
             LOGGER.log(Level.SEVERE,
 807  
                     "Unexpected exception occurred during analysis; please see the verbose error log for more details.");
 808  0
             LOGGER.log(Level.FINE, null, ex);
 809  0
         } catch (Throwable ex) {
 810  0
             LOGGER.log(Level.SEVERE,
 811  
                     "Unexpected exception occurred during analysis; please see the verbose error log for more details.");
 812  0
             LOGGER.log(Level.FINE, null, ex);
 813  0
         }
 814  0
     }
 815  
 
 816  
     /**
 817  
      * Takes the properties supplied and updates the dependency-check settings. Additionally, this sets the system
 818  
      * properties required to change the proxy server, port, and connection timeout.
 819  
      */
 820  
     private void populateSettings() {
 821  0
         Settings.initialize();
 822  0
         if (dataDirectory != null) {
 823  0
             Settings.setString(Settings.KEYS.DATA_DIRECTORY, dataDirectory);
 824  
         } else {
 825  0
             final File jarPath = new File(DependencyCheckScanAgent.class.getProtectionDomain().getCodeSource().getLocation().getPath());
 826  0
             final File base = jarPath.getParentFile();
 827  0
             final String sub = Settings.getString(Settings.KEYS.DATA_DIRECTORY);
 828  0
             final File dataDir = new File(base, sub);
 829  0
             Settings.setString(Settings.KEYS.DATA_DIRECTORY, dataDir.getAbsolutePath());
 830  
         }
 831  
 
 832  0
         Settings.setBoolean(Settings.KEYS.AUTO_UPDATE, autoUpdate);
 833  
 
 834  0
         if (proxyServer != null && !proxyServer.isEmpty()) {
 835  0
             Settings.setString(Settings.KEYS.PROXY_SERVER, proxyServer);
 836  
         }
 837  0
         if (proxyPort != null && !proxyPort.isEmpty()) {
 838  0
             Settings.setString(Settings.KEYS.PROXY_PORT, proxyPort);
 839  
         }
 840  0
         if (proxyUsername != null && !proxyUsername.isEmpty()) {
 841  0
             Settings.setString(Settings.KEYS.PROXY_USERNAME, proxyUsername);
 842  
         }
 843  0
         if (proxyPassword != null && !proxyPassword.isEmpty()) {
 844  0
             Settings.setString(Settings.KEYS.PROXY_PASSWORD, proxyPassword);
 845  
         }
 846  0
         if (connectionTimeout != null && !connectionTimeout.isEmpty()) {
 847  0
             Settings.setString(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout);
 848  
         }
 849  0
         if (suppressionFile != null && !suppressionFile.isEmpty()) {
 850  0
             Settings.setString(Settings.KEYS.SUPPRESSION_FILE, suppressionFile);
 851  
         }
 852  0
         Settings.setBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED, nexusAnalyzerEnabled);
 853  0
         if (nexusUrl != null && !nexusUrl.isEmpty()) {
 854  0
             Settings.setString(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl);
 855  
         }
 856  0
         Settings.setBoolean(Settings.KEYS.ANALYZER_NEXUS_PROXY, nexusUsesProxy);
 857  0
         if (databaseDriverName != null && !databaseDriverName.isEmpty()) {
 858  0
             Settings.setString(Settings.KEYS.DB_DRIVER_NAME, databaseDriverName);
 859  
         }
 860  0
         if (databaseDriverPath != null && !databaseDriverPath.isEmpty()) {
 861  0
             Settings.setString(Settings.KEYS.DB_DRIVER_PATH, databaseDriverPath);
 862  
         }
 863  0
         if (connectionString != null && !connectionString.isEmpty()) {
 864  0
             Settings.setString(Settings.KEYS.DB_CONNECTION_STRING, connectionString);
 865  
         }
 866  0
         if (databaseUser != null && !databaseUser.isEmpty()) {
 867  0
             Settings.setString(Settings.KEYS.DB_USER, databaseUser);
 868  
         }
 869  0
         if (databasePassword != null && !databasePassword.isEmpty()) {
 870  0
             Settings.setString(Settings.KEYS.DB_PASSWORD, databasePassword);
 871  
         }
 872  0
         if (zipExtensions != null && !zipExtensions.isEmpty()) {
 873  0
             Settings.setString(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS, zipExtensions);
 874  
         }
 875  0
         if (cveUrl12Modified != null && !cveUrl12Modified.isEmpty()) {
 876  0
             Settings.setString(Settings.KEYS.CVE_MODIFIED_12_URL, cveUrl12Modified);
 877  
         }
 878  0
         if (cveUrl20Modified != null && !cveUrl20Modified.isEmpty()) {
 879  0
             Settings.setString(Settings.KEYS.CVE_MODIFIED_20_URL, cveUrl20Modified);
 880  
         }
 881  0
         if (cveUrl12Base != null && !cveUrl12Base.isEmpty()) {
 882  0
             Settings.setString(Settings.KEYS.CVE_SCHEMA_1_2, cveUrl12Base);
 883  
         }
 884  0
         if (cveUrl20Base != null && !cveUrl20Base.isEmpty()) {
 885  0
             Settings.setString(Settings.KEYS.CVE_SCHEMA_2_0, cveUrl20Base);
 886  
         }
 887  0
         if (pathToMono != null && !pathToMono.isEmpty()) {
 888  0
             Settings.setString(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, pathToMono);
 889  
         }
 890  0
     }
 891  
 
 892  
     /**
 893  
      * Executes the dependency-check and generates the report.
 894  
      *
 895  
      * @throws org.owasp.dependencycheck.exception.ScanAgentException thrown if there is an exception executing the
 896  
      * scan.
 897  
      */
 898  
     public void execute() throws ScanAgentException {
 899  0
         Engine engine = null;
 900  
         try {
 901  0
             engine = executeDependencyCheck();
 902  0
             generateExternalReports(engine, new File(this.reportOutputDirectory));
 903  0
             if (this.showSummary) {
 904  0
                 showSummary(engine.getDependencies());
 905  
             }
 906  0
             if (this.failBuildOnCVSS <= 10) {
 907  0
                 checkForFailure(engine.getDependencies());
 908  
             }
 909  0
         } catch (DatabaseException ex) {
 910  0
             LOGGER.log(Level.SEVERE,
 911  
                     "Unable to connect to the dependency-check database; analysis has stopped");
 912  0
             LOGGER.log(Level.FINE, "", ex);
 913  
         } finally {
 914  0
             Settings.cleanup(true);
 915  0
             if (engine != null) {
 916  0
                 engine.cleanup();
 917  
             }
 918  
         }
 919  0
     }
 920  
 
 921  
     /**
 922  
      * Checks to see if a vulnerability has been identified with a CVSS score that is above the threshold set in the
 923  
      * configuration.
 924  
      *
 925  
      * @param dependencies the list of dependency objects
 926  
      * @throws org.owasp.dependencycheck.exception.ScanAgentException thrown if there is an exception executing the
 927  
      * scan.
 928  
      */
 929  
     private void checkForFailure(List<Dependency> dependencies) throws ScanAgentException {
 930  0
         final StringBuilder ids = new StringBuilder();
 931  0
         for (Dependency d : dependencies) {
 932  0
             boolean addName = true;
 933  0
             for (Vulnerability v : d.getVulnerabilities()) {
 934  0
                 if (v.getCvssScore() >= failBuildOnCVSS) {
 935  0
                     if (addName) {
 936  0
                         addName = false;
 937  0
                         ids.append(NEW_LINE).append(d.getFileName()).append(": ");
 938  0
                         ids.append(v.getName());
 939  
                     } else {
 940  0
                         ids.append(", ").append(v.getName());
 941  
                     }
 942  
                 }
 943  0
             }
 944  0
         }
 945  0
         if (ids.length() > 0) {
 946  0
             final String msg = String.format("%n%nDependency-Check Failure:%n"
 947  
                     + "One or more dependencies were identified with vulnerabilities that have a CVSS score greater then '%.1f': %s%n"
 948  
                     + "See the dependency-check report for more details.%n%n", failBuildOnCVSS, ids.toString());
 949  
 
 950  0
             throw new ScanAgentException(msg);
 951  
         }
 952  0
     }
 953  
 
 954  
     /**
 955  
      * Generates a warning message listing a summary of dependencies and their associated CPE and CVE entries.
 956  
      *
 957  
      * @param dependencies a list of dependency objects
 958  
      */
 959  
     private void showSummary(List<Dependency> dependencies) {
 960  0
         final StringBuilder summary = new StringBuilder();
 961  0
         for (Dependency d : dependencies) {
 962  0
             boolean firstEntry = true;
 963  0
             final StringBuilder ids = new StringBuilder();
 964  0
             for (Vulnerability v : d.getVulnerabilities()) {
 965  0
                 if (firstEntry) {
 966  0
                     firstEntry = false;
 967  
                 } else {
 968  0
                     ids.append(", ");
 969  
                 }
 970  0
                 ids.append(v.getName());
 971  0
             }
 972  0
             if (ids.length() > 0) {
 973  0
                 summary.append(d.getFileName()).append(" (");
 974  0
                 firstEntry = true;
 975  0
                 for (Identifier id : d.getIdentifiers()) {
 976  0
                     if (firstEntry) {
 977  0
                         firstEntry = false;
 978  
                     } else {
 979  0
                         summary.append(", ");
 980  
                     }
 981  0
                     summary.append(id.getValue());
 982  0
                 }
 983  0
                 summary.append(") : ").append(ids).append(NEW_LINE);
 984  
             }
 985  0
         }
 986  0
         if (summary.length() > 0) {
 987  0
             final String msg = String.format("%n%n"
 988  
                     + "One or more dependencies were identified with known vulnerabilities:%n%n%s"
 989  
                     + "%n%nSee the dependency-check report for more details.%n%n", summary.toString());
 990  0
             LOGGER.log(Level.WARNING, msg);
 991  
         }
 992  0
     }
 993  
 
 994  
 }