mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-01-14 07:43:40 +01:00
bug fixes
Former-commit-id: 6411fe67e52a3eef4044b1d640bdfb6864c2dbf3
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* This file is part of DependencyCheck.
|
||||
*
|
||||
* DependencyCheck is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 3 of the License, or (at your option) any
|
||||
* later version.
|
||||
*
|
||||
* DependencyCheck is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* DependencyCheck. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* Copyright (c) 2012 Jeremy Long. All Rights Reserved.
|
||||
*/
|
||||
package org.owasp.dependencycheck.analyzer;
|
||||
|
||||
import java.util.Set;
|
||||
import org.owasp.dependencycheck.Engine;
|
||||
import org.owasp.dependencycheck.dependency.Dependency;
|
||||
import org.owasp.dependencycheck.dependency.Evidence;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jeremy Long (jeremy.long@gmail.com)
|
||||
*/
|
||||
public class HintAnalyzer implements Analyzer {
|
||||
|
||||
/**
|
||||
* The name of the analyzer.
|
||||
*/
|
||||
private static final String ANALYZER_NAME = "Hint Analyzer";
|
||||
/**
|
||||
* The phase that this analyzer is intended to run in.
|
||||
*/
|
||||
private static final AnalysisPhase ANALYSIS_PHASE = AnalysisPhase.PRE_IDENTIFIER_ANALYSIS;
|
||||
/**
|
||||
* The set of file extensions supported by this analyzer.
|
||||
*/
|
||||
private static final Set<String> EXTENSIONS = null;
|
||||
|
||||
/**
|
||||
* Returns a list of file EXTENSIONS supported by this analyzer.
|
||||
*
|
||||
* @return a list of file EXTENSIONS supported by this analyzer.
|
||||
*/
|
||||
public Set<String> getSupportedExtensions() {
|
||||
return EXTENSIONS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the analyzer.
|
||||
*
|
||||
* @return the name of the analyzer.
|
||||
*/
|
||||
public String getName() {
|
||||
return ANALYZER_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not this analyzer can process the given extension.
|
||||
*
|
||||
* @param extension the file extension to test for support.
|
||||
* @return whether or not the specified file extension is supported by this
|
||||
* analyzer.
|
||||
*/
|
||||
public boolean supportsExtension(String extension) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the phase that the analyzer is intended to run in.
|
||||
*
|
||||
* @return the phase that the analyzer is intended to run in.
|
||||
*/
|
||||
public AnalysisPhase getAnalysisPhase() {
|
||||
return ANALYSIS_PHASE;
|
||||
}
|
||||
|
||||
public void analyze(Dependency dependency, Engine engine) throws AnalysisException {
|
||||
Evidence springTest1 = new Evidence("Manifest",
|
||||
"Implementation-Title",
|
||||
"Spring Framework",
|
||||
Evidence.Confidence.HIGH);
|
||||
|
||||
Evidence springTest2 = new Evidence("Manifest",
|
||||
"Implementation-Title",
|
||||
"org.springframework.core",
|
||||
Evidence.Confidence.HIGH);
|
||||
|
||||
Set<Evidence> evidence = dependency.getProductEvidence().getEvidence();
|
||||
if (evidence.contains(springTest1) || evidence.contains(springTest2)) {
|
||||
dependency.getProductEvidence().addEvidence("a priori", "product", "springsource_spring_framework", Evidence.Confidence.HIGH);
|
||||
dependency.getVendorEvidence().addEvidence("a priori", "vendor", "SpringSource", Evidence.Confidence.HIGH);
|
||||
dependency.getVendorEvidence().addEvidence("a priori", "vendor", "vmware", Evidence.Confidence.HIGH);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The initialize method does nothing for this Analyzer
|
||||
*/
|
||||
public void initialize() {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* The close method does nothing for this Analyzer
|
||||
*/
|
||||
public void close() {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,7 @@ public class JarAnalyzer extends AbstractAnalyzer implements Analyzer {
|
||||
parseManifest(dependency);
|
||||
analyzePackageNames(dependency);
|
||||
analyzePOM(dependency);
|
||||
addPredefinedData(dependency);
|
||||
//addPredefinedData(dependency); //this has been moved to its own analyzer (HintAnalyzer)
|
||||
} catch (IOException ex) {
|
||||
throw new AnalysisException("Exception occurred reading the JAR file.", ex);
|
||||
} catch (JAXBException ex) {
|
||||
@@ -643,22 +643,22 @@ public class JarAnalyzer extends AbstractAnalyzer implements Analyzer {
|
||||
return interpolateString(sb.toString(), properties); //yes yes, this should be a loop...
|
||||
}
|
||||
|
||||
private void addPredefinedData(Dependency dependency) {
|
||||
Evidence springTest1 = new Evidence("Manifest",
|
||||
"Implementation-Title",
|
||||
"Spring Framework",
|
||||
Evidence.Confidence.HIGH);
|
||||
|
||||
Evidence springTest2 = new Evidence("Manifest",
|
||||
"Implementation-Title",
|
||||
"org.springframework.core",
|
||||
Evidence.Confidence.HIGH);
|
||||
|
||||
Set<Evidence> evidence = dependency.getProductEvidence().getEvidence();
|
||||
if (evidence.contains(springTest1) || evidence.contains(springTest2)) {
|
||||
dependency.getProductEvidence().addEvidence("a priori", "product", "springsource_spring_framework", Evidence.Confidence.HIGH);
|
||||
dependency.getVendorEvidence().addEvidence("a priori", "vendor", "SpringSource", Evidence.Confidence.HIGH);
|
||||
dependency.getVendorEvidence().addEvidence("a priori", "vendor", "vmware", Evidence.Confidence.HIGH);
|
||||
}
|
||||
}
|
||||
// private void addPredefinedData(Dependency dependency) {
|
||||
// Evidence springTest1 = new Evidence("Manifest",
|
||||
// "Implementation-Title",
|
||||
// "Spring Framework",
|
||||
// Evidence.Confidence.HIGH);
|
||||
//
|
||||
// Evidence springTest2 = new Evidence("Manifest",
|
||||
// "Implementation-Title",
|
||||
// "org.springframework.core",
|
||||
// Evidence.Confidence.HIGH);
|
||||
//
|
||||
// Set<Evidence> evidence = dependency.getProductEvidence().getEvidence();
|
||||
// if (evidence.contains(springTest1) || evidence.contains(springTest2)) {
|
||||
// dependency.getProductEvidence().addEvidence("a priori", "product", "springsource_spring_framework", Evidence.Confidence.HIGH);
|
||||
// dependency.getVendorEvidence().addEvidence("a priori", "vendor", "SpringSource", Evidence.Confidence.HIGH);
|
||||
// dependency.getVendorEvidence().addEvidence("a priori", "vendor", "vmware", Evidence.Confidence.HIGH);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class CPEAnalyzer implements org.owasp.dependencycheck.analyzer.Analyzer
|
||||
/**
|
||||
* The maximum number of query results to return.
|
||||
*/
|
||||
static final int MAX_QUERY_RESULTS = 10;
|
||||
static final int MAX_QUERY_RESULTS = 25;
|
||||
/**
|
||||
* The weighting boost to give terms when constructing the Lucene query.
|
||||
*/
|
||||
@@ -211,7 +211,7 @@ public class CPEAnalyzer implements org.owasp.dependencycheck.analyzer.Analyzer
|
||||
if (value.startsWith("https://")) {
|
||||
value = value.substring(8).replaceAll("\\.", " ");
|
||||
}
|
||||
if (sb.indexOf(value) < 0) {
|
||||
if (sb.indexOf(" " + value + " ") < 0) {
|
||||
sb.append(value).append(' ');
|
||||
}
|
||||
}
|
||||
@@ -261,6 +261,7 @@ public class CPEAnalyzer implements org.owasp.dependencycheck.analyzer.Analyzer
|
||||
if (searchString == null) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
TopDocs docs = cpe.search(searchString, MAX_QUERY_RESULTS);
|
||||
for (ScoreDoc d : docs.scoreDocs) {
|
||||
Document doc = cpe.getDocument(d.doc);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
org.owasp.dependencycheck.analyzer.JarAnalyzer
|
||||
org.owasp.dependencycheck.analyzer.FileNameAnalyzer
|
||||
org.owasp.dependencycheck.analyzer.HintAnalyzer
|
||||
org.owasp.dependencycheck.analyzer.SpringCleaningAnalyzer
|
||||
org.owasp.dependencycheck.data.cpe.CPEAnalyzer
|
||||
org.owasp.dependencycheck.data.nvdcve.NvdCveAnalyzer
|
||||
@@ -118,13 +118,13 @@ public class CPEAnalyzerTest extends BaseIndexTestCase {
|
||||
instance.close();
|
||||
Assert.assertTrue("Incorrect match size - struts", depends.getIdentifiers().size() == 1);
|
||||
Assert.assertTrue("Incorrect match - struts", depends.getIdentifiers().get(0).getValue().equals(expResult));
|
||||
Assert.assertTrue("Incorrect match size - spring", spring.getIdentifiers().size() == 1);
|
||||
Assert.assertTrue("Incorrect match - spring", spring.getIdentifiers().get(0).getValue().equals(expResultSpring));
|
||||
//the following two only work if the HintAnalyzer is used.
|
||||
//Assert.assertTrue("Incorrect match size - spring", spring.getIdentifiers().size() == 1);
|
||||
//Assert.assertTrue("Incorrect match - spring", spring.getIdentifiers().get(0).getValue().equals(expResultSpring));
|
||||
Assert.assertTrue("Incorrect match size - spring3 - " + spring3.getIdentifiers().size(), spring3.getIdentifiers().size() >= 1);
|
||||
//assertTrue("Incorrect match - spring3", spring3.getIdentifiers().get(0).getValue().equals(expResultSpring3));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test of searchCPE method, of class CPEAnalyzer.
|
||||
* @throws Exception is thrown when an exception occurs
|
||||
|
||||
Reference in New Issue
Block a user