| 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.File; |
| 21 | |
import java.io.IOException; |
| 22 | |
import java.io.InputStream; |
| 23 | |
import java.io.UnsupportedEncodingException; |
| 24 | |
import java.net.URLEncoder; |
| 25 | |
import java.text.DateFormat; |
| 26 | |
import java.util.Date; |
| 27 | |
import java.util.List; |
| 28 | |
import java.util.Locale; |
| 29 | |
import java.util.Set; |
| 30 | |
import java.util.logging.Level; |
| 31 | |
import java.util.logging.Logger; |
| 32 | |
import org.apache.maven.artifact.Artifact; |
| 33 | |
import org.apache.maven.doxia.sink.Sink; |
| 34 | |
import org.apache.maven.doxia.sink.SinkFactory; |
| 35 | |
import org.apache.maven.plugin.AbstractMojo; |
| 36 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 37 | |
import org.apache.maven.plugin.MojoFailureException; |
| 38 | |
import org.apache.maven.plugins.annotations.Component; |
| 39 | |
import org.apache.maven.plugins.annotations.LifecyclePhase; |
| 40 | |
import org.apache.maven.plugins.annotations.Mojo; |
| 41 | |
import org.apache.maven.plugins.annotations.Parameter; |
| 42 | |
import org.apache.maven.plugins.annotations.ResolutionScope; |
| 43 | |
import org.apache.maven.project.MavenProject; |
| 44 | |
import org.apache.maven.reporting.MavenMultiPageReport; |
| 45 | |
import org.apache.maven.reporting.MavenReport; |
| 46 | |
import org.apache.maven.reporting.MavenReportException; |
| 47 | |
import org.apache.maven.settings.Proxy; |
| 48 | |
import org.owasp.dependencycheck.Engine; |
| 49 | |
import org.owasp.dependencycheck.data.nvdcve.CveDB; |
| 50 | |
import org.owasp.dependencycheck.data.nvdcve.DatabaseException; |
| 51 | |
import org.owasp.dependencycheck.data.nvdcve.DatabaseProperties; |
| 52 | |
import org.owasp.dependencycheck.dependency.Dependency; |
| 53 | |
import org.owasp.dependencycheck.dependency.Evidence; |
| 54 | |
import org.owasp.dependencycheck.dependency.Identifier; |
| 55 | |
import org.owasp.dependencycheck.dependency.Reference; |
| 56 | |
import org.owasp.dependencycheck.dependency.Vulnerability; |
| 57 | |
import org.owasp.dependencycheck.dependency.VulnerableSoftware; |
| 58 | |
import org.owasp.dependencycheck.reporting.ReportGenerator; |
| 59 | |
import org.owasp.dependencycheck.utils.LogUtils; |
| 60 | |
import org.owasp.dependencycheck.utils.Settings; |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
@Mojo(name = "check", defaultPhase = LifecyclePhase.COMPILE, threadSafe = true, |
| 68 | |
requiresDependencyResolution = ResolutionScope.RUNTIME_PLUS_SYSTEM, |
| 69 | |
requiresOnline = true) |
| 70 | 0 | public class DependencyCheckMojo extends AbstractMojo implements MavenMultiPageReport { |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | 0 | private final Logger logger = Logger.getLogger(DependencyCheckMojo.class.getName()); |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
private static final String PROPERTIES_FILE = "mojo.properties"; |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
private static final String LOG_PROPERTIES_FILE = "log.properties"; |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | 0 | private static final String NEW_LINE = System.getProperty("line.separator", "\n").intern(); |
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
@Component |
| 94 | |
private MavenProject project; |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
@Parameter(property = "logfile", defaultValue = "") |
| 99 | |
private String logFile; |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
@Parameter(property = "name", defaultValue = "Dependency-Check") |
| 104 | |
private String name; |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
@Parameter(property = "description", defaultValue = "A report providing details on any published " |
| 109 | |
+ "vulnerabilities within project dependencies. This report is a best effort but may contain " |
| 110 | |
+ "false positives and false negatives.") |
| 111 | |
private String description; |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
@Parameter(property = "reportOutputDirectory", defaultValue = "${project.reporting.outputDirectory}", required = true) |
| 117 | |
private File reportOutputDirectory; |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
@Parameter(defaultValue = "${project.build.directory}", required = true) |
| 122 | |
private File outputDirectory; |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | 0 | @SuppressWarnings("CanBeFinal") |
| 128 | |
@Parameter(property = "failBuildOnCVSS", defaultValue = "11", required = true) |
| 129 | |
private float failBuildOnCVSS = 11; |
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | 0 | @SuppressWarnings("CanBeFinal") |
| 135 | |
@Parameter(property = "autoupdate", defaultValue = "true", required = true) |
| 136 | |
private boolean autoUpdate = true; |
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 142 | |
@Parameter(property = "format", defaultValue = "HTML", required = true) |
| 143 | |
private String format = "HTML"; |
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 148 | |
@Parameter(property = "externalReport", defaultValue = "false", required = true) |
| 149 | |
private boolean externalReport = false; |
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 156 | |
@Parameter(property = "proxyUrl", defaultValue = "", required = false) |
| 157 | |
@Deprecated |
| 158 | |
private String proxyUrl = null; |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
@SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 164 | |
@Parameter(property = "mavenSettings", defaultValue = "${settings}", required = false) |
| 165 | |
private org.apache.maven.settings.Settings mavenSettings; |
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
@SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 171 | |
@Parameter(property = "mavenSettingsProxyId", required = false) |
| 172 | |
private String mavenSettingsProxyId; |
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 180 | |
@Parameter(property = "proxyPort", defaultValue = "", required = false) |
| 181 | |
@Deprecated |
| 182 | |
private String proxyPort = null; |
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 189 | |
@Parameter(property = "proxyUsername", defaultValue = "", required = false) |
| 190 | |
@Deprecated |
| 191 | |
private String proxyUsername = null; |
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 198 | |
@Parameter(property = "proxyPassword", defaultValue = "", required = false) |
| 199 | |
@Deprecated |
| 200 | |
private String proxyPassword = null; |
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 205 | |
@Parameter(property = "connectionTimeout", defaultValue = "", required = false) |
| 206 | |
private String connectionTimeout = null; |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 211 | |
@Parameter(property = "suppressionFile", defaultValue = "", required = false) |
| 212 | |
private String suppressionFile = null; |
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 217 | |
@Parameter(property = "showSummary", defaultValue = "true", required = false) |
| 218 | |
private boolean showSummary = true; |
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 224 | |
@Parameter(property = "jarAnalyzerEnabled", defaultValue = "true", required = false) |
| 225 | |
private boolean jarAnalyzerEnabled = true; |
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 231 | |
@Parameter(property = "archiveAnalyzerEnabled", defaultValue = "true", required = false) |
| 232 | |
private boolean archiveAnalyzerEnabled = true; |
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 238 | |
@Parameter(property = "assemblyAnalyzerEnabled", defaultValue = "true", required = false) |
| 239 | |
private boolean assemblyAnalyzerEnabled = true; |
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 245 | |
@Parameter(property = "nuspecAnalyzerEnabled", defaultValue = "true", required = false) |
| 246 | |
private boolean nuspecAnalyzerEnabled = true; |
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 252 | |
@Parameter(property = "nexusAnalyzerEnabled", defaultValue = "true", required = false) |
| 253 | |
private boolean nexusAnalyzerEnabled = true; |
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
@SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 258 | |
@Parameter(property = "nexusUrl", defaultValue = "", required = false) |
| 259 | |
private String nexusUrl; |
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 264 | |
@Parameter(property = "nexusUsesProxy", defaultValue = "true", required = false) |
| 265 | |
private boolean nexusUsesProxy = true; |
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
@SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 270 | |
@Parameter(property = "connectionString", defaultValue = "", required = false) |
| 271 | |
private String connectionString; |
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
@SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 276 | |
@Parameter(property = "databaseDriverName", defaultValue = "", required = false) |
| 277 | |
private String databaseDriverName; |
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
@SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 282 | |
@Parameter(property = "databaseDriverPath", defaultValue = "", required = false) |
| 283 | |
private String databaseDriverPath; |
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
@SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 288 | |
@Parameter(property = "databaseUser", defaultValue = "", required = false) |
| 289 | |
private String databaseUser; |
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
@SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 294 | |
@Parameter(property = "databasePassword", defaultValue = "", required = false) |
| 295 | |
private String databasePassword; |
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
@Parameter(property = "zipExtensions", required = false) |
| 300 | |
private String zipExtensions; |
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | 0 | @SuppressWarnings("CanBeFinal") |
| 305 | |
@Parameter(property = "skipTestScope", defaultValue = "true", required = false) |
| 306 | |
private boolean skipTestScope = true; |
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | 0 | @SuppressWarnings("CanBeFinal") |
| 311 | |
@Parameter(property = "skipRuntimeScope", defaultValue = "false", required = false) |
| 312 | |
private boolean skipRuntimeScope = false; |
| 313 | |
|
| 314 | |
|
| 315 | |
|
| 316 | 0 | @SuppressWarnings("CanBeFinal") |
| 317 | |
@Parameter(property = "skipProvidedScope", defaultValue = "false", required = false) |
| 318 | |
private boolean skipProvidedScope = false; |
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
@Parameter(property = "dataDirectory", defaultValue = "", required = false) |
| 323 | |
private String dataDirectory; |
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
@Parameter(property = "cveUrl12Modified", defaultValue = "", required = false) |
| 328 | |
private String cveUrl12Modified; |
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
@Parameter(property = "cveUrl20Modified", defaultValue = "", required = false) |
| 333 | |
private String cveUrl20Modified; |
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
@Parameter(property = "cveUrl12Base", defaultValue = "", required = false) |
| 338 | |
private String cveUrl12Base; |
| 339 | |
|
| 340 | |
|
| 341 | |
|
| 342 | |
@Parameter(property = "cveUrl20Base", defaultValue = "", required = false) |
| 343 | |
private String cveUrl20Base; |
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
@Parameter(property = "pathToMono", defaultValue = "", required = false) |
| 349 | |
private String pathToMono; |
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
private Engine executeDependencyCheck() throws DatabaseException { |
| 359 | |
|
| 360 | 0 | final InputStream in = DependencyCheckMojo.class.getClassLoader().getResourceAsStream(LOG_PROPERTIES_FILE); |
| 361 | 0 | LogUtils.prepareLogger(in, logFile); |
| 362 | |
|
| 363 | 0 | populateSettings(); |
| 364 | 0 | final Engine engine = new Engine(); |
| 365 | |
|
| 366 | 0 | final Set<Artifact> artifacts = project.getArtifacts(); |
| 367 | 0 | for (Artifact a : artifacts) { |
| 368 | 0 | if (skipTestScope && Artifact.SCOPE_TEST.equals(a.getScope())) { |
| 369 | 0 | continue; |
| 370 | |
} |
| 371 | |
|
| 372 | 0 | if (skipProvidedScope && Artifact.SCOPE_PROVIDED.equals(a.getScope())) { |
| 373 | 0 | continue; |
| 374 | |
} |
| 375 | |
|
| 376 | 0 | if (skipRuntimeScope && !Artifact.SCOPE_RUNTIME.equals(a.getScope())) { |
| 377 | 0 | continue; |
| 378 | |
} |
| 379 | |
|
| 380 | 0 | engine.scan(a.getFile().getAbsolutePath()); |
| 381 | 0 | } |
| 382 | 0 | engine.analyzeDependencies(); |
| 383 | |
|
| 384 | 0 | return engine; |
| 385 | |
} |
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
private void generateExternalReports(Engine engine, File outDirectory) { |
| 394 | 0 | DatabaseProperties prop = null; |
| 395 | 0 | CveDB cve = null; |
| 396 | |
try { |
| 397 | 0 | cve = new CveDB(); |
| 398 | 0 | cve.open(); |
| 399 | 0 | prop = cve.getDatabaseProperties(); |
| 400 | 0 | } catch (DatabaseException ex) { |
| 401 | 0 | logger.log(Level.FINE, "Unable to retrieve DB Properties", ex); |
| 402 | |
} finally { |
| 403 | 0 | if (cve != null) { |
| 404 | 0 | cve.close(); |
| 405 | |
} |
| 406 | |
} |
| 407 | 0 | final ReportGenerator r = new ReportGenerator(project.getName(), engine.getDependencies(), engine.getAnalyzers(), prop); |
| 408 | |
try { |
| 409 | 0 | r.generateReports(outDirectory.getCanonicalPath(), format); |
| 410 | 0 | } catch (IOException ex) { |
| 411 | 0 | logger.log(Level.SEVERE, |
| 412 | |
"Unexpected exception occurred during analysis; please see the verbose error log for more details."); |
| 413 | 0 | logger.log(Level.FINE, null, ex); |
| 414 | 0 | } catch (Throwable ex) { |
| 415 | 0 | logger.log(Level.SEVERE, |
| 416 | |
"Unexpected exception occurred during analysis; please see the verbose error log for more details."); |
| 417 | 0 | logger.log(Level.FINE, null, ex); |
| 418 | 0 | } |
| 419 | 0 | } |
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
|
| 427 | |
private void generateMavenSiteReport(final Engine engine, Sink sink) { |
| 428 | 0 | final List<Dependency> dependencies = engine.getDependencies(); |
| 429 | |
|
| 430 | 0 | writeSiteReportHeader(sink, project.getName()); |
| 431 | 0 | writeSiteReportTOC(sink, dependencies); |
| 432 | |
|
| 433 | 0 | int cnt = 0; |
| 434 | 0 | for (Dependency d : dependencies) { |
| 435 | 0 | writeSiteReportDependencyHeader(sink, d); |
| 436 | 0 | cnt = writeSiteReportDependencyEvidenceUsed(d, cnt, sink); |
| 437 | 0 | cnt = writeSiteReportDependencyRelatedDependencies(d, cnt, sink); |
| 438 | 0 | writeSiteReportDependencyIdentifiers(d, sink); |
| 439 | 0 | writeSiteReportDependencyVulnerabilities(d, sink, cnt); |
| 440 | 0 | } |
| 441 | 0 | sink.body_(); |
| 442 | 0 | } |
| 443 | |
|
| 444 | |
|
| 445 | |
|
| 446 | |
|
| 447 | |
|
| 448 | |
|
| 449 | |
|
| 450 | |
|
| 451 | |
|
| 452 | |
private void writeSiteReportDependencyVulnerabilities(Dependency d, Sink sink, int collapsibleHeaderCount) { |
| 453 | 0 | int cnt = collapsibleHeaderCount; |
| 454 | 0 | if (d.getVulnerabilities() != null && !d.getVulnerabilities().isEmpty()) { |
| 455 | 0 | for (Vulnerability v : d.getVulnerabilities()) { |
| 456 | |
|
| 457 | 0 | sink.paragraph(); |
| 458 | 0 | sink.bold(); |
| 459 | |
try { |
| 460 | 0 | sink.link("http://web.nvd.nist.gov/view/vuln/detail?vulnId=" + URLEncoder.encode(v.getName(), "US-ASCII")); |
| 461 | 0 | sink.text(v.getName()); |
| 462 | 0 | sink.link_(); |
| 463 | 0 | sink.bold_(); |
| 464 | 0 | } catch (UnsupportedEncodingException ex) { |
| 465 | 0 | sink.text(v.getName()); |
| 466 | 0 | sink.bold_(); |
| 467 | 0 | sink.lineBreak(); |
| 468 | 0 | sink.text("http://web.nvd.nist.gov/view/vuln/detail?vulnId=" + v.getName()); |
| 469 | 0 | } |
| 470 | 0 | sink.paragraph_(); |
| 471 | 0 | sink.paragraph(); |
| 472 | 0 | sink.text("Severity: "); |
| 473 | 0 | if (v.getCvssScore() < 4.0) { |
| 474 | 0 | sink.text("Low"); |
| 475 | |
} else { |
| 476 | 0 | if (v.getCvssScore() >= 7.0) { |
| 477 | 0 | sink.text("High"); |
| 478 | |
} else { |
| 479 | 0 | sink.text("Medium"); |
| 480 | |
} |
| 481 | |
} |
| 482 | 0 | sink.lineBreak(); |
| 483 | 0 | sink.text("CVSS Score: " + v.getCvssScore()); |
| 484 | 0 | if (v.getCwe() != null && !v.getCwe().isEmpty()) { |
| 485 | 0 | sink.lineBreak(); |
| 486 | 0 | sink.text("CWE: "); |
| 487 | 0 | sink.text(v.getCwe()); |
| 488 | |
} |
| 489 | 0 | sink.paragraph_(); |
| 490 | 0 | sink.paragraph(); |
| 491 | 0 | sink.text(v.getDescription()); |
| 492 | 0 | if (v.getReferences() != null && !v.getReferences().isEmpty()) { |
| 493 | 0 | sink.list(); |
| 494 | 0 | for (Reference ref : v.getReferences()) { |
| 495 | 0 | sink.listItem(); |
| 496 | 0 | sink.text(ref.getSource()); |
| 497 | 0 | sink.text(" - "); |
| 498 | 0 | sink.link(ref.getUrl()); |
| 499 | 0 | sink.text(ref.getName()); |
| 500 | 0 | sink.link_(); |
| 501 | 0 | sink.listItem_(); |
| 502 | 0 | } |
| 503 | 0 | sink.list_(); |
| 504 | |
} |
| 505 | 0 | sink.paragraph_(); |
| 506 | 0 | if (v.getVulnerableSoftware() != null && !v.getVulnerableSoftware().isEmpty()) { |
| 507 | 0 | sink.paragraph(); |
| 508 | |
|
| 509 | 0 | cnt += 1; |
| 510 | 0 | sink.rawText("Vulnerable Software <a href=\"javascript:toggleElement(this, 'vulnSoft" + cnt + "')\">[-]</a>"); |
| 511 | 0 | sink.rawText("<div id=\"vulnSoft" + cnt + "\" style=\"display:block\">"); |
| 512 | 0 | sink.list(); |
| 513 | 0 | for (VulnerableSoftware vs : v.getVulnerableSoftware()) { |
| 514 | 0 | sink.listItem(); |
| 515 | |
try { |
| 516 | 0 | sink.link("http://web.nvd.nist.gov/view/vuln/search-results?cpe=" + URLEncoder.encode(vs.getName(), "US-ASCII")); |
| 517 | 0 | sink.text(vs.getName()); |
| 518 | 0 | sink.link_(); |
| 519 | 0 | if (vs.hasPreviousVersion()) { |
| 520 | 0 | sink.text(" and all previous versions."); |
| 521 | |
} |
| 522 | 0 | } catch (UnsupportedEncodingException ex) { |
| 523 | 0 | sink.text(vs.getName()); |
| 524 | 0 | if (vs.hasPreviousVersion()) { |
| 525 | 0 | sink.text(" and all previous versions."); |
| 526 | |
} |
| 527 | 0 | sink.text(" (http://web.nvd.nist.gov/view/vuln/search-results?cpe=" + vs.getName() + ")"); |
| 528 | 0 | } |
| 529 | |
|
| 530 | 0 | sink.listItem_(); |
| 531 | 0 | } |
| 532 | 0 | sink.list_(); |
| 533 | 0 | sink.rawText("</div>"); |
| 534 | 0 | sink.paragraph_(); |
| 535 | |
} |
| 536 | 0 | } |
| 537 | |
} |
| 538 | 0 | } |
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | |
|
| 545 | |
|
| 546 | |
private void writeSiteReportDependencyIdentifiers(Dependency d, Sink sink) { |
| 547 | 0 | if (d.getIdentifiers() != null && !d.getIdentifiers().isEmpty()) { |
| 548 | 0 | sink.sectionTitle4(); |
| 549 | 0 | sink.text("Identifiers"); |
| 550 | 0 | sink.sectionTitle4_(); |
| 551 | 0 | sink.list(); |
| 552 | 0 | for (Identifier i : d.getIdentifiers()) { |
| 553 | 0 | sink.listItem(); |
| 554 | 0 | sink.text(i.getType()); |
| 555 | 0 | sink.text(": "); |
| 556 | 0 | if (i.getUrl() != null && i.getUrl().length() > 0) { |
| 557 | 0 | sink.link(i.getUrl()); |
| 558 | 0 | sink.text(i.getValue()); |
| 559 | 0 | sink.link_(); |
| 560 | |
} else { |
| 561 | 0 | sink.text(i.getValue()); |
| 562 | |
} |
| 563 | 0 | if (i.getDescription() != null && i.getDescription().length() > 0) { |
| 564 | 0 | sink.lineBreak(); |
| 565 | 0 | sink.text(i.getDescription()); |
| 566 | |
} |
| 567 | 0 | sink.listItem_(); |
| 568 | 0 | } |
| 569 | 0 | sink.list_(); |
| 570 | |
} |
| 571 | 0 | } |
| 572 | |
|
| 573 | |
|
| 574 | |
|
| 575 | |
|
| 576 | |
|
| 577 | |
|
| 578 | |
|
| 579 | |
|
| 580 | |
|
| 581 | |
private int writeSiteReportDependencyRelatedDependencies(Dependency d, int collapsibleHeaderCount, Sink sink) { |
| 582 | 0 | int cnt = collapsibleHeaderCount; |
| 583 | 0 | if (d.getRelatedDependencies() != null && !d.getRelatedDependencies().isEmpty()) { |
| 584 | 0 | cnt += 1; |
| 585 | 0 | sink.sectionTitle4(); |
| 586 | 0 | sink.rawText("Related Dependencies <a href=\"javascript:toggleElement(this, 'related" + cnt + "')\">[+]</a>"); |
| 587 | 0 | sink.sectionTitle4_(); |
| 588 | 0 | sink.rawText("<div id=\"related" + cnt + "\" style=\"display:none\">"); |
| 589 | 0 | sink.list(); |
| 590 | 0 | for (Dependency r : d.getRelatedDependencies()) { |
| 591 | 0 | sink.listItem(); |
| 592 | 0 | sink.text(r.getFileName()); |
| 593 | 0 | sink.list(); |
| 594 | 0 | writeListItem(sink, "File Path: " + r.getFilePath()); |
| 595 | 0 | writeListItem(sink, "SHA1: " + r.getSha1sum()); |
| 596 | 0 | writeListItem(sink, "MD5: " + r.getMd5sum()); |
| 597 | 0 | sink.list_(); |
| 598 | 0 | sink.listItem_(); |
| 599 | 0 | } |
| 600 | 0 | sink.list_(); |
| 601 | 0 | sink.rawText("</div>"); |
| 602 | |
} |
| 603 | 0 | return cnt; |
| 604 | |
} |
| 605 | |
|
| 606 | |
|
| 607 | |
|
| 608 | |
|
| 609 | |
|
| 610 | |
|
| 611 | |
|
| 612 | |
|
| 613 | |
|
| 614 | |
private int writeSiteReportDependencyEvidenceUsed(Dependency d, int collapsibleHeaderCount, Sink sink) { |
| 615 | 0 | int cnt = collapsibleHeaderCount; |
| 616 | 0 | if (d.getEvidenceUsed() != null && d.getEvidenceUsed().size() > 0) { |
| 617 | 0 | cnt += 1; |
| 618 | 0 | sink.sectionTitle4(); |
| 619 | 0 | sink.rawText("Evidence Collected <a href=\"javascript:toggleElement(this, 'evidence" + cnt + "')\">[+]</a>"); |
| 620 | 0 | sink.sectionTitle4_(); |
| 621 | 0 | sink.rawText("<div id=\"evidence" + cnt + "\" style=\"display:none\">"); |
| 622 | 0 | sink.table(); |
| 623 | 0 | sink.tableRow(); |
| 624 | 0 | writeTableHeaderCell(sink, "Source"); |
| 625 | 0 | writeTableHeaderCell(sink, "Name"); |
| 626 | 0 | writeTableHeaderCell(sink, "Value"); |
| 627 | 0 | sink.tableRow_(); |
| 628 | 0 | for (Evidence e : d.getEvidenceUsed()) { |
| 629 | 0 | sink.tableRow(); |
| 630 | 0 | writeTableCell(sink, e.getSource()); |
| 631 | 0 | writeTableCell(sink, e.getName()); |
| 632 | 0 | writeTableCell(sink, e.getValue()); |
| 633 | 0 | sink.tableRow_(); |
| 634 | 0 | } |
| 635 | 0 | sink.table_(); |
| 636 | 0 | sink.rawText("</div>"); |
| 637 | |
} |
| 638 | 0 | return cnt; |
| 639 | |
} |
| 640 | |
|
| 641 | |
|
| 642 | |
|
| 643 | |
|
| 644 | |
|
| 645 | |
|
| 646 | |
|
| 647 | |
private void writeSiteReportDependencyHeader(Sink sink, Dependency d) { |
| 648 | 0 | sink.sectionTitle2(); |
| 649 | 0 | sink.anchor("sha1" + d.getSha1sum()); |
| 650 | 0 | sink.text(d.getFileName()); |
| 651 | 0 | sink.anchor_(); |
| 652 | 0 | sink.sectionTitle2_(); |
| 653 | 0 | if (d.getDescription() != null && d.getDescription().length() > 0) { |
| 654 | 0 | sink.paragraph(); |
| 655 | 0 | sink.bold(); |
| 656 | 0 | sink.text("Description: "); |
| 657 | 0 | sink.bold_(); |
| 658 | 0 | sink.text(d.getDescription()); |
| 659 | 0 | sink.paragraph_(); |
| 660 | |
} |
| 661 | 0 | if (d.getLicense() != null && d.getLicense().length() > 0) { |
| 662 | 0 | sink.paragraph(); |
| 663 | 0 | sink.bold(); |
| 664 | 0 | sink.text("License: "); |
| 665 | 0 | sink.bold_(); |
| 666 | 0 | if (d.getLicense().startsWith("http://") && !d.getLicense().contains(" ")) { |
| 667 | 0 | sink.link(d.getLicense()); |
| 668 | 0 | sink.text(d.getLicense()); |
| 669 | 0 | sink.link_(); |
| 670 | |
} else { |
| 671 | 0 | sink.text(d.getLicense()); |
| 672 | |
} |
| 673 | 0 | sink.paragraph_(); |
| 674 | |
} |
| 675 | 0 | } |
| 676 | |
|
| 677 | |
|
| 678 | |
|
| 679 | |
|
| 680 | |
|
| 681 | |
|
| 682 | |
|
| 683 | |
private void writeListItem(Sink sink, String text) { |
| 684 | 0 | sink.listItem(); |
| 685 | 0 | sink.text(text); |
| 686 | 0 | sink.listItem_(); |
| 687 | 0 | } |
| 688 | |
|
| 689 | |
|
| 690 | |
|
| 691 | |
|
| 692 | |
|
| 693 | |
|
| 694 | |
|
| 695 | |
private void writeTableCell(Sink sink, String text) { |
| 696 | 0 | sink.tableCell(); |
| 697 | 0 | sink.text(text); |
| 698 | 0 | sink.tableCell_(); |
| 699 | 0 | } |
| 700 | |
|
| 701 | |
|
| 702 | |
|
| 703 | |
|
| 704 | |
|
| 705 | |
|
| 706 | |
|
| 707 | |
private void writeTableHeaderCell(Sink sink, String text) { |
| 708 | 0 | sink.tableHeaderCell(); |
| 709 | 0 | sink.text(text); |
| 710 | 0 | sink.tableHeaderCell_(); |
| 711 | 0 | } |
| 712 | |
|
| 713 | |
|
| 714 | |
|
| 715 | |
|
| 716 | |
|
| 717 | |
|
| 718 | |
|
| 719 | |
private void writeSiteReportTOC(Sink sink, final List<Dependency> dependencies) { |
| 720 | 0 | sink.list(); |
| 721 | 0 | for (Dependency d : dependencies) { |
| 722 | 0 | sink.listItem(); |
| 723 | 0 | sink.link("#sha1" + d.getSha1sum()); |
| 724 | 0 | sink.text(d.getFileName()); |
| 725 | 0 | sink.link_(); |
| 726 | 0 | if (!d.getVulnerabilities().isEmpty()) { |
| 727 | 0 | sink.rawText(" <font style=\"color:red\">•</font>"); |
| 728 | |
} |
| 729 | 0 | if (!d.getRelatedDependencies().isEmpty()) { |
| 730 | 0 | sink.list(); |
| 731 | 0 | for (Dependency r : d.getRelatedDependencies()) { |
| 732 | 0 | writeListItem(sink, r.getFileName()); |
| 733 | 0 | } |
| 734 | 0 | sink.list_(); |
| 735 | |
} |
| 736 | 0 | sink.listItem_(); |
| 737 | 0 | } |
| 738 | 0 | sink.list_(); |
| 739 | 0 | } |
| 740 | |
|
| 741 | |
|
| 742 | |
|
| 743 | |
|
| 744 | |
|
| 745 | |
|
| 746 | |
|
| 747 | |
private void writeSiteReportHeader(Sink sink, String projectName) { |
| 748 | 0 | sink.head(); |
| 749 | 0 | sink.title(); |
| 750 | 0 | sink.text("Dependency-Check Report: " + projectName); |
| 751 | 0 | sink.title_(); |
| 752 | 0 | sink.head_(); |
| 753 | 0 | sink.body(); |
| 754 | 0 | sink.rawText("<script type=\"text/javascript\">"); |
| 755 | 0 | sink.rawText("function toggleElement(el, targetId) {"); |
| 756 | 0 | sink.rawText("if (el.innerText == '[+]') {"); |
| 757 | 0 | sink.rawText(" el.innerText = '[-]';"); |
| 758 | 0 | sink.rawText(" document.getElementById(targetId).style.display='block';"); |
| 759 | 0 | sink.rawText("} else {"); |
| 760 | 0 | sink.rawText(" el.innerText = '[+]';"); |
| 761 | 0 | sink.rawText(" document.getElementById(targetId).style.display='none';"); |
| 762 | 0 | sink.rawText("}"); |
| 763 | |
|
| 764 | 0 | sink.rawText("}"); |
| 765 | 0 | sink.rawText("</script>"); |
| 766 | 0 | sink.section1(); |
| 767 | 0 | sink.sectionTitle1(); |
| 768 | 0 | sink.text("Project: " + projectName); |
| 769 | 0 | sink.sectionTitle1_(); |
| 770 | 0 | sink.date(); |
| 771 | 0 | final Date now = new Date(); |
| 772 | 0 | sink.text(DateFormat.getDateTimeInstance().format(now)); |
| 773 | 0 | sink.date_(); |
| 774 | 0 | sink.section1_(); |
| 775 | 0 | } |
| 776 | |
|
| 777 | |
|
| 778 | |
|
| 779 | |
|
| 780 | |
|
| 781 | |
|
| 782 | |
|
| 783 | |
|
| 784 | |
private String getMavenSettingsProxyUrl(Proxy proxy) { |
| 785 | 0 | return new StringBuilder(proxy.getProtocol()).append("://").append(proxy.getHost()).toString(); |
| 786 | |
} |
| 787 | |
|
| 788 | |
|
| 789 | |
|
| 790 | |
|
| 791 | |
|
| 792 | |
|
| 793 | |
private Proxy getMavenProxy() { |
| 794 | 0 | if (mavenSettings != null) { |
| 795 | 0 | final List<Proxy> proxies = mavenSettings.getProxies(); |
| 796 | 0 | if (proxies != null && proxies.size() > 0) { |
| 797 | 0 | if (mavenSettingsProxyId != null) { |
| 798 | 0 | for (Proxy proxy : proxies) { |
| 799 | 0 | if (mavenSettingsProxyId.equalsIgnoreCase(proxy.getId())) { |
| 800 | 0 | return proxy; |
| 801 | |
} |
| 802 | 0 | } |
| 803 | 0 | } else if (proxies.size() == 1) { |
| 804 | 0 | return proxies.get(0); |
| 805 | |
} else { |
| 806 | 0 | throw new IllegalStateException("Ambiguous proxy definition"); |
| 807 | |
} |
| 808 | |
} |
| 809 | |
} |
| 810 | 0 | return null; |
| 811 | |
} |
| 812 | |
|
| 813 | |
|
| 814 | |
|
| 815 | |
|
| 816 | |
|
| 817 | |
private void populateSettings() { |
| 818 | 0 | Settings.initialize(); |
| 819 | 0 | InputStream mojoProperties = null; |
| 820 | |
try { |
| 821 | 0 | mojoProperties = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILE); |
| 822 | 0 | Settings.mergeProperties(mojoProperties); |
| 823 | 0 | } catch (IOException ex) { |
| 824 | 0 | logger.log(Level.WARNING, "Unable to load the dependency-check ant task.properties file."); |
| 825 | 0 | logger.log(Level.FINE, null, ex); |
| 826 | |
} finally { |
| 827 | 0 | if (mojoProperties != null) { |
| 828 | |
try { |
| 829 | 0 | mojoProperties.close(); |
| 830 | 0 | } catch (IOException ex) { |
| 831 | 0 | logger.log(Level.FINEST, null, ex); |
| 832 | 0 | } |
| 833 | |
} |
| 834 | |
} |
| 835 | |
|
| 836 | 0 | Settings.setBoolean(Settings.KEYS.AUTO_UPDATE, autoUpdate); |
| 837 | |
|
| 838 | 0 | final Proxy proxy = getMavenProxy(); |
| 839 | 0 | if (proxy != null) { |
| 840 | 0 | Settings.setString(Settings.KEYS.PROXY_URL, getMavenSettingsProxyUrl(proxy)); |
| 841 | 0 | Settings.setString(Settings.KEYS.PROXY_PORT, Integer.toString(proxy.getPort())); |
| 842 | 0 | final String userName = proxy.getUsername(); |
| 843 | 0 | final String password = proxy.getPassword(); |
| 844 | 0 | if (userName != null && password != null) { |
| 845 | 0 | Settings.setString(Settings.KEYS.PROXY_USERNAME, userName); |
| 846 | 0 | Settings.setString(Settings.KEYS.PROXY_PASSWORD, password); |
| 847 | |
} |
| 848 | |
} |
| 849 | |
|
| 850 | 0 | if (proxyUrl != null && !proxyUrl.isEmpty()) { |
| 851 | 0 | Settings.setString(Settings.KEYS.PROXY_URL, proxyUrl); |
| 852 | |
} |
| 853 | 0 | if (proxyPort != null && !proxyPort.isEmpty()) { |
| 854 | 0 | Settings.setString(Settings.KEYS.PROXY_PORT, proxyPort); |
| 855 | |
} |
| 856 | 0 | if (proxyUsername != null && !proxyUsername.isEmpty()) { |
| 857 | 0 | Settings.setString(Settings.KEYS.PROXY_USERNAME, proxyUsername); |
| 858 | |
} |
| 859 | 0 | if (proxyPassword != null && !proxyPassword.isEmpty()) { |
| 860 | 0 | Settings.setString(Settings.KEYS.PROXY_PASSWORD, proxyPassword); |
| 861 | |
} |
| 862 | 0 | if (connectionTimeout != null && !connectionTimeout.isEmpty()) { |
| 863 | 0 | Settings.setString(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout); |
| 864 | |
} |
| 865 | 0 | if (suppressionFile != null && !suppressionFile.isEmpty()) { |
| 866 | 0 | Settings.setString(Settings.KEYS.SUPPRESSION_FILE, suppressionFile); |
| 867 | |
} |
| 868 | |
|
| 869 | |
|
| 870 | |
|
| 871 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_JAR_ENABLED, jarAnalyzerEnabled); |
| 872 | |
|
| 873 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_NUSPEC_ENABLED, nuspecAnalyzerEnabled); |
| 874 | |
|
| 875 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED, nexusAnalyzerEnabled); |
| 876 | 0 | if (nexusUrl != null && !nexusUrl.isEmpty()) { |
| 877 | 0 | Settings.setString(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl); |
| 878 | |
} |
| 879 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_NEXUS_PROXY, nexusUsesProxy); |
| 880 | |
|
| 881 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, archiveAnalyzerEnabled); |
| 882 | 0 | if (zipExtensions != null && !zipExtensions.isEmpty()) { |
| 883 | 0 | Settings.setString(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS, zipExtensions); |
| 884 | |
} |
| 885 | |
|
| 886 | 0 | Settings.setBoolean(Settings.KEYS.ANALYZER_ASSEMBLY_ENABLED, assemblyAnalyzerEnabled); |
| 887 | 0 | if (pathToMono != null && !pathToMono.isEmpty()) { |
| 888 | 0 | Settings.setString(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, pathToMono); |
| 889 | |
} |
| 890 | |
|
| 891 | |
|
| 892 | 0 | if (databaseDriverName != null && !databaseDriverName.isEmpty()) { |
| 893 | 0 | Settings.setString(Settings.KEYS.DB_DRIVER_NAME, databaseDriverName); |
| 894 | |
} |
| 895 | 0 | if (databaseDriverPath != null && !databaseDriverPath.isEmpty()) { |
| 896 | 0 | Settings.setString(Settings.KEYS.DB_DRIVER_PATH, databaseDriverPath); |
| 897 | |
} |
| 898 | 0 | if (connectionString != null && !connectionString.isEmpty()) { |
| 899 | 0 | Settings.setString(Settings.KEYS.DB_CONNECTION_STRING, connectionString); |
| 900 | |
} |
| 901 | 0 | if (databaseUser != null && !databaseUser.isEmpty()) { |
| 902 | 0 | Settings.setString(Settings.KEYS.DB_USER, databaseUser); |
| 903 | |
} |
| 904 | 0 | if (databasePassword != null && !databasePassword.isEmpty()) { |
| 905 | 0 | Settings.setString(Settings.KEYS.DB_PASSWORD, databasePassword); |
| 906 | |
} |
| 907 | |
|
| 908 | 0 | if (dataDirectory != null && !dataDirectory.isEmpty()) { |
| 909 | 0 | Settings.setString(Settings.KEYS.DATA_DIRECTORY, dataDirectory); |
| 910 | |
} |
| 911 | |
|
| 912 | |
|
| 913 | 0 | Settings.setBoolean(Settings.KEYS.SKIP_TEST_SCOPE, skipTestScope); |
| 914 | 0 | Settings.setBoolean(Settings.KEYS.SKIP_RUNTIME_SCOPE, skipRuntimeScope); |
| 915 | 0 | Settings.setBoolean(Settings.KEYS.SKIP_PROVIDED_SCOPE, skipProvidedScope); |
| 916 | |
|
| 917 | |
|
| 918 | 0 | if (cveUrl12Modified != null && !cveUrl12Modified.isEmpty()) { |
| 919 | 0 | Settings.setString(Settings.KEYS.CVE_MODIFIED_12_URL, cveUrl12Modified); |
| 920 | |
} |
| 921 | 0 | if (cveUrl20Modified != null && !cveUrl20Modified.isEmpty()) { |
| 922 | 0 | Settings.setString(Settings.KEYS.CVE_MODIFIED_20_URL, cveUrl20Modified); |
| 923 | |
} |
| 924 | 0 | if (cveUrl12Base != null && !cveUrl12Base.isEmpty()) { |
| 925 | 0 | Settings.setString(Settings.KEYS.CVE_SCHEMA_1_2, cveUrl12Base); |
| 926 | |
} |
| 927 | 0 | if (cveUrl20Base != null && !cveUrl20Base.isEmpty()) { |
| 928 | 0 | Settings.setString(Settings.KEYS.CVE_SCHEMA_2_0, cveUrl20Base); |
| 929 | |
} |
| 930 | |
|
| 931 | 0 | } |
| 932 | |
|
| 933 | |
|
| 934 | |
|
| 935 | |
|
| 936 | |
|
| 937 | |
|
| 938 | |
|
| 939 | |
public void execute() throws MojoExecutionException, MojoFailureException { |
| 940 | 0 | Engine engine = null; |
| 941 | |
try { |
| 942 | 0 | engine = executeDependencyCheck(); |
| 943 | 0 | generateExternalReports(engine, outputDirectory); |
| 944 | 0 | if (this.showSummary) { |
| 945 | 0 | showSummary(engine.getDependencies()); |
| 946 | |
} |
| 947 | 0 | if (this.failBuildOnCVSS <= 10) { |
| 948 | 0 | checkForFailure(engine.getDependencies()); |
| 949 | |
} |
| 950 | 0 | } catch (DatabaseException ex) { |
| 951 | 0 | logger.log(Level.SEVERE, |
| 952 | |
"Unable to connect to the dependency-check database; analysis has stopped"); |
| 953 | 0 | logger.log(Level.FINE, "", ex); |
| 954 | |
} finally { |
| 955 | 0 | Settings.cleanup(); |
| 956 | 0 | if (engine != null) { |
| 957 | 0 | engine.cleanup(); |
| 958 | |
} |
| 959 | |
} |
| 960 | 0 | } |
| 961 | |
|
| 962 | |
|
| 963 | |
|
| 964 | |
|
| 965 | |
|
| 966 | |
|
| 967 | |
|
| 968 | |
|
| 969 | |
public void generate(@SuppressWarnings("deprecation") org.codehaus.doxia.sink.Sink sink, |
| 970 | |
Locale locale) throws MavenReportException { |
| 971 | 0 | generate((Sink) sink, null, locale); |
| 972 | 0 | } |
| 973 | |
|
| 974 | |
|
| 975 | |
|
| 976 | |
|
| 977 | |
|
| 978 | |
|
| 979 | |
|
| 980 | |
|
| 981 | |
|
| 982 | |
public void generate(Sink sink, SinkFactory sinkFactory, Locale locale) throws MavenReportException { |
| 983 | 0 | Engine engine = null; |
| 984 | |
try { |
| 985 | 0 | engine = executeDependencyCheck(); |
| 986 | 0 | if (this.externalReport) { |
| 987 | 0 | generateExternalReports(engine, reportOutputDirectory); |
| 988 | |
} else { |
| 989 | 0 | generateMavenSiteReport(engine, sink); |
| 990 | |
} |
| 991 | 0 | } catch (DatabaseException ex) { |
| 992 | 0 | logger.log(Level.SEVERE, |
| 993 | |
"Unable to connect to the dependency-check database; analysis has stopped"); |
| 994 | 0 | logger.log(Level.FINE, "", ex); |
| 995 | |
} finally { |
| 996 | 0 | Settings.cleanup(); |
| 997 | 0 | if (engine != null) { |
| 998 | 0 | engine.cleanup(); |
| 999 | |
} |
| 1000 | |
} |
| 1001 | 0 | } |
| 1002 | |
|
| 1003 | |
|
| 1004 | |
|
| 1005 | |
|
| 1006 | |
|
| 1007 | |
|
| 1008 | |
|
| 1009 | |
public String getOutputName() { |
| 1010 | 0 | if ("HTML".equalsIgnoreCase(this.format) |
| 1011 | |
|| "ALL".equalsIgnoreCase(this.format)) { |
| 1012 | 0 | return "dependency-check-report"; |
| 1013 | 0 | } else if ("XML".equalsIgnoreCase(this.format)) { |
| 1014 | 0 | return "dependency-check-report.xml#"; |
| 1015 | 0 | } else if ("VULN".equalsIgnoreCase(this.format)) { |
| 1016 | 0 | return "dependency-check-vulnerability"; |
| 1017 | |
} else { |
| 1018 | 0 | logger.log(Level.WARNING, "Unknown report format used during site generation."); |
| 1019 | 0 | return "dependency-check-report"; |
| 1020 | |
} |
| 1021 | |
} |
| 1022 | |
|
| 1023 | |
|
| 1024 | |
|
| 1025 | |
|
| 1026 | |
|
| 1027 | |
|
| 1028 | |
public String getCategoryName() { |
| 1029 | 0 | return MavenReport.CATEGORY_PROJECT_REPORTS; |
| 1030 | |
} |
| 1031 | |
|
| 1032 | |
|
| 1033 | |
|
| 1034 | |
|
| 1035 | |
|
| 1036 | |
|
| 1037 | |
|
| 1038 | |
public String getName(Locale locale) { |
| 1039 | 0 | return name; |
| 1040 | |
} |
| 1041 | |
|
| 1042 | |
|
| 1043 | |
|
| 1044 | |
|
| 1045 | |
|
| 1046 | |
|
| 1047 | |
public void setReportOutputDirectory(File directory) { |
| 1048 | 0 | reportOutputDirectory = directory; |
| 1049 | 0 | } |
| 1050 | |
|
| 1051 | |
|
| 1052 | |
|
| 1053 | |
|
| 1054 | |
|
| 1055 | |
|
| 1056 | |
public File getReportOutputDirectory() { |
| 1057 | 0 | return reportOutputDirectory; |
| 1058 | |
} |
| 1059 | |
|
| 1060 | |
|
| 1061 | |
|
| 1062 | |
|
| 1063 | |
|
| 1064 | |
|
| 1065 | |
|
| 1066 | |
public String getDescription(Locale locale) { |
| 1067 | 0 | return description; |
| 1068 | |
} |
| 1069 | |
|
| 1070 | |
|
| 1071 | |
|
| 1072 | |
|
| 1073 | |
|
| 1074 | |
|
| 1075 | |
public boolean isExternalReport() { |
| 1076 | 0 | return externalReport; |
| 1077 | |
} |
| 1078 | |
|
| 1079 | |
|
| 1080 | |
|
| 1081 | |
|
| 1082 | |
|
| 1083 | |
|
| 1084 | |
public boolean canGenerateReport() { |
| 1085 | 0 | return true; |
| 1086 | |
} |
| 1087 | |
|
| 1088 | |
|
| 1089 | |
|
| 1090 | |
|
| 1091 | |
|
| 1092 | |
|
| 1093 | |
|
| 1094 | |
|
| 1095 | |
|
| 1096 | |
private void checkForFailure(List<Dependency> dependencies) throws MojoFailureException { |
| 1097 | 0 | final StringBuilder ids = new StringBuilder(); |
| 1098 | 0 | for (Dependency d : dependencies) { |
| 1099 | 0 | boolean addName = true; |
| 1100 | 0 | for (Vulnerability v : d.getVulnerabilities()) { |
| 1101 | 0 | if (v.getCvssScore() >= failBuildOnCVSS) { |
| 1102 | 0 | if (addName) { |
| 1103 | 0 | addName = false; |
| 1104 | 0 | ids.append(NEW_LINE).append(d.getFileName()).append(": "); |
| 1105 | 0 | ids.append(v.getName()); |
| 1106 | |
} else { |
| 1107 | 0 | ids.append(", ").append(v.getName()); |
| 1108 | |
} |
| 1109 | |
} |
| 1110 | 0 | } |
| 1111 | 0 | } |
| 1112 | 0 | if (ids.length() > 0) { |
| 1113 | 0 | final String msg = String.format("%n%nDependency-Check Failure:%n" |
| 1114 | |
+ "One or more dependencies were identified with vulnerabilities that have a CVSS score greater then '%.1f': %s%n" |
| 1115 | |
+ "See the dependency-check report for more details.%n%n", failBuildOnCVSS, ids.toString()); |
| 1116 | 0 | throw new MojoFailureException(msg); |
| 1117 | |
} |
| 1118 | 0 | } |
| 1119 | |
|
| 1120 | |
|
| 1121 | |
|
| 1122 | |
|
| 1123 | |
|
| 1124 | |
|
| 1125 | |
private void showSummary(List<Dependency> dependencies) { |
| 1126 | 0 | final StringBuilder summary = new StringBuilder(); |
| 1127 | 0 | for (Dependency d : dependencies) { |
| 1128 | 0 | boolean firstEntry = true; |
| 1129 | 0 | final StringBuilder ids = new StringBuilder(); |
| 1130 | 0 | for (Vulnerability v : d.getVulnerabilities()) { |
| 1131 | 0 | if (firstEntry) { |
| 1132 | 0 | firstEntry = false; |
| 1133 | |
} else { |
| 1134 | 0 | ids.append(", "); |
| 1135 | |
} |
| 1136 | 0 | ids.append(v.getName()); |
| 1137 | 0 | } |
| 1138 | 0 | if (ids.length() > 0) { |
| 1139 | 0 | summary.append(d.getFileName()).append(" ("); |
| 1140 | 0 | firstEntry = true; |
| 1141 | 0 | for (Identifier id : d.getIdentifiers()) { |
| 1142 | 0 | if (firstEntry) { |
| 1143 | 0 | firstEntry = false; |
| 1144 | |
} else { |
| 1145 | 0 | summary.append(", "); |
| 1146 | |
} |
| 1147 | 0 | summary.append(id.getValue()); |
| 1148 | 0 | } |
| 1149 | 0 | summary.append(") : ").append(ids).append(NEW_LINE); |
| 1150 | |
} |
| 1151 | 0 | } |
| 1152 | 0 | if (summary.length() > 0) { |
| 1153 | 0 | final String msg = String.format("%n%n" |
| 1154 | |
+ "One or more dependencies were identified with known vulnerabilities:%n%n%s" |
| 1155 | |
+ "%n%nSee the dependency-check report for more details.%n%n", summary.toString()); |
| 1156 | 0 | logger.log(Level.WARNING, msg); |
| 1157 | |
} |
| 1158 | 0 | } |
| 1159 | |
} |