| 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.io.InputStream; |
| 23 | |
import java.util.List; |
| 24 | |
import java.util.logging.Level; |
| 25 | |
import java.util.logging.Logger; |
| 26 | |
import org.apache.tools.ant.BuildException; |
| 27 | |
import org.apache.tools.ant.Task; |
| 28 | |
import org.apache.tools.ant.types.EnumeratedAttribute; |
| 29 | |
import org.apache.tools.ant.types.Reference; |
| 30 | |
import org.apache.tools.ant.types.Resource; |
| 31 | |
import org.apache.tools.ant.types.ResourceCollection; |
| 32 | |
import org.apache.tools.ant.types.resources.FileProvider; |
| 33 | |
import org.apache.tools.ant.types.resources.Resources; |
| 34 | |
import org.owasp.dependencycheck.Engine; |
| 35 | |
import org.owasp.dependencycheck.data.nvdcve.CveDB; |
| 36 | |
import org.owasp.dependencycheck.data.nvdcve.DatabaseException; |
| 37 | |
import org.owasp.dependencycheck.data.nvdcve.DatabaseProperties; |
| 38 | |
import org.owasp.dependencycheck.dependency.Dependency; |
| 39 | |
import org.owasp.dependencycheck.dependency.Identifier; |
| 40 | |
import org.owasp.dependencycheck.dependency.Vulnerability; |
| 41 | |
import org.owasp.dependencycheck.reporting.ReportGenerator; |
| 42 | |
import org.owasp.dependencycheck.reporting.ReportGenerator.Format; |
| 43 | |
import org.owasp.dependencycheck.utils.LogUtils; |
| 44 | |
import org.owasp.dependencycheck.utils.Settings; |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
public class DependencyCheckTask extends Task { |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
private static final String PROPERTIES_FILE = "task.properties"; |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
private static final String LOG_PROPERTIES_FILE = "log.properties"; |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | 1 | private static final String NEW_LINE = System.getProperty("line.separator", "\n").intern(); |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
public DependencyCheckTask() { |
| 70 | 4 | super(); |
| 71 | 4 | } |
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | 4 | private Resources path = null; |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | 4 | private Reference refid = null; |
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
public void add(ResourceCollection rc) { |
| 90 | 4 | if (isReference()) { |
| 91 | 0 | throw new BuildException("Nested elements are not allowed when using the refid attribute."); |
| 92 | |
} |
| 93 | 4 | getPath().add(rc); |
| 94 | 4 | } |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
private synchronized Resources getPath() { |
| 103 | 4 | if (path == null) { |
| 104 | 3 | path = new Resources(getProject()); |
| 105 | 3 | path.setCache(true); |
| 106 | |
} |
| 107 | 4 | return path; |
| 108 | |
} |
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
public boolean isReference() { |
| 116 | 8 | return refid != null; |
| 117 | |
} |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
public void setRefid(Reference r) { |
| 125 | 0 | if (path != null) { |
| 126 | 0 | throw new BuildException("Nested elements are not allowed when using the refid attribute."); |
| 127 | |
} |
| 128 | 0 | refid = r; |
| 129 | 0 | } |
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
private void dealWithReferences() throws BuildException { |
| 137 | 4 | if (isReference()) { |
| 138 | 0 | final Object o = refid.getReferencedObject(getProject()); |
| 139 | 0 | if (!(o instanceof ResourceCollection)) { |
| 140 | 0 | throw new BuildException("refid '" + refid.getRefId() |
| 141 | |
+ "' does not refer to a resource collection."); |
| 142 | |
} |
| 143 | 0 | getPath().add((ResourceCollection) o); |
| 144 | |
} |
| 145 | 4 | } |
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | 4 | private String applicationName = "Dependency-Check"; |
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
public String getApplicationName() { |
| 158 | 0 | return applicationName; |
| 159 | |
} |
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
public void setApplicationName(String applicationName) { |
| 167 | 4 | this.applicationName = applicationName; |
| 168 | 4 | } |
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | 4 | private String dataDirectory = null; |
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
public String getDataDirectory() { |
| 180 | 0 | return dataDirectory; |
| 181 | |
} |
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
public void setDataDirectory(String dataDirectory) { |
| 189 | 0 | this.dataDirectory = dataDirectory; |
| 190 | 0 | } |
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | 4 | private String reportOutputDirectory = "."; |
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
public String getReportOutputDirectory() { |
| 202 | 0 | return reportOutputDirectory; |
| 203 | |
} |
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
public void setReportOutputDirectory(String reportOutputDirectory) { |
| 211 | 4 | this.reportOutputDirectory = reportOutputDirectory; |
| 212 | 4 | } |
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | 4 | private float failBuildOnCVSS = 11; |
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
public float getFailBuildOnCVSS() { |
| 226 | 0 | return failBuildOnCVSS; |
| 227 | |
} |
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
public void setFailBuildOnCVSS(float failBuildOnCVSS) { |
| 235 | 1 | this.failBuildOnCVSS = failBuildOnCVSS; |
| 236 | 1 | } |
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | 4 | private boolean autoUpdate = true; |
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
public boolean isAutoUpdate() { |
| 249 | 0 | return autoUpdate; |
| 250 | |
} |
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
public void setAutoUpdate(boolean autoUpdate) { |
| 258 | 4 | this.autoUpdate = autoUpdate; |
| 259 | 4 | } |
| 260 | |
|
| 261 | |
|
| 262 | |
|
| 263 | |
|
| 264 | 4 | private String reportFormat = "HTML"; |
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
public String getReportFormat() { |
| 272 | 0 | return reportFormat; |
| 273 | |
} |
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
public void setReportFormat(ReportFormats reportFormat) { |
| 281 | 4 | this.reportFormat = reportFormat.getValue(); |
| 282 | 4 | } |
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
private String proxyUrl; |
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
public String getProxyUrl() { |
| 294 | 0 | return proxyUrl; |
| 295 | |
} |
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | |
public void setProxyUrl(String proxyUrl) { |
| 303 | 0 | this.proxyUrl = proxyUrl; |
| 304 | 0 | } |
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
private String proxyPort; |
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
|
| 315 | |
public String getProxyPort() { |
| 316 | 0 | return proxyPort; |
| 317 | |
} |
| 318 | |
|
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
public void setProxyPort(String proxyPort) { |
| 325 | 0 | this.proxyPort = proxyPort; |
| 326 | 0 | } |
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
private String proxyUsername; |
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
public String getProxyUsername() { |
| 338 | 0 | return proxyUsername; |
| 339 | |
} |
| 340 | |
|
| 341 | |
|
| 342 | |
|
| 343 | |
|
| 344 | |
|
| 345 | |
|
| 346 | |
public void setProxyUsername(String proxyUsername) { |
| 347 | 0 | this.proxyUsername = proxyUsername; |
| 348 | 0 | } |
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
private String proxyPassword; |
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | |
public String getProxyPassword() { |
| 360 | 0 | return proxyPassword; |
| 361 | |
} |
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
public void setProxyPassword(String proxyPassword) { |
| 369 | 0 | this.proxyPassword = proxyPassword; |
| 370 | 0 | } |
| 371 | |
|
| 372 | |
|
| 373 | |
|
| 374 | |
private String connectionTimeout; |
| 375 | |
|
| 376 | |
|
| 377 | |
|
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
public String getConnectionTimeout() { |
| 382 | 0 | return connectionTimeout; |
| 383 | |
} |
| 384 | |
|
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
public void setConnectionTimeout(String connectionTimeout) { |
| 391 | 0 | this.connectionTimeout = connectionTimeout; |
| 392 | 0 | } |
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | 4 | private String logFile = null; |
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
public String getLogFile() { |
| 404 | 0 | return logFile; |
| 405 | |
} |
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
|
| 412 | |
public void setLogFile(String logFile) { |
| 413 | 0 | this.logFile = logFile; |
| 414 | 0 | } |
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
private String suppressionFile; |
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
public String getSuppressionFile() { |
| 426 | 0 | return suppressionFile; |
| 427 | |
} |
| 428 | |
|
| 429 | |
|
| 430 | |
|
| 431 | |
|
| 432 | |
|
| 433 | |
|
| 434 | |
public void setSuppressionFile(String suppressionFile) { |
| 435 | 0 | this.suppressionFile = suppressionFile; |
| 436 | 0 | } |
| 437 | |
|
| 438 | |
|
| 439 | |
|
| 440 | 4 | private boolean showSummary = true; |
| 441 | |
|
| 442 | |
|
| 443 | |
|
| 444 | |
|
| 445 | |
|
| 446 | |
|
| 447 | |
public boolean isShowSummary() { |
| 448 | 0 | return showSummary; |
| 449 | |
} |
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
public void setShowSummary(boolean showSummary) { |
| 457 | 0 | this.showSummary = showSummary; |
| 458 | 0 | } |
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
|
| 463 | 4 | private boolean nexusAnalyzerEnabled = true; |
| 464 | |
|
| 465 | |
|
| 466 | |
|
| 467 | |
|
| 468 | |
|
| 469 | |
|
| 470 | |
public boolean isNexusAnalyzerEnabled() { |
| 471 | 0 | return nexusAnalyzerEnabled; |
| 472 | |
} |
| 473 | |
|
| 474 | |
|
| 475 | |
|
| 476 | |
|
| 477 | |
|
| 478 | |
|
| 479 | |
public void setNexusAnalyzerEnabled(boolean nexusAnalyzerEnabled) { |
| 480 | 0 | this.nexusAnalyzerEnabled = nexusAnalyzerEnabled; |
| 481 | 0 | } |
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
private String nexusUrl; |
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
|
| 492 | |
|
| 493 | |
public String getNexusUrl() { |
| 494 | 0 | return nexusUrl; |
| 495 | |
} |
| 496 | |
|
| 497 | |
|
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
|
| 502 | |
public void setNexusUrl(String nexusUrl) { |
| 503 | 0 | this.nexusUrl = nexusUrl; |
| 504 | 0 | } |
| 505 | |
|
| 506 | |
|
| 507 | |
|
| 508 | |
|
| 509 | |
private String databaseDriverName; |
| 510 | |
|
| 511 | |
|
| 512 | |
|
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | |
public String getDatabaseDriverName() { |
| 517 | 0 | return databaseDriverName; |
| 518 | |
} |
| 519 | |
|
| 520 | |
|
| 521 | |
|
| 522 | |
|
| 523 | |
|
| 524 | |
|
| 525 | |
public void setDatabaseDriverName(String databaseDriverName) { |
| 526 | 0 | this.databaseDriverName = databaseDriverName; |
| 527 | 0 | } |
| 528 | |
|
| 529 | |
|
| 530 | |
|
| 531 | |
|
| 532 | |
private String databaseDriverPath; |
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
|
| 538 | |
|
| 539 | |
public String getDatabaseDriverPath() { |
| 540 | 0 | return databaseDriverPath; |
| 541 | |
} |
| 542 | |
|
| 543 | |
|
| 544 | |
|
| 545 | |
|
| 546 | |
|
| 547 | |
|
| 548 | |
public void setDatabaseDriverPath(String databaseDriverPath) { |
| 549 | 0 | this.databaseDriverPath = databaseDriverPath; |
| 550 | 0 | } |
| 551 | |
|
| 552 | |
|
| 553 | |
|
| 554 | |
private String connectionString; |
| 555 | |
|
| 556 | |
|
| 557 | |
|
| 558 | |
|
| 559 | |
|
| 560 | |
|
| 561 | |
public String getConnectionString() { |
| 562 | 0 | return connectionString; |
| 563 | |
} |
| 564 | |
|
| 565 | |
|
| 566 | |
|
| 567 | |
|
| 568 | |
|
| 569 | |
|
| 570 | |
public void setConnectionString(String connectionString) { |
| 571 | 0 | this.connectionString = connectionString; |
| 572 | 0 | } |
| 573 | |
|
| 574 | |
|
| 575 | |
|
| 576 | |
private String databaseUser; |
| 577 | |
|
| 578 | |
|
| 579 | |
|
| 580 | |
|
| 581 | |
|
| 582 | |
|
| 583 | |
public String getDatabaseUser() { |
| 584 | 0 | return databaseUser; |
| 585 | |
} |
| 586 | |
|
| 587 | |
|
| 588 | |
|
| 589 | |
|
| 590 | |
|
| 591 | |
|
| 592 | |
public void setDatabaseUser(String databaseUser) { |
| 593 | 0 | this.databaseUser = databaseUser; |
| 594 | 0 | } |
| 595 | |
|
| 596 | |
|
| 597 | |
|
| 598 | |
|
| 599 | |
private String databasePassword; |
| 600 | |
|
| 601 | |
|
| 602 | |
|
| 603 | |
|
| 604 | |
|
| 605 | |
|
| 606 | |
public String getDatabasePassword() { |
| 607 | 0 | return databasePassword; |
| 608 | |
} |
| 609 | |
|
| 610 | |
|
| 611 | |
|
| 612 | |
|
| 613 | |
|
| 614 | |
|
| 615 | |
public void setDatabasePassword(String databasePassword) { |
| 616 | 0 | this.databasePassword = databasePassword; |
| 617 | 0 | } |
| 618 | |
|
| 619 | |
@Override |
| 620 | |
public void execute() throws BuildException { |
| 621 | 4 | final InputStream in = DependencyCheckTask.class.getClassLoader().getResourceAsStream(LOG_PROPERTIES_FILE); |
| 622 | 4 | LogUtils.prepareLogger(in, logFile); |
| 623 | |
|
| 624 | 4 | dealWithReferences(); |
| 625 | 4 | validateConfiguration(); |
| 626 | 3 | populateSettings(); |
| 627 | |
|
| 628 | 3 | final Engine engine = new Engine(); |
| 629 | 3 | for (Resource resource : path) { |
| 630 | 5 | final FileProvider provider = resource.as(FileProvider.class); |
| 631 | 5 | if (provider != null) { |
| 632 | 5 | final File file = provider.getFile(); |
| 633 | 5 | if (file != null && file.exists()) { |
| 634 | 4 | engine.scan(file); |
| 635 | |
} |
| 636 | |
} |
| 637 | 5 | } |
| 638 | |
try { |
| 639 | 3 | engine.analyzeDependencies(); |
| 640 | 3 | DatabaseProperties prop = null; |
| 641 | 3 | CveDB cve = null; |
| 642 | |
try { |
| 643 | 3 | cve = new CveDB(); |
| 644 | 3 | cve.open(); |
| 645 | 3 | prop = cve.getDatabaseProperties(); |
| 646 | 0 | } catch (DatabaseException ex) { |
| 647 | 0 | Logger.getLogger(DependencyCheckTask.class.getName()).log(Level.FINE, "Unable to retrieve DB Properties", ex); |
| 648 | |
} finally { |
| 649 | 3 | if (cve != null) { |
| 650 | 3 | cve.close(); |
| 651 | |
} |
| 652 | |
} |
| 653 | 3 | final ReportGenerator reporter = new ReportGenerator(applicationName, engine.getDependencies(), engine.getAnalyzers(), prop); |
| 654 | 3 | reporter.generateReports(reportOutputDirectory, reportFormat); |
| 655 | |
|
| 656 | 3 | if (this.failBuildOnCVSS <= 10) { |
| 657 | 0 | checkForFailure(engine.getDependencies()); |
| 658 | |
} |
| 659 | 3 | if (this.showSummary) { |
| 660 | 3 | showSummary(engine.getDependencies()); |
| 661 | |
} |
| 662 | 0 | } catch (IOException ex) { |
| 663 | 0 | Logger.getLogger(DependencyCheckTask.class.getName()).log(Level.FINE, "Unable to generate dependency-check report", ex); |
| 664 | 0 | throw new BuildException("Unable to generate dependency-check report", ex); |
| 665 | 0 | } catch (Exception ex) { |
| 666 | 0 | Logger.getLogger(DependencyCheckTask.class.getName()).log(Level.FINE, "An exception occurred; unable to continue task", ex); |
| 667 | 0 | throw new BuildException("An exception occurred; unable to continue task", ex); |
| 668 | 3 | } |
| 669 | 3 | } |
| 670 | |
|
| 671 | |
|
| 672 | |
|
| 673 | |
|
| 674 | |
|
| 675 | |
|
| 676 | |
private void validateConfiguration() throws BuildException { |
| 677 | 4 | if (path == null) { |
| 678 | 1 | throw new BuildException("No project dependencies have been defined to analyze."); |
| 679 | |
} |
| 680 | 3 | if (failBuildOnCVSS < 0 || failBuildOnCVSS > 11) { |
| 681 | 0 | throw new BuildException("Invalid configuration, failBuildOnCVSS must be between 0 and 11."); |
| 682 | |
} |
| 683 | 3 | } |
| 684 | |
|
| 685 | |
|
| 686 | |
|
| 687 | |
|
| 688 | |
|
| 689 | |
private void populateSettings() { |
| 690 | 3 | InputStream taskProperties = null; |
| 691 | |
try { |
| 692 | 3 | taskProperties = this.getClass().getClassLoader().getResourceAsStream(PROPERTIES_FILE); |
| 693 | 3 | Settings.mergeProperties(taskProperties); |
| 694 | 0 | } catch (IOException ex) { |
| 695 | 0 | Logger.getLogger(DependencyCheckTask.class.getName()).log(Level.WARNING, "Unable to load the dependency-check ant task.properties file."); |
| 696 | 0 | Logger.getLogger(DependencyCheckTask.class.getName()).log(Level.FINE, null, ex); |
| 697 | |
} finally { |
| 698 | 3 | if (taskProperties != null) { |
| 699 | |
try { |
| 700 | 3 | taskProperties.close(); |
| 701 | 0 | } catch (IOException ex) { |
| 702 | 0 | Logger.getLogger(DependencyCheckTask.class.getName()).log(Level.FINEST, null, ex); |
| 703 | 3 | } |
| 704 | |
} |
| 705 | |
} |
| 706 | 3 | if (dataDirectory != null) { |
| 707 | 0 | Settings.setString(Settings.KEYS.DATA_DIRECTORY, dataDirectory); |
| 708 | |
} else { |
| 709 | 3 | final File jarPath = new File(DependencyCheckTask.class.getProtectionDomain().getCodeSource().getLocation().getPath()); |
| 710 | 3 | final File base = jarPath.getParentFile(); |
| 711 | 3 | final String sub = Settings.getString(Settings.KEYS.DATA_DIRECTORY); |
| 712 | 3 | final File dataDir = new File(base, sub); |
| 713 | 3 | Settings.setString(Settings.KEYS.DATA_DIRECTORY, dataDir.getAbsolutePath()); |
| 714 | |
} |
| 715 | |
|
| 716 | 3 | Settings.setBoolean(Settings.KEYS.AUTO_UPDATE, autoUpdate); |
| 717 | |
|
| 718 | 3 | if (proxyUrl != null && !proxyUrl.isEmpty()) { |
| 719 | 0 | Settings.setString(Settings.KEYS.PROXY_URL, proxyUrl); |
| 720 | |
} |
| 721 | 3 | if (proxyPort != null && !proxyPort.isEmpty()) { |
| 722 | 0 | Settings.setString(Settings.KEYS.PROXY_PORT, proxyPort); |
| 723 | |
} |
| 724 | 3 | if (proxyUsername != null && !proxyUsername.isEmpty()) { |
| 725 | 0 | Settings.setString(Settings.KEYS.PROXY_USERNAME, proxyUsername); |
| 726 | |
} |
| 727 | 3 | if (proxyPassword != null && !proxyPassword.isEmpty()) { |
| 728 | 0 | Settings.setString(Settings.KEYS.PROXY_PASSWORD, proxyPassword); |
| 729 | |
} |
| 730 | 3 | if (connectionTimeout != null && !connectionTimeout.isEmpty()) { |
| 731 | 0 | Settings.setString(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout); |
| 732 | |
} |
| 733 | 3 | if (suppressionFile != null && !suppressionFile.isEmpty()) { |
| 734 | 0 | Settings.setString(Settings.KEYS.SUPPRESSION_FILE, suppressionFile); |
| 735 | |
} |
| 736 | 3 | Settings.setBoolean(Settings.KEYS.ANALYZER_NEXUS_ENABLED, nexusAnalyzerEnabled); |
| 737 | 3 | if (nexusUrl != null && !nexusUrl.isEmpty()) { |
| 738 | 0 | Settings.setString(Settings.KEYS.ANALYZER_NEXUS_URL, nexusUrl); |
| 739 | |
} |
| 740 | 3 | if (databaseDriverName != null && !databaseDriverName.isEmpty()) { |
| 741 | 0 | Settings.setString(Settings.KEYS.DB_DRIVER_NAME, databaseDriverName); |
| 742 | |
} |
| 743 | 3 | if (databaseDriverPath != null && !databaseDriverPath.isEmpty()) { |
| 744 | 0 | Settings.setString(Settings.KEYS.DB_DRIVER_PATH, databaseDriverPath); |
| 745 | |
} |
| 746 | 3 | if (connectionString != null && !connectionString.isEmpty()) { |
| 747 | 0 | Settings.setString(Settings.KEYS.DB_CONNECTION_STRING, connectionString); |
| 748 | |
} |
| 749 | 3 | if (databaseUser != null && !databaseUser.isEmpty()) { |
| 750 | 0 | Settings.setString(Settings.KEYS.DB_USER, databaseUser); |
| 751 | |
} |
| 752 | 3 | if (databasePassword != null && !databasePassword.isEmpty()) { |
| 753 | 0 | Settings.setString(Settings.KEYS.DB_PASSWORD, databasePassword); |
| 754 | |
} |
| 755 | 3 | } |
| 756 | |
|
| 757 | |
|
| 758 | |
|
| 759 | |
|
| 760 | |
|
| 761 | |
|
| 762 | |
|
| 763 | |
|
| 764 | |
private void checkForFailure(List<Dependency> dependencies) throws BuildException { |
| 765 | 0 | final StringBuilder ids = new StringBuilder(); |
| 766 | 0 | for (Dependency d : dependencies) { |
| 767 | 0 | for (Vulnerability v : d.getVulnerabilities()) { |
| 768 | 0 | if (v.getCvssScore() >= failBuildOnCVSS) { |
| 769 | 0 | if (ids.length() == 0) { |
| 770 | 0 | ids.append(v.getName()); |
| 771 | |
} else { |
| 772 | 0 | ids.append(", ").append(v.getName()); |
| 773 | |
} |
| 774 | |
} |
| 775 | 0 | } |
| 776 | 0 | } |
| 777 | 0 | if (ids.length() > 0) { |
| 778 | 0 | final String msg = String.format("%n%nDependency-Check Failure:%n" |
| 779 | |
+ "One or more dependencies were identified with vulnerabilities that have a CVSS score greater then '%.1f': %s%n" |
| 780 | |
+ "See the dependency-check report for more details.%n%n", failBuildOnCVSS, ids.toString()); |
| 781 | 0 | throw new BuildException(msg); |
| 782 | |
} |
| 783 | 0 | } |
| 784 | |
|
| 785 | |
|
| 786 | |
|
| 787 | |
|
| 788 | |
|
| 789 | |
|
| 790 | |
private void showSummary(List<Dependency> dependencies) { |
| 791 | 3 | final StringBuilder summary = new StringBuilder(); |
| 792 | 3 | for (Dependency d : dependencies) { |
| 793 | 5 | boolean firstEntry = true; |
| 794 | 5 | final StringBuilder ids = new StringBuilder(); |
| 795 | 5 | for (Vulnerability v : d.getVulnerabilities()) { |
| 796 | 20 | if (firstEntry) { |
| 797 | 4 | firstEntry = false; |
| 798 | |
} else { |
| 799 | 16 | ids.append(", "); |
| 800 | |
} |
| 801 | 20 | ids.append(v.getName()); |
| 802 | 20 | } |
| 803 | 5 | if (ids.length() > 0) { |
| 804 | 4 | summary.append(d.getFileName()).append(" ("); |
| 805 | 4 | firstEntry = true; |
| 806 | 4 | for (Identifier id : d.getIdentifiers()) { |
| 807 | 12 | if (firstEntry) { |
| 808 | 4 | firstEntry = false; |
| 809 | |
} else { |
| 810 | 8 | summary.append(", "); |
| 811 | |
} |
| 812 | 12 | summary.append(id.getValue()); |
| 813 | 12 | } |
| 814 | 4 | summary.append(") : ").append(ids).append(NEW_LINE); |
| 815 | |
} |
| 816 | 5 | } |
| 817 | 3 | if (summary.length() > 0) { |
| 818 | 3 | final String msg = String.format("%n%n" |
| 819 | |
+ "One or more dependencies were identified with known vulnerabilities:%n%n%s" |
| 820 | |
+ "%n%nSee the dependency-check report for more details.%n%n", summary.toString()); |
| 821 | 3 | Logger.getLogger(DependencyCheckTask.class.getName()).log(Level.WARNING, msg); |
| 822 | |
} |
| 823 | 3 | } |
| 824 | |
|
| 825 | |
|
| 826 | |
|
| 827 | |
|
| 828 | 4 | public static class ReportFormats extends EnumeratedAttribute { |
| 829 | |
|
| 830 | |
|
| 831 | |
|
| 832 | |
|
| 833 | |
|
| 834 | |
|
| 835 | |
@Override |
| 836 | |
public String[] getValues() { |
| 837 | 4 | int i = 0; |
| 838 | 4 | final Format[] formats = Format.values(); |
| 839 | 4 | final String[] values = new String[formats.length]; |
| 840 | 20 | for (Format format : formats) { |
| 841 | 16 | values[i++] = format.name(); |
| 842 | |
} |
| 843 | 4 | return values; |
| 844 | |
} |
| 845 | |
} |
| 846 | |
} |