| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.owasp.dependencycheck.analyzer; |
| 19 | |
|
| 20 | |
import java.util.ArrayList; |
| 21 | |
import java.util.Iterator; |
| 22 | |
import java.util.List; |
| 23 | |
import java.util.Set; |
| 24 | |
import org.owasp.dependencycheck.Engine; |
| 25 | |
import org.owasp.dependencycheck.analyzer.exception.AnalysisException; |
| 26 | |
import org.owasp.dependencycheck.dependency.Confidence; |
| 27 | |
import org.owasp.dependencycheck.dependency.Dependency; |
| 28 | |
import org.owasp.dependencycheck.dependency.Evidence; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | 5 | public class HintAnalyzer extends AbstractAnalyzer implements Analyzer { |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
private static final String ANALYZER_NAME = "Hint Analyzer"; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | 1 | private static final AnalysisPhase ANALYSIS_PHASE = AnalysisPhase.PRE_IDENTIFIER_ANALYSIS; |
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
@Override |
| 52 | |
public String getName() { |
| 53 | 5 | return ANALYZER_NAME; |
| 54 | |
} |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
@Override |
| 62 | |
public AnalysisPhase getAnalysisPhase() { |
| 63 | 2 | return ANALYSIS_PHASE; |
| 64 | |
} |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
@Override |
| 76 | |
public void analyze(Dependency dependency, Engine engine) throws AnalysisException { |
| 77 | 2 | final Evidence springTest1 = new Evidence("Manifest", |
| 78 | |
"Implementation-Title", |
| 79 | |
"Spring Framework", |
| 80 | |
Confidence.HIGH); |
| 81 | |
|
| 82 | 2 | final Evidence springTest2 = new Evidence("Manifest", |
| 83 | |
"Implementation-Title", |
| 84 | |
"org.springframework.core", |
| 85 | |
Confidence.HIGH); |
| 86 | |
|
| 87 | 2 | final Evidence springTest3 = new Evidence("Manifest", |
| 88 | |
"Implementation-Title", |
| 89 | |
"spring-core", |
| 90 | |
Confidence.HIGH); |
| 91 | |
|
| 92 | 2 | final Evidence springTest4 = new Evidence("Manifest", |
| 93 | |
"Bundle-Vendor", |
| 94 | |
"SpringSource", |
| 95 | |
Confidence.HIGH); |
| 96 | |
|
| 97 | 2 | final Evidence springTest5 = new Evidence("jar", |
| 98 | |
"package name", |
| 99 | |
"springframework", |
| 100 | |
Confidence.LOW); |
| 101 | |
|
| 102 | |
|
| 103 | 2 | final Set<Evidence> product = dependency.getProductEvidence().getEvidence(); |
| 104 | 2 | final Set<Evidence> vendor = dependency.getVendorEvidence().getEvidence(); |
| 105 | |
|
| 106 | 2 | if (product.contains(springTest1) || product.contains(springTest2) || product.contains(springTest3) |
| 107 | |
|| (dependency.getFileName().contains("spring") && (product.contains(springTest5) || vendor.contains(springTest5)))) { |
| 108 | 1 | dependency.getProductEvidence().addEvidence("hint analyzer", "product", "springsource spring framework", Confidence.HIGH); |
| 109 | 1 | dependency.getVendorEvidence().addEvidence("hint analyzer", "vendor", "SpringSource", Confidence.HIGH); |
| 110 | 1 | dependency.getVendorEvidence().addEvidence("hint analyzer", "vendor", "vmware", Confidence.HIGH); |
| 111 | |
} |
| 112 | |
|
| 113 | 2 | if (vendor.contains(springTest4)) { |
| 114 | 1 | dependency.getProductEvidence().addEvidence("hint analyzer", "product", "springsource_spring_framework", Confidence.HIGH); |
| 115 | 1 | dependency.getVendorEvidence().addEvidence("hint analyzer", "vendor", "vmware", Confidence.HIGH); |
| 116 | |
} |
| 117 | |
|
| 118 | |
|
| 119 | 2 | final Iterator<Evidence> itr = dependency.getVendorEvidence().iterator(); |
| 120 | 2 | final List<Evidence> newEntries = new ArrayList<Evidence>(); |
| 121 | 28 | while (itr.hasNext()) { |
| 122 | 26 | final Evidence e = itr.next(); |
| 123 | 26 | if ("sun".equalsIgnoreCase(e.getValue(false))) { |
| 124 | 0 | final Evidence newEvidence = new Evidence(e.getSource() + " (hint)", e.getName(), "oracle", e.getConfidence()); |
| 125 | 0 | newEntries.add(newEvidence); |
| 126 | 0 | } else if ("oracle".equalsIgnoreCase(e.getValue(false))) { |
| 127 | 0 | final Evidence newEvidence = new Evidence(e.getSource() + " (hint)", e.getName(), "sun", e.getConfidence()); |
| 128 | 0 | newEntries.add(newEvidence); |
| 129 | |
} |
| 130 | 26 | } |
| 131 | 2 | for (Evidence e : newEntries) { |
| 132 | 0 | dependency.getVendorEvidence().addEvidence(e); |
| 133 | 0 | } |
| 134 | |
|
| 135 | 2 | } |
| 136 | |
} |