| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.owasp.dependencycheck.maven; |
| 19 | |
|
| 20 | |
import java.io.BufferedOutputStream; |
| 21 | |
import java.io.File; |
| 22 | |
import java.io.FileInputStream; |
| 23 | |
import java.io.FileNotFoundException; |
| 24 | |
import java.io.FileOutputStream; |
| 25 | |
import java.io.IOException; |
| 26 | |
import java.io.InputStream; |
| 27 | |
import java.io.ObjectInputStream; |
| 28 | |
import java.io.ObjectOutputStream; |
| 29 | |
import java.io.OutputStream; |
| 30 | |
import java.util.List; |
| 31 | |
import java.util.Locale; |
| 32 | |
import org.apache.maven.artifact.Artifact; |
| 33 | |
import org.apache.maven.doxia.sink.Sink; |
| 34 | |
import org.apache.maven.plugin.AbstractMojo; |
| 35 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 36 | |
import org.apache.maven.plugin.MojoFailureException; |
| 37 | |
import org.apache.maven.plugins.annotations.Parameter; |
| 38 | |
import org.apache.maven.project.MavenProject; |
| 39 | |
import org.apache.maven.reporting.MavenReport; |
| 40 | |
import org.apache.maven.reporting.MavenReportException; |
| 41 | |
import org.apache.maven.settings.Proxy; |
| 42 | |
import org.owasp.dependencycheck.data.nexus.MavenArtifact; |
| 43 | |
import org.owasp.dependencycheck.data.nvdcve.CveDB; |
| 44 | |
import org.owasp.dependencycheck.data.nvdcve.DatabaseException; |
| 45 | |
import org.owasp.dependencycheck.data.nvdcve.DatabaseProperties; |
| 46 | |
import org.owasp.dependencycheck.dependency.Confidence; |
| 47 | |
import org.owasp.dependencycheck.dependency.Dependency; |
| 48 | |
import org.owasp.dependencycheck.dependency.Identifier; |
| 49 | |
import org.owasp.dependencycheck.dependency.Vulnerability; |
| 50 | |
import org.owasp.dependencycheck.reporting.ReportGenerator; |
| 51 | |
import org.owasp.dependencycheck.utils.Settings; |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | 1 | public abstract class BaseDependencyCheckMojo extends AbstractMojo implements MavenReport { |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
private static final String PROPERTIES_FILE = "mojo.properties"; |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | 1 | private static final String NEW_LINE = System.getProperty("line.separator", "\n").intern(); |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
@Parameter(property = "metaFileName", defaultValue = "dependency-check.ser", required = true) |
| 72 | |
private String dataFileName; |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
@Parameter(property = "project", required = true, readonly = true) |
| 80 | |
private MavenProject project; |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
@Parameter(readonly = true, required = true, property = "reactorProjects") |
| 85 | |
private List<MavenProject> reactorProjects; |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
@Parameter(defaultValue = "${project.build.directory}", required = true) |
| 91 | |
private File outputDirectory; |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
@Parameter(property = "project.reporting.outputDirectory", required = true) |
| 96 | |
private File reportOutputDirectory; |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | 1 | @SuppressWarnings("CanBeFinal") |
| 102 | |
@Parameter(property = "failBuildOnCVSS", defaultValue = "11", required = true) |
| 103 | |
private float failBuildOnCVSS = 11; |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | 1 | @SuppressWarnings("CanBeFinal") |
| 109 | |
@Parameter(property = "autoupdate", defaultValue = "true", required = true) |
| 110 | |
private boolean autoUpdate = true; |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
@Parameter(property = "aggregate", defaultValue = "false") |
| 117 | |
@Deprecated |
| 118 | |
private boolean aggregate; |
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | 1 | @SuppressWarnings("CanBeFinal") |
| 124 | |
@Parameter(property = "format", defaultValue = "HTML", required = true) |
| 125 | |
private String format = "HTML"; |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
@Parameter(property = "mavenSettings", defaultValue = "${settings}", required = false) |
| 130 | |
private org.apache.maven.settings.Settings mavenSettings; |
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
@SuppressWarnings("CanBeFinal") |
| 136 | |
@Parameter(property = "mavenSettingsProxyId", required = false) |
| 137 | |
private String mavenSettingsProxyId; |
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | 1 | @SuppressWarnings("CanBeFinal") |
| 143 | |
@Parameter(property = "connectionTimeout", defaultValue = "", required = false) |
| 144 | |
private String connectionTimeout = null; |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | 1 | @SuppressWarnings("CanBeFinal") |
| 149 | |
@Parameter(property = "suppressionFile", defaultValue = "", required = false) |
| 150 | |
private String suppressionFile = null; |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | 1 | @SuppressWarnings("CanBeFinal") |
| 155 | |
@Parameter(property = "showSummary", defaultValue = "true", required = false) |
| 156 | |
private boolean showSummary = true; |
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | 1 | @SuppressWarnings("CanBeFinal") |
| 162 | |
@Parameter(property = "jarAnalyzerEnabled", defaultValue = "true", required = false) |
| 163 | |
private boolean jarAnalyzerEnabled = true; |
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | 1 | @SuppressWarnings("CanBeFinal") |
| 169 | |
@Parameter(property = "archiveAnalyzerEnabled", defaultValue = "true", required = false) |
| 170 | |
private boolean archiveAnalyzerEnabled = true; |
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | 1 | @SuppressWarnings("CanBeFinal") |
| 176 | |
@Parameter(property = "assemblyAnalyzerEnabled", defaultValue = "true", required = false) |
| 177 | |
private boolean assemblyAnalyzerEnabled = true; |
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | 1 | @SuppressWarnings("CanBeFinal") |
| 183 | |
@Parameter(property = "nuspecAnalyzerEnabled", defaultValue = "true", required = false) |
| 184 | |
private boolean nuspecAnalyzerEnabled = true; |
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | 1 | @SuppressWarnings("CanBeFinal") |
| 190 | |
@Parameter(property = "centralAnalyzerEnabled", defaultValue = "true", required = false) |
| 191 | |
private boolean centralAnalyzerEnabled = true; |
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | 1 | @SuppressWarnings("CanBeFinal") |
| 197 | |
@Parameter(property = "nexusAnalyzerEnabled", defaultValue = "true", required = false) |
| 198 | |
private boolean nexusAnalyzerEnabled = true; |
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
@Parameter(property = "nexusUrl", defaultValue = "", required = false) |
| 204 | |
private String nexusUrl; |
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | 1 | @Parameter(property = "nexusUsesProxy", defaultValue = "true", required = false) |
| 209 | |
private boolean nexusUsesProxy = true; |
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
@Parameter(property = "connectionString", defaultValue = "", required = false) |
| 214 | |
private String connectionString; |
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
protected String getConnectionString() { |
| 222 | 0 | return connectionString; |
| 223 | |
} |
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
@Parameter(property = "databaseDriverName", defaultValue = "", required = false) |
| 228 | |
private String databaseDriverName; |
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
@Parameter(property = "databaseDriverPath", defaultValue = "", required = false) |
| 233 | |
private String databaseDriverPath; |
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
@Parameter(property = "databaseUser", defaultValue = "", required = false) |
| 238 | |
private String databaseUser; |
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
@Parameter(property = "databasePassword", defaultValue = "", required = false) |
| 243 | |
private String databasePassword; |
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
@Parameter(property = "zipExtensions", required = false) |
| 248 | |
private String zipExtensions; |
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | 1 | @SuppressWarnings("CanBeFinal") |
| 253 | |
@Parameter(property = "skipTestScope", defaultValue = "true", required = false) |
| 254 | |
private boolean skipTestScope = true; |
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | 1 | @SuppressWarnings("CanBeFinal") |
| 259 | |
@Parameter(property = "skipRuntimeScope", defaultValue = "false", required = false) |
| 260 | |
private boolean skipRuntimeScope = false; |
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | 1 | @SuppressWarnings("CanBeFinal") |
| 265 | |
@Parameter(property = "skipProvidedScope", defaultValue = "false", required = false) |
| 266 | |
private boolean skipProvidedScope = false; |
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
@Parameter(property = "dataDirectory", defaultValue = "", required = false) |
| 271 | |
private String dataDirectory; |
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
@Parameter(property = "cveUrl12Modified", defaultValue = "", required = false) |
| 276 | |
private String cveUrl12Modified; |
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
@Parameter(property = "cveUrl20Modified", defaultValue = "", required = false) |
| 281 | |
private String cveUrl20Modified; |
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
@Parameter(property = "cveUrl12Base", defaultValue = "", required = false) |
| 286 | |
private String cveUrl12Base; |
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
@Parameter(property = "cveUrl20Base", defaultValue = "", required = false) |
| 291 | |
private String cveUrl20Base; |
| 292 | |
|
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
@Parameter(property = "pathToMono", defaultValue = "", required = false) |
| 297 | |
private String pathToMono; |
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | 1 | @SuppressWarnings("CanBeFinal") |
| 305 | |
@Parameter(property = "proxyUrl", defaultValue = "", required = false) |
| 306 | |
@Deprecated |
| 307 | |
private String proxyUrl = null; |
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | 1 | @SuppressWarnings("CanBeFinal") |
| 314 | |
@Parameter(property = "externalReport") |
| 315 | |
@Deprecated |
| 316 | |
private String externalReport = null; |
| 317 | |
|
| 318 | |
|
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
@Override |
| 327 | |
public void execute() throws MojoExecutionException, MojoFailureException { |
| 328 | 0 | validateAggregate(); |
| 329 | 0 | project.setContextValue(getOutputDirectoryContextKey(), this.outputDirectory); |
| 330 | 0 | runCheck(); |
| 331 | 0 | } |
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | |
|
| 339 | |
private void validateAggregate() throws MojoExecutionException { |
| 340 | 0 | if (aggregate) { |
| 341 | 0 | final String msg = "Aggregate configuration detected - as of dependency-check 1.2.8 this no longer supported. " |
| 342 | |
+ "Please use the aggregate goal instead."; |
| 343 | 0 | throw new MojoExecutionException(msg); |
| 344 | |
} |
| 345 | 0 | } |
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
@Override |
| 356 | |
@Deprecated |
| 357 | |
public final void generate(@SuppressWarnings("deprecation") org.codehaus.doxia.sink.Sink sink, Locale locale) throws MavenReportException { |
| 358 | 0 | generate((Sink) sink, locale); |
| 359 | 0 | } |
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
public void generate(Sink sink, Locale locale) throws MavenReportException { |
| 369 | |
try { |
| 370 | 0 | validateAggregate(); |
| 371 | 0 | } catch (MojoExecutionException ex) { |
| 372 | 0 | throw new MavenReportException(ex.getMessage()); |
| 373 | 0 | } |
| 374 | 0 | project.setContextValue(getOutputDirectoryContextKey(), getReportOutputDirectory()); |
| 375 | |
try { |
| 376 | 0 | runCheck(); |
| 377 | 0 | } catch (MojoExecutionException ex) { |
| 378 | 0 | throw new MavenReportException(ex.getMessage(), ex); |
| 379 | 0 | } catch (MojoFailureException ex) { |
| 380 | 0 | getLog().warn("Vulnerabilities were identifies that exceed the CVSS threshold for failing the build"); |
| 381 | 0 | } |
| 382 | 0 | } |
| 383 | |
|
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
protected File getCorrectOutputDirectory() throws MojoExecutionException { |
| 391 | 0 | return getCorrectOutputDirectory(this.project); |
| 392 | |
} |
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
protected File getCorrectOutputDirectory(MavenProject current) { |
| 401 | 0 | final Object obj = current.getContextValue(getOutputDirectoryContextKey()); |
| 402 | 0 | if (obj != null && obj instanceof File) { |
| 403 | 0 | return (File) obj; |
| 404 | |
} |
| 405 | 0 | File target = new File(current.getBuild().getDirectory()); |
| 406 | 0 | if (target.getParentFile() != null && "target".equals(target.getParentFile().getName())) { |
| 407 | 0 | target = target.getParentFile(); |
| 408 | |
} |
| 409 | 0 | return target; |
| 410 | |
} |
| 411 | |
|
| 412 | |
|
| 413 | |
|
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
protected File getDataFile(MavenProject current) { |
| 419 | 0 | if (getLog().isDebugEnabled()) { |
| 420 | 0 | getLog().debug(String.format("Getting data filefor %s using key '%s'", current.getName(), getDataFileContextKey())); |
| 421 | |
} |
| 422 | 0 | final Object obj = current.getContextValue(getDataFileContextKey()); |
| 423 | 0 | if (obj != null) { |
| 424 | 0 | if (obj instanceof String) { |
| 425 | 0 | final File f = new File((String) obj); |
| 426 | 0 | return f; |
| 427 | |
} |
| 428 | |
} else { |
| 429 | 0 | if (getLog().isDebugEnabled()) { |
| 430 | 0 | getLog().debug("Context value not found"); |
| 431 | |
} |
| 432 | |
} |
| 433 | 0 | return null; |
| 434 | |
} |
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
|
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
protected void scanArtifacts(MavenProject project, Engine engine) { |
| 443 | 1 | for (Artifact a : project.getArtifacts()) { |
| 444 | 1 | if (excludeFromScan(a)) { |
| 445 | 0 | continue; |
| 446 | |
} |
| 447 | 1 | final List<Dependency> deps = engine.scan(a.getFile().getAbsoluteFile()); |
| 448 | 1 | if (deps != null) { |
| 449 | 1 | if (deps.size() == 1) { |
| 450 | 1 | final Dependency d = deps.get(0); |
| 451 | 1 | if (d != null) { |
| 452 | 1 | final MavenArtifact ma = new MavenArtifact(a.getGroupId(), a.getArtifactId(), a.getVersion()); |
| 453 | 1 | d.addAsEvidence("pom", ma, Confidence.HIGHEST); |
| 454 | 1 | d.addProjectReference(project.getName()); |
| 455 | 1 | if (getLog().isDebugEnabled()) { |
| 456 | 0 | getLog().debug(String.format("Adding project reference %s on dependency %s", project.getName(), |
| 457 | |
d.getDisplayFileName())); |
| 458 | |
} |
| 459 | |
} |
| 460 | 1 | } else { |
| 461 | 0 | if (getLog().isDebugEnabled()) { |
| 462 | 0 | final String msg = String.format("More then 1 dependency was identified in first pass scan of '%s:%s:%s'", |
| 463 | |
a.getGroupId(), a.getArtifactId(), a.getVersion()); |
| 464 | 0 | getLog().debug(msg); |
| 465 | |
} |
| 466 | |
} |
| 467 | |
} |
| 468 | 1 | } |
| 469 | 1 | } |
| 470 | |
|
| 471 | |
|
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | |
|
| 476 | |
|
| 477 | |
public abstract void runCheck() throws MojoExecutionException, MojoFailureException; |
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
@Override |
| 485 | |
public void setReportOutputDirectory(File directory) { |
| 486 | 0 | reportOutputDirectory = directory; |
| 487 | 0 | } |
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
|
| 492 | |
|
| 493 | |
|
| 494 | |
@Override |
| 495 | |
public File getReportOutputDirectory() { |
| 496 | 0 | return reportOutputDirectory; |
| 497 | |
} |
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
|
| 502 | |
|
| 503 | |
|
| 504 | |
public File getOutputDirectory() { |
| 505 | 0 | return outputDirectory; |
| 506 | |
} |
| 507 | |
|
| 508 | |
|
| 509 | |
|
| 510 | |
|
| 511 | |
|
| 512 | |
|
| 513 | |
@Override |
| 514 | |
public final boolean isExternalReport() { |
| 515 | 0 | return true; |
| 516 | |
} |
| 517 | |
|
| 518 | |
|
| 519 | |
|
| 520 | |
|
| 521 | |
|
| 522 | |
|
| 523 | |
@Override |
| 524 | |
public String getOutputName() { |
| 525 | 0 | if ("HTML".equalsIgnoreCase(this.format) || "ALL".equalsIgnoreCase(this.format)) { |
| 526 | 0 | return "dependency-check-report"; |
| 527 | 0 | } else if ("XML".equalsIgnoreCase(this.format)) { |
| 528 | 0 | return "dependency-check-report.xml#"; |
| 529 | 0 | } else if ("VULN".equalsIgnoreCase(this.format)) { |
| 530 | 0 | return "dependency-check-vulnerability"; |
| 531 | |
} else { |
| 532 | 0 | getLog().warn("Unknown report format used during site generation."); |
| 533 | 0 | return "dependency-check-report"; |
| 534 | |
} |
| 535 | |
} |
| 536 | |
|
| 537 | |
|
| 538 | |
|
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
@Override |
| 543 | |
public String getCategoryName() { |
| 544 | 0 | return MavenReport.CATEGORY_PROJECT_REPORTS; |
| 545 | |
} |
| 546 | |
|
| 547 | |
|
| 548 | |
|
| 549 | |
|
| 550 | |
|
| 551 | |
|
| 552 | |
|
| 553 | |
|
| 554 | |
protected Engine initializeEngine() throws DatabaseException { |
| 555 | 0 | populateSettings(); |
| 556 | 0 | return new Engine(this.project, |
| 557 | |
this.reactorProjects); |
| 558 | |
} |
| 559 | |
|
| 560 | |
|
| 561 | |
|
| 562 | |
|
| 563 | |
|
| 564 | |
protected void populateSettings() { |
| 565 | 0 | Settings.initialize(); |
| 566 | 0 | InputStream mojoProperties = null; |
| 567 | |
try { |
| 568 | 0 | mojoProperties = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILE); |
| 569 | 0 | Settings.mergeProperties(mojoProperties); |
| 570 | 0 | } catch (IOException ex) { |
| 571 | 0 | getLog().warn("Unable to load the dependency-check ant task.properties file."); |
| 572 | 0 | if (getLog().isDebugEnabled()) { |
| 573 | 0 | getLog().debug("", ex); |
| 574 | |
} |
| 575 | |
} finally { |
| 576 | 0 | if (mojoProperties != null) { |
| 577 | |
try { |
| 578 | 0 | mojoProperties.close(); |
| 579 | 0 | } catch (IOException ex) { |
| 580 | 0 | if (getLog().isDebugEnabled()) { |
| 581 | 0 | getLog().debug("", ex); |
| 582 | |
} |
| 583 | 0 | } |
| 584 | |
} |
| 585 | |
} |
| 586 | |
|
| 587 | 0 | Settings.setBoolean(Settings.KEYS.AUTO_UPDATE, autoUpdate); |
| 588 | 0 | if (externalReport != null) { |
| 589 | 0 | getLog().warn("The 'externalReport' option was set; this configuration option has been removed. " |
| 590 | |
+ "Please update the dependency-check-maven plugin's configuration"); |
| 591 | |
} |
| 592 | |
|
| 593 | 0 | if (proxyUrl != null && !proxyUrl.isEmpty()) { |
| 594 | 0 | getLog().warn("Deprecated configuration detected, proxyUrl will be ignored; use the maven settings " + "to configure the proxy instead"); |
| 595 | |
} |
| 596 | 0 | final Proxy proxy = getMavenProxy(); |
| 597 | 0 | if (proxy != null) { |
| 598 | 0 | Settings.setString(Settings.KEYS.PROXY_SERVER, proxy.getHost()); |
| 599 | 0 | Settings.setString(Settings.KEYS.PROXY_PORT, Integer.toString(proxy.getPort())); |
| 600 | 0 | final String userName = proxy.getUsername(); |
| 601 | 0 | final String password = proxy.getPassword(); |
| 602 | 0 | if (userName != null) { |
| 603 | 0 | Settings.setString(Settings.KEYS.PROXY_USERNAME, userName); |
| 604 | |
} |
| 605 | 0 | if (password != null) { |
| 606 | 0 | Settings.setString(Settings.KEYS.PROXY_PASSWORD, password); |
| 607 | |
} |
| 608 | |
|
| 609 | |
} |
| 610 | |
|
| 611 | 0 | if (connectionTimeout != null && !connectionTimeout.isEmpty()) { |
| 612 | 0 | Settings.setString(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout); |
| 613 | |
} |
| 614 | 0 | if (suppressionFile != null && !suppressionFile.isEmpty()) { |
| 615 | 0 | Settings.setString(Settings.KEYS.SUPPRESSION_FILE, suppressionFile); |
| 616 | |
} |
| 617 | |
|
| 618 | |
|
| 619 | |
|
| 620 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_JAR_ENABLED, jarAnalyzerEnabled); |
| 621 | |
|
| 622 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_NUSPEC_ENABLED, nuspecAnalyzerEnabled); |
| 623 | |
|
| 624 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_CENTRAL_ENABLED, centralAnalyzerEnabled); |
| 625 | |
|
| 626 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED, nexusAnalyzerEnabled); |
| 627 | 0 | if (nexusUrl != null && !nexusUrl.isEmpty()) { |
| 628 | 0 | Settings.setString(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl); |
| 629 | |
} |
| 630 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_NEXUS_PROXY, nexusUsesProxy); |
| 631 | |
|
| 632 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, archiveAnalyzerEnabled); |
| 633 | 0 | if (zipExtensions != null && !zipExtensions.isEmpty()) { |
| 634 | 0 | Settings.setString(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS, zipExtensions); |
| 635 | |
} |
| 636 | |
|
| 637 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_ASSEMBLY_ENABLED, assemblyAnalyzerEnabled); |
| 638 | 0 | if (pathToMono != null && !pathToMono.isEmpty()) { |
| 639 | 0 | Settings.setString(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, pathToMono); |
| 640 | |
} |
| 641 | |
|
| 642 | |
|
| 643 | 0 | if (databaseDriverName != null && !databaseDriverName.isEmpty()) { |
| 644 | 0 | Settings.setString(Settings.KEYS.DB_DRIVER_NAME, databaseDriverName); |
| 645 | |
} |
| 646 | 0 | if (databaseDriverPath != null && !databaseDriverPath.isEmpty()) { |
| 647 | 0 | Settings.setString(Settings.KEYS.DB_DRIVER_PATH, databaseDriverPath); |
| 648 | |
} |
| 649 | 0 | if (connectionString != null && !connectionString.isEmpty()) { |
| 650 | 0 | Settings.setString(Settings.KEYS.DB_CONNECTION_STRING, connectionString); |
| 651 | |
} |
| 652 | 0 | if (databaseUser != null && !databaseUser.isEmpty()) { |
| 653 | 0 | Settings.setString(Settings.KEYS.DB_USER, databaseUser); |
| 654 | |
} |
| 655 | 0 | if (databasePassword != null && !databasePassword.isEmpty()) { |
| 656 | 0 | Settings.setString(Settings.KEYS.DB_PASSWORD, databasePassword); |
| 657 | |
} |
| 658 | |
|
| 659 | 0 | if (dataDirectory != null && !dataDirectory.isEmpty()) { |
| 660 | 0 | Settings.setString(Settings.KEYS.DATA_DIRECTORY, dataDirectory); |
| 661 | |
} |
| 662 | |
|
| 663 | |
|
| 664 | 0 | Settings.setBoolean(Settings.KEYS.SKIP_TEST_SCOPE, skipTestScope); |
| 665 | 0 | Settings.setBoolean(Settings.KEYS.SKIP_RUNTIME_SCOPE, skipRuntimeScope); |
| 666 | 0 | Settings.setBoolean(Settings.KEYS.SKIP_PROVIDED_SCOPE, skipProvidedScope); |
| 667 | |
|
| 668 | |
|
| 669 | 0 | if (cveUrl12Modified != null && !cveUrl12Modified.isEmpty()) { |
| 670 | 0 | Settings.setString(Settings.KEYS.CVE_MODIFIED_12_URL, cveUrl12Modified); |
| 671 | |
} |
| 672 | 0 | if (cveUrl20Modified != null && !cveUrl20Modified.isEmpty()) { |
| 673 | 0 | Settings.setString(Settings.KEYS.CVE_MODIFIED_20_URL, cveUrl20Modified); |
| 674 | |
} |
| 675 | 0 | if (cveUrl12Base != null && !cveUrl12Base.isEmpty()) { |
| 676 | 0 | Settings.setString(Settings.KEYS.CVE_SCHEMA_1_2, cveUrl12Base); |
| 677 | |
} |
| 678 | 0 | if (cveUrl20Base != null && !cveUrl20Base.isEmpty()) { |
| 679 | 0 | Settings.setString(Settings.KEYS.CVE_SCHEMA_2_0, cveUrl20Base); |
| 680 | |
} |
| 681 | 0 | } |
| 682 | |
|
| 683 | |
|
| 684 | |
|
| 685 | |
|
| 686 | |
|
| 687 | |
|
| 688 | |
private Proxy getMavenProxy() { |
| 689 | 0 | if (mavenSettings != null) { |
| 690 | 0 | final List<Proxy> proxies = mavenSettings.getProxies(); |
| 691 | 0 | if (proxies != null && !proxies.isEmpty()) { |
| 692 | 0 | if (mavenSettingsProxyId != null) { |
| 693 | 0 | for (Proxy proxy : proxies) { |
| 694 | 0 | if (mavenSettingsProxyId.equalsIgnoreCase(proxy.getId())) { |
| 695 | 0 | return proxy; |
| 696 | |
} |
| 697 | 0 | } |
| 698 | 0 | } else if (proxies.size() == 1) { |
| 699 | 0 | return proxies.get(0); |
| 700 | |
} else { |
| 701 | 0 | getLog().warn("Multiple proxy definitions exist in the Maven settings. In the dependency-check " |
| 702 | |
+ "configuration set the mavenSettingsProxyId so that the correct proxy will be used."); |
| 703 | 0 | throw new IllegalStateException("Ambiguous proxy definition"); |
| 704 | |
} |
| 705 | |
} |
| 706 | |
} |
| 707 | 0 | return null; |
| 708 | |
} |
| 709 | |
|
| 710 | |
|
| 711 | |
|
| 712 | |
|
| 713 | |
|
| 714 | |
|
| 715 | |
|
| 716 | |
protected boolean excludeFromScan(Artifact a) { |
| 717 | 1 | if (skipTestScope && Artifact.SCOPE_TEST.equals(a.getScope())) { |
| 718 | 0 | return true; |
| 719 | |
} |
| 720 | 1 | if (skipProvidedScope && Artifact.SCOPE_PROVIDED.equals(a.getScope())) { |
| 721 | 0 | return true; |
| 722 | |
} |
| 723 | 1 | if (skipRuntimeScope && !Artifact.SCOPE_RUNTIME.equals(a.getScope())) { |
| 724 | 0 | return true; |
| 725 | |
} |
| 726 | 1 | return false; |
| 727 | |
} |
| 728 | |
|
| 729 | |
|
| 730 | |
|
| 731 | |
|
| 732 | |
|
| 733 | |
|
| 734 | |
|
| 735 | |
|
| 736 | |
|
| 737 | |
protected MavenProject getProject() { |
| 738 | 0 | return project; |
| 739 | |
} |
| 740 | |
|
| 741 | |
|
| 742 | |
|
| 743 | |
|
| 744 | |
|
| 745 | |
|
| 746 | |
protected List<MavenProject> getReactorProjects() { |
| 747 | 0 | return reactorProjects; |
| 748 | |
} |
| 749 | |
|
| 750 | |
|
| 751 | |
|
| 752 | |
|
| 753 | |
|
| 754 | |
|
| 755 | |
protected String getFormat() { |
| 756 | 0 | return format; |
| 757 | |
} |
| 758 | |
|
| 759 | |
|
| 760 | |
|
| 761 | |
|
| 762 | |
|
| 763 | |
|
| 764 | |
|
| 765 | |
|
| 766 | |
protected void writeReports(Engine engine, MavenProject p, File outputDir) { |
| 767 | 0 | DatabaseProperties prop = null; |
| 768 | 0 | CveDB cve = null; |
| 769 | |
try { |
| 770 | 0 | cve = new CveDB(); |
| 771 | 0 | cve.open(); |
| 772 | 0 | prop = cve.getDatabaseProperties(); |
| 773 | 0 | } catch (DatabaseException ex) { |
| 774 | 0 | if (getLog().isDebugEnabled()) { |
| 775 | 0 | getLog().debug("Unable to retrieve DB Properties", ex); |
| 776 | |
} |
| 777 | |
} finally { |
| 778 | 0 | if (cve != null) { |
| 779 | 0 | cve.close(); |
| 780 | |
} |
| 781 | |
} |
| 782 | 0 | final ReportGenerator r = new ReportGenerator(p.getName(), engine.getDependencies(), engine.getAnalyzers(), prop); |
| 783 | |
try { |
| 784 | 0 | r.generateReports(outputDir.getAbsolutePath(), format); |
| 785 | 0 | } catch (IOException ex) { |
| 786 | 0 | getLog().error( |
| 787 | |
"Unexpected exception occurred during analysis; please see the verbose error log for more details."); |
| 788 | 0 | if (getLog().isDebugEnabled()) { |
| 789 | 0 | getLog().debug("", ex); |
| 790 | |
} |
| 791 | 0 | } catch (Throwable ex) { |
| 792 | 0 | getLog().error( |
| 793 | |
"Unexpected exception occurred during analysis; please see the verbose error log for more details."); |
| 794 | 0 | if (getLog().isDebugEnabled()) { |
| 795 | 0 | getLog().debug("", ex); |
| 796 | |
} |
| 797 | 0 | } |
| 798 | 0 | } |
| 799 | |
|
| 800 | |
|
| 801 | |
|
| 802 | |
|
| 803 | |
|
| 804 | |
|
| 805 | |
|
| 806 | |
|
| 807 | |
|
| 808 | |
protected void checkForFailure(List<Dependency> dependencies) throws MojoFailureException { |
| 809 | 0 | if (failBuildOnCVSS <= 10) { |
| 810 | 0 | final StringBuilder ids = new StringBuilder(); |
| 811 | 0 | for (Dependency d : dependencies) { |
| 812 | 0 | boolean addName = true; |
| 813 | 0 | for (Vulnerability v : d.getVulnerabilities()) { |
| 814 | 0 | if (v.getCvssScore() >= failBuildOnCVSS) { |
| 815 | 0 | if (addName) { |
| 816 | 0 | addName = false; |
| 817 | 0 | ids.append(NEW_LINE).append(d.getFileName()).append(": "); |
| 818 | 0 | ids.append(v.getName()); |
| 819 | |
} else { |
| 820 | 0 | ids.append(", ").append(v.getName()); |
| 821 | |
} |
| 822 | |
} |
| 823 | 0 | } |
| 824 | 0 | } |
| 825 | 0 | if (ids.length() > 0) { |
| 826 | 0 | final String msg = String.format("%n%nDependency-Check Failure:%n" |
| 827 | |
+ "One or more dependencies were identified with vulnerabilities that have a CVSS score greater then '%.1f': %s%n" |
| 828 | |
+ "See the dependency-check report for more details.%n%n", failBuildOnCVSS, ids.toString()); |
| 829 | 0 | throw new MojoFailureException(msg); |
| 830 | |
} |
| 831 | |
} |
| 832 | 0 | } |
| 833 | |
|
| 834 | |
|
| 835 | |
|
| 836 | |
|
| 837 | |
|
| 838 | |
|
| 839 | |
|
| 840 | |
protected void showSummary(MavenProject mp, List<Dependency> dependencies) { |
| 841 | 0 | if (showSummary) { |
| 842 | 0 | final StringBuilder summary = new StringBuilder(); |
| 843 | 0 | for (Dependency d : dependencies) { |
| 844 | 0 | boolean firstEntry = true; |
| 845 | 0 | final StringBuilder ids = new StringBuilder(); |
| 846 | 0 | for (Vulnerability v : d.getVulnerabilities()) { |
| 847 | 0 | if (firstEntry) { |
| 848 | 0 | firstEntry = false; |
| 849 | |
} else { |
| 850 | 0 | ids.append(", "); |
| 851 | |
} |
| 852 | 0 | ids.append(v.getName()); |
| 853 | 0 | } |
| 854 | 0 | if (ids.length() > 0) { |
| 855 | 0 | summary.append(d.getFileName()).append(" ("); |
| 856 | 0 | firstEntry = true; |
| 857 | 0 | for (Identifier id : d.getIdentifiers()) { |
| 858 | 0 | if (firstEntry) { |
| 859 | 0 | firstEntry = false; |
| 860 | |
} else { |
| 861 | 0 | summary.append(", "); |
| 862 | |
} |
| 863 | 0 | summary.append(id.getValue()); |
| 864 | 0 | } |
| 865 | 0 | summary.append(") : ").append(ids).append(NEW_LINE); |
| 866 | |
} |
| 867 | 0 | } |
| 868 | 0 | if (summary.length() > 0) { |
| 869 | 0 | final String msg = String.format("%n%n" + "One or more dependencies were identified with known vulnerabilities in %s:%n%n%s" |
| 870 | |
+ "%n%nSee the dependency-check report for more details.%n%n", mp.getName(), summary.toString()); |
| 871 | 0 | getLog().warn(msg); |
| 872 | |
} |
| 873 | |
} |
| 874 | 0 | } |
| 875 | |
|
| 876 | |
|
| 877 | |
|
| 878 | |
|
| 879 | |
|
| 880 | |
|
| 881 | |
|
| 882 | |
|
| 883 | |
|
| 884 | |
protected String getDataFileContextKey() { |
| 885 | 0 | return "dependency-check-path-" + dataFileName; |
| 886 | |
} |
| 887 | |
|
| 888 | |
|
| 889 | |
|
| 890 | |
|
| 891 | |
|
| 892 | |
|
| 893 | |
|
| 894 | |
protected String getOutputDirectoryContextKey() { |
| 895 | 0 | return "dependency-output-dir-" + dataFileName; |
| 896 | |
} |
| 897 | |
|
| 898 | |
|
| 899 | |
|
| 900 | |
|
| 901 | |
|
| 902 | |
|
| 903 | |
|
| 904 | |
|
| 905 | |
protected void writeDataFile(MavenProject mp, File writeTo, List<Dependency> dependencies) { |
| 906 | |
File file; |
| 907 | |
|
| 908 | 0 | if (mp.getContextValue(this.getDataFileContextKey()) == null) { |
| 909 | 0 | if (writeTo == null) { |
| 910 | 0 | file = new File(mp.getBuild().getDirectory()); |
| 911 | 0 | file = new File(file, dataFileName); |
| 912 | |
} else { |
| 913 | 0 | file = new File(writeTo, dataFileName); |
| 914 | |
} |
| 915 | 0 | final File parent = file.getParentFile(); |
| 916 | 0 | if (!parent.isDirectory() && parent.mkdirs()) { |
| 917 | 0 | getLog().error(String.format("Directory '%s' does not exist and cannot be created; unable to write data file.", |
| 918 | |
parent.getAbsolutePath())); |
| 919 | |
} |
| 920 | |
|
| 921 | 0 | OutputStream os = null; |
| 922 | 0 | OutputStream bos = null; |
| 923 | 0 | ObjectOutputStream out = null; |
| 924 | |
try { |
| 925 | 0 | if (dependencies != null) { |
| 926 | 0 | os = new FileOutputStream(file); |
| 927 | 0 | bos = new BufferedOutputStream(os); |
| 928 | 0 | out = new ObjectOutputStream(bos); |
| 929 | 0 | out.writeObject(dependencies); |
| 930 | 0 | out.flush(); |
| 931 | |
|
| 932 | |
|
| 933 | |
|
| 934 | 0 | out.reset(); |
| 935 | |
} |
| 936 | 0 | if (getLog().isDebugEnabled()) { |
| 937 | 0 | getLog().debug(String.format("Serialized data file written to '%s' for %s, referenced by key %s", |
| 938 | |
file.getAbsolutePath(), mp.getName(), this.getDataFileContextKey())); |
| 939 | |
} |
| 940 | 0 | mp.setContextValue(this.getDataFileContextKey(), file.getAbsolutePath()); |
| 941 | 0 | } catch (IOException ex) { |
| 942 | 0 | getLog().warn("Unable to create data file used for report aggregation; " |
| 943 | |
+ "if report aggregation is being used the results may be incomplete."); |
| 944 | 0 | if (getLog().isDebugEnabled()) { |
| 945 | 0 | getLog().debug(ex.getMessage(), ex); |
| 946 | |
} |
| 947 | |
} finally { |
| 948 | 0 | if (out != null) { |
| 949 | |
try { |
| 950 | 0 | out.close(); |
| 951 | 0 | } catch (IOException ex) { |
| 952 | 0 | if (getLog().isDebugEnabled()) { |
| 953 | 0 | getLog().debug("ignore", ex); |
| 954 | |
} |
| 955 | 0 | } |
| 956 | |
} |
| 957 | 0 | if (bos != null) { |
| 958 | |
try { |
| 959 | 0 | bos.close(); |
| 960 | 0 | } catch (IOException ex) { |
| 961 | 0 | if (getLog().isDebugEnabled()) { |
| 962 | 0 | getLog().debug("ignore", ex); |
| 963 | |
} |
| 964 | 0 | } |
| 965 | |
} |
| 966 | 0 | if (os != null) { |
| 967 | |
try { |
| 968 | 0 | os.close(); |
| 969 | 0 | } catch (IOException ex) { |
| 970 | 0 | if (getLog().isDebugEnabled()) { |
| 971 | 0 | getLog().debug("ignore", ex); |
| 972 | |
} |
| 973 | 0 | } |
| 974 | |
} |
| 975 | |
} |
| 976 | |
} |
| 977 | 0 | } |
| 978 | |
|
| 979 | |
|
| 980 | |
|
| 981 | |
|
| 982 | |
|
| 983 | |
|
| 984 | |
|
| 985 | |
|
| 986 | |
|
| 987 | |
protected List<Dependency> readDataFile(MavenProject project) { |
| 988 | 0 | final Object oPath = project.getContextValue(this.getDataFileContextKey()); |
| 989 | 0 | if (oPath == null) { |
| 990 | 0 | return null; |
| 991 | |
} |
| 992 | 0 | List<Dependency> ret = null; |
| 993 | 0 | final String path = (String) oPath; |
| 994 | 0 | ObjectInputStream ois = null; |
| 995 | |
try { |
| 996 | 0 | ois = new ObjectInputStream(new FileInputStream(path)); |
| 997 | 0 | ret = (List<Dependency>) ois.readObject(); |
| 998 | 0 | } catch (FileNotFoundException ex) { |
| 999 | |
|
| 1000 | 0 | getLog().error("", ex); |
| 1001 | 0 | } catch (IOException ex) { |
| 1002 | 0 | getLog().error("", ex); |
| 1003 | 0 | } catch (ClassNotFoundException ex) { |
| 1004 | 0 | getLog().error("", ex); |
| 1005 | |
} finally { |
| 1006 | 0 | if (ois != null) { |
| 1007 | |
try { |
| 1008 | 0 | ois.close(); |
| 1009 | 0 | } catch (IOException ex) { |
| 1010 | 0 | getLog().error("", ex); |
| 1011 | 0 | } |
| 1012 | |
} |
| 1013 | |
} |
| 1014 | 0 | return ret; |
| 1015 | |
} |
| 1016 | |
|
| 1017 | |
} |