| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.owasp.dependencycheck.taskdefs; |
| 19 | |
|
| 20 | |
import java.io.File; |
| 21 | |
import java.io.IOException; |
| 22 | |
import java.util.List; |
| 23 | |
import org.apache.tools.ant.BuildException; |
| 24 | |
import org.apache.tools.ant.Project; |
| 25 | |
import org.apache.tools.ant.types.EnumeratedAttribute; |
| 26 | |
import org.apache.tools.ant.types.Reference; |
| 27 | |
import org.apache.tools.ant.types.Resource; |
| 28 | |
import org.apache.tools.ant.types.ResourceCollection; |
| 29 | |
import org.apache.tools.ant.types.resources.FileProvider; |
| 30 | |
import org.apache.tools.ant.types.resources.Resources; |
| 31 | |
import org.owasp.dependencycheck.Engine; |
| 32 | |
import org.owasp.dependencycheck.data.nvdcve.CveDB; |
| 33 | |
import org.owasp.dependencycheck.data.nvdcve.DatabaseException; |
| 34 | |
import org.owasp.dependencycheck.data.nvdcve.DatabaseProperties; |
| 35 | |
import org.owasp.dependencycheck.dependency.Dependency; |
| 36 | |
import org.owasp.dependencycheck.dependency.Identifier; |
| 37 | |
import org.owasp.dependencycheck.dependency.Vulnerability; |
| 38 | |
import org.owasp.dependencycheck.reporting.ReportGenerator; |
| 39 | |
import org.owasp.dependencycheck.reporting.ReportGenerator.Format; |
| 40 | |
import org.owasp.dependencycheck.utils.Settings; |
| 41 | |
import org.slf4j.impl.StaticLoggerBinder; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public class Check extends Update { |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | 2 | private static final String NEW_LINE = System.getProperty("line.separator", "\n").intern(); |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
public Check() { |
| 59 | 8 | super(); |
| 60 | |
|
| 61 | |
|
| 62 | 8 | StaticLoggerBinder.getSingleton().setTask(this); |
| 63 | 8 | } |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | 8 | private Resources path = null; |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | 8 | private Reference refid = null; |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
public void add(ResourceCollection rc) { |
| 82 | 8 | if (isReference()) { |
| 83 | 0 | throw new BuildException("Nested elements are not allowed when using the refid attribute."); |
| 84 | |
} |
| 85 | 8 | getPath().add(rc); |
| 86 | 8 | } |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
private synchronized Resources getPath() { |
| 95 | 8 | if (path == null) { |
| 96 | 6 | path = new Resources(getProject()); |
| 97 | 6 | path.setCache(true); |
| 98 | |
} |
| 99 | 8 | return path; |
| 100 | |
} |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
public boolean isReference() { |
| 108 | 16 | return refid != null; |
| 109 | |
} |
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
public void setRefid(Reference r) { |
| 118 | 0 | if (path != null) { |
| 119 | 0 | throw new BuildException("Nested elements are not allowed when using the refid attribute."); |
| 120 | |
} |
| 121 | 0 | refid = r; |
| 122 | 0 | } |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
private void dealWithReferences() throws BuildException { |
| 131 | 8 | if (isReference()) { |
| 132 | 0 | final Object o = refid.getReferencedObject(getProject()); |
| 133 | 0 | if (!(o instanceof ResourceCollection)) { |
| 134 | 0 | throw new BuildException("refid '" + refid.getRefId() |
| 135 | |
+ "' does not refer to a resource collection."); |
| 136 | |
} |
| 137 | 0 | getPath().add((ResourceCollection) o); |
| 138 | |
} |
| 139 | 8 | } |
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | 8 | @Deprecated |
| 147 | |
private String applicationName = null; |
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
@Deprecated |
| 157 | |
public String getApplicationName() { |
| 158 | 0 | return applicationName; |
| 159 | |
} |
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
@Deprecated |
| 168 | |
public void setApplicationName(String applicationName) { |
| 169 | 8 | this.applicationName = applicationName; |
| 170 | 8 | } |
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | 8 | private String projectName = "dependency-check"; |
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
public String getProjectName() { |
| 182 | 6 | if (applicationName != null) { |
| 183 | 6 | log("Configuration 'applicationName' has been deprecated, please use 'projectName' instead", Project.MSG_WARN); |
| 184 | 6 | if ("dependency-check".equals(projectName)) { |
| 185 | 6 | projectName = applicationName; |
| 186 | |
} |
| 187 | |
} |
| 188 | 6 | return projectName; |
| 189 | |
} |
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
public void setProjectName(String projectName) { |
| 197 | 0 | this.projectName = projectName; |
| 198 | 0 | } |
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | 8 | private String reportOutputDirectory = "."; |
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
public String getReportOutputDirectory() { |
| 212 | 0 | return reportOutputDirectory; |
| 213 | |
} |
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
public void setReportOutputDirectory(String reportOutputDirectory) { |
| 221 | 8 | this.reportOutputDirectory = reportOutputDirectory; |
| 222 | 8 | } |
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | 8 | private float failBuildOnCVSS = 11; |
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
public float getFailBuildOnCVSS() { |
| 238 | 0 | return failBuildOnCVSS; |
| 239 | |
} |
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
public void setFailBuildOnCVSS(float failBuildOnCVSS) { |
| 247 | 2 | this.failBuildOnCVSS = failBuildOnCVSS; |
| 248 | 2 | } |
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
private Boolean autoUpdate; |
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
|
| 260 | |
public Boolean isAutoUpdate() { |
| 261 | 0 | return autoUpdate; |
| 262 | |
} |
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
public void setAutoUpdate(Boolean autoUpdate) { |
| 270 | 8 | this.autoUpdate = autoUpdate; |
| 271 | 8 | } |
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | 8 | @Deprecated |
| 278 | |
private boolean updateOnly = false; |
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
@Deprecated |
| 287 | |
public boolean isUpdateOnly() { |
| 288 | 6 | return updateOnly; |
| 289 | |
} |
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
|
| 297 | |
@Deprecated |
| 298 | |
public void setUpdateOnly(boolean updateOnly) { |
| 299 | 0 | this.updateOnly = updateOnly; |
| 300 | 0 | } |
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | 8 | private String reportFormat = "HTML"; |
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
public String getReportFormat() { |
| 314 | 0 | return reportFormat; |
| 315 | |
} |
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
public void setReportFormat(ReportFormats reportFormat) { |
| 323 | 8 | this.reportFormat = reportFormat.getValue(); |
| 324 | 8 | } |
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
private String suppressionFile; |
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
public String getSuppressionFile() { |
| 336 | 0 | return suppressionFile; |
| 337 | |
} |
| 338 | |
|
| 339 | |
|
| 340 | |
|
| 341 | |
|
| 342 | |
|
| 343 | |
|
| 344 | |
public void setSuppressionFile(String suppressionFile) { |
| 345 | 0 | this.suppressionFile = suppressionFile; |
| 346 | 0 | } |
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | 8 | private boolean showSummary = true; |
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
public boolean isShowSummary() { |
| 358 | 0 | return showSummary; |
| 359 | |
} |
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
public void setShowSummary(boolean showSummary) { |
| 367 | 0 | this.showSummary = showSummary; |
| 368 | 0 | } |
| 369 | |
|
| 370 | |
|
| 371 | |
|
| 372 | |
|
| 373 | |
private Boolean enableExperimental; |
| 374 | |
|
| 375 | |
|
| 376 | |
|
| 377 | |
|
| 378 | |
|
| 379 | |
|
| 380 | |
public Boolean isEnableExperimental() { |
| 381 | 0 | return enableExperimental; |
| 382 | |
} |
| 383 | |
|
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
public void setEnableExperimental(Boolean enableExperimental) { |
| 390 | 0 | this.enableExperimental = enableExperimental; |
| 391 | 0 | } |
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
private Boolean jarAnalyzerEnabled; |
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
public Boolean isJarAnalyzerEnabled() { |
| 404 | 0 | return jarAnalyzerEnabled; |
| 405 | |
} |
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
|
| 412 | |
public void setJarAnalyzerEnabled(Boolean jarAnalyzerEnabled) { |
| 413 | 0 | this.jarAnalyzerEnabled = jarAnalyzerEnabled; |
| 414 | 0 | } |
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
private Boolean archiveAnalyzerEnabled; |
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
public Boolean isArchiveAnalyzerEnabled() { |
| 426 | 0 | return archiveAnalyzerEnabled; |
| 427 | |
} |
| 428 | |
|
| 429 | |
|
| 430 | |
|
| 431 | |
private Boolean assemblyAnalyzerEnabled; |
| 432 | |
|
| 433 | |
|
| 434 | |
|
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
public void setArchiveAnalyzerEnabled(Boolean archiveAnalyzerEnabled) { |
| 439 | 0 | this.archiveAnalyzerEnabled = archiveAnalyzerEnabled; |
| 440 | 0 | } |
| 441 | |
|
| 442 | |
|
| 443 | |
|
| 444 | |
|
| 445 | |
|
| 446 | |
|
| 447 | |
public Boolean isAssemblyAnalyzerEnabled() { |
| 448 | 0 | return assemblyAnalyzerEnabled; |
| 449 | |
} |
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
public void setAssemblyAnalyzerEnabled(Boolean assemblyAnalyzerEnabled) { |
| 457 | 0 | this.assemblyAnalyzerEnabled = assemblyAnalyzerEnabled; |
| 458 | 0 | } |
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
private Boolean nuspecAnalyzerEnabled; |
| 463 | |
|
| 464 | |
|
| 465 | |
|
| 466 | |
|
| 467 | |
|
| 468 | |
|
| 469 | |
public Boolean isNuspecAnalyzerEnabled() { |
| 470 | 0 | return nuspecAnalyzerEnabled; |
| 471 | |
} |
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | |
|
| 476 | |
|
| 477 | |
|
| 478 | |
public void setNuspecAnalyzerEnabled(Boolean nuspecAnalyzerEnabled) { |
| 479 | 0 | this.nuspecAnalyzerEnabled = nuspecAnalyzerEnabled; |
| 480 | 0 | } |
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
private Boolean composerAnalyzerEnabled; |
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
public Boolean isComposerAnalyzerEnabled() { |
| 492 | 0 | return composerAnalyzerEnabled; |
| 493 | |
} |
| 494 | |
|
| 495 | |
|
| 496 | |
|
| 497 | |
|
| 498 | |
|
| 499 | |
|
| 500 | |
public void setComposerAnalyzerEnabled(Boolean composerAnalyzerEnabled) { |
| 501 | 0 | this.composerAnalyzerEnabled = composerAnalyzerEnabled; |
| 502 | 0 | } |
| 503 | |
|
| 504 | |
|
| 505 | |
|
| 506 | |
private Boolean autoconfAnalyzerEnabled; |
| 507 | |
|
| 508 | |
|
| 509 | |
|
| 510 | |
|
| 511 | |
|
| 512 | |
|
| 513 | |
public Boolean isAutoconfAnalyzerEnabled() { |
| 514 | 0 | return autoconfAnalyzerEnabled; |
| 515 | |
} |
| 516 | |
|
| 517 | |
|
| 518 | |
|
| 519 | |
|
| 520 | |
|
| 521 | |
|
| 522 | |
public void setAutoconfAnalyzerEnabled(Boolean autoconfAnalyzerEnabled) { |
| 523 | 0 | this.autoconfAnalyzerEnabled = autoconfAnalyzerEnabled; |
| 524 | 0 | } |
| 525 | |
|
| 526 | |
|
| 527 | |
|
| 528 | |
private Boolean cmakeAnalyzerEnabled; |
| 529 | |
|
| 530 | |
|
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
|
| 535 | |
public Boolean isCMakeAnalyzerEnabled() { |
| 536 | 0 | return cmakeAnalyzerEnabled; |
| 537 | |
} |
| 538 | |
|
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | |
public void setCMakeAnalyzerEnabled(Boolean cmakeAnalyzerEnabled) { |
| 545 | 0 | this.cmakeAnalyzerEnabled = cmakeAnalyzerEnabled; |
| 546 | 0 | } |
| 547 | |
|
| 548 | |
|
| 549 | |
|
| 550 | |
private Boolean opensslAnalyzerEnabled; |
| 551 | |
|
| 552 | |
|
| 553 | |
|
| 554 | |
|
| 555 | |
|
| 556 | |
|
| 557 | |
public Boolean isOpensslAnalyzerEnabled() { |
| 558 | 0 | return opensslAnalyzerEnabled; |
| 559 | |
} |
| 560 | |
|
| 561 | |
|
| 562 | |
|
| 563 | |
|
| 564 | |
|
| 565 | |
|
| 566 | |
public void setOpensslAnalyzerEnabled(Boolean opensslAnalyzerEnabled) { |
| 567 | 0 | this.opensslAnalyzerEnabled = opensslAnalyzerEnabled; |
| 568 | 0 | } |
| 569 | |
|
| 570 | |
|
| 571 | |
|
| 572 | |
private Boolean nodeAnalyzerEnabled; |
| 573 | |
|
| 574 | |
|
| 575 | |
|
| 576 | |
|
| 577 | |
|
| 578 | |
|
| 579 | |
public Boolean isNodeAnalyzerEnabled() { |
| 580 | 0 | return nodeAnalyzerEnabled; |
| 581 | |
} |
| 582 | |
|
| 583 | |
|
| 584 | |
|
| 585 | |
|
| 586 | |
|
| 587 | |
|
| 588 | |
public void setNodeAnalyzerEnabled(Boolean nodeAnalyzerEnabled) { |
| 589 | 0 | this.nodeAnalyzerEnabled = nodeAnalyzerEnabled; |
| 590 | 0 | } |
| 591 | |
|
| 592 | |
|
| 593 | |
|
| 594 | |
private Boolean rubygemsAnalyzerEnabled; |
| 595 | |
|
| 596 | |
|
| 597 | |
|
| 598 | |
|
| 599 | |
|
| 600 | |
|
| 601 | |
public Boolean isRubygemsAnalyzerEnabled() { |
| 602 | 0 | return rubygemsAnalyzerEnabled; |
| 603 | |
} |
| 604 | |
|
| 605 | |
|
| 606 | |
|
| 607 | |
|
| 608 | |
|
| 609 | |
|
| 610 | |
public void setRubygemsAnalyzerEnabled(Boolean rubygemsAnalyzerEnabled) { |
| 611 | 0 | this.rubygemsAnalyzerEnabled = rubygemsAnalyzerEnabled; |
| 612 | 0 | } |
| 613 | |
|
| 614 | |
|
| 615 | |
|
| 616 | |
private Boolean pyPackageAnalyzerEnabled; |
| 617 | |
|
| 618 | |
|
| 619 | |
|
| 620 | |
|
| 621 | |
|
| 622 | |
|
| 623 | |
public Boolean isPyPackageAnalyzerEnabled() { |
| 624 | 0 | return pyPackageAnalyzerEnabled; |
| 625 | |
} |
| 626 | |
|
| 627 | |
|
| 628 | |
|
| 629 | |
|
| 630 | |
|
| 631 | |
|
| 632 | |
public void setPyPackageAnalyzerEnabled(Boolean pyPackageAnalyzerEnabled) { |
| 633 | 0 | this.pyPackageAnalyzerEnabled = pyPackageAnalyzerEnabled; |
| 634 | 0 | } |
| 635 | |
|
| 636 | |
|
| 637 | |
|
| 638 | |
|
| 639 | |
private Boolean pyDistributionAnalyzerEnabled; |
| 640 | |
|
| 641 | |
|
| 642 | |
|
| 643 | |
|
| 644 | |
|
| 645 | |
|
| 646 | |
public Boolean isPyDistributionAnalyzerEnabled() { |
| 647 | 0 | return pyDistributionAnalyzerEnabled; |
| 648 | |
} |
| 649 | |
|
| 650 | |
|
| 651 | |
|
| 652 | |
|
| 653 | |
|
| 654 | |
|
| 655 | |
|
| 656 | |
public void setPyDistributionAnalyzerEnabled(Boolean pyDistributionAnalyzerEnabled) { |
| 657 | 0 | this.pyDistributionAnalyzerEnabled = pyDistributionAnalyzerEnabled; |
| 658 | 0 | } |
| 659 | |
|
| 660 | |
|
| 661 | |
|
| 662 | |
|
| 663 | |
private Boolean centralAnalyzerEnabled; |
| 664 | |
|
| 665 | |
|
| 666 | |
|
| 667 | |
|
| 668 | |
|
| 669 | |
|
| 670 | |
public Boolean isCentralAnalyzerEnabled() { |
| 671 | 0 | return centralAnalyzerEnabled; |
| 672 | |
} |
| 673 | |
|
| 674 | |
|
| 675 | |
|
| 676 | |
|
| 677 | |
|
| 678 | |
|
| 679 | |
public void setCentralAnalyzerEnabled(Boolean centralAnalyzerEnabled) { |
| 680 | 0 | this.centralAnalyzerEnabled = centralAnalyzerEnabled; |
| 681 | 0 | } |
| 682 | |
|
| 683 | |
|
| 684 | |
|
| 685 | |
|
| 686 | |
private Boolean nexusAnalyzerEnabled; |
| 687 | |
|
| 688 | |
|
| 689 | |
|
| 690 | |
|
| 691 | |
|
| 692 | |
|
| 693 | |
public Boolean isNexusAnalyzerEnabled() { |
| 694 | 0 | return nexusAnalyzerEnabled; |
| 695 | |
} |
| 696 | |
|
| 697 | |
|
| 698 | |
|
| 699 | |
|
| 700 | |
|
| 701 | |
|
| 702 | |
public void setNexusAnalyzerEnabled(Boolean nexusAnalyzerEnabled) { |
| 703 | 0 | this.nexusAnalyzerEnabled = nexusAnalyzerEnabled; |
| 704 | 0 | } |
| 705 | |
|
| 706 | |
|
| 707 | |
|
| 708 | |
|
| 709 | |
|
| 710 | |
private String nexusUrl; |
| 711 | |
|
| 712 | |
|
| 713 | |
|
| 714 | |
|
| 715 | |
|
| 716 | |
|
| 717 | |
public String getNexusUrl() { |
| 718 | 0 | return nexusUrl; |
| 719 | |
} |
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
|
| 724 | |
|
| 725 | |
|
| 726 | |
public void setNexusUrl(String nexusUrl) { |
| 727 | 0 | this.nexusUrl = nexusUrl; |
| 728 | 0 | } |
| 729 | |
|
| 730 | |
|
| 731 | |
|
| 732 | |
private Boolean nexusUsesProxy; |
| 733 | |
|
| 734 | |
|
| 735 | |
|
| 736 | |
|
| 737 | |
|
| 738 | |
|
| 739 | |
public Boolean isNexusUsesProxy() { |
| 740 | 0 | return nexusUsesProxy; |
| 741 | |
} |
| 742 | |
|
| 743 | |
|
| 744 | |
|
| 745 | |
|
| 746 | |
|
| 747 | |
|
| 748 | |
public void setNexusUsesProxy(Boolean nexusUsesProxy) { |
| 749 | 0 | this.nexusUsesProxy = nexusUsesProxy; |
| 750 | 0 | } |
| 751 | |
|
| 752 | |
|
| 753 | |
|
| 754 | |
|
| 755 | |
|
| 756 | |
private String zipExtensions; |
| 757 | |
|
| 758 | |
|
| 759 | |
|
| 760 | |
|
| 761 | |
|
| 762 | |
|
| 763 | |
public String getZipExtensions() { |
| 764 | 0 | return zipExtensions; |
| 765 | |
} |
| 766 | |
|
| 767 | |
|
| 768 | |
|
| 769 | |
|
| 770 | |
|
| 771 | |
|
| 772 | |
public void setZipExtensions(String zipExtensions) { |
| 773 | 0 | this.zipExtensions = zipExtensions; |
| 774 | 0 | } |
| 775 | |
|
| 776 | |
|
| 777 | |
|
| 778 | |
|
| 779 | |
private String pathToMono; |
| 780 | |
|
| 781 | |
|
| 782 | |
|
| 783 | |
|
| 784 | |
|
| 785 | |
|
| 786 | |
public String getPathToMono() { |
| 787 | 0 | return pathToMono; |
| 788 | |
} |
| 789 | |
|
| 790 | |
|
| 791 | |
|
| 792 | |
|
| 793 | |
|
| 794 | |
|
| 795 | |
public void setPathToMono(String pathToMono) { |
| 796 | 0 | this.pathToMono = pathToMono; |
| 797 | 0 | } |
| 798 | |
|
| 799 | |
@Override |
| 800 | |
public void execute() throws BuildException { |
| 801 | 8 | dealWithReferences(); |
| 802 | 8 | validateConfiguration(); |
| 803 | 6 | populateSettings(); |
| 804 | 6 | Engine engine = null; |
| 805 | |
try { |
| 806 | 6 | engine = new Engine(Check.class.getClassLoader()); |
| 807 | 6 | if (isUpdateOnly()) { |
| 808 | 0 | log("Deprecated 'UpdateOnly' property set; please use the UpdateTask instead", Project.MSG_WARN); |
| 809 | 0 | engine.doUpdates(); |
| 810 | |
} else { |
| 811 | |
try { |
| 812 | 6 | for (Resource resource : path) { |
| 813 | 10 | final FileProvider provider = resource.as(FileProvider.class); |
| 814 | 10 | if (provider != null) { |
| 815 | 10 | final File file = provider.getFile(); |
| 816 | 10 | if (file != null && file.exists()) { |
| 817 | 8 | engine.scan(file); |
| 818 | |
} |
| 819 | |
} |
| 820 | 10 | } |
| 821 | |
|
| 822 | 6 | engine.analyzeDependencies(); |
| 823 | 6 | DatabaseProperties prop = null; |
| 824 | 6 | CveDB cve = null; |
| 825 | |
try { |
| 826 | 6 | cve = new CveDB(); |
| 827 | 6 | cve.open(); |
| 828 | 6 | prop = cve.getDatabaseProperties(); |
| 829 | 0 | } catch (DatabaseException ex) { |
| 830 | 0 | log("Unable to retrieve DB Properties", ex, Project.MSG_DEBUG); |
| 831 | |
} finally { |
| 832 | 6 | if (cve != null) { |
| 833 | 6 | cve.close(); |
| 834 | |
} |
| 835 | |
} |
| 836 | 6 | final ReportGenerator reporter = new ReportGenerator(getProjectName(), engine.getDependencies(), engine.getAnalyzers(), prop); |
| 837 | 6 | reporter.generateReports(reportOutputDirectory, reportFormat); |
| 838 | |
|
| 839 | 6 | if (this.failBuildOnCVSS <= 10) { |
| 840 | 0 | checkForFailure(engine.getDependencies()); |
| 841 | |
} |
| 842 | 6 | if (this.showSummary) { |
| 843 | 6 | showSummary(engine.getDependencies()); |
| 844 | |
} |
| 845 | 0 | } catch (IOException ex) { |
| 846 | 0 | log("Unable to generate dependency-check report", ex, Project.MSG_DEBUG); |
| 847 | 0 | throw new BuildException("Unable to generate dependency-check report", ex); |
| 848 | 0 | } catch (Exception ex) { |
| 849 | 0 | log("An exception occurred; unable to continue task", ex, Project.MSG_DEBUG); |
| 850 | 0 | throw new BuildException("An exception occurred; unable to continue task", ex); |
| 851 | 6 | } |
| 852 | |
} |
| 853 | 0 | } catch (DatabaseException ex) { |
| 854 | 0 | log("Unable to connect to the dependency-check database; analysis has stopped", ex, Project.MSG_ERR); |
| 855 | |
} finally { |
| 856 | 6 | Settings.cleanup(true); |
| 857 | 6 | if (engine != null) { |
| 858 | 6 | engine.cleanup(); |
| 859 | |
} |
| 860 | |
} |
| 861 | 6 | } |
| 862 | |
|
| 863 | |
|
| 864 | |
|
| 865 | |
|
| 866 | |
|
| 867 | |
|
| 868 | |
|
| 869 | |
private void validateConfiguration() throws BuildException { |
| 870 | 8 | if (path == null) { |
| 871 | 2 | throw new BuildException("No project dependencies have been defined to analyze."); |
| 872 | |
} |
| 873 | 6 | if (failBuildOnCVSS < 0 || failBuildOnCVSS > 11) { |
| 874 | 0 | throw new BuildException("Invalid configuration, failBuildOnCVSS must be between 0 and 11."); |
| 875 | |
} |
| 876 | 6 | } |
| 877 | |
|
| 878 | |
|
| 879 | |
|
| 880 | |
|
| 881 | |
|
| 882 | |
|
| 883 | |
|
| 884 | |
|
| 885 | |
@Override |
| 886 | |
protected void populateSettings() throws BuildException { |
| 887 | 6 | super.populateSettings(); |
| 888 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.AUTO_UPDATE, autoUpdate); |
| 889 | 6 | Settings.setStringIfNotEmpty(Settings.KEYS.SUPPRESSION_FILE, suppressionFile); |
| 890 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_EXPERIMENTAL_ENABLED, enableExperimental); |
| 891 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_JAR_ENABLED, jarAnalyzerEnabled); |
| 892 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_PYTHON_DISTRIBUTION_ENABLED, pyDistributionAnalyzerEnabled); |
| 893 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_PYTHON_PACKAGE_ENABLED, pyPackageAnalyzerEnabled); |
| 894 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_RUBY_GEMSPEC_ENABLED, rubygemsAnalyzerEnabled); |
| 895 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_OPENSSL_ENABLED, opensslAnalyzerEnabled); |
| 896 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_CMAKE_ENABLED, cmakeAnalyzerEnabled); |
| 897 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_AUTOCONF_ENABLED, autoconfAnalyzerEnabled); |
| 898 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_COMPOSER_LOCK_ENABLED, composerAnalyzerEnabled); |
| 899 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NODE_PACKAGE_ENABLED, nodeAnalyzerEnabled); |
| 900 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NUSPEC_ENABLED, nuspecAnalyzerEnabled); |
| 901 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_CENTRAL_ENABLED, centralAnalyzerEnabled); |
| 902 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NEXUS_ENABLED, nexusAnalyzerEnabled); |
| 903 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ARCHIVE_ENABLED, archiveAnalyzerEnabled); |
| 904 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_ASSEMBLY_ENABLED, assemblyAnalyzerEnabled); |
| 905 | 6 | Settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl); |
| 906 | 6 | Settings.setBooleanIfNotNull(Settings.KEYS.ANALYZER_NEXUS_USES_PROXY, nexusUsesProxy); |
| 907 | 6 | Settings.setStringIfNotEmpty(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS, zipExtensions); |
| 908 | 6 | Settings.setStringIfNotEmpty(Settings.KEYS.ANALYZER_ASSEMBLY_MONO_PATH, pathToMono); |
| 909 | 6 | } |
| 910 | |
|
| 911 | |
|
| 912 | |
|
| 913 | |
|
| 914 | |
|
| 915 | |
|
| 916 | |
|
| 917 | |
|
| 918 | |
|
| 919 | |
private void checkForFailure(List<Dependency> dependencies) throws BuildException { |
| 920 | 0 | final StringBuilder ids = new StringBuilder(); |
| 921 | 0 | for (Dependency d : dependencies) { |
| 922 | 0 | for (Vulnerability v : d.getVulnerabilities()) { |
| 923 | 0 | if (v.getCvssScore() >= failBuildOnCVSS) { |
| 924 | 0 | if (ids.length() == 0) { |
| 925 | 0 | ids.append(v.getName()); |
| 926 | |
} else { |
| 927 | 0 | ids.append(", ").append(v.getName()); |
| 928 | |
} |
| 929 | |
} |
| 930 | 0 | } |
| 931 | 0 | } |
| 932 | 0 | if (ids.length() > 0) { |
| 933 | 0 | final String msg = String.format("%n%nDependency-Check Failure:%n" |
| 934 | |
+ "One or more dependencies were identified with vulnerabilities that have a CVSS score greater then '%.1f': %s%n" |
| 935 | 0 | + "See the dependency-check report for more details.%n%n", failBuildOnCVSS, ids.toString()); |
| 936 | 0 | throw new BuildException(msg); |
| 937 | |
} |
| 938 | 0 | } |
| 939 | |
|
| 940 | |
|
| 941 | |
|
| 942 | |
|
| 943 | |
|
| 944 | |
|
| 945 | |
|
| 946 | |
private void showSummary(List<Dependency> dependencies) { |
| 947 | 6 | final StringBuilder summary = new StringBuilder(); |
| 948 | 6 | for (Dependency d : dependencies) { |
| 949 | 10 | boolean firstEntry = true; |
| 950 | 10 | final StringBuilder ids = new StringBuilder(); |
| 951 | 10 | for (Vulnerability v : d.getVulnerabilities()) { |
| 952 | 36 | if (firstEntry) { |
| 953 | 8 | firstEntry = false; |
| 954 | |
} else { |
| 955 | 28 | ids.append(", "); |
| 956 | |
} |
| 957 | 36 | ids.append(v.getName()); |
| 958 | 36 | } |
| 959 | 10 | if (ids.length() > 0) { |
| 960 | 8 | summary.append(d.getFileName()).append(" ("); |
| 961 | 8 | firstEntry = true; |
| 962 | 8 | for (Identifier id : d.getIdentifiers()) { |
| 963 | 30 | if (firstEntry) { |
| 964 | 8 | firstEntry = false; |
| 965 | |
} else { |
| 966 | 22 | summary.append(", "); |
| 967 | |
} |
| 968 | 30 | summary.append(id.getValue()); |
| 969 | 30 | } |
| 970 | 8 | summary.append(") : ").append(ids).append(NEW_LINE); |
| 971 | |
} |
| 972 | 10 | } |
| 973 | 6 | if (summary.length() > 0) { |
| 974 | 12 | final String msg = String.format("%n%n" |
| 975 | |
+ "One or more dependencies were identified with known vulnerabilities:%n%n%s" |
| 976 | 6 | + "%n%nSee the dependency-check report for more details.%n%n", summary.toString()); |
| 977 | 6 | log(msg, Project.MSG_WARN); |
| 978 | |
} |
| 979 | 6 | } |
| 980 | |
|
| 981 | |
|
| 982 | |
|
| 983 | |
|
| 984 | |
|
| 985 | 8 | public static class ReportFormats extends EnumeratedAttribute { |
| 986 | |
|
| 987 | |
|
| 988 | |
|
| 989 | |
|
| 990 | |
|
| 991 | |
|
| 992 | |
@Override |
| 993 | |
public String[] getValues() { |
| 994 | 8 | int i = 0; |
| 995 | 8 | final Format[] formats = Format.values(); |
| 996 | 8 | final String[] values = new String[formats.length]; |
| 997 | 40 | for (Format format : formats) { |
| 998 | 32 | values[i++] = format.name(); |
| 999 | |
} |
| 1000 | 8 | return values; |
| 1001 | |
} |
| 1002 | |
} |
| 1003 | |
} |