| 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.FileNotFoundException; |
| 23 | |
import java.io.FileOutputStream; |
| 24 | |
import java.io.IOException; |
| 25 | |
import java.io.InputStream; |
| 26 | |
import java.io.ObjectOutputStream; |
| 27 | |
import java.util.List; |
| 28 | |
import java.util.Locale; |
| 29 | |
import org.eclipse.aether.artifact.Artifact; |
| 30 | |
import org.apache.maven.doxia.sink.Sink; |
| 31 | |
import org.apache.maven.plugin.AbstractMojo; |
| 32 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 33 | |
import org.apache.maven.plugin.MojoFailureException; |
| 34 | |
import org.apache.maven.plugins.annotations.Component; |
| 35 | |
import org.apache.maven.plugins.annotations.Parameter; |
| 36 | |
import org.apache.maven.project.MavenProject; |
| 37 | |
import org.apache.maven.reporting.MavenReport; |
| 38 | |
import org.apache.maven.reporting.MavenReportException; |
| 39 | |
import org.apache.maven.settings.Proxy; |
| 40 | |
import org.apache.maven.settings.Server; |
| 41 | |
import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder; |
| 42 | |
import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException; |
| 43 | |
import org.apache.maven.shared.dependency.graph.DependencyNode; |
| 44 | |
import org.eclipse.aether.RepositorySystem; |
| 45 | |
import org.eclipse.aether.RepositorySystemSession; |
| 46 | |
import org.eclipse.aether.artifact.DefaultArtifact; |
| 47 | |
import org.eclipse.aether.repository.RemoteRepository; |
| 48 | |
import org.eclipse.aether.resolution.ArtifactRequest; |
| 49 | |
import org.eclipse.aether.resolution.ArtifactResolutionException; |
| 50 | |
import org.eclipse.aether.resolution.ArtifactResult; |
| 51 | |
import org.owasp.dependencycheck.Engine; |
| 52 | |
import org.owasp.dependencycheck.data.nexus.MavenArtifact; |
| 53 | |
import org.owasp.dependencycheck.data.nvdcve.CveDB; |
| 54 | |
import org.owasp.dependencycheck.data.nvdcve.DatabaseException; |
| 55 | |
import org.owasp.dependencycheck.data.nvdcve.DatabaseProperties; |
| 56 | |
import org.owasp.dependencycheck.dependency.Confidence; |
| 57 | |
import org.owasp.dependencycheck.dependency.Dependency; |
| 58 | |
import org.owasp.dependencycheck.dependency.Identifier; |
| 59 | |
import org.owasp.dependencycheck.dependency.Vulnerability; |
| 60 | |
import org.owasp.dependencycheck.exception.ExceptionCollection; |
| 61 | |
import org.owasp.dependencycheck.exception.ReportException; |
| 62 | |
import org.owasp.dependencycheck.reporting.ReportGenerator; |
| 63 | |
import org.owasp.dependencycheck.utils.Settings; |
| 64 | |
import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher; |
| 65 | |
import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; |
| 66 | |
import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException; |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | 0 | public abstract class BaseDependencyCheckMojo extends AbstractMojo implements MavenReport { |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
private static final String PROPERTIES_FILE = "mojo.properties"; |
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | 0 | private static final String NEW_LINE = System.getProperty("line.separator", "\n").intern(); |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
@Parameter(property = "metaFileName", defaultValue = "dependency-check.ser", required = true) |
| 89 | |
private String dataFileName; |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
@Parameter(property = "failOnError", defaultValue = "true", required = true) |
| 94 | |
private boolean failOnError; |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
protected boolean isFailOnError() { |
| 102 | 0 | return failOnError; |
| 103 | |
} |
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
@Parameter(property = "project", required = true, readonly = true) |
| 109 | |
private MavenProject project; |
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
@Parameter(readonly = true, required = true, property = "reactorProjects") |
| 114 | |
private List<MavenProject> reactorProjects; |
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
@Component |
| 119 | |
private RepositorySystem repoSystem; |
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
@Parameter(defaultValue = "${repositorySystemSession}", readonly = true) |
| 125 | |
private RepositorySystemSession repoSession; |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
@Parameter(defaultValue = "${project.remotePluginRepositories}", readonly = true) |
| 132 | |
private List<RemoteRepository> remoteRepos; |
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
@Component |
| 138 | |
private DependencyGraphBuilder dependencyGraphBuilder; |
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
@Parameter(defaultValue = "${project.build.directory}", required = true) |
| 144 | |
private File outputDirectory; |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
@Parameter(property = "project.reporting.outputDirectory", required = true) |
| 150 | |
private File reportOutputDirectory; |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | 0 | @SuppressWarnings("CanBeFinal") |
| 157 | |
@Parameter(property = "failBuildOnCVSS", defaultValue = "11", required = true) |
| 158 | |
private float failBuildOnCVSS = 11; |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | 0 | @SuppressWarnings("CanBeFinal") |
| 163 | |
@Parameter(property = "failBuildOnAnyVulnerability", defaultValue = "false", required = true) |
| 164 | |
private boolean failBuildOnAnyVulnerability = false; |
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
@Parameter(property = "autoUpdate") |
| 170 | |
private Boolean autoUpdate; |
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
@Parameter(property = "enableExperimental") |
| 175 | |
private Boolean enableExperimental; |
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
@Parameter(property = "aggregate") |
| 182 | |
@Deprecated |
| 183 | |
private Boolean aggregate; |
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | 0 | @SuppressWarnings("CanBeFinal") |
| 190 | |
@Parameter(property = "format", defaultValue = "HTML", required = true) |
| 191 | |
private String format = "HTML"; |
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
@Parameter(property = "mavenSettings", defaultValue = "${settings}", required = false) |
| 196 | |
private org.apache.maven.settings.Settings mavenSettings; |
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
@Parameter(property = "mavenSettingsProxyId", required = false) |
| 202 | |
private String mavenSettingsProxyId; |
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
@Parameter(property = "connectionTimeout", defaultValue = "", required = false) |
| 208 | |
private String connectionTimeout; |
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
@Parameter(property = "suppressionFile", defaultValue = "", required = false) |
| 213 | |
private String suppressionFile; |
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
@Parameter(property = "hintsFile", defaultValue = "", required = false) |
| 219 | |
private String hintsFile; |
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | 0 | @SuppressWarnings("CanBeFinal") |
| 225 | |
@Parameter(property = "showSummary", defaultValue = "true", required = false) |
| 226 | |
private boolean showSummary = true; |
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
@Parameter(property = "jarAnalyzerEnabled", required = false) |
| 232 | |
private Boolean jarAnalyzerEnabled; |
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
@Parameter(property = "archiveAnalyzerEnabled", required = false) |
| 238 | |
private Boolean archiveAnalyzerEnabled; |
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
@Parameter(property = "pyDistributionAnalyzerEnabled", required = false) |
| 244 | |
private Boolean pyDistributionAnalyzerEnabled; |
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
@Parameter(property = "pyPackageAnalyzerEnabled", required = false) |
| 249 | |
private Boolean pyPackageAnalyzerEnabled; |
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
@Parameter(property = "rubygemsAnalyzerEnabled", required = false) |
| 254 | |
private Boolean rubygemsAnalyzerEnabled; |
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
@Parameter(property = "opensslAnalyzerEnabled", required = false) |
| 259 | |
private Boolean opensslAnalyzerEnabled; |
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
@Parameter(property = "cmakeAnalyzerEnabled", required = false) |
| 264 | |
private Boolean cmakeAnalyzerEnabled; |
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
@Parameter(property = "autoconfAnalyzerEnabled", required = false) |
| 269 | |
private Boolean autoconfAnalyzerEnabled; |
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
@Parameter(property = "composerAnalyzerEnabled", required = false) |
| 274 | |
private Boolean composerAnalyzerEnabled; |
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
@Parameter(property = "nodeAnalyzerEnabled", required = false) |
| 279 | |
private Boolean nodeAnalyzerEnabled; |
| 280 | |
|
| 281 | |
|
| 282 | |
|
| 283 | |
|
| 284 | |
@Parameter(property = "assemblyAnalyzerEnabled", required = false) |
| 285 | |
private Boolean assemblyAnalyzerEnabled; |
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
@Parameter(property = "nuspecAnalyzerEnabled", required = false) |
| 291 | |
private Boolean nuspecAnalyzerEnabled; |
| 292 | |
|
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
@Parameter(property = "centralAnalyzerEnabled", required = false) |
| 297 | |
private Boolean centralAnalyzerEnabled; |
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | |
@Parameter(property = "nexusAnalyzerEnabled", required = false) |
| 303 | |
private Boolean nexusAnalyzerEnabled; |
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
@Parameter(property = "bundleAuditAnalyzerEnabled", required = false) |
| 309 | |
private Boolean bundleAuditAnalyzerEnabled; |
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
@Parameter(property = "bundleAuditPath", defaultValue = "", required = false) |
| 315 | |
private String bundleAuditPath; |
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | |
|
| 320 | |
@Parameter(property = "cocoapodsAnalyzerEnabled", required = false) |
| 321 | |
private Boolean cocoapodsAnalyzerEnabled; |
| 322 | |
|
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
@Parameter(property = "swiftPackageManagerAnalyzerEnabled", required = false) |
| 327 | |
private Boolean swiftPackageManagerAnalyzerEnabled; |
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
@Parameter(property = "nexusUrl", required = false) |
| 334 | |
private String nexusUrl; |
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | |
@Parameter(property = "nexusUsesProxy", required = false) |
| 339 | |
private Boolean nexusUsesProxy; |
| 340 | |
|
| 341 | |
|
| 342 | |
|
| 343 | |
@Parameter(property = "connectionString", defaultValue = "", required = false) |
| 344 | |
private String connectionString; |
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
protected String getConnectionString() { |
| 352 | 0 | return connectionString; |
| 353 | |
} |
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
@Parameter(property = "databaseDriverName", defaultValue = "", required = false) |
| 358 | |
private String databaseDriverName; |
| 359 | |
|
| 360 | |
|
| 361 | |
|
| 362 | |
@Parameter(property = "databaseDriverPath", defaultValue = "", required = false) |
| 363 | |
private String databaseDriverPath; |
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
@Parameter(property = "serverId", defaultValue = "", required = false) |
| 369 | |
private String serverId; |
| 370 | |
|
| 371 | |
|
| 372 | |
|
| 373 | |
@Parameter(defaultValue = "${settings}", readonly = true, required = true) |
| 374 | |
private org.apache.maven.settings.Settings settingsXml; |
| 375 | |
|
| 376 | |
|
| 377 | |
|
| 378 | |
@Component(role = SecDispatcher.class, hint = "default") |
| 379 | |
private SecDispatcher securityDispatcher; |
| 380 | |
|
| 381 | |
|
| 382 | |
|
| 383 | |
@Parameter(property = "databaseUser", defaultValue = "", required = false) |
| 384 | |
private String databaseUser; |
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
@Parameter(property = "databasePassword", defaultValue = "", required = false) |
| 389 | |
private String databasePassword; |
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
@Parameter(property = "zipExtensions", required = false) |
| 395 | |
private String zipExtensions; |
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | 0 | @SuppressWarnings("CanBeFinal") |
| 400 | |
@Parameter(property = "dependency-check.skip", defaultValue = "false", required = false) |
| 401 | |
private boolean skip = false; |
| 402 | |
|
| 403 | |
|
| 404 | |
|
| 405 | 0 | @SuppressWarnings("CanBeFinal") |
| 406 | |
@Parameter(property = "skipTestScope", defaultValue = "true", required = false) |
| 407 | |
private boolean skipTestScope = true; |
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | 0 | @SuppressWarnings("CanBeFinal") |
| 412 | |
@Parameter(property = "skipRuntimeScope", defaultValue = "false", required = false) |
| 413 | |
private boolean skipRuntimeScope = false; |
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | 0 | @SuppressWarnings("CanBeFinal") |
| 418 | |
@Parameter(property = "skipProvidedScope", defaultValue = "false", required = false) |
| 419 | |
private boolean skipProvidedScope = false; |
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
@Parameter(property = "dataDirectory", defaultValue = "", required = false) |
| 424 | |
private String dataDirectory; |
| 425 | |
|
| 426 | |
|
| 427 | |
|
| 428 | |
@Parameter(property = "cveUrl12Modified", defaultValue = "", required = false) |
| 429 | |
private String cveUrl12Modified; |
| 430 | |
|
| 431 | |
|
| 432 | |
|
| 433 | |
@Parameter(property = "cveUrl20Modified", defaultValue = "", required = false) |
| 434 | |
private String cveUrl20Modified; |
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
@Parameter(property = "cveUrl12Base", defaultValue = "", required = false) |
| 439 | |
private String cveUrl12Base; |
| 440 | |
|
| 441 | |
|
| 442 | |
|
| 443 | |
@Parameter(property = "cveUrl20Base", defaultValue = "", required = false) |
| 444 | |
private String cveUrl20Base; |
| 445 | |
|
| 446 | |
|
| 447 | |
|
| 448 | |
|
| 449 | |
@Parameter(property = "cveValidForHours", defaultValue = "", required = false) |
| 450 | |
private Integer cveValidForHours; |
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
@Parameter(property = "pathToMono", defaultValue = "", required = false) |
| 456 | |
private String pathToMono; |
| 457 | |
|
| 458 | |
|
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
|
| 463 | 0 | @SuppressWarnings("CanBeFinal") |
| 464 | |
@Parameter(property = "proxyUrl", defaultValue = "", required = false) |
| 465 | |
@Deprecated |
| 466 | |
private String proxyUrl = null; |
| 467 | |
|
| 468 | |
|
| 469 | |
|
| 470 | |
|
| 471 | |
|
| 472 | 0 | @SuppressWarnings("CanBeFinal") |
| 473 | |
@Parameter(property = "externalReport") |
| 474 | |
@Deprecated |
| 475 | |
private String externalReport = null; |
| 476 | |
|
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
@Override |
| 487 | |
public void execute() throws MojoExecutionException, MojoFailureException { |
| 488 | 0 | generatingSite = false; |
| 489 | 0 | if (skip) { |
| 490 | 0 | getLog().info("Skipping " + getName(Locale.US)); |
| 491 | |
} else { |
| 492 | 0 | validateAggregate(); |
| 493 | 0 | project.setContextValue(getOutputDirectoryContextKey(), this.outputDirectory); |
| 494 | 0 | runCheck(); |
| 495 | |
} |
| 496 | 0 | } |
| 497 | |
|
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
|
| 502 | |
|
| 503 | |
|
| 504 | |
|
| 505 | |
private void validateAggregate() throws MojoExecutionException { |
| 506 | 0 | if (aggregate != null && aggregate) { |
| 507 | 0 | final String msg = "Aggregate configuration detected - as of dependency-check 1.2.8 this no longer supported. " |
| 508 | |
+ "Please use the aggregate goal instead."; |
| 509 | 0 | throw new MojoExecutionException(msg); |
| 510 | |
} |
| 511 | 0 | } |
| 512 | |
|
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | |
|
| 517 | |
|
| 518 | |
|
| 519 | |
|
| 520 | |
|
| 521 | |
|
| 522 | |
|
| 523 | |
@Override |
| 524 | |
@Deprecated |
| 525 | |
public final void generate(@SuppressWarnings("deprecation") org.codehaus.doxia.sink.Sink sink, Locale locale) throws MavenReportException { |
| 526 | 0 | generate((Sink) sink, locale); |
| 527 | 0 | } |
| 528 | |
|
| 529 | |
|
| 530 | |
|
| 531 | |
|
| 532 | 0 | private boolean generatingSite = false; |
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
|
| 538 | |
|
| 539 | |
protected boolean isGeneratingSite() { |
| 540 | 0 | return generatingSite; |
| 541 | |
} |
| 542 | |
|
| 543 | |
|
| 544 | |
|
| 545 | |
|
| 546 | |
|
| 547 | |
|
| 548 | |
|
| 549 | |
|
| 550 | |
public void generate(Sink sink, Locale locale) throws MavenReportException { |
| 551 | 0 | generatingSite = true; |
| 552 | |
try { |
| 553 | 0 | validateAggregate(); |
| 554 | 0 | } catch (MojoExecutionException ex) { |
| 555 | 0 | throw new MavenReportException(ex.getMessage()); |
| 556 | 0 | } |
| 557 | 0 | project.setContextValue(getOutputDirectoryContextKey(), getReportOutputDirectory()); |
| 558 | |
try { |
| 559 | 0 | runCheck(); |
| 560 | 0 | } catch (MojoExecutionException ex) { |
| 561 | 0 | throw new MavenReportException(ex.getMessage(), ex); |
| 562 | 0 | } catch (MojoFailureException ex) { |
| 563 | 0 | getLog().warn("Vulnerabilities were identifies that exceed the CVSS threshold for failing the build"); |
| 564 | 0 | } |
| 565 | 0 | } |
| 566 | |
|
| 567 | |
|
| 568 | |
|
| 569 | |
|
| 570 | |
|
| 571 | |
|
| 572 | |
|
| 573 | |
|
| 574 | |
|
| 575 | |
protected File getCorrectOutputDirectory() throws MojoExecutionException { |
| 576 | 0 | return getCorrectOutputDirectory(this.project); |
| 577 | |
} |
| 578 | |
|
| 579 | |
|
| 580 | |
|
| 581 | |
|
| 582 | |
|
| 583 | |
|
| 584 | |
|
| 585 | |
|
| 586 | |
protected File getCorrectOutputDirectory(MavenProject current) { |
| 587 | 0 | final Object obj = current.getContextValue(getOutputDirectoryContextKey()); |
| 588 | 0 | if (obj != null && obj instanceof File) { |
| 589 | 0 | return (File) obj; |
| 590 | |
} |
| 591 | 0 | File target = new File(current.getBuild().getDirectory()); |
| 592 | 0 | if (target.getParentFile() != null && "target".equals(target.getParentFile().getName())) { |
| 593 | 0 | target = target.getParentFile(); |
| 594 | |
} |
| 595 | 0 | return target; |
| 596 | |
} |
| 597 | |
|
| 598 | |
|
| 599 | |
|
| 600 | |
|
| 601 | |
|
| 602 | |
|
| 603 | |
|
| 604 | |
|
| 605 | |
protected File getDataFile(MavenProject current) { |
| 606 | 0 | if (getLog().isDebugEnabled()) { |
| 607 | 0 | getLog().debug(String.format("Getting data filefor %s using key '%s'", current.getName(), getDataFileContextKey())); |
| 608 | |
} |
| 609 | 0 | final Object obj = current.getContextValue(getDataFileContextKey()); |
| 610 | 0 | if (obj != null) { |
| 611 | 0 | if (obj instanceof String) { |
| 612 | 0 | final File f = new File((String) obj); |
| 613 | 0 | return f; |
| 614 | |
} |
| 615 | 0 | } else if (getLog().isDebugEnabled()) { |
| 616 | 0 | getLog().debug("Context value not found"); |
| 617 | |
} |
| 618 | 0 | return null; |
| 619 | |
} |
| 620 | |
|
| 621 | |
|
| 622 | |
|
| 623 | |
|
| 624 | |
|
| 625 | |
|
| 626 | |
|
| 627 | |
|
| 628 | |
|
| 629 | |
|
| 630 | |
protected ExceptionCollection scanArtifacts(MavenProject project, Engine engine) { |
| 631 | |
try { |
| 632 | 0 | final DependencyNode dn = dependencyGraphBuilder.buildDependencyGraph(project, null, reactorProjects); |
| 633 | 0 | return collectDependencies(engine, project, dn.getChildren()); |
| 634 | 0 | } catch (DependencyGraphBuilderException ex) { |
| 635 | 0 | final String msg = String.format("Unable to build dependency graph on project %s", project.getName()); |
| 636 | 0 | getLog().debug(msg, ex); |
| 637 | 0 | return new ExceptionCollection(msg, ex); |
| 638 | |
} |
| 639 | |
} |
| 640 | |
|
| 641 | |
|
| 642 | |
|
| 643 | |
|
| 644 | |
|
| 645 | |
|
| 646 | |
|
| 647 | |
|
| 648 | |
|
| 649 | |
|
| 650 | |
|
| 651 | |
|
| 652 | |
private ExceptionCollection collectDependencies(Engine engine, MavenProject project, List<DependencyNode> nodes) { |
| 653 | 0 | ExceptionCollection exCol = null; |
| 654 | 0 | for (DependencyNode dependencyNode : nodes) { |
| 655 | 0 | exCol = collectDependencies(engine, project, dependencyNode.getChildren()); |
| 656 | 0 | if (excludeFromScan(dependencyNode.getArtifact().getScope())) { |
| 657 | 0 | continue; |
| 658 | |
} |
| 659 | |
try { |
| 660 | |
|
| 661 | |
|
| 662 | 0 | final ArtifactRequest request = new ArtifactRequest(); |
| 663 | 0 | request.setArtifact(new DefaultArtifact(dependencyNode.getArtifact().getId())); |
| 664 | 0 | request.setRepositories(remoteRepos); |
| 665 | 0 | final ArtifactResult result = repoSystem.resolveArtifact(repoSession, request); |
| 666 | 0 | if (result.isResolved() && result.getArtifact() != null && result.getArtifact().getFile() != null) { |
| 667 | 0 | final List<Dependency> deps = engine.scan(result.getArtifact().getFile().getAbsoluteFile(), |
| 668 | 0 | project.getName() + ":" + dependencyNode.getArtifact().getScope()); |
| 669 | 0 | if (deps != null) { |
| 670 | 0 | if (deps.size() == 1) { |
| 671 | 0 | final Dependency d = deps.get(0); |
| 672 | 0 | if (d != null) { |
| 673 | 0 | final Artifact a = result.getArtifact(); |
| 674 | 0 | final MavenArtifact ma = new MavenArtifact(a.getGroupId(), a.getArtifactId(), a.getVersion()); |
| 675 | 0 | d.addAsEvidence("pom", ma, Confidence.HIGHEST); |
| 676 | 0 | if (getLog().isDebugEnabled()) { |
| 677 | 0 | getLog().debug(String.format("Adding project reference %s on dependency %s", |
| 678 | 0 | project.getName(), d.getDisplayFileName())); |
| 679 | |
} |
| 680 | |
} |
| 681 | 0 | } else if (getLog().isDebugEnabled()) { |
| 682 | 0 | final String msg = String.format("More then 1 dependency was identified in first pass scan of '%s' in project %s", |
| 683 | 0 | dependencyNode.getArtifact().getId(), project.getName()); |
| 684 | 0 | getLog().debug(msg); |
| 685 | 0 | } |
| 686 | |
} else { |
| 687 | 0 | final String msg = String.format("Error resolving '%s' in project %s", |
| 688 | 0 | dependencyNode.getArtifact().getId(), project.getName()); |
| 689 | 0 | if (exCol == null) { |
| 690 | 0 | exCol = new ExceptionCollection(); |
| 691 | |
} |
| 692 | 0 | getLog().error(msg); |
| 693 | 0 | for (Exception ex : result.getExceptions()) { |
| 694 | 0 | exCol.addException(ex); |
| 695 | 0 | } |
| 696 | |
} |
| 697 | 0 | } else { |
| 698 | 0 | final String msg = String.format("Unable to resolve '%s' in project %s", |
| 699 | 0 | dependencyNode.getArtifact().getId(), project.getName()); |
| 700 | 0 | getLog().debug(msg); |
| 701 | 0 | if (exCol == null) { |
| 702 | 0 | exCol = new ExceptionCollection(); |
| 703 | |
} |
| 704 | 0 | for (Exception ex : result.getExceptions()) { |
| 705 | 0 | exCol.addException(ex); |
| 706 | 0 | } |
| 707 | |
} |
| 708 | 0 | } catch (ArtifactResolutionException ex) { |
| 709 | 0 | if (exCol == null) { |
| 710 | 0 | exCol = new ExceptionCollection(); |
| 711 | |
} |
| 712 | 0 | exCol.addException(ex); |
| 713 | 0 | } |
| 714 | 0 | } |
| 715 | 0 | return exCol; |
| 716 | |
} |
| 717 | |
|
| 718 | |
|
| 719 | |
|
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
|
| 724 | |
|
| 725 | |
|
| 726 | |
public abstract void runCheck() throws MojoExecutionException, MojoFailureException; |
| 727 | |
|
| 728 | |
|
| 729 | |
|
| 730 | |
|
| 731 | |
|
| 732 | |
|
| 733 | |
@Override |
| 734 | |
public void setReportOutputDirectory(File directory) { |
| 735 | 0 | reportOutputDirectory = directory; |
| 736 | 0 | } |
| 737 | |
|
| 738 | |
|
| 739 | |
|
| 740 | |
|
| 741 | |
|
| 742 | |
|
| 743 | |
@Override |
| 744 | |
public File getReportOutputDirectory() { |
| 745 | 0 | return reportOutputDirectory; |
| 746 | |
} |
| 747 | |
|
| 748 | |
|
| 749 | |
|
| 750 | |
|
| 751 | |
|
| 752 | |
|
| 753 | |
public File getOutputDirectory() { |
| 754 | 0 | return outputDirectory; |
| 755 | |
} |
| 756 | |
|
| 757 | |
|
| 758 | |
|
| 759 | |
|
| 760 | |
|
| 761 | |
|
| 762 | |
|
| 763 | |
@Override |
| 764 | |
public final boolean isExternalReport() { |
| 765 | 0 | return true; |
| 766 | |
} |
| 767 | |
|
| 768 | |
|
| 769 | |
|
| 770 | |
|
| 771 | |
|
| 772 | |
|
| 773 | |
@Override |
| 774 | |
public String getOutputName() { |
| 775 | 0 | if ("HTML".equalsIgnoreCase(this.format) || "ALL".equalsIgnoreCase(this.format)) { |
| 776 | 0 | return "dependency-check-report"; |
| 777 | 0 | } else if ("XML".equalsIgnoreCase(this.format)) { |
| 778 | 0 | return "dependency-check-report.xml#"; |
| 779 | 0 | } else if ("VULN".equalsIgnoreCase(this.format)) { |
| 780 | 0 | return "dependency-check-vulnerability"; |
| 781 | |
} else { |
| 782 | 0 | getLog().warn("Unknown report format used during site generation."); |
| 783 | 0 | return "dependency-check-report"; |
| 784 | |
} |
| 785 | |
} |
| 786 | |
|
| 787 | |
|
| 788 | |
|
| 789 | |
|
| 790 | |
|
| 791 | |
|
| 792 | |
@Override |
| 793 | |
public String getCategoryName() { |
| 794 | 0 | return MavenReport.CATEGORY_PROJECT_REPORTS; |
| 795 | |
} |
| 796 | |
|
| 797 | |
|
| 798 | |
|
| 799 | |
|
| 800 | |
|
| 801 | |
|
| 802 | |
|
| 803 | |
|
| 804 | |
protected Engine initializeEngine() throws DatabaseException { |
| 805 | 0 | populateSettings(); |
| 806 | 0 | return new Engine(); |
| 807 | |
} |
| 808 | |
|
| 809 | |
|
| 810 | |
|
| 811 | |
|
| 812 | |
|
| 813 | |
|
| 814 | |
protected void populateSettings() { |
| 815 | 0 | Settings.initialize(); |
| 816 | 0 | InputStream mojoProperties = null; |
| 817 | |
try { |
| 818 | 0 | mojoProperties = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILE); |
| 819 | 0 | Settings.mergeProperties(mojoProperties); |
| 820 | 0 | } catch (IOException ex) { |
| 821 | 0 | getLog().warn("Unable to load the dependency-check ant task.properties file."); |
| 822 | 0 | if (getLog().isDebugEnabled()) { |
| 823 | 0 | getLog().debug("", ex); |
| 824 | |
} |
| 825 | |
} finally { |
| 826 | 0 | if (mojoProperties != null) { |
| 827 | |
try { |
| 828 | 0 | mojoProperties.close(); |
| 829 | 0 | } catch (IOException ex) { |
| 830 | 0 | if (getLog().isDebugEnabled()) { |
| 831 | 0 | getLog().debug("", ex); |
| 832 | |
} |
| 833 | 0 | } |
| 834 | |
} |
| 835 | |
} |
| 836 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.AUTO_UPDATE, autoUpdate); |
| 837 | |
|
| 838 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_EXPERIMENTAL_ENABLED, enableExperimental); |
| 839 | |
|
| 840 | 0 | if (externalReport != null) { |
| 841 | 0 | getLog().warn("The 'externalReport' option was set; this configuration option has been removed. " |
| 842 | |
+ "Please update the dependency-check-maven plugin's configuration"); |
| 843 | |
} |
| 844 | |
|
| 845 | 0 | if (proxyUrl != null && !proxyUrl.isEmpty()) { |
| 846 | 0 | getLog().warn("Deprecated configuration detected, proxyUrl will be ignored; use the maven settings to configure the proxy instead"); |
| 847 | |
} |
| 848 | 0 | final Proxy proxy = getMavenProxy(); |
| 849 | 0 | if (proxy != null) { |
| 850 | 0 | Settings.setString(Settings.KEYS.PROXY_SERVER, proxy.getHost()); |
| 851 | 0 | Settings.setString(Settings.KEYS.PROXY_PORT, Integer.toString(proxy.getPort())); |
| 852 | 0 | final String userName = proxy.getUsername(); |
| 853 | 0 | final String password = proxy.getPassword(); |
| 854 | 0 | Settings.setStringIfNotNull(Settings.KEYS.PROXY_USERNAME, userName); |
| 855 | 0 | Settings.setStringIfNotNull(Settings.KEYS.PROXY_PASSWORD, password); |
| 856 | 0 | Settings.setStringIfNotNull(Settings.KEYS.PROXY_NON_PROXY_HOSTS, proxy.getNonProxyHosts()); |
| 857 | |
} |
| 858 | |
|
| 859 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout); |
| 860 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.SUPPRESSION_FILE, suppressionFile); |
| 861 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.HINTS_FILE, hintsFile); |
| 862 | |
|
| 863 | |
|
| 864 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_JAR_ENABLED, jarAnalyzerEnabled); |
| 865 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NUSPEC_ENABLED, nuspecAnalyzerEnabled); |
| 866 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_CENTRAL_ENABLED, centralAnalyzerEnabled); |
| 867 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NEXUS_ENABLED, nexusAnalyzerEnabled); |
| 868 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl); |
| 869 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NEXUS_USES_PROXY, nexusUsesProxy); |
| 870 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ASSEMBLY_ENABLED, assemblyAnalyzerEnabled); |
| 871 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, archiveAnalyzerEnabled); |
| 872 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS, zipExtensions); |
| 873 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, pathToMono); |
| 874 | |
|
| 875 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_PYTHON_DISTRIBUTION_ENABLED, pyDistributionAnalyzerEnabled); |
| 876 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_PYTHON_PACKAGE_ENABLED, pyPackageAnalyzerEnabled); |
| 877 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_RUBY_GEMSPEC_ENABLED, rubygemsAnalyzerEnabled); |
| 878 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_OPENSSL_ENABLED, opensslAnalyzerEnabled); |
| 879 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_CMAKE_ENABLED, cmakeAnalyzerEnabled); |
| 880 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_AUTOCONF_ENABLED, autoconfAnalyzerEnabled); |
| 881 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_COMPOSER_LOCK_ENABLED, composerAnalyzerEnabled); |
| 882 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_PACKAGE_ENABLED, nodeAnalyzerEnabled); |
| 883 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_BUNDLE_AUDIT_ENABLED, bundleAuditAnalyzerEnabled); |
| 884 | 0 | Settings.setStringIfNotNull(Settings.KEYS.ANALYZER_BUNDLE_AUDIT_PATH, bundleAuditPath); |
| 885 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_COCOAPODS_ENABLED, cocoapodsAnalyzerEnabled); |
| 886 | 0 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_SWIFT_PACKAGE_MANAGER_ENABLED, swiftPackageManagerAnalyzerEnabled); |
| 887 | |
|
| 888 | |
|
| 889 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.DB_DRIVER_NAME, databaseDriverName); |
| 890 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.DB_DRIVER_PATH, databaseDriverPath); |
| 891 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.DB_CONNECTION_STRING, connectionString); |
| 892 | |
|
| 893 | 0 | if (databaseUser == null && databasePassword == null && serverId != null) { |
| 894 | 0 | final Server server = settingsXml.getServer(serverId); |
| 895 | 0 | if (server != null) { |
| 896 | 0 | databaseUser = server.getUsername(); |
| 897 | |
try { |
| 898 | |
|
| 899 | |
|
| 900 | |
|
| 901 | |
|
| 902 | |
|
| 903 | |
|
| 904 | |
|
| 905 | 0 | if (securityDispatcher instanceof DefaultSecDispatcher) { |
| 906 | 0 | ((DefaultSecDispatcher) securityDispatcher).setConfigurationFile("~/.m2/settings-security.xml"); |
| 907 | |
} |
| 908 | |
|
| 909 | 0 | databasePassword = securityDispatcher.decrypt(server.getPassword()); |
| 910 | 0 | } catch (SecDispatcherException ex) { |
| 911 | 0 | if (ex.getCause() instanceof FileNotFoundException |
| 912 | 0 | || (ex.getCause() != null && ex.getCause().getCause() instanceof FileNotFoundException)) { |
| 913 | |
|
| 914 | 0 | final String tmp = server.getPassword(); |
| 915 | 0 | if (tmp.startsWith("{") && tmp.endsWith("}")) { |
| 916 | 0 | getLog().error(String.format( |
| 917 | |
"Unable to decrypt the server password for server id '%s' in settings.xml%n\tCause: %s", |
| 918 | 0 | serverId, ex.getMessage())); |
| 919 | |
} else { |
| 920 | 0 | databasePassword = tmp; |
| 921 | |
} |
| 922 | 0 | } else { |
| 923 | 0 | getLog().error(String.format( |
| 924 | |
"Unable to decrypt the server password for server id '%s' in settings.xml%n\tCause: %s", |
| 925 | 0 | serverId, ex.getMessage())); |
| 926 | |
} |
| 927 | 0 | } |
| 928 | |
} else { |
| 929 | 0 | getLog().error(String.format("Server '%s' not found in the settings.xml file", serverId)); |
| 930 | |
} |
| 931 | |
} |
| 932 | |
|
| 933 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.DB_USER, databaseUser); |
| 934 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.DB_PASSWORD, databasePassword); |
| 935 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.DATA_DIRECTORY, dataDirectory); |
| 936 | |
|
| 937 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.CVE_MODIFIED_12_URL, cveUrl12Modified); |
| 938 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.CVE_MODIFIED_20_URL, cveUrl20Modified); |
| 939 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.CVE_SCHEMA_1_2, cveUrl12Base); |
| 940 | 0 | Settings.setStringIfNotEmpty(Settings.KEYS.CVE_SCHEMA_2_0, cveUrl20Base); |
| 941 | 0 | Settings.setIntIfNotNull(Settings.KEYS.CVE_CHECK_VALID_FOR_HOURS, cveValidForHours); |
| 942 | |
|
| 943 | 0 | } |
| 944 | |
|
| 945 | |
|
| 946 | |
|
| 947 | |
|
| 948 | |
|
| 949 | |
|
| 950 | |
private Proxy getMavenProxy() { |
| 951 | 0 | if (mavenSettings != null) { |
| 952 | 0 | final List<Proxy> proxies = mavenSettings.getProxies(); |
| 953 | 0 | if (proxies != null && !proxies.isEmpty()) { |
| 954 | 0 | if (mavenSettingsProxyId != null) { |
| 955 | 0 | for (Proxy proxy : proxies) { |
| 956 | 0 | if (mavenSettingsProxyId.equalsIgnoreCase(proxy.getId())) { |
| 957 | 0 | return proxy; |
| 958 | |
} |
| 959 | 0 | } |
| 960 | 0 | } else if (proxies.size() == 1) { |
| 961 | 0 | return proxies.get(0); |
| 962 | |
} else { |
| 963 | 0 | getLog().warn("Multiple proxy definitions exist in the Maven settings. In the dependency-check " |
| 964 | |
+ "configuration set the mavenSettingsProxyId so that the correct proxy will be used."); |
| 965 | 0 | throw new IllegalStateException("Ambiguous proxy definition"); |
| 966 | |
} |
| 967 | |
} |
| 968 | |
} |
| 969 | 0 | return null; |
| 970 | |
} |
| 971 | |
|
| 972 | |
|
| 973 | |
|
| 974 | |
|
| 975 | |
|
| 976 | |
|
| 977 | |
|
| 978 | |
|
| 979 | |
|
| 980 | |
protected boolean excludeFromScan(String scope) { |
| 981 | 0 | if (skipTestScope && org.apache.maven.artifact.Artifact.SCOPE_TEST.equals(scope)) { |
| 982 | 0 | return true; |
| 983 | |
} |
| 984 | 0 | if (skipProvidedScope && org.apache.maven.artifact.Artifact.SCOPE_PROVIDED.equals(scope)) { |
| 985 | 0 | return true; |
| 986 | |
} |
| 987 | 0 | if (skipRuntimeScope && !org.apache.maven.artifact.Artifact.SCOPE_RUNTIME.equals(scope)) { |
| 988 | 0 | return true; |
| 989 | |
} |
| 990 | 0 | return false; |
| 991 | |
} |
| 992 | |
|
| 993 | |
|
| 994 | |
|
| 995 | |
|
| 996 | |
|
| 997 | |
|
| 998 | |
|
| 999 | |
|
| 1000 | |
|
| 1001 | |
|
| 1002 | |
|
| 1003 | |
protected MavenProject getProject() { |
| 1004 | 0 | return project; |
| 1005 | |
} |
| 1006 | |
|
| 1007 | |
|
| 1008 | |
|
| 1009 | |
|
| 1010 | |
|
| 1011 | |
|
| 1012 | |
protected List<MavenProject> getReactorProjects() { |
| 1013 | 0 | return reactorProjects; |
| 1014 | |
} |
| 1015 | |
|
| 1016 | |
|
| 1017 | |
|
| 1018 | |
|
| 1019 | |
|
| 1020 | |
|
| 1021 | |
protected String getFormat() { |
| 1022 | 0 | return format; |
| 1023 | |
} |
| 1024 | |
|
| 1025 | |
|
| 1026 | |
|
| 1027 | |
|
| 1028 | |
|
| 1029 | |
|
| 1030 | |
|
| 1031 | |
|
| 1032 | |
|
| 1033 | |
protected void writeReports(Engine engine, MavenProject p, File outputDir) throws ReportException { |
| 1034 | 0 | DatabaseProperties prop = null; |
| 1035 | 0 | CveDB cve = null; |
| 1036 | |
try { |
| 1037 | 0 | cve = new CveDB(); |
| 1038 | 0 | cve.open(); |
| 1039 | 0 | prop = cve.getDatabaseProperties(); |
| 1040 | 0 | } catch (DatabaseException ex) { |
| 1041 | 0 | if (getLog().isDebugEnabled()) { |
| 1042 | 0 | getLog().debug("Unable to retrieve DB Properties", ex); |
| 1043 | |
} |
| 1044 | |
} finally { |
| 1045 | 0 | if (cve != null) { |
| 1046 | 0 | cve.close(); |
| 1047 | |
} |
| 1048 | |
} |
| 1049 | 0 | final ReportGenerator r = new ReportGenerator(p.getName(), engine.getDependencies(), engine.getAnalyzers(), prop); |
| 1050 | |
try { |
| 1051 | 0 | r.generateReports(outputDir.getAbsolutePath(), format); |
| 1052 | 0 | } catch (ReportException ex) { |
| 1053 | 0 | final String msg = String.format("Error generating the report for %s", p.getName()); |
| 1054 | 0 | throw new ReportException(msg, ex); |
| 1055 | 0 | } |
| 1056 | |
|
| 1057 | 0 | } |
| 1058 | |
|
| 1059 | |
|
| 1060 | |
|
| 1061 | |
|
| 1062 | |
|
| 1063 | |
|
| 1064 | |
|
| 1065 | |
|
| 1066 | |
|
| 1067 | |
|
| 1068 | |
protected void checkForFailure(List<Dependency> dependencies) throws MojoFailureException { |
| 1069 | 0 | final StringBuilder ids = new StringBuilder(); |
| 1070 | 0 | for (Dependency d : dependencies) { |
| 1071 | 0 | boolean addName = true; |
| 1072 | 0 | for (Vulnerability v : d.getVulnerabilities()) { |
| 1073 | 0 | if (failBuildOnAnyVulnerability || v.getCvssScore() >= failBuildOnCVSS) { |
| 1074 | 0 | if (addName) { |
| 1075 | 0 | addName = false; |
| 1076 | 0 | ids.append(NEW_LINE).append(d.getFileName()).append(": "); |
| 1077 | 0 | ids.append(v.getName()); |
| 1078 | |
} else { |
| 1079 | 0 | ids.append(", ").append(v.getName()); |
| 1080 | |
} |
| 1081 | |
} |
| 1082 | 0 | } |
| 1083 | 0 | } |
| 1084 | 0 | if (ids.length() > 0) { |
| 1085 | |
final String msg; |
| 1086 | 0 | if (failBuildOnAnyVulnerability) { |
| 1087 | 0 | msg = String.format("%n%nOne or more dependencies were identified with vulnerabilities: %n%s%n%n" |
| 1088 | 0 | + "See the dependency-check report for more details.%n%n", ids.toString()); |
| 1089 | |
} else { |
| 1090 | 0 | msg = String.format("%n%nOne or more dependencies were identified with vulnerabilities that have a CVSS score greater then '%.1f': %n%s%n%n" |
| 1091 | 0 | + "See the dependency-check report for more details.%n%n", failBuildOnCVSS, ids.toString()); |
| 1092 | |
} |
| 1093 | |
|
| 1094 | 0 | throw new MojoFailureException(msg); |
| 1095 | |
} |
| 1096 | 0 | } |
| 1097 | |
|
| 1098 | |
|
| 1099 | |
|
| 1100 | |
|
| 1101 | |
|
| 1102 | |
|
| 1103 | |
|
| 1104 | |
|
| 1105 | |
protected void showSummary(MavenProject mp, List<Dependency> dependencies) { |
| 1106 | 0 | if (showSummary) { |
| 1107 | 0 | final StringBuilder summary = new StringBuilder(); |
| 1108 | 0 | for (Dependency d : dependencies) { |
| 1109 | 0 | boolean firstEntry = true; |
| 1110 | 0 | final StringBuilder ids = new StringBuilder(); |
| 1111 | 0 | for (Vulnerability v : d.getVulnerabilities()) { |
| 1112 | 0 | if (firstEntry) { |
| 1113 | 0 | firstEntry = false; |
| 1114 | |
} else { |
| 1115 | 0 | ids.append(", "); |
| 1116 | |
} |
| 1117 | 0 | ids.append(v.getName()); |
| 1118 | 0 | } |
| 1119 | 0 | if (ids.length() > 0) { |
| 1120 | 0 | summary.append(d.getFileName()).append(" ("); |
| 1121 | 0 | firstEntry = true; |
| 1122 | 0 | for (Identifier id : d.getIdentifiers()) { |
| 1123 | 0 | if (firstEntry) { |
| 1124 | 0 | firstEntry = false; |
| 1125 | |
} else { |
| 1126 | 0 | summary.append(", "); |
| 1127 | |
} |
| 1128 | 0 | summary.append(id.getValue()); |
| 1129 | 0 | } |
| 1130 | 0 | summary.append(") : ").append(ids).append(NEW_LINE); |
| 1131 | |
} |
| 1132 | 0 | } |
| 1133 | 0 | if (summary.length() > 0) { |
| 1134 | 0 | final String msg = String.format("%n%n" + "One or more dependencies were identified with known vulnerabilities in %s:%n%n%s" |
| 1135 | 0 | + "%n%nSee the dependency-check report for more details.%n%n", mp.getName(), summary.toString()); |
| 1136 | 0 | getLog().warn(msg); |
| 1137 | |
} |
| 1138 | |
} |
| 1139 | 0 | } |
| 1140 | |
|
| 1141 | |
|
| 1142 | |
|
| 1143 | |
|
| 1144 | |
|
| 1145 | |
|
| 1146 | |
|
| 1147 | |
|
| 1148 | |
|
| 1149 | |
|
| 1150 | |
protected String getDataFileContextKey() { |
| 1151 | 0 | return "dependency-check-path-" + dataFileName; |
| 1152 | |
} |
| 1153 | |
|
| 1154 | |
|
| 1155 | |
|
| 1156 | |
|
| 1157 | |
|
| 1158 | |
|
| 1159 | |
|
| 1160 | |
|
| 1161 | |
protected String getOutputDirectoryContextKey() { |
| 1162 | 0 | return "dependency-output-dir-" + dataFileName; |
| 1163 | |
} |
| 1164 | |
|
| 1165 | |
|
| 1166 | |
|
| 1167 | |
|
| 1168 | |
|
| 1169 | |
|
| 1170 | |
|
| 1171 | |
|
| 1172 | |
|
| 1173 | |
protected void writeDataFile(MavenProject mp, File writeTo, List<Dependency> dependencies) { |
| 1174 | |
File file; |
| 1175 | |
|
| 1176 | 0 | if (mp.getContextValue(this.getDataFileContextKey()) == null) { |
| 1177 | 0 | if (writeTo == null) { |
| 1178 | 0 | file = new File(mp.getBuild().getDirectory()); |
| 1179 | 0 | file = new File(file, dataFileName); |
| 1180 | |
} else { |
| 1181 | 0 | file = new File(writeTo, dataFileName); |
| 1182 | |
} |
| 1183 | 0 | final File parent = file.getParentFile(); |
| 1184 | 0 | if (!parent.isDirectory() && !parent.mkdirs()) { |
| 1185 | 0 | getLog().error(String.format("Directory '%s' does not exist and cannot be created; unable to write data file.", |
| 1186 | 0 | parent.getAbsolutePath())); |
| 1187 | |
} |
| 1188 | |
|
| 1189 | 0 | ObjectOutputStream out = null; |
| 1190 | |
try { |
| 1191 | 0 | if (dependencies != null) { |
| 1192 | 0 | out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file))); |
| 1193 | 0 | out.writeObject(dependencies); |
| 1194 | |
} |
| 1195 | 0 | if (getLog().isDebugEnabled()) { |
| 1196 | 0 | getLog().debug(String.format("Serialized data file written to '%s' for %s, referenced by key %s", |
| 1197 | 0 | file.getAbsolutePath(), mp.getName(), this.getDataFileContextKey())); |
| 1198 | |
} |
| 1199 | 0 | mp.setContextValue(this.getDataFileContextKey(), file.getAbsolutePath()); |
| 1200 | 0 | } catch (IOException ex) { |
| 1201 | 0 | getLog().warn("Unable to create data file used for report aggregation; " |
| 1202 | |
+ "if report aggregation is being used the results may be incomplete."); |
| 1203 | 0 | if (getLog().isDebugEnabled()) { |
| 1204 | 0 | getLog().debug(ex.getMessage(), ex); |
| 1205 | |
} |
| 1206 | |
} finally { |
| 1207 | 0 | if (out != null) { |
| 1208 | |
try { |
| 1209 | 0 | out.close(); |
| 1210 | 0 | } catch (IOException ex) { |
| 1211 | 0 | if (getLog().isDebugEnabled()) { |
| 1212 | 0 | getLog().debug("ignore", ex); |
| 1213 | |
} |
| 1214 | 0 | } |
| 1215 | |
} |
| 1216 | |
} |
| 1217 | |
} |
| 1218 | 0 | } |
| 1219 | |
|
| 1220 | |
|
| 1221 | |
} |