| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.owasp.dependencycheck.maven; |
| 20 | |
|
| 21 | |
import java.io.File; |
| 22 | |
import java.io.IOException; |
| 23 | |
import java.io.InputStream; |
| 24 | |
import java.io.UnsupportedEncodingException; |
| 25 | |
import java.net.URLEncoder; |
| 26 | |
import java.text.DateFormat; |
| 27 | |
import java.util.Date; |
| 28 | |
import java.util.List; |
| 29 | |
import java.util.Locale; |
| 30 | |
import java.util.logging.Level; |
| 31 | |
import java.util.logging.Logger; |
| 32 | |
import org.apache.maven.doxia.sink.SinkFactory; |
| 33 | |
import org.apache.maven.plugin.AbstractMojo; |
| 34 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 35 | |
import org.apache.maven.project.MavenProject; |
| 36 | |
import java.util.Set; |
| 37 | |
import org.apache.maven.artifact.Artifact; |
| 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.reporting.MavenMultiPageReport; |
| 44 | |
import org.apache.maven.reporting.MavenReport; |
| 45 | |
import org.apache.maven.reporting.MavenReportException; |
| 46 | |
import org.apache.maven.doxia.sink.Sink; |
| 47 | |
import org.apache.maven.plugin.MojoFailureException; |
| 48 | |
import org.owasp.dependencycheck.Engine; |
| 49 | |
import org.owasp.dependencycheck.dependency.Dependency; |
| 50 | |
import org.owasp.dependencycheck.dependency.Evidence; |
| 51 | |
import org.owasp.dependencycheck.dependency.Identifier; |
| 52 | |
import org.owasp.dependencycheck.dependency.Reference; |
| 53 | |
import org.owasp.dependencycheck.dependency.Vulnerability; |
| 54 | |
import org.owasp.dependencycheck.dependency.VulnerableSoftware; |
| 55 | |
import org.owasp.dependencycheck.reporting.ReportGenerator; |
| 56 | |
import org.owasp.dependencycheck.utils.LogUtils; |
| 57 | |
import org.owasp.dependencycheck.utils.Settings; |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
@Mojo(name = "check", defaultPhase = LifecyclePhase.COMPILE, threadSafe = true, |
| 66 | |
requiresDependencyResolution = ResolutionScope.RUNTIME_PLUS_SYSTEM, |
| 67 | |
requiresOnline = true) |
| 68 | 0 | public class DependencyCheckMojo extends AbstractMojo implements MavenMultiPageReport { |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
private static final String PROPERTIES_FILE = "mojo.properties"; |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
private static final String LOG_PROPERTIES_FILE = "log.properties"; |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
public static final String TEST_SCOPE = "test"; |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
@Component |
| 87 | |
private MavenProject project; |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
@Parameter(property = "report-name", defaultValue = "dependency-check-report") |
| 92 | |
private String reportName; |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
@Parameter(property = "logfile", defaultValue = "") |
| 97 | |
private String logFile; |
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
@Parameter(property = "name", defaultValue = "Dependency-Check") |
| 103 | |
private String name; |
| 104 | |
|
| 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 | |
|
| 122 | |
|
| 123 | 0 | @Parameter(property = "failBuildOnCVSS", defaultValue = "11", required = true) |
| 124 | |
private float failBuildOnCVSS = 11; |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
@Parameter(defaultValue = "${project.build.directory}", required = true) |
| 129 | |
private File outputDirectory; |
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 135 | |
@Parameter(property = "autoupdate", defaultValue = "true", required = true) |
| 136 | |
private boolean autoUpdate = true; |
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 143 | |
@Parameter(property = "format", defaultValue = "HTML", required = true) |
| 144 | |
private String format = "HTML"; |
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | 0 | @SuppressWarnings({"CanBeFinal", "FieldCanBeLocal"}) |
| 149 | |
@Parameter(property = "externalReport", defaultValue = "false", required = true) |
| 150 | |
private boolean externalReport = false; |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | 0 | @SuppressWarnings("CanBeFinal") |
| 155 | |
@Parameter(property = "proxyUrl", defaultValue = "", required = false) |
| 156 | |
private String proxyUrl = null; |
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | 0 | @SuppressWarnings("CanBeFinal") |
| 161 | |
@Parameter(property = "proxyPort", defaultValue = "", required = false) |
| 162 | |
private String proxyPort = null; |
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | 0 | @SuppressWarnings("CanBeFinal") |
| 167 | |
@Parameter(property = "proxyUsername", defaultValue = "", required = false) |
| 168 | |
private String proxyUsername = null; |
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | 0 | @SuppressWarnings("CanBeFinal") |
| 173 | |
@Parameter(property = "proxyPassword", defaultValue = "", required = false) |
| 174 | |
private String proxyPassword = null; |
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | 0 | @SuppressWarnings("CanBeFinal") |
| 179 | |
@Parameter(property = "connectionTimeout", defaultValue = "", required = false) |
| 180 | |
private String connectionTimeout = null; |
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | 0 | @SuppressWarnings("CanBeFinal") |
| 185 | |
@Parameter(property = "suppressionFile", defaultValue = "", required = false) |
| 186 | |
private String suppressionFile = null; |
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
private Engine executeDependencyCheck() { |
| 195 | |
|
| 196 | 0 | final InputStream in = DependencyCheckMojo.class.getClassLoader().getResourceAsStream(LOG_PROPERTIES_FILE); |
| 197 | 0 | LogUtils.prepareLogger(in, logFile); |
| 198 | |
|
| 199 | 0 | populateSettings(); |
| 200 | 0 | final Engine engine = new Engine(); |
| 201 | 0 | final Set<Artifact> artifacts = project.getArtifacts(); |
| 202 | 0 | for (Artifact a : artifacts) { |
| 203 | 0 | if (!TEST_SCOPE.equals(a.getScope())) { |
| 204 | 0 | engine.scan(a.getFile().getAbsolutePath()); |
| 205 | |
} |
| 206 | |
} |
| 207 | 0 | engine.analyzeDependencies(); |
| 208 | 0 | return engine; |
| 209 | |
} |
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
private void generateExternalReports(Engine engine) { |
| 217 | 0 | final ReportGenerator r = new ReportGenerator(project.getName(), engine.getDependencies(), engine.getAnalyzers()); |
| 218 | |
try { |
| 219 | 0 | r.generateReports(outputDirectory.getCanonicalPath(), format); |
| 220 | 0 | } catch (IOException ex) { |
| 221 | 0 | Logger.getLogger(DependencyCheckMojo.class.getName()).log(Level.SEVERE, null, ex); |
| 222 | 0 | } catch (Exception ex) { |
| 223 | 0 | Logger.getLogger(DependencyCheckMojo.class.getName()).log(Level.SEVERE, null, ex); |
| 224 | 0 | } |
| 225 | 0 | } |
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
private void generateMavenSiteReport(final Engine engine, Sink sink) { |
| 234 | 0 | final List<Dependency> dependencies = engine.getDependencies(); |
| 235 | |
|
| 236 | 0 | writeSiteReportHeader(sink, project.getName()); |
| 237 | 0 | writeSiteReportTOC(sink, dependencies); |
| 238 | |
|
| 239 | 0 | int cnt = 0; |
| 240 | 0 | for (Dependency d : dependencies) { |
| 241 | 0 | writeSiteReportDependencyHeader(sink, d); |
| 242 | 0 | cnt = writeSiteReportDependencyAnalysisExceptions(d, cnt, sink); |
| 243 | 0 | cnt = writeSiteReportDependencyEvidenceUsed(d, cnt, sink); |
| 244 | 0 | cnt = writeSiteReportDependencyRelatedDependencies(d, cnt, sink); |
| 245 | 0 | writeSiteReportDependencyIdentifiers(d, sink); |
| 246 | 0 | writeSiteReportDependencyVulnerabilities(d, sink, cnt); |
| 247 | |
} |
| 248 | 0 | sink.body_(); |
| 249 | 0 | } |
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
private void writeSiteReportDependencyVulnerabilities(Dependency d, Sink sink, int collapsibleHeaderCount) { |
| 260 | 0 | int cnt = collapsibleHeaderCount; |
| 261 | 0 | if (d.getVulnerabilities() != null && !d.getVulnerabilities().isEmpty()) { |
| 262 | 0 | for (Vulnerability v : d.getVulnerabilities()) { |
| 263 | |
|
| 264 | 0 | sink.paragraph(); |
| 265 | 0 | sink.bold(); |
| 266 | |
try { |
| 267 | 0 | sink.link("http://web.nvd.nist.gov/view/vuln/detail?vulnId=" + URLEncoder.encode(v.getName(), "US-ASCII")); |
| 268 | 0 | sink.text(v.getName()); |
| 269 | 0 | sink.link_(); |
| 270 | 0 | sink.bold_(); |
| 271 | 0 | } catch (UnsupportedEncodingException ex) { |
| 272 | 0 | sink.text(v.getName()); |
| 273 | 0 | sink.bold_(); |
| 274 | 0 | sink.lineBreak(); |
| 275 | 0 | sink.text("http://web.nvd.nist.gov/view/vuln/detail?vulnId=" + v.getName()); |
| 276 | 0 | } |
| 277 | 0 | sink.paragraph_(); |
| 278 | 0 | sink.paragraph(); |
| 279 | 0 | sink.text("Severity: "); |
| 280 | 0 | if (v.getCvssScore() < 4.0) { |
| 281 | 0 | sink.text("Low"); |
| 282 | |
} else { |
| 283 | 0 | if (v.getCvssScore() >= 7.0) { |
| 284 | 0 | sink.text("High"); |
| 285 | |
} else { |
| 286 | 0 | sink.text("Medium"); |
| 287 | |
} |
| 288 | |
} |
| 289 | 0 | sink.lineBreak(); |
| 290 | 0 | sink.text("CVSS Score: " + v.getCvssScore()); |
| 291 | 0 | if (v.getCwe() != null && !v.getCwe().isEmpty()) { |
| 292 | 0 | sink.lineBreak(); |
| 293 | 0 | sink.text("CWE: "); |
| 294 | 0 | sink.text(v.getCwe()); |
| 295 | |
} |
| 296 | 0 | sink.paragraph_(); |
| 297 | 0 | sink.paragraph(); |
| 298 | 0 | sink.text(v.getDescription()); |
| 299 | 0 | if (v.getReferences() != null && !v.getReferences().isEmpty()) { |
| 300 | 0 | sink.list(); |
| 301 | 0 | for (Reference ref : v.getReferences()) { |
| 302 | 0 | sink.listItem(); |
| 303 | 0 | sink.text(ref.getSource()); |
| 304 | 0 | sink.text(" - "); |
| 305 | 0 | sink.link(ref.getUrl()); |
| 306 | 0 | sink.text(ref.getName()); |
| 307 | 0 | sink.link_(); |
| 308 | 0 | sink.listItem_(); |
| 309 | |
} |
| 310 | 0 | sink.list_(); |
| 311 | |
} |
| 312 | 0 | sink.paragraph_(); |
| 313 | 0 | if (v.getVulnerableSoftware() != null && !v.getVulnerableSoftware().isEmpty()) { |
| 314 | 0 | sink.paragraph(); |
| 315 | |
|
| 316 | 0 | cnt += 1; |
| 317 | 0 | sink.rawText("Vulnerable Software <a href=\"javascript:toggleElement(this, 'vulnSoft" + cnt + "')\">[-]</a>"); |
| 318 | 0 | sink.rawText("<div id=\"vulnSoft" + cnt + "\" style=\"display:block\">"); |
| 319 | 0 | sink.list(); |
| 320 | 0 | for (VulnerableSoftware vs : v.getVulnerableSoftware()) { |
| 321 | 0 | sink.listItem(); |
| 322 | |
try { |
| 323 | 0 | sink.link("http://web.nvd.nist.gov/view/vuln/search-results?cpe=" + URLEncoder.encode(vs.getName(), "US-ASCII")); |
| 324 | 0 | sink.text(vs.getName()); |
| 325 | 0 | sink.link_(); |
| 326 | 0 | if (vs.hasPreviousVersion()) { |
| 327 | 0 | sink.text(" and all previous versions."); |
| 328 | |
} |
| 329 | 0 | } catch (UnsupportedEncodingException ex) { |
| 330 | 0 | sink.text(vs.getName()); |
| 331 | 0 | if (vs.hasPreviousVersion()) { |
| 332 | 0 | sink.text(" and all previous versions."); |
| 333 | |
} |
| 334 | 0 | sink.text(" (http://web.nvd.nist.gov/view/vuln/search-results?cpe=" + vs.getName() + ")"); |
| 335 | 0 | } |
| 336 | |
|
| 337 | 0 | sink.listItem_(); |
| 338 | |
} |
| 339 | 0 | sink.list_(); |
| 340 | 0 | sink.rawText("</div>"); |
| 341 | 0 | sink.paragraph_(); |
| 342 | |
} |
| 343 | |
} |
| 344 | |
} |
| 345 | 0 | } |
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
private void writeSiteReportDependencyIdentifiers(Dependency d, Sink sink) { |
| 354 | 0 | if (d.getIdentifiers() != null && !d.getIdentifiers().isEmpty()) { |
| 355 | 0 | sink.sectionTitle4(); |
| 356 | 0 | sink.text("Identifiers"); |
| 357 | 0 | sink.sectionTitle4_(); |
| 358 | 0 | sink.list(); |
| 359 | 0 | for (Identifier i : d.getIdentifiers()) { |
| 360 | 0 | sink.listItem(); |
| 361 | 0 | sink.text(i.getType()); |
| 362 | 0 | sink.text(": "); |
| 363 | 0 | if (i.getUrl() != null && i.getUrl().length() > 0) { |
| 364 | 0 | sink.link(i.getUrl()); |
| 365 | 0 | sink.text(i.getValue()); |
| 366 | 0 | sink.link_(); |
| 367 | |
} else { |
| 368 | 0 | sink.text(i.getValue()); |
| 369 | |
} |
| 370 | 0 | if (i.getDescription() != null && i.getDescription().length() > 0) { |
| 371 | 0 | sink.lineBreak(); |
| 372 | 0 | sink.text(i.getDescription()); |
| 373 | |
} |
| 374 | 0 | sink.listItem_(); |
| 375 | |
} |
| 376 | 0 | sink.list_(); |
| 377 | |
} |
| 378 | 0 | } |
| 379 | |
|
| 380 | |
|
| 381 | |
|
| 382 | |
|
| 383 | |
|
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
private int writeSiteReportDependencyRelatedDependencies(Dependency d, int collapsibleHeaderCount, Sink sink) { |
| 389 | 0 | int cnt = collapsibleHeaderCount; |
| 390 | 0 | if (d.getRelatedDependencies() != null && !d.getRelatedDependencies().isEmpty()) { |
| 391 | 0 | cnt += 1; |
| 392 | 0 | sink.sectionTitle4(); |
| 393 | 0 | sink.rawText("Related Dependencies <a href=\"javascript:toggleElement(this, 'related" + cnt + "')\">[+]</a>"); |
| 394 | 0 | sink.sectionTitle4_(); |
| 395 | 0 | sink.rawText("<div id=\"related" + cnt + "\" style=\"display:none\">"); |
| 396 | 0 | sink.list(); |
| 397 | 0 | for (Dependency r : d.getRelatedDependencies()) { |
| 398 | 0 | sink.listItem(); |
| 399 | 0 | sink.text(r.getFileName()); |
| 400 | 0 | sink.list(); |
| 401 | 0 | writeListItem(sink, "File Path: " + r.getFilePath()); |
| 402 | 0 | writeListItem(sink, "SHA1: " + r.getSha1sum()); |
| 403 | 0 | writeListItem(sink, "MD5: " + r.getMd5sum()); |
| 404 | 0 | sink.list_(); |
| 405 | 0 | sink.listItem_(); |
| 406 | |
} |
| 407 | 0 | sink.list_(); |
| 408 | 0 | sink.rawText("</div>"); |
| 409 | |
} |
| 410 | 0 | return cnt; |
| 411 | |
} |
| 412 | |
|
| 413 | |
|
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
private int writeSiteReportDependencyEvidenceUsed(Dependency d, int collapsibleHeaderCount, Sink sink) { |
| 422 | 0 | int cnt = collapsibleHeaderCount; |
| 423 | 0 | if (d.getEvidenceUsed() != null && d.getEvidenceUsed().size() > 0) { |
| 424 | 0 | cnt += 1; |
| 425 | 0 | sink.sectionTitle4(); |
| 426 | 0 | sink.rawText("Evidence Collected <a href=\"javascript:toggleElement(this, 'evidence" + cnt + "')\">[+]</a>"); |
| 427 | 0 | sink.sectionTitle4_(); |
| 428 | 0 | sink.rawText("<div id=\"evidence" + cnt + "\" style=\"display:none\">"); |
| 429 | 0 | sink.table(); |
| 430 | 0 | sink.tableRow(); |
| 431 | 0 | writeTableHeaderCell(sink, "Source"); |
| 432 | 0 | writeTableHeaderCell(sink, "Name"); |
| 433 | 0 | writeTableHeaderCell(sink, "Value"); |
| 434 | 0 | sink.tableRow_(); |
| 435 | 0 | for (Evidence e : d.getEvidenceUsed()) { |
| 436 | 0 | sink.tableRow(); |
| 437 | 0 | writeTableCell(sink, e.getSource()); |
| 438 | 0 | writeTableCell(sink, e.getName()); |
| 439 | 0 | writeTableCell(sink, e.getValue()); |
| 440 | 0 | sink.tableRow_(); |
| 441 | |
} |
| 442 | 0 | sink.table_(); |
| 443 | 0 | sink.rawText("</div>"); |
| 444 | |
} |
| 445 | 0 | return cnt; |
| 446 | |
} |
| 447 | |
|
| 448 | |
|
| 449 | |
|
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
|
| 457 | |
private int writeSiteReportDependencyAnalysisExceptions(Dependency d, int collapsibleHeaderCount, Sink sink) { |
| 458 | 0 | int cnt = collapsibleHeaderCount; |
| 459 | 0 | if (d.getAnalysisExceptions() != null && !d.getAnalysisExceptions().isEmpty()) { |
| 460 | 0 | cnt += 1; |
| 461 | 0 | sink.sectionTitle4(); |
| 462 | 0 | sink.rawText("<font style=\"color:red\">Errors occurred during analysis:</font> <a href=\"javascript:toggleElement(this, 'errors" |
| 463 | |
+ cnt + "')\">[+]</a>"); |
| 464 | 0 | sink.sectionTitle4_(); |
| 465 | 0 | sink.rawText("<div id=\"errors" + cnt + "\">"); |
| 466 | 0 | sink.list(); |
| 467 | 0 | for (Exception e : d.getAnalysisExceptions()) { |
| 468 | 0 | sink.listItem(); |
| 469 | 0 | sink.text(e.getMessage()); |
| 470 | 0 | sink.listItem_(); |
| 471 | |
} |
| 472 | 0 | sink.list_(); |
| 473 | 0 | sink.rawText("</div>"); |
| 474 | |
} |
| 475 | 0 | return cnt; |
| 476 | |
} |
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
private void writeSiteReportDependencyHeader(Sink sink, Dependency d) { |
| 485 | 0 | sink.sectionTitle2(); |
| 486 | 0 | sink.anchor("sha1" + d.getSha1sum()); |
| 487 | 0 | sink.text(d.getFileName()); |
| 488 | 0 | sink.anchor_(); |
| 489 | 0 | sink.sectionTitle2_(); |
| 490 | 0 | if (d.getDescription() != null && d.getDescription().length() > 0) { |
| 491 | 0 | sink.paragraph(); |
| 492 | 0 | sink.bold(); |
| 493 | 0 | sink.text("Description: "); |
| 494 | 0 | sink.bold_(); |
| 495 | 0 | sink.text(d.getDescription()); |
| 496 | 0 | sink.paragraph_(); |
| 497 | |
} |
| 498 | 0 | if (d.getLicense() != null && d.getLicense().length() > 0) { |
| 499 | 0 | sink.paragraph(); |
| 500 | 0 | sink.bold(); |
| 501 | 0 | sink.text("License: "); |
| 502 | 0 | sink.bold_(); |
| 503 | 0 | if (d.getLicense().startsWith("http://") && !d.getLicense().contains(" ")) { |
| 504 | 0 | sink.link(d.getLicense()); |
| 505 | 0 | sink.text(d.getLicense()); |
| 506 | 0 | sink.link_(); |
| 507 | |
} else { |
| 508 | 0 | sink.text(d.getLicense()); |
| 509 | |
} |
| 510 | 0 | sink.paragraph_(); |
| 511 | |
} |
| 512 | 0 | } |
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | |
|
| 517 | |
|
| 518 | |
|
| 519 | |
|
| 520 | |
private void writeListItem(Sink sink, String text) { |
| 521 | 0 | sink.listItem(); |
| 522 | 0 | sink.text(text); |
| 523 | 0 | sink.listItem_(); |
| 524 | 0 | } |
| 525 | |
|
| 526 | |
|
| 527 | |
|
| 528 | |
|
| 529 | |
|
| 530 | |
|
| 531 | |
|
| 532 | |
private void writeTableCell(Sink sink, String text) { |
| 533 | 0 | sink.tableCell(); |
| 534 | 0 | sink.text(text); |
| 535 | 0 | sink.tableCell_(); |
| 536 | 0 | } |
| 537 | |
|
| 538 | |
|
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | |
private void writeTableHeaderCell(Sink sink, String text) { |
| 545 | 0 | sink.tableHeaderCell(); |
| 546 | 0 | sink.text(text); |
| 547 | 0 | sink.tableHeaderCell_(); |
| 548 | 0 | } |
| 549 | |
|
| 550 | |
|
| 551 | |
|
| 552 | |
|
| 553 | |
|
| 554 | |
|
| 555 | |
|
| 556 | |
private void writeSiteReportTOC(Sink sink, final List<Dependency> dependencies) { |
| 557 | 0 | sink.list(); |
| 558 | 0 | for (Dependency d : dependencies) { |
| 559 | 0 | sink.listItem(); |
| 560 | 0 | sink.link("#sha1" + d.getSha1sum()); |
| 561 | 0 | sink.text(d.getFileName()); |
| 562 | 0 | sink.link_(); |
| 563 | 0 | if (!d.getVulnerabilities().isEmpty()) { |
| 564 | 0 | sink.rawText(" <font style=\"color:red\">•</font>"); |
| 565 | |
} |
| 566 | 0 | if (!d.getRelatedDependencies().isEmpty()) { |
| 567 | 0 | sink.list(); |
| 568 | 0 | for (Dependency r : d.getRelatedDependencies()) { |
| 569 | 0 | writeListItem(sink, r.getFileName()); |
| 570 | |
} |
| 571 | 0 | sink.list_(); |
| 572 | |
} |
| 573 | 0 | sink.listItem_(); |
| 574 | |
} |
| 575 | 0 | sink.list_(); |
| 576 | 0 | } |
| 577 | |
|
| 578 | |
|
| 579 | |
|
| 580 | |
|
| 581 | |
|
| 582 | |
|
| 583 | |
|
| 584 | |
private void writeSiteReportHeader(Sink sink, String projectName) { |
| 585 | 0 | sink.head(); |
| 586 | 0 | sink.title(); |
| 587 | 0 | sink.text("Dependency-Check Report: " + projectName); |
| 588 | 0 | sink.title_(); |
| 589 | 0 | sink.head_(); |
| 590 | 0 | sink.body(); |
| 591 | 0 | sink.rawText("<script type=\"text/javascript\">"); |
| 592 | 0 | sink.rawText("function toggleElement(el, targetId) {"); |
| 593 | 0 | sink.rawText("if (el.innerText == '[+]') {"); |
| 594 | 0 | sink.rawText(" el.innerText = '[-]';"); |
| 595 | 0 | sink.rawText(" document.getElementById(targetId).style.display='block';"); |
| 596 | 0 | sink.rawText("} else {"); |
| 597 | 0 | sink.rawText(" el.innerText = '[+]';"); |
| 598 | 0 | sink.rawText(" document.getElementById(targetId).style.display='none';"); |
| 599 | 0 | sink.rawText("}"); |
| 600 | |
|
| 601 | 0 | sink.rawText("}"); |
| 602 | 0 | sink.rawText("</script>"); |
| 603 | 0 | sink.section1(); |
| 604 | 0 | sink.sectionTitle1(); |
| 605 | 0 | sink.text("Project: " + projectName); |
| 606 | 0 | sink.sectionTitle1_(); |
| 607 | 0 | sink.date(); |
| 608 | 0 | final Date now = new Date(); |
| 609 | 0 | sink.text(DateFormat.getDateTimeInstance().format(now)); |
| 610 | 0 | sink.date_(); |
| 611 | 0 | sink.section1_(); |
| 612 | 0 | } |
| 613 | |
|
| 614 | |
|
| 615 | |
|
| 616 | |
|
| 617 | |
|
| 618 | |
|
| 619 | |
|
| 620 | |
private void populateSettings() { |
| 621 | 0 | InputStream mojoProperties = null; |
| 622 | |
try { |
| 623 | 0 | mojoProperties = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILE); |
| 624 | 0 | Settings.mergeProperties(mojoProperties); |
| 625 | 0 | } catch (IOException ex) { |
| 626 | 0 | Logger.getLogger(DependencyCheckMojo.class.getName()).log(Level.WARNING, "Unable to load the dependency-check ant task.properties file."); |
| 627 | 0 | Logger.getLogger(DependencyCheckMojo.class.getName()).log(Level.FINE, null, ex); |
| 628 | |
} finally { |
| 629 | 0 | if (mojoProperties != null) { |
| 630 | |
try { |
| 631 | 0 | mojoProperties.close(); |
| 632 | 0 | } catch (IOException ex) { |
| 633 | 0 | Logger.getLogger(DependencyCheckMojo.class.getName()).log(Level.FINEST, null, ex); |
| 634 | 0 | } |
| 635 | |
} |
| 636 | |
} |
| 637 | |
|
| 638 | 0 | Settings.setBoolean(Settings.KEYS.AUTO_UPDATE, autoUpdate); |
| 639 | |
|
| 640 | 0 | if (proxyUrl != null && !proxyUrl.isEmpty()) { |
| 641 | 0 | Settings.setString(Settings.KEYS.PROXY_URL, proxyUrl); |
| 642 | |
} |
| 643 | 0 | if (proxyPort != null && !proxyPort.isEmpty()) { |
| 644 | 0 | Settings.setString(Settings.KEYS.PROXY_PORT, proxyPort); |
| 645 | |
} |
| 646 | 0 | if (proxyUsername != null && !proxyUsername.isEmpty()) { |
| 647 | 0 | Settings.setString(Settings.KEYS.PROXY_USERNAME, proxyUsername); |
| 648 | |
} |
| 649 | 0 | if (proxyPassword != null && !proxyPassword.isEmpty()) { |
| 650 | 0 | Settings.setString(Settings.KEYS.PROXY_PASSWORD, proxyPassword); |
| 651 | |
} |
| 652 | 0 | if (connectionTimeout != null && !connectionTimeout.isEmpty()) { |
| 653 | 0 | Settings.setString(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout); |
| 654 | |
} |
| 655 | 0 | if (suppressionFile != null && !suppressionFile.isEmpty()) { |
| 656 | 0 | Settings.setString(Settings.KEYS.SUPPRESSION_FILE, suppressionFile); |
| 657 | |
} |
| 658 | 0 | } |
| 659 | |
|
| 660 | |
|
| 661 | |
|
| 662 | |
|
| 663 | |
|
| 664 | |
|
| 665 | |
|
| 666 | |
|
| 667 | |
public void execute() throws MojoExecutionException, MojoFailureException { |
| 668 | 0 | final Engine engine = executeDependencyCheck(); |
| 669 | 0 | generateExternalReports(engine); |
| 670 | 0 | if (this.failBuildOnCVSS <= 10) { |
| 671 | 0 | checkForFailure(engine.getDependencies()); |
| 672 | |
} |
| 673 | 0 | } |
| 674 | |
|
| 675 | |
|
| 676 | |
|
| 677 | |
|
| 678 | |
|
| 679 | |
|
| 680 | |
|
| 681 | |
|
| 682 | |
public void generate(@SuppressWarnings("deprecation") org.codehaus.doxia.sink.Sink sink, |
| 683 | |
Locale locale) throws MavenReportException { |
| 684 | 0 | generate((Sink) sink, null, locale); |
| 685 | 0 | } |
| 686 | |
|
| 687 | |
|
| 688 | |
|
| 689 | |
|
| 690 | |
|
| 691 | |
|
| 692 | |
|
| 693 | |
|
| 694 | |
|
| 695 | |
public void generate(Sink sink, SinkFactory sinkFactory, Locale locale) throws MavenReportException { |
| 696 | 0 | final Engine engine = executeDependencyCheck(); |
| 697 | 0 | generateMavenSiteReport(engine, sink); |
| 698 | 0 | } |
| 699 | |
|
| 700 | |
|
| 701 | |
|
| 702 | |
|
| 703 | |
|
| 704 | |
|
| 705 | |
|
| 706 | |
public String getOutputName() { |
| 707 | 0 | return reportName; |
| 708 | |
} |
| 709 | |
|
| 710 | |
|
| 711 | |
|
| 712 | |
|
| 713 | |
|
| 714 | |
|
| 715 | |
public String getCategoryName() { |
| 716 | 0 | return MavenReport.CATEGORY_PROJECT_REPORTS; |
| 717 | |
} |
| 718 | |
|
| 719 | |
|
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
|
| 724 | |
|
| 725 | |
public String getName(Locale locale) { |
| 726 | 0 | return name; |
| 727 | |
} |
| 728 | |
|
| 729 | |
|
| 730 | |
|
| 731 | |
|
| 732 | |
|
| 733 | |
|
| 734 | |
public void setReportOutputDirectory(File directory) { |
| 735 | 0 | reportOutputDirectory = directory; |
| 736 | 0 | } |
| 737 | |
|
| 738 | |
|
| 739 | |
|
| 740 | |
|
| 741 | |
|
| 742 | |
|
| 743 | |
public File getReportOutputDirectory() { |
| 744 | 0 | return reportOutputDirectory; |
| 745 | |
} |
| 746 | |
|
| 747 | |
|
| 748 | |
|
| 749 | |
|
| 750 | |
|
| 751 | |
|
| 752 | |
|
| 753 | |
|
| 754 | |
public String getDescription(Locale locale) { |
| 755 | 0 | return description; |
| 756 | |
} |
| 757 | |
|
| 758 | |
|
| 759 | |
|
| 760 | |
|
| 761 | |
|
| 762 | |
|
| 763 | |
public boolean isExternalReport() { |
| 764 | 0 | return externalReport; |
| 765 | |
} |
| 766 | |
|
| 767 | |
|
| 768 | |
|
| 769 | |
|
| 770 | |
|
| 771 | |
|
| 772 | |
public boolean canGenerateReport() { |
| 773 | 0 | return true; |
| 774 | |
} |
| 775 | |
|
| 776 | |
|
| 777 | |
|
| 778 | |
|
| 779 | |
|
| 780 | |
|
| 781 | |
|
| 782 | |
|
| 783 | |
|
| 784 | |
|
| 785 | |
private void checkForFailure(List<Dependency> dependencies) throws MojoFailureException { |
| 786 | 0 | final StringBuilder ids = new StringBuilder(); |
| 787 | 0 | for (Dependency d : dependencies) { |
| 788 | 0 | for (Vulnerability v : d.getVulnerabilities()) { |
| 789 | 0 | if (v.getCvssScore() >= failBuildOnCVSS) { |
| 790 | 0 | if (ids.length() == 0) { |
| 791 | 0 | ids.append(v.getName()); |
| 792 | |
} else { |
| 793 | 0 | ids.append(", ").append(v.getName()); |
| 794 | |
} |
| 795 | |
} |
| 796 | |
} |
| 797 | |
} |
| 798 | 0 | if (ids.length() > 0) { |
| 799 | 0 | final String msg = String.format("%n%nDependency-Check Failure:%n" |
| 800 | |
+ "One or more dependencies were identified with vulnerabilities that have a CVSS score greater then '%.1f': %s%n" |
| 801 | |
+ "See the dependency-check report for more details.%n%n", failBuildOnCVSS, ids.toString()); |
| 802 | 0 | throw new MojoFailureException(msg); |
| 803 | |
} |
| 804 | 0 | } |
| 805 | |
} |