id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
list | docstring
stringlengths 3
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 105
339
|
|---|---|---|---|---|---|---|---|---|---|---|---|
17,800
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/dependency/Dependency.java
|
Dependency.getVulnerabilities
|
public synchronized Set<Vulnerability> getVulnerabilities(boolean sorted) {
final Set<Vulnerability> vulnerabilitySet;
if (sorted) {
vulnerabilitySet = new TreeSet<>(vulnerabilities);
} else {
vulnerabilitySet = vulnerabilities;
}
return Collections.unmodifiableSet(vulnerabilitySet);
}
|
java
|
public synchronized Set<Vulnerability> getVulnerabilities(boolean sorted) {
final Set<Vulnerability> vulnerabilitySet;
if (sorted) {
vulnerabilitySet = new TreeSet<>(vulnerabilities);
} else {
vulnerabilitySet = vulnerabilities;
}
return Collections.unmodifiableSet(vulnerabilitySet);
}
|
[
"public",
"synchronized",
"Set",
"<",
"Vulnerability",
">",
"getVulnerabilities",
"(",
"boolean",
"sorted",
")",
"{",
"final",
"Set",
"<",
"Vulnerability",
">",
"vulnerabilitySet",
";",
"if",
"(",
"sorted",
")",
"{",
"vulnerabilitySet",
"=",
"new",
"TreeSet",
"<>",
"(",
"vulnerabilities",
")",
";",
"}",
"else",
"{",
"vulnerabilitySet",
"=",
"vulnerabilities",
";",
"}",
"return",
"Collections",
".",
"unmodifiableSet",
"(",
"vulnerabilitySet",
")",
";",
"}"
] |
Get the unmodifiable list of vulnerabilities; optionally sorted.
@param sorted if true the list will be sorted
@return the unmodifiable list set of vulnerabilities
|
[
"Get",
"the",
"unmodifiable",
"list",
"of",
"vulnerabilities",
";",
"optionally",
"sorted",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/dependency/Dependency.java#L589-L597
|
17,801
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/dependency/Dependency.java
|
Dependency.getSuppressedVulnerabilities
|
public synchronized Set<Vulnerability> getSuppressedVulnerabilities(boolean sorted) {
final Set<Vulnerability> vulnerabilitySet;
if (sorted) {
vulnerabilitySet = new TreeSet<>(suppressedVulnerabilities);
} else {
vulnerabilitySet = suppressedVulnerabilities;
}
return Collections.unmodifiableSet(vulnerabilitySet);
}
|
java
|
public synchronized Set<Vulnerability> getSuppressedVulnerabilities(boolean sorted) {
final Set<Vulnerability> vulnerabilitySet;
if (sorted) {
vulnerabilitySet = new TreeSet<>(suppressedVulnerabilities);
} else {
vulnerabilitySet = suppressedVulnerabilities;
}
return Collections.unmodifiableSet(vulnerabilitySet);
}
|
[
"public",
"synchronized",
"Set",
"<",
"Vulnerability",
">",
"getSuppressedVulnerabilities",
"(",
"boolean",
"sorted",
")",
"{",
"final",
"Set",
"<",
"Vulnerability",
">",
"vulnerabilitySet",
";",
"if",
"(",
"sorted",
")",
"{",
"vulnerabilitySet",
"=",
"new",
"TreeSet",
"<>",
"(",
"suppressedVulnerabilities",
")",
";",
"}",
"else",
"{",
"vulnerabilitySet",
"=",
"suppressedVulnerabilities",
";",
"}",
"return",
"Collections",
".",
"unmodifiableSet",
"(",
"vulnerabilitySet",
")",
";",
"}"
] |
Get an unmodifiable, optionally sorted. set of suppressedVulnerabilities.
@param sorted whether or not the set is sorted
@return the unmodifiable sorted set of suppressedVulnerabilities
|
[
"Get",
"an",
"unmodifiable",
"optionally",
"sorted",
".",
"set",
"of",
"suppressedVulnerabilities",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/dependency/Dependency.java#L614-L622
|
17,802
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/dependency/Dependency.java
|
Dependency.determineHashes
|
private String determineHashes(HashingFunction hashFunction) {
if (isVirtual) {
return null;
}
try {
final File file = getActualFile();
return hashFunction.hash(file);
} catch (IOException | RuntimeException ex) {
LOGGER.warn("Unable to read '{}' to determine hashes.", actualFilePath);
LOGGER.debug("", ex);
} catch (NoSuchAlgorithmException ex) {
LOGGER.warn("Unable to use MD5 or SHA1 checksums.");
LOGGER.debug("", ex);
}
return null;
}
|
java
|
private String determineHashes(HashingFunction hashFunction) {
if (isVirtual) {
return null;
}
try {
final File file = getActualFile();
return hashFunction.hash(file);
} catch (IOException | RuntimeException ex) {
LOGGER.warn("Unable to read '{}' to determine hashes.", actualFilePath);
LOGGER.debug("", ex);
} catch (NoSuchAlgorithmException ex) {
LOGGER.warn("Unable to use MD5 or SHA1 checksums.");
LOGGER.debug("", ex);
}
return null;
}
|
[
"private",
"String",
"determineHashes",
"(",
"HashingFunction",
"hashFunction",
")",
"{",
"if",
"(",
"isVirtual",
")",
"{",
"return",
"null",
";",
"}",
"try",
"{",
"final",
"File",
"file",
"=",
"getActualFile",
"(",
")",
";",
"return",
"hashFunction",
".",
"hash",
"(",
"file",
")",
";",
"}",
"catch",
"(",
"IOException",
"|",
"RuntimeException",
"ex",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Unable to read '{}' to determine hashes.\"",
",",
"actualFilePath",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"\"",
",",
"ex",
")",
";",
"}",
"catch",
"(",
"NoSuchAlgorithmException",
"ex",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Unable to use MD5 or SHA1 checksums.\"",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"\"",
",",
"ex",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Determines the SHA1 and MD5 sum for the given file.
@param hashFunction the hashing function
@return the checksum
|
[
"Determines",
"the",
"SHA1",
"and",
"MD5",
"sum",
"for",
"the",
"given",
"file",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/dependency/Dependency.java#L689-L704
|
17,803
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/dependency/Dependency.java
|
Dependency.addRelatedDependency
|
@SuppressWarnings("ReferenceEquality")
public synchronized void addRelatedDependency(Dependency dependency) {
if (this == dependency) {
LOGGER.warn("Attempted to add a circular reference - please post the log file to issue #172 here "
+ "https://github.com/jeremylong/DependencyCheck/issues/172");
LOGGER.debug("this: {}", this);
LOGGER.debug("dependency: {}", dependency);
} else if (!relatedDependencies.add(dependency)) {
LOGGER.debug("Failed to add dependency, likely due to referencing the same file as another dependency in the set.");
LOGGER.debug("this: {}", this);
LOGGER.debug("dependency: {}", dependency);
}
}
|
java
|
@SuppressWarnings("ReferenceEquality")
public synchronized void addRelatedDependency(Dependency dependency) {
if (this == dependency) {
LOGGER.warn("Attempted to add a circular reference - please post the log file to issue #172 here "
+ "https://github.com/jeremylong/DependencyCheck/issues/172");
LOGGER.debug("this: {}", this);
LOGGER.debug("dependency: {}", dependency);
} else if (!relatedDependencies.add(dependency)) {
LOGGER.debug("Failed to add dependency, likely due to referencing the same file as another dependency in the set.");
LOGGER.debug("this: {}", this);
LOGGER.debug("dependency: {}", dependency);
}
}
|
[
"@",
"SuppressWarnings",
"(",
"\"ReferenceEquality\"",
")",
"public",
"synchronized",
"void",
"addRelatedDependency",
"(",
"Dependency",
"dependency",
")",
"{",
"if",
"(",
"this",
"==",
"dependency",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Attempted to add a circular reference - please post the log file to issue #172 here \"",
"+",
"\"https://github.com/jeremylong/DependencyCheck/issues/172\"",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"this: {}\"",
",",
"this",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"dependency: {}\"",
",",
"dependency",
")",
";",
"}",
"else",
"if",
"(",
"!",
"relatedDependencies",
".",
"add",
"(",
"dependency",
")",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Failed to add dependency, likely due to referencing the same file as another dependency in the set.\"",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"this: {}\"",
",",
"this",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"dependency: {}\"",
",",
"dependency",
")",
";",
"}",
"}"
] |
Adds a related dependency.
@param dependency a reference to the related dependency
|
[
"Adds",
"a",
"related",
"dependency",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/dependency/Dependency.java#L776-L788
|
17,804
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/NvdCveAnalyzer.java
|
NvdCveAnalyzer.analyzeDependency
|
@Override
protected void analyzeDependency(Dependency dependency, Engine engine) throws AnalysisException {
final CveDB cveDB = engine.getDatabase();
try {
dependency.getVulnerableSoftwareIdentifiers().stream()
.filter((i) -> (i instanceof CpeIdentifier))
.map(i -> (CpeIdentifier) i)
.forEach(i -> {
try {
final List<Vulnerability> vulns = cveDB.getVulnerabilities(i.getCpe());
dependency.addVulnerabilities(vulns);
} catch (DatabaseException ex) {
throw new LambdaExceptionWrapper(new AnalysisException(ex));
}
});
dependency.getSuppressedIdentifiers().stream()
.filter((i) -> (i instanceof CpeIdentifier))
.map(i -> (CpeIdentifier) i)
.forEach(i -> {
try {
final List<Vulnerability> vulns = cveDB.getVulnerabilities(i.getCpe());
dependency.addSuppressedVulnerabilities(vulns);
} catch (DatabaseException ex) {
throw new LambdaExceptionWrapper(new AnalysisException(ex));
}
});
} catch (LambdaExceptionWrapper ex) {
throw (AnalysisException) ex.getCause();
}
}
|
java
|
@Override
protected void analyzeDependency(Dependency dependency, Engine engine) throws AnalysisException {
final CveDB cveDB = engine.getDatabase();
try {
dependency.getVulnerableSoftwareIdentifiers().stream()
.filter((i) -> (i instanceof CpeIdentifier))
.map(i -> (CpeIdentifier) i)
.forEach(i -> {
try {
final List<Vulnerability> vulns = cveDB.getVulnerabilities(i.getCpe());
dependency.addVulnerabilities(vulns);
} catch (DatabaseException ex) {
throw new LambdaExceptionWrapper(new AnalysisException(ex));
}
});
dependency.getSuppressedIdentifiers().stream()
.filter((i) -> (i instanceof CpeIdentifier))
.map(i -> (CpeIdentifier) i)
.forEach(i -> {
try {
final List<Vulnerability> vulns = cveDB.getVulnerabilities(i.getCpe());
dependency.addSuppressedVulnerabilities(vulns);
} catch (DatabaseException ex) {
throw new LambdaExceptionWrapper(new AnalysisException(ex));
}
});
} catch (LambdaExceptionWrapper ex) {
throw (AnalysisException) ex.getCause();
}
}
|
[
"@",
"Override",
"protected",
"void",
"analyzeDependency",
"(",
"Dependency",
"dependency",
",",
"Engine",
"engine",
")",
"throws",
"AnalysisException",
"{",
"final",
"CveDB",
"cveDB",
"=",
"engine",
".",
"getDatabase",
"(",
")",
";",
"try",
"{",
"dependency",
".",
"getVulnerableSoftwareIdentifiers",
"(",
")",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"(",
"i",
")",
"-",
">",
"(",
"i",
"instanceof",
"CpeIdentifier",
")",
")",
".",
"map",
"(",
"i",
"->",
"(",
"CpeIdentifier",
")",
"i",
")",
".",
"forEach",
"(",
"i",
"->",
"{",
"try",
"{",
"final",
"List",
"<",
"Vulnerability",
">",
"vulns",
"=",
"cveDB",
".",
"getVulnerabilities",
"(",
"i",
".",
"getCpe",
"(",
")",
")",
";",
"dependency",
".",
"addVulnerabilities",
"(",
"vulns",
")",
";",
"}",
"catch",
"(",
"DatabaseException",
"ex",
")",
"{",
"throw",
"new",
"LambdaExceptionWrapper",
"(",
"new",
"AnalysisException",
"(",
"ex",
")",
")",
";",
"}",
"}",
")",
";",
"dependency",
".",
"getSuppressedIdentifiers",
"(",
")",
".",
"stream",
"(",
")",
".",
"filter",
"(",
"(",
"i",
")",
"-",
">",
"(",
"i",
"instanceof",
"CpeIdentifier",
")",
")",
".",
"map",
"(",
"i",
"->",
"(",
"CpeIdentifier",
")",
"i",
")",
".",
"forEach",
"(",
"i",
"->",
"{",
"try",
"{",
"final",
"List",
"<",
"Vulnerability",
">",
"vulns",
"=",
"cveDB",
".",
"getVulnerabilities",
"(",
"i",
".",
"getCpe",
"(",
")",
")",
";",
"dependency",
".",
"addSuppressedVulnerabilities",
"(",
"vulns",
")",
";",
"}",
"catch",
"(",
"DatabaseException",
"ex",
")",
"{",
"throw",
"new",
"LambdaExceptionWrapper",
"(",
"new",
"AnalysisException",
"(",
"ex",
")",
")",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"LambdaExceptionWrapper",
"ex",
")",
"{",
"throw",
"(",
"AnalysisException",
")",
"ex",
".",
"getCause",
"(",
")",
";",
"}",
"}"
] |
Analyzes a dependency and attempts to determine if there are any CPE
identifiers for this dependency.
@param dependency The Dependency to analyze
@param engine The analysis engine
@throws AnalysisException thrown if there is an issue analyzing the
dependency
|
[
"Analyzes",
"a",
"dependency",
"and",
"attempts",
"to",
"determine",
"if",
"there",
"are",
"any",
"CPE",
"identifiers",
"for",
"this",
"dependency",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/NvdCveAnalyzer.java#L55-L84
|
17,805
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/App.java
|
App.runScan
|
private int runScan(String reportDirectory, String outputFormat, String applicationName, String[] files,
String[] excludes, int symLinkDepth, int cvssFailScore) throws DatabaseException,
ExceptionCollection, ReportException {
Engine engine = null;
try {
final List<String> antStylePaths = getPaths(files);
final Set<File> paths = scanAntStylePaths(antStylePaths, symLinkDepth, excludes);
engine = new Engine(settings);
engine.scan(paths);
ExceptionCollection exCol = null;
try {
engine.analyzeDependencies();
} catch (ExceptionCollection ex) {
if (ex.isFatal()) {
throw ex;
}
exCol = ex;
}
try {
engine.writeReports(applicationName, new File(reportDirectory), outputFormat);
} catch (ReportException ex) {
if (exCol != null) {
exCol.addException(ex);
throw exCol;
} else {
throw ex;
}
}
if (exCol != null && !exCol.getExceptions().isEmpty()) {
throw exCol;
}
return determineReturnCode(engine, cvssFailScore);
} finally {
if (engine != null) {
engine.close();
}
}
}
|
java
|
private int runScan(String reportDirectory, String outputFormat, String applicationName, String[] files,
String[] excludes, int symLinkDepth, int cvssFailScore) throws DatabaseException,
ExceptionCollection, ReportException {
Engine engine = null;
try {
final List<String> antStylePaths = getPaths(files);
final Set<File> paths = scanAntStylePaths(antStylePaths, symLinkDepth, excludes);
engine = new Engine(settings);
engine.scan(paths);
ExceptionCollection exCol = null;
try {
engine.analyzeDependencies();
} catch (ExceptionCollection ex) {
if (ex.isFatal()) {
throw ex;
}
exCol = ex;
}
try {
engine.writeReports(applicationName, new File(reportDirectory), outputFormat);
} catch (ReportException ex) {
if (exCol != null) {
exCol.addException(ex);
throw exCol;
} else {
throw ex;
}
}
if (exCol != null && !exCol.getExceptions().isEmpty()) {
throw exCol;
}
return determineReturnCode(engine, cvssFailScore);
} finally {
if (engine != null) {
engine.close();
}
}
}
|
[
"private",
"int",
"runScan",
"(",
"String",
"reportDirectory",
",",
"String",
"outputFormat",
",",
"String",
"applicationName",
",",
"String",
"[",
"]",
"files",
",",
"String",
"[",
"]",
"excludes",
",",
"int",
"symLinkDepth",
",",
"int",
"cvssFailScore",
")",
"throws",
"DatabaseException",
",",
"ExceptionCollection",
",",
"ReportException",
"{",
"Engine",
"engine",
"=",
"null",
";",
"try",
"{",
"final",
"List",
"<",
"String",
">",
"antStylePaths",
"=",
"getPaths",
"(",
"files",
")",
";",
"final",
"Set",
"<",
"File",
">",
"paths",
"=",
"scanAntStylePaths",
"(",
"antStylePaths",
",",
"symLinkDepth",
",",
"excludes",
")",
";",
"engine",
"=",
"new",
"Engine",
"(",
"settings",
")",
";",
"engine",
".",
"scan",
"(",
"paths",
")",
";",
"ExceptionCollection",
"exCol",
"=",
"null",
";",
"try",
"{",
"engine",
".",
"analyzeDependencies",
"(",
")",
";",
"}",
"catch",
"(",
"ExceptionCollection",
"ex",
")",
"{",
"if",
"(",
"ex",
".",
"isFatal",
"(",
")",
")",
"{",
"throw",
"ex",
";",
"}",
"exCol",
"=",
"ex",
";",
"}",
"try",
"{",
"engine",
".",
"writeReports",
"(",
"applicationName",
",",
"new",
"File",
"(",
"reportDirectory",
")",
",",
"outputFormat",
")",
";",
"}",
"catch",
"(",
"ReportException",
"ex",
")",
"{",
"if",
"(",
"exCol",
"!=",
"null",
")",
"{",
"exCol",
".",
"addException",
"(",
"ex",
")",
";",
"throw",
"exCol",
";",
"}",
"else",
"{",
"throw",
"ex",
";",
"}",
"}",
"if",
"(",
"exCol",
"!=",
"null",
"&&",
"!",
"exCol",
".",
"getExceptions",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"exCol",
";",
"}",
"return",
"determineReturnCode",
"(",
"engine",
",",
"cvssFailScore",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"engine",
"!=",
"null",
")",
"{",
"engine",
".",
"close",
"(",
")",
";",
"}",
"}",
"}"
] |
Scans the specified directories and writes the dependency reports to the
reportDirectory.
@param reportDirectory the path to the directory where the reports will
be written
@param outputFormat the output format of the report
@param applicationName the application name for the report
@param files the files/directories to scan
@param excludes the patterns for files/directories to exclude
@param symLinkDepth the depth that symbolic links will be followed
@param cvssFailScore the score to fail on if a vulnerability is found
@return the exit code if there was an error
@throws ReportException thrown when the report cannot be generated
@throws DatabaseException thrown when there is an error connecting to the
database
@throws ExceptionCollection thrown when an exception occurs during
analysis; there may be multiple exceptions contained within the
collection.
|
[
"Scans",
"the",
"specified",
"directories",
"and",
"writes",
"the",
"dependency",
"reports",
"to",
"the",
"reportDirectory",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/App.java#L241-L281
|
17,806
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/App.java
|
App.determineReturnCode
|
private int determineReturnCode(Engine engine, int cvssFailScore) {
int retCode = 0;
//Set the exit code based on whether we found a high enough vulnerability
for (Dependency dep : engine.getDependencies()) {
if (!dep.getVulnerabilities().isEmpty()) {
for (Vulnerability vuln : dep.getVulnerabilities()) {
LOGGER.debug("VULNERABILITY FOUND {}", dep.getDisplayFileName());
if ((vuln.getCvssV2() != null && vuln.getCvssV2().getScore() > cvssFailScore)
|| (vuln.getCvssV3() != null && vuln.getCvssV3().getBaseScore() > cvssFailScore)) {
retCode = 1;
}
}
}
}
return retCode;
}
|
java
|
private int determineReturnCode(Engine engine, int cvssFailScore) {
int retCode = 0;
//Set the exit code based on whether we found a high enough vulnerability
for (Dependency dep : engine.getDependencies()) {
if (!dep.getVulnerabilities().isEmpty()) {
for (Vulnerability vuln : dep.getVulnerabilities()) {
LOGGER.debug("VULNERABILITY FOUND {}", dep.getDisplayFileName());
if ((vuln.getCvssV2() != null && vuln.getCvssV2().getScore() > cvssFailScore)
|| (vuln.getCvssV3() != null && vuln.getCvssV3().getBaseScore() > cvssFailScore)) {
retCode = 1;
}
}
}
}
return retCode;
}
|
[
"private",
"int",
"determineReturnCode",
"(",
"Engine",
"engine",
",",
"int",
"cvssFailScore",
")",
"{",
"int",
"retCode",
"=",
"0",
";",
"//Set the exit code based on whether we found a high enough vulnerability",
"for",
"(",
"Dependency",
"dep",
":",
"engine",
".",
"getDependencies",
"(",
")",
")",
"{",
"if",
"(",
"!",
"dep",
".",
"getVulnerabilities",
"(",
")",
".",
"isEmpty",
"(",
")",
")",
"{",
"for",
"(",
"Vulnerability",
"vuln",
":",
"dep",
".",
"getVulnerabilities",
"(",
")",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"VULNERABILITY FOUND {}\"",
",",
"dep",
".",
"getDisplayFileName",
"(",
")",
")",
";",
"if",
"(",
"(",
"vuln",
".",
"getCvssV2",
"(",
")",
"!=",
"null",
"&&",
"vuln",
".",
"getCvssV2",
"(",
")",
".",
"getScore",
"(",
")",
">",
"cvssFailScore",
")",
"||",
"(",
"vuln",
".",
"getCvssV3",
"(",
")",
"!=",
"null",
"&&",
"vuln",
".",
"getCvssV3",
"(",
")",
".",
"getBaseScore",
"(",
")",
">",
"cvssFailScore",
")",
")",
"{",
"retCode",
"=",
"1",
";",
"}",
"}",
"}",
"}",
"return",
"retCode",
";",
"}"
] |
Determines the return code based on if one of the dependencies scanned
has a vulnerability with a CVSS score above the cvssFailScore.
@param engine the engine used during analysis
@param cvssFailScore the max allowed CVSS score
@return returns <code>1</code> if a severe enough vulnerability is
identified; otherwise <code>0</code>
|
[
"Determines",
"the",
"return",
"code",
"based",
"on",
"if",
"one",
"of",
"the",
"dependencies",
"scanned",
"has",
"a",
"vulnerability",
"with",
"a",
"CVSS",
"score",
"above",
"the",
"cvssFailScore",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/App.java#L292-L307
|
17,807
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/App.java
|
App.scanAntStylePaths
|
private Set<File> scanAntStylePaths(List<String> antStylePaths, int symLinkDepth, String[] excludes) {
final Set<File> paths = new HashSet<>();
for (String file : antStylePaths) {
LOGGER.debug("Scanning {}", file);
final DirectoryScanner scanner = new DirectoryScanner();
String include = file.replace('\\', '/');
final File baseDir;
final int pos = getLastFileSeparator(include);
final String tmpBase = include.substring(0, pos);
final String tmpInclude = include.substring(pos + 1);
if (tmpInclude.indexOf('*') >= 0 || tmpInclude.indexOf('?') >= 0
|| new File(include).isFile()) {
baseDir = new File(tmpBase);
include = tmpInclude;
} else {
baseDir = new File(tmpBase, tmpInclude);
include = "**/*";
}
scanner.setBasedir(baseDir);
final String[] includes = {include};
scanner.setIncludes(includes);
scanner.setMaxLevelsOfSymlinks(symLinkDepth);
if (symLinkDepth <= 0) {
scanner.setFollowSymlinks(false);
}
if (excludes != null && excludes.length > 0) {
scanner.addExcludes(excludes);
}
scanner.scan();
if (scanner.getIncludedFilesCount() > 0) {
for (String s : scanner.getIncludedFiles()) {
final File f = new File(baseDir, s);
LOGGER.debug("Found file {}", f.toString());
paths.add(f);
}
}
}
return paths;
}
|
java
|
private Set<File> scanAntStylePaths(List<String> antStylePaths, int symLinkDepth, String[] excludes) {
final Set<File> paths = new HashSet<>();
for (String file : antStylePaths) {
LOGGER.debug("Scanning {}", file);
final DirectoryScanner scanner = new DirectoryScanner();
String include = file.replace('\\', '/');
final File baseDir;
final int pos = getLastFileSeparator(include);
final String tmpBase = include.substring(0, pos);
final String tmpInclude = include.substring(pos + 1);
if (tmpInclude.indexOf('*') >= 0 || tmpInclude.indexOf('?') >= 0
|| new File(include).isFile()) {
baseDir = new File(tmpBase);
include = tmpInclude;
} else {
baseDir = new File(tmpBase, tmpInclude);
include = "**/*";
}
scanner.setBasedir(baseDir);
final String[] includes = {include};
scanner.setIncludes(includes);
scanner.setMaxLevelsOfSymlinks(symLinkDepth);
if (symLinkDepth <= 0) {
scanner.setFollowSymlinks(false);
}
if (excludes != null && excludes.length > 0) {
scanner.addExcludes(excludes);
}
scanner.scan();
if (scanner.getIncludedFilesCount() > 0) {
for (String s : scanner.getIncludedFiles()) {
final File f = new File(baseDir, s);
LOGGER.debug("Found file {}", f.toString());
paths.add(f);
}
}
}
return paths;
}
|
[
"private",
"Set",
"<",
"File",
">",
"scanAntStylePaths",
"(",
"List",
"<",
"String",
">",
"antStylePaths",
",",
"int",
"symLinkDepth",
",",
"String",
"[",
"]",
"excludes",
")",
"{",
"final",
"Set",
"<",
"File",
">",
"paths",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"for",
"(",
"String",
"file",
":",
"antStylePaths",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Scanning {}\"",
",",
"file",
")",
";",
"final",
"DirectoryScanner",
"scanner",
"=",
"new",
"DirectoryScanner",
"(",
")",
";",
"String",
"include",
"=",
"file",
".",
"replace",
"(",
"'",
"'",
",",
"'",
"'",
")",
";",
"final",
"File",
"baseDir",
";",
"final",
"int",
"pos",
"=",
"getLastFileSeparator",
"(",
"include",
")",
";",
"final",
"String",
"tmpBase",
"=",
"include",
".",
"substring",
"(",
"0",
",",
"pos",
")",
";",
"final",
"String",
"tmpInclude",
"=",
"include",
".",
"substring",
"(",
"pos",
"+",
"1",
")",
";",
"if",
"(",
"tmpInclude",
".",
"indexOf",
"(",
"'",
"'",
")",
">=",
"0",
"||",
"tmpInclude",
".",
"indexOf",
"(",
"'",
"'",
")",
">=",
"0",
"||",
"new",
"File",
"(",
"include",
")",
".",
"isFile",
"(",
")",
")",
"{",
"baseDir",
"=",
"new",
"File",
"(",
"tmpBase",
")",
";",
"include",
"=",
"tmpInclude",
";",
"}",
"else",
"{",
"baseDir",
"=",
"new",
"File",
"(",
"tmpBase",
",",
"tmpInclude",
")",
";",
"include",
"=",
"\"**/*\"",
";",
"}",
"scanner",
".",
"setBasedir",
"(",
"baseDir",
")",
";",
"final",
"String",
"[",
"]",
"includes",
"=",
"{",
"include",
"}",
";",
"scanner",
".",
"setIncludes",
"(",
"includes",
")",
";",
"scanner",
".",
"setMaxLevelsOfSymlinks",
"(",
"symLinkDepth",
")",
";",
"if",
"(",
"symLinkDepth",
"<=",
"0",
")",
"{",
"scanner",
".",
"setFollowSymlinks",
"(",
"false",
")",
";",
"}",
"if",
"(",
"excludes",
"!=",
"null",
"&&",
"excludes",
".",
"length",
">",
"0",
")",
"{",
"scanner",
".",
"addExcludes",
"(",
"excludes",
")",
";",
"}",
"scanner",
".",
"scan",
"(",
")",
";",
"if",
"(",
"scanner",
".",
"getIncludedFilesCount",
"(",
")",
">",
"0",
")",
"{",
"for",
"(",
"String",
"s",
":",
"scanner",
".",
"getIncludedFiles",
"(",
")",
")",
"{",
"final",
"File",
"f",
"=",
"new",
"File",
"(",
"baseDir",
",",
"s",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"Found file {}\"",
",",
"f",
".",
"toString",
"(",
")",
")",
";",
"paths",
".",
"add",
"(",
"f",
")",
";",
"}",
"}",
"}",
"return",
"paths",
";",
"}"
] |
Scans the give Ant Style paths and collects the actual files.
@param antStylePaths a list of ant style paths to scan for actual files
@param symLinkDepth the depth to traverse symbolic links
@param excludes an array of ant style excludes
@return returns the set of identified files
|
[
"Scans",
"the",
"give",
"Ant",
"Style",
"paths",
"and",
"collects",
"the",
"actual",
"files",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/App.java#L317-L356
|
17,808
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/App.java
|
App.getPaths
|
private List<String> getPaths(String[] files) {
final List<String> antStylePaths = new ArrayList<>();
for (String file : files) {
final String antPath = ensureCanonicalPath(file);
antStylePaths.add(antPath);
}
return antStylePaths;
}
|
java
|
private List<String> getPaths(String[] files) {
final List<String> antStylePaths = new ArrayList<>();
for (String file : files) {
final String antPath = ensureCanonicalPath(file);
antStylePaths.add(antPath);
}
return antStylePaths;
}
|
[
"private",
"List",
"<",
"String",
">",
"getPaths",
"(",
"String",
"[",
"]",
"files",
")",
"{",
"final",
"List",
"<",
"String",
">",
"antStylePaths",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"String",
"file",
":",
"files",
")",
"{",
"final",
"String",
"antPath",
"=",
"ensureCanonicalPath",
"(",
"file",
")",
";",
"antStylePaths",
".",
"add",
"(",
"antPath",
")",
";",
"}",
"return",
"antStylePaths",
";",
"}"
] |
Determines the ant style paths from the given array of files.
@param files an array of file paths
@return a list containing ant style paths
|
[
"Determines",
"the",
"ant",
"style",
"paths",
"from",
"the",
"given",
"array",
"of",
"files",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/App.java#L364-L371
|
17,809
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/App.java
|
App.prepareLogger
|
private void prepareLogger(String verboseLog) {
final StaticLoggerBinder loggerBinder = StaticLoggerBinder.getSingleton();
final LoggerContext context = (LoggerContext) loggerBinder.getLoggerFactory();
final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setPattern("%d %C:%L%n%-5level - %msg%n");
encoder.setContext(context);
encoder.start();
final FileAppender<ILoggingEvent> fa = new FileAppender<>();
fa.setAppend(true);
fa.setEncoder(encoder);
fa.setContext(context);
fa.setFile(verboseLog);
final File f = new File(verboseLog);
String name = f.getName();
final int i = name.lastIndexOf('.');
if (i > 1) {
name = name.substring(0, i);
}
fa.setName(name);
fa.start();
final ch.qos.logback.classic.Logger rootLogger = context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
rootLogger.setLevel(Level.DEBUG);
final ThresholdFilter filter = new ThresholdFilter();
filter.setLevel(LogLevel.INFO.getValue());
filter.setContext(context);
filter.start();
rootLogger.iteratorForAppenders().forEachRemaining(action -> {
action.addFilter(filter);
});
rootLogger.addAppender(fa);
}
|
java
|
private void prepareLogger(String verboseLog) {
final StaticLoggerBinder loggerBinder = StaticLoggerBinder.getSingleton();
final LoggerContext context = (LoggerContext) loggerBinder.getLoggerFactory();
final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setPattern("%d %C:%L%n%-5level - %msg%n");
encoder.setContext(context);
encoder.start();
final FileAppender<ILoggingEvent> fa = new FileAppender<>();
fa.setAppend(true);
fa.setEncoder(encoder);
fa.setContext(context);
fa.setFile(verboseLog);
final File f = new File(verboseLog);
String name = f.getName();
final int i = name.lastIndexOf('.');
if (i > 1) {
name = name.substring(0, i);
}
fa.setName(name);
fa.start();
final ch.qos.logback.classic.Logger rootLogger = context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
rootLogger.setLevel(Level.DEBUG);
final ThresholdFilter filter = new ThresholdFilter();
filter.setLevel(LogLevel.INFO.getValue());
filter.setContext(context);
filter.start();
rootLogger.iteratorForAppenders().forEachRemaining(action -> {
action.addFilter(filter);
});
rootLogger.addAppender(fa);
}
|
[
"private",
"void",
"prepareLogger",
"(",
"String",
"verboseLog",
")",
"{",
"final",
"StaticLoggerBinder",
"loggerBinder",
"=",
"StaticLoggerBinder",
".",
"getSingleton",
"(",
")",
";",
"final",
"LoggerContext",
"context",
"=",
"(",
"LoggerContext",
")",
"loggerBinder",
".",
"getLoggerFactory",
"(",
")",
";",
"final",
"PatternLayoutEncoder",
"encoder",
"=",
"new",
"PatternLayoutEncoder",
"(",
")",
";",
"encoder",
".",
"setPattern",
"(",
"\"%d %C:%L%n%-5level - %msg%n\"",
")",
";",
"encoder",
".",
"setContext",
"(",
"context",
")",
";",
"encoder",
".",
"start",
"(",
")",
";",
"final",
"FileAppender",
"<",
"ILoggingEvent",
">",
"fa",
"=",
"new",
"FileAppender",
"<>",
"(",
")",
";",
"fa",
".",
"setAppend",
"(",
"true",
")",
";",
"fa",
".",
"setEncoder",
"(",
"encoder",
")",
";",
"fa",
".",
"setContext",
"(",
"context",
")",
";",
"fa",
".",
"setFile",
"(",
"verboseLog",
")",
";",
"final",
"File",
"f",
"=",
"new",
"File",
"(",
"verboseLog",
")",
";",
"String",
"name",
"=",
"f",
".",
"getName",
"(",
")",
";",
"final",
"int",
"i",
"=",
"name",
".",
"lastIndexOf",
"(",
"'",
"'",
")",
";",
"if",
"(",
"i",
">",
"1",
")",
"{",
"name",
"=",
"name",
".",
"substring",
"(",
"0",
",",
"i",
")",
";",
"}",
"fa",
".",
"setName",
"(",
"name",
")",
";",
"fa",
".",
"start",
"(",
")",
";",
"final",
"ch",
".",
"qos",
".",
"logback",
".",
"classic",
".",
"Logger",
"rootLogger",
"=",
"context",
".",
"getLogger",
"(",
"ch",
".",
"qos",
".",
"logback",
".",
"classic",
".",
"Logger",
".",
"ROOT_LOGGER_NAME",
")",
";",
"rootLogger",
".",
"setLevel",
"(",
"Level",
".",
"DEBUG",
")",
";",
"final",
"ThresholdFilter",
"filter",
"=",
"new",
"ThresholdFilter",
"(",
")",
";",
"filter",
".",
"setLevel",
"(",
"LogLevel",
".",
"INFO",
".",
"getValue",
"(",
")",
")",
";",
"filter",
".",
"setContext",
"(",
"context",
")",
";",
"filter",
".",
"start",
"(",
")",
";",
"rootLogger",
".",
"iteratorForAppenders",
"(",
")",
".",
"forEachRemaining",
"(",
"action",
"->",
"{",
"action",
".",
"addFilter",
"(",
"filter",
")",
";",
"}",
")",
";",
"rootLogger",
".",
"addAppender",
"(",
"fa",
")",
";",
"}"
] |
Creates a file appender and adds it to logback.
@param verboseLog the path to the verbose log file
|
[
"Creates",
"a",
"file",
"appender",
"and",
"adds",
"it",
"to",
"logback",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/App.java#L523-L554
|
17,810
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/App.java
|
App.getLastFileSeparator
|
private int getLastFileSeparator(String file) {
if (file.contains("*") || file.contains("?")) {
int p1 = file.indexOf('*');
int p2 = file.indexOf('?');
p1 = p1 > 0 ? p1 : file.length();
p2 = p2 > 0 ? p2 : file.length();
int pos = p1 < p2 ? p1 : p2;
pos = file.lastIndexOf('/', pos);
return pos;
} else {
return file.lastIndexOf('/');
}
}
|
java
|
private int getLastFileSeparator(String file) {
if (file.contains("*") || file.contains("?")) {
int p1 = file.indexOf('*');
int p2 = file.indexOf('?');
p1 = p1 > 0 ? p1 : file.length();
p2 = p2 > 0 ? p2 : file.length();
int pos = p1 < p2 ? p1 : p2;
pos = file.lastIndexOf('/', pos);
return pos;
} else {
return file.lastIndexOf('/');
}
}
|
[
"private",
"int",
"getLastFileSeparator",
"(",
"String",
"file",
")",
"{",
"if",
"(",
"file",
".",
"contains",
"(",
"\"*\"",
")",
"||",
"file",
".",
"contains",
"(",
"\"?\"",
")",
")",
"{",
"int",
"p1",
"=",
"file",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"int",
"p2",
"=",
"file",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"p1",
"=",
"p1",
">",
"0",
"?",
"p1",
":",
"file",
".",
"length",
"(",
")",
";",
"p2",
"=",
"p2",
">",
"0",
"?",
"p2",
":",
"file",
".",
"length",
"(",
")",
";",
"int",
"pos",
"=",
"p1",
"<",
"p2",
"?",
"p1",
":",
"p2",
";",
"pos",
"=",
"file",
".",
"lastIndexOf",
"(",
"'",
"'",
",",
"pos",
")",
";",
"return",
"pos",
";",
"}",
"else",
"{",
"return",
"file",
".",
"lastIndexOf",
"(",
"'",
"'",
")",
";",
"}",
"}"
] |
Returns the position of the last file separator.
@param file a file path
@return the position of the last file separator
|
[
"Returns",
"the",
"position",
"of",
"the",
"last",
"file",
"separator",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/App.java#L601-L613
|
17,811
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/FileUtils.java
|
FileUtils.createTempDirectory
|
@NotNull
public static File createTempDirectory(@Nullable final File base) throws IOException {
final File tempDir = new File(base, "dctemp" + UUID.randomUUID().toString());
if (tempDir.exists()) {
return createTempDirectory(base);
}
if (!tempDir.mkdirs()) {
throw new IOException("Could not create temp directory `" + tempDir.getAbsolutePath() + "`");
}
LOGGER.debug("Temporary directory is `{}`", tempDir.getAbsolutePath());
return tempDir;
}
|
java
|
@NotNull
public static File createTempDirectory(@Nullable final File base) throws IOException {
final File tempDir = new File(base, "dctemp" + UUID.randomUUID().toString());
if (tempDir.exists()) {
return createTempDirectory(base);
}
if (!tempDir.mkdirs()) {
throw new IOException("Could not create temp directory `" + tempDir.getAbsolutePath() + "`");
}
LOGGER.debug("Temporary directory is `{}`", tempDir.getAbsolutePath());
return tempDir;
}
|
[
"@",
"NotNull",
"public",
"static",
"File",
"createTempDirectory",
"(",
"@",
"Nullable",
"final",
"File",
"base",
")",
"throws",
"IOException",
"{",
"final",
"File",
"tempDir",
"=",
"new",
"File",
"(",
"base",
",",
"\"dctemp\"",
"+",
"UUID",
".",
"randomUUID",
"(",
")",
".",
"toString",
"(",
")",
")",
";",
"if",
"(",
"tempDir",
".",
"exists",
"(",
")",
")",
"{",
"return",
"createTempDirectory",
"(",
"base",
")",
";",
"}",
"if",
"(",
"!",
"tempDir",
".",
"mkdirs",
"(",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Could not create temp directory `\"",
"+",
"tempDir",
".",
"getAbsolutePath",
"(",
")",
"+",
"\"`\"",
")",
";",
"}",
"LOGGER",
".",
"debug",
"(",
"\"Temporary directory is `{}`\"",
",",
"tempDir",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"return",
"tempDir",
";",
"}"
] |
Creates a unique temporary directory in the given directory.
@param base the base directory to create a temporary directory within
@return the temporary directory
@throws java.io.IOException thrown when a directory cannot be created
within the base directory
|
[
"Creates",
"a",
"unique",
"temporary",
"directory",
"in",
"the",
"given",
"directory",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/FileUtils.java#L108-L119
|
17,812
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/FileUtils.java
|
FileUtils.getResourceAsFile
|
public static File getResourceAsFile(final String resource) {
final ClassLoader classLoader = FileUtils.class.getClassLoader();
final String path = classLoader != null
? classLoader.getResource(resource).getFile()
: ClassLoader.getSystemResource(resource).getFile();
if (path == null) {
return new File(resource);
}
return new File(path);
}
|
java
|
public static File getResourceAsFile(final String resource) {
final ClassLoader classLoader = FileUtils.class.getClassLoader();
final String path = classLoader != null
? classLoader.getResource(resource).getFile()
: ClassLoader.getSystemResource(resource).getFile();
if (path == null) {
return new File(resource);
}
return new File(path);
}
|
[
"public",
"static",
"File",
"getResourceAsFile",
"(",
"final",
"String",
"resource",
")",
"{",
"final",
"ClassLoader",
"classLoader",
"=",
"FileUtils",
".",
"class",
".",
"getClassLoader",
"(",
")",
";",
"final",
"String",
"path",
"=",
"classLoader",
"!=",
"null",
"?",
"classLoader",
".",
"getResource",
"(",
"resource",
")",
".",
"getFile",
"(",
")",
":",
"ClassLoader",
".",
"getSystemResource",
"(",
"resource",
")",
".",
"getFile",
"(",
")",
";",
"if",
"(",
"path",
"==",
"null",
")",
"{",
"return",
"new",
"File",
"(",
"resource",
")",
";",
"}",
"return",
"new",
"File",
"(",
"path",
")",
";",
"}"
] |
Returns a File object for the given resource. The resource is attempted
to be loaded from the class loader.
@param resource path
@return the file reference for the resource
|
[
"Returns",
"a",
"File",
"object",
"for",
"the",
"given",
"resource",
".",
"The",
"resource",
"is",
"attempted",
"to",
"be",
"loaded",
"from",
"the",
"class",
"loader",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/FileUtils.java#L178-L188
|
17,813
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java
|
Settings.initialize
|
private void initialize(@NotNull final String propertiesFilePath) {
props = new Properties();
try (InputStream in = FileUtils.getResourceAsStream(propertiesFilePath)) {
props.load(in);
} catch (NullPointerException ex) {
LOGGER.error("Did not find settings file '{}'.", propertiesFilePath);
LOGGER.debug("", ex);
} catch (IOException ex) {
LOGGER.error("Unable to load settings from '{}'.", propertiesFilePath);
LOGGER.debug("", ex);
}
logProperties("Properties loaded", props);
}
|
java
|
private void initialize(@NotNull final String propertiesFilePath) {
props = new Properties();
try (InputStream in = FileUtils.getResourceAsStream(propertiesFilePath)) {
props.load(in);
} catch (NullPointerException ex) {
LOGGER.error("Did not find settings file '{}'.", propertiesFilePath);
LOGGER.debug("", ex);
} catch (IOException ex) {
LOGGER.error("Unable to load settings from '{}'.", propertiesFilePath);
LOGGER.debug("", ex);
}
logProperties("Properties loaded", props);
}
|
[
"private",
"void",
"initialize",
"(",
"@",
"NotNull",
"final",
"String",
"propertiesFilePath",
")",
"{",
"props",
"=",
"new",
"Properties",
"(",
")",
";",
"try",
"(",
"InputStream",
"in",
"=",
"FileUtils",
".",
"getResourceAsStream",
"(",
"propertiesFilePath",
")",
")",
"{",
"props",
".",
"load",
"(",
"in",
")",
";",
"}",
"catch",
"(",
"NullPointerException",
"ex",
")",
"{",
"LOGGER",
".",
"error",
"(",
"\"Did not find settings file '{}'.\"",
",",
"propertiesFilePath",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"\"",
",",
"ex",
")",
";",
"}",
"catch",
"(",
"IOException",
"ex",
")",
"{",
"LOGGER",
".",
"error",
"(",
"\"Unable to load settings from '{}'.\"",
",",
"propertiesFilePath",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"\"",
",",
"ex",
")",
";",
"}",
"logProperties",
"(",
"\"Properties loaded\"",
",",
"props",
")",
";",
"}"
] |
Initializes the settings object from the given file.
@param propertiesFilePath the path to the settings property file
|
[
"Initializes",
"the",
"settings",
"object",
"from",
"the",
"given",
"file",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java#L593-L605
|
17,814
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java
|
Settings.cleanup
|
public synchronized void cleanup(boolean deleteTemporary) {
if (deleteTemporary && tempDirectory != null && tempDirectory.exists()) {
LOGGER.debug("Deleting ALL temporary files from `{}`", tempDirectory.toString());
FileUtils.delete(tempDirectory);
tempDirectory = null;
}
}
|
java
|
public synchronized void cleanup(boolean deleteTemporary) {
if (deleteTemporary && tempDirectory != null && tempDirectory.exists()) {
LOGGER.debug("Deleting ALL temporary files from `{}`", tempDirectory.toString());
FileUtils.delete(tempDirectory);
tempDirectory = null;
}
}
|
[
"public",
"synchronized",
"void",
"cleanup",
"(",
"boolean",
"deleteTemporary",
")",
"{",
"if",
"(",
"deleteTemporary",
"&&",
"tempDirectory",
"!=",
"null",
"&&",
"tempDirectory",
".",
"exists",
"(",
")",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Deleting ALL temporary files from `{}`\"",
",",
"tempDirectory",
".",
"toString",
"(",
")",
")",
";",
"FileUtils",
".",
"delete",
"(",
"tempDirectory",
")",
";",
"tempDirectory",
"=",
"null",
";",
"}",
"}"
] |
Cleans up resources to prevent memory leaks.
@param deleteTemporary flag indicating whether any temporary directories
generated should be removed
|
[
"Cleans",
"up",
"resources",
"to",
"prevent",
"memory",
"leaks",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java#L620-L626
|
17,815
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java
|
Settings.logProperties
|
private void logProperties(@NotNull final String header, @NotNull final Properties properties) {
if (LOGGER.isDebugEnabled()) {
final StringWriter sw = new StringWriter();
try (final PrintWriter pw = new PrintWriter(sw)) {
pw.format("%s:%n%n", header);
final Enumeration<?> e = properties.propertyNames();
while (e.hasMoreElements()) {
final String key = (String) e.nextElement();
if (key.contains("password")) {
pw.format("%s='*****'%n", key);
} else {
final String value = properties.getProperty(key);
if (value != null) {
pw.format("%s='%s'%n", key, value);
}
}
}
pw.flush();
LOGGER.debug(sw.toString());
}
}
}
|
java
|
private void logProperties(@NotNull final String header, @NotNull final Properties properties) {
if (LOGGER.isDebugEnabled()) {
final StringWriter sw = new StringWriter();
try (final PrintWriter pw = new PrintWriter(sw)) {
pw.format("%s:%n%n", header);
final Enumeration<?> e = properties.propertyNames();
while (e.hasMoreElements()) {
final String key = (String) e.nextElement();
if (key.contains("password")) {
pw.format("%s='*****'%n", key);
} else {
final String value = properties.getProperty(key);
if (value != null) {
pw.format("%s='%s'%n", key, value);
}
}
}
pw.flush();
LOGGER.debug(sw.toString());
}
}
}
|
[
"private",
"void",
"logProperties",
"(",
"@",
"NotNull",
"final",
"String",
"header",
",",
"@",
"NotNull",
"final",
"Properties",
"properties",
")",
"{",
"if",
"(",
"LOGGER",
".",
"isDebugEnabled",
"(",
")",
")",
"{",
"final",
"StringWriter",
"sw",
"=",
"new",
"StringWriter",
"(",
")",
";",
"try",
"(",
"final",
"PrintWriter",
"pw",
"=",
"new",
"PrintWriter",
"(",
"sw",
")",
")",
"{",
"pw",
".",
"format",
"(",
"\"%s:%n%n\"",
",",
"header",
")",
";",
"final",
"Enumeration",
"<",
"?",
">",
"e",
"=",
"properties",
".",
"propertyNames",
"(",
")",
";",
"while",
"(",
"e",
".",
"hasMoreElements",
"(",
")",
")",
"{",
"final",
"String",
"key",
"=",
"(",
"String",
")",
"e",
".",
"nextElement",
"(",
")",
";",
"if",
"(",
"key",
".",
"contains",
"(",
"\"password\"",
")",
")",
"{",
"pw",
".",
"format",
"(",
"\"%s='*****'%n\"",
",",
"key",
")",
";",
"}",
"else",
"{",
"final",
"String",
"value",
"=",
"properties",
".",
"getProperty",
"(",
"key",
")",
";",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"pw",
".",
"format",
"(",
"\"%s='%s'%n\"",
",",
"key",
",",
"value",
")",
";",
"}",
"}",
"}",
"pw",
".",
"flush",
"(",
")",
";",
"LOGGER",
".",
"debug",
"(",
"sw",
".",
"toString",
"(",
")",
")",
";",
"}",
"}",
"}"
] |
Logs the properties. This will not log any properties that contain
'password' in the key.
@param header the header to print with the log message
@param properties the properties to log
|
[
"Logs",
"the",
"properties",
".",
"This",
"will",
"not",
"log",
"any",
"properties",
"that",
"contain",
"password",
"in",
"the",
"key",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java#L635-L657
|
17,816
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java
|
Settings.setStringIfNotEmpty
|
public void setStringIfNotEmpty(@NotNull final String key, @Nullable final String value) {
if (null != value && !value.isEmpty()) {
setString(key, value);
}
}
|
java
|
public void setStringIfNotEmpty(@NotNull final String key, @Nullable final String value) {
if (null != value && !value.isEmpty()) {
setString(key, value);
}
}
|
[
"public",
"void",
"setStringIfNotEmpty",
"(",
"@",
"NotNull",
"final",
"String",
"key",
",",
"@",
"Nullable",
"final",
"String",
"value",
")",
"{",
"if",
"(",
"null",
"!=",
"value",
"&&",
"!",
"value",
".",
"isEmpty",
"(",
")",
")",
"{",
"setString",
"(",
"key",
",",
"value",
")",
";",
"}",
"}"
] |
Sets a property value only if the value is not null and not empty.
@param key the key for the property
@param value the value for the property
|
[
"Sets",
"a",
"property",
"value",
"only",
"if",
"the",
"value",
"is",
"not",
"null",
"and",
"not",
"empty",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java#L688-L692
|
17,817
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java
|
Settings.getJarPath
|
private File getJarPath() {
String decodedPath = ".";
String jarPath = "";
final ProtectionDomain domain = Settings.class.getProtectionDomain();
if (domain != null && domain.getCodeSource() != null && domain.getCodeSource().getLocation() != null) {
jarPath = Settings.class.getProtectionDomain().getCodeSource().getLocation().getPath();
}
try {
decodedPath = URLDecoder.decode(jarPath, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException ex) {
LOGGER.trace("", ex);
}
final File path = new File(decodedPath);
if (path.getName().toLowerCase().endsWith(".jar")) {
return path.getParentFile();
} else {
return new File(".");
}
}
|
java
|
private File getJarPath() {
String decodedPath = ".";
String jarPath = "";
final ProtectionDomain domain = Settings.class.getProtectionDomain();
if (domain != null && domain.getCodeSource() != null && domain.getCodeSource().getLocation() != null) {
jarPath = Settings.class.getProtectionDomain().getCodeSource().getLocation().getPath();
}
try {
decodedPath = URLDecoder.decode(jarPath, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException ex) {
LOGGER.trace("", ex);
}
final File path = new File(decodedPath);
if (path.getName().toLowerCase().endsWith(".jar")) {
return path.getParentFile();
} else {
return new File(".");
}
}
|
[
"private",
"File",
"getJarPath",
"(",
")",
"{",
"String",
"decodedPath",
"=",
"\".\"",
";",
"String",
"jarPath",
"=",
"\"\"",
";",
"final",
"ProtectionDomain",
"domain",
"=",
"Settings",
".",
"class",
".",
"getProtectionDomain",
"(",
")",
";",
"if",
"(",
"domain",
"!=",
"null",
"&&",
"domain",
".",
"getCodeSource",
"(",
")",
"!=",
"null",
"&&",
"domain",
".",
"getCodeSource",
"(",
")",
".",
"getLocation",
"(",
")",
"!=",
"null",
")",
"{",
"jarPath",
"=",
"Settings",
".",
"class",
".",
"getProtectionDomain",
"(",
")",
".",
"getCodeSource",
"(",
")",
".",
"getLocation",
"(",
")",
".",
"getPath",
"(",
")",
";",
"}",
"try",
"{",
"decodedPath",
"=",
"URLDecoder",
".",
"decode",
"(",
"jarPath",
",",
"StandardCharsets",
".",
"UTF_8",
".",
"name",
"(",
")",
")",
";",
"}",
"catch",
"(",
"UnsupportedEncodingException",
"ex",
")",
"{",
"LOGGER",
".",
"trace",
"(",
"\"\"",
",",
"ex",
")",
";",
"}",
"final",
"File",
"path",
"=",
"new",
"File",
"(",
"decodedPath",
")",
";",
"if",
"(",
"path",
".",
"getName",
"(",
")",
".",
"toLowerCase",
"(",
")",
".",
"endsWith",
"(",
"\".jar\"",
")",
")",
"{",
"return",
"path",
".",
"getParentFile",
"(",
")",
";",
"}",
"else",
"{",
"return",
"new",
"File",
"(",
"\".\"",
")",
";",
"}",
"}"
] |
Attempts to retrieve the folder containing the Jar file containing the
Settings class.
@return a File object
|
[
"Attempts",
"to",
"retrieve",
"the",
"folder",
"containing",
"the",
"Jar",
"file",
"containing",
"the",
"Settings",
"class",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java#L871-L890
|
17,818
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java
|
Settings.getTempDirectory
|
public synchronized File getTempDirectory() throws IOException {
if (tempDirectory == null) {
final File baseTemp = new File(getString(Settings.KEYS.TEMP_DIRECTORY, System.getProperty("java.io.tmpdir")));
tempDirectory = FileUtils.createTempDirectory(baseTemp);
}
return tempDirectory;
}
|
java
|
public synchronized File getTempDirectory() throws IOException {
if (tempDirectory == null) {
final File baseTemp = new File(getString(Settings.KEYS.TEMP_DIRECTORY, System.getProperty("java.io.tmpdir")));
tempDirectory = FileUtils.createTempDirectory(baseTemp);
}
return tempDirectory;
}
|
[
"public",
"synchronized",
"File",
"getTempDirectory",
"(",
")",
"throws",
"IOException",
"{",
"if",
"(",
"tempDirectory",
"==",
"null",
")",
"{",
"final",
"File",
"baseTemp",
"=",
"new",
"File",
"(",
"getString",
"(",
"Settings",
".",
"KEYS",
".",
"TEMP_DIRECTORY",
",",
"System",
".",
"getProperty",
"(",
"\"java.io.tmpdir\"",
")",
")",
")",
";",
"tempDirectory",
"=",
"FileUtils",
".",
"createTempDirectory",
"(",
"baseTemp",
")",
";",
"}",
"return",
"tempDirectory",
";",
"}"
] |
Returns the temporary directory.
@return the temporary directory
@throws java.io.IOException if any.
|
[
"Returns",
"the",
"temporary",
"directory",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java#L912-L918
|
17,819
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java
|
Settings.getArray
|
public String[] getArray(@NotNull final String key) {
final String string = getString(key);
if (string != null) {
if (string.charAt(0) == '{' || string.charAt(0) == '[') {
return new Gson().fromJson(string, String[].class);
} else {
return string.split(ARRAY_SEP);
}
}
return null;
}
|
java
|
public String[] getArray(@NotNull final String key) {
final String string = getString(key);
if (string != null) {
if (string.charAt(0) == '{' || string.charAt(0) == '[') {
return new Gson().fromJson(string, String[].class);
} else {
return string.split(ARRAY_SEP);
}
}
return null;
}
|
[
"public",
"String",
"[",
"]",
"getArray",
"(",
"@",
"NotNull",
"final",
"String",
"key",
")",
"{",
"final",
"String",
"string",
"=",
"getString",
"(",
"key",
")",
";",
"if",
"(",
"string",
"!=",
"null",
")",
"{",
"if",
"(",
"string",
".",
"charAt",
"(",
"0",
")",
"==",
"'",
"'",
"||",
"string",
".",
"charAt",
"(",
"0",
")",
"==",
"'",
"'",
")",
"{",
"return",
"new",
"Gson",
"(",
")",
".",
"fromJson",
"(",
"string",
",",
"String",
"[",
"]",
".",
"class",
")",
";",
"}",
"else",
"{",
"return",
"string",
".",
"split",
"(",
"ARRAY_SEP",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns a list with the given key.
If the property is not set then {@code null} will be returned.
@param key the key to get from this
{@link org.owasp.dependencycheck.utils.Settings}.
@return the list or {@code null} if the key wasn't present.
|
[
"Returns",
"a",
"list",
"with",
"the",
"given",
"key",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java#L942-L952
|
17,820
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java
|
Settings.getLong
|
public long getLong(@NotNull final String key) throws InvalidSettingException {
try {
return Long.parseLong(getString(key));
} catch (NumberFormatException ex) {
throw new InvalidSettingException("Could not convert property '" + key + "' to a long.", ex);
}
}
|
java
|
public long getLong(@NotNull final String key) throws InvalidSettingException {
try {
return Long.parseLong(getString(key));
} catch (NumberFormatException ex) {
throw new InvalidSettingException("Could not convert property '" + key + "' to a long.", ex);
}
}
|
[
"public",
"long",
"getLong",
"(",
"@",
"NotNull",
"final",
"String",
"key",
")",
"throws",
"InvalidSettingException",
"{",
"try",
"{",
"return",
"Long",
".",
"parseLong",
"(",
"getString",
"(",
"key",
")",
")",
";",
"}",
"catch",
"(",
"NumberFormatException",
"ex",
")",
"{",
"throw",
"new",
"InvalidSettingException",
"(",
"\"Could not convert property '\"",
"+",
"key",
"+",
"\"' to a long.\"",
",",
"ex",
")",
";",
"}",
"}"
] |
Returns a long value from the properties file. If the value was specified
as a system property or passed in via the -Dprop=value argument - this
method will return the value from the system properties before the values
in the contained configuration file.
@param key the key to lookup within the properties file
@return the property from the properties file
@throws org.owasp.dependencycheck.utils.InvalidSettingException is thrown
if there is an error retrieving the setting
|
[
"Returns",
"a",
"long",
"value",
"from",
"the",
"properties",
"file",
".",
"If",
"the",
"value",
"was",
"specified",
"as",
"a",
"system",
"property",
"or",
"passed",
"in",
"via",
"the",
"-",
"Dprop",
"=",
"value",
"argument",
"-",
"this",
"method",
"will",
"return",
"the",
"value",
"from",
"the",
"system",
"properties",
"before",
"the",
"values",
"in",
"the",
"contained",
"configuration",
"file",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java#L1018-L1024
|
17,821
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java
|
Settings.getConnectionString
|
public String getConnectionString(String connectionStringKey, String dbFileNameKey)
throws IOException, InvalidSettingException {
final String connStr = getString(connectionStringKey);
if (connStr == null) {
final String msg = String.format("Invalid properties file; %s is missing.", connectionStringKey);
throw new InvalidSettingException(msg);
}
if (connStr.contains("%s")) {
final File directory = getH2DataDirectory();
LOGGER.debug("Data directory: {}", directory);
String fileName = null;
if (dbFileNameKey != null) {
fileName = getString(dbFileNameKey);
}
if (fileName == null) {
final String msg = String.format("Invalid properties file to get a file based connection string; '%s' must be defined.",
dbFileNameKey);
throw new InvalidSettingException(msg);
}
if (connStr.startsWith("jdbc:h2:file:") && fileName.endsWith(".mv.db")) {
fileName = fileName.substring(0, fileName.length() - 6);
}
// yes, for H2 this path won't actually exists - but this is sufficient to get the value needed
final File dbFile = new File(directory, fileName);
final String cString = String.format(connStr, dbFile.getCanonicalPath());
LOGGER.debug("Connection String: '{}'", cString);
return cString;
}
return connStr;
}
|
java
|
public String getConnectionString(String connectionStringKey, String dbFileNameKey)
throws IOException, InvalidSettingException {
final String connStr = getString(connectionStringKey);
if (connStr == null) {
final String msg = String.format("Invalid properties file; %s is missing.", connectionStringKey);
throw new InvalidSettingException(msg);
}
if (connStr.contains("%s")) {
final File directory = getH2DataDirectory();
LOGGER.debug("Data directory: {}", directory);
String fileName = null;
if (dbFileNameKey != null) {
fileName = getString(dbFileNameKey);
}
if (fileName == null) {
final String msg = String.format("Invalid properties file to get a file based connection string; '%s' must be defined.",
dbFileNameKey);
throw new InvalidSettingException(msg);
}
if (connStr.startsWith("jdbc:h2:file:") && fileName.endsWith(".mv.db")) {
fileName = fileName.substring(0, fileName.length() - 6);
}
// yes, for H2 this path won't actually exists - but this is sufficient to get the value needed
final File dbFile = new File(directory, fileName);
final String cString = String.format(connStr, dbFile.getCanonicalPath());
LOGGER.debug("Connection String: '{}'", cString);
return cString;
}
return connStr;
}
|
[
"public",
"String",
"getConnectionString",
"(",
"String",
"connectionStringKey",
",",
"String",
"dbFileNameKey",
")",
"throws",
"IOException",
",",
"InvalidSettingException",
"{",
"final",
"String",
"connStr",
"=",
"getString",
"(",
"connectionStringKey",
")",
";",
"if",
"(",
"connStr",
"==",
"null",
")",
"{",
"final",
"String",
"msg",
"=",
"String",
".",
"format",
"(",
"\"Invalid properties file; %s is missing.\"",
",",
"connectionStringKey",
")",
";",
"throw",
"new",
"InvalidSettingException",
"(",
"msg",
")",
";",
"}",
"if",
"(",
"connStr",
".",
"contains",
"(",
"\"%s\"",
")",
")",
"{",
"final",
"File",
"directory",
"=",
"getH2DataDirectory",
"(",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"Data directory: {}\"",
",",
"directory",
")",
";",
"String",
"fileName",
"=",
"null",
";",
"if",
"(",
"dbFileNameKey",
"!=",
"null",
")",
"{",
"fileName",
"=",
"getString",
"(",
"dbFileNameKey",
")",
";",
"}",
"if",
"(",
"fileName",
"==",
"null",
")",
"{",
"final",
"String",
"msg",
"=",
"String",
".",
"format",
"(",
"\"Invalid properties file to get a file based connection string; '%s' must be defined.\"",
",",
"dbFileNameKey",
")",
";",
"throw",
"new",
"InvalidSettingException",
"(",
"msg",
")",
";",
"}",
"if",
"(",
"connStr",
".",
"startsWith",
"(",
"\"jdbc:h2:file:\"",
")",
"&&",
"fileName",
".",
"endsWith",
"(",
"\".mv.db\"",
")",
")",
"{",
"fileName",
"=",
"fileName",
".",
"substring",
"(",
"0",
",",
"fileName",
".",
"length",
"(",
")",
"-",
"6",
")",
";",
"}",
"// yes, for H2 this path won't actually exists - but this is sufficient to get the value needed",
"final",
"File",
"dbFile",
"=",
"new",
"File",
"(",
"directory",
",",
"fileName",
")",
";",
"final",
"String",
"cString",
"=",
"String",
".",
"format",
"(",
"connStr",
",",
"dbFile",
".",
"getCanonicalPath",
"(",
")",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"Connection String: '{}'\"",
",",
"cString",
")",
";",
"return",
"cString",
";",
"}",
"return",
"connStr",
";",
"}"
] |
Returns a connection string from the configured properties. If the
connection string contains a %s, this method will determine the 'data'
directory and replace the %s with the path to the data directory. If the
data directory does not exist it will be created.
@param connectionStringKey the property file key for the connection
string
@param dbFileNameKey the settings key for the db filename
@return the connection string
@throws IOException thrown the data directory cannot be created
@throws InvalidSettingException thrown if there is an invalid setting
|
[
"Returns",
"a",
"connection",
"string",
"from",
"the",
"configured",
"properties",
".",
"If",
"the",
"connection",
"string",
"contains",
"a",
"%s",
"this",
"method",
"will",
"determine",
"the",
"data",
"directory",
"and",
"replace",
"the",
"%s",
"with",
"the",
"path",
"to",
"the",
"data",
"directory",
".",
"If",
"the",
"data",
"directory",
"does",
"not",
"exist",
"it",
"will",
"be",
"created",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java#L1095-L1124
|
17,822
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java
|
Settings.getDataDirectory
|
public File getDataDirectory() throws IOException {
final File path = getDataFile(Settings.KEYS.DATA_DIRECTORY);
if (path != null && (path.exists() || path.mkdirs())) {
return path;
}
throw new IOException(String.format("Unable to create the data directory '%s'",
(path == null) ? "unknown" : path.getAbsolutePath()));
}
|
java
|
public File getDataDirectory() throws IOException {
final File path = getDataFile(Settings.KEYS.DATA_DIRECTORY);
if (path != null && (path.exists() || path.mkdirs())) {
return path;
}
throw new IOException(String.format("Unable to create the data directory '%s'",
(path == null) ? "unknown" : path.getAbsolutePath()));
}
|
[
"public",
"File",
"getDataDirectory",
"(",
")",
"throws",
"IOException",
"{",
"final",
"File",
"path",
"=",
"getDataFile",
"(",
"Settings",
".",
"KEYS",
".",
"DATA_DIRECTORY",
")",
";",
"if",
"(",
"path",
"!=",
"null",
"&&",
"(",
"path",
".",
"exists",
"(",
")",
"||",
"path",
".",
"mkdirs",
"(",
")",
")",
")",
"{",
"return",
"path",
";",
"}",
"throw",
"new",
"IOException",
"(",
"String",
".",
"format",
"(",
"\"Unable to create the data directory '%s'\"",
",",
"(",
"path",
"==",
"null",
")",
"?",
"\"unknown\"",
":",
"path",
".",
"getAbsolutePath",
"(",
")",
")",
")",
";",
"}"
] |
Retrieves the primary data directory that is used for caching web
content.
@return the data directory to store data files
@throws java.io.IOException is thrown if an java.io.IOException occurs of
course...
|
[
"Retrieves",
"the",
"primary",
"data",
"directory",
"that",
"is",
"used",
"for",
"caching",
"web",
"content",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java#L1134-L1141
|
17,823
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java
|
Settings.getH2DataDirectory
|
public File getH2DataDirectory() throws IOException {
final String h2Test = getString(Settings.KEYS.H2_DATA_DIRECTORY);
final File path;
if (h2Test != null && !h2Test.isEmpty()) {
path = getDataFile(Settings.KEYS.H2_DATA_DIRECTORY);
} else {
path = getDataFile(Settings.KEYS.DATA_DIRECTORY);
}
if (path != null && (path.exists() || path.mkdirs())) {
return path;
}
throw new IOException(String.format("Unable to create the h2 data directory '%s'",
(path == null) ? "unknown" : path.getAbsolutePath()));
}
|
java
|
public File getH2DataDirectory() throws IOException {
final String h2Test = getString(Settings.KEYS.H2_DATA_DIRECTORY);
final File path;
if (h2Test != null && !h2Test.isEmpty()) {
path = getDataFile(Settings.KEYS.H2_DATA_DIRECTORY);
} else {
path = getDataFile(Settings.KEYS.DATA_DIRECTORY);
}
if (path != null && (path.exists() || path.mkdirs())) {
return path;
}
throw new IOException(String.format("Unable to create the h2 data directory '%s'",
(path == null) ? "unknown" : path.getAbsolutePath()));
}
|
[
"public",
"File",
"getH2DataDirectory",
"(",
")",
"throws",
"IOException",
"{",
"final",
"String",
"h2Test",
"=",
"getString",
"(",
"Settings",
".",
"KEYS",
".",
"H2_DATA_DIRECTORY",
")",
";",
"final",
"File",
"path",
";",
"if",
"(",
"h2Test",
"!=",
"null",
"&&",
"!",
"h2Test",
".",
"isEmpty",
"(",
")",
")",
"{",
"path",
"=",
"getDataFile",
"(",
"Settings",
".",
"KEYS",
".",
"H2_DATA_DIRECTORY",
")",
";",
"}",
"else",
"{",
"path",
"=",
"getDataFile",
"(",
"Settings",
".",
"KEYS",
".",
"DATA_DIRECTORY",
")",
";",
"}",
"if",
"(",
"path",
"!=",
"null",
"&&",
"(",
"path",
".",
"exists",
"(",
")",
"||",
"path",
".",
"mkdirs",
"(",
")",
")",
")",
"{",
"return",
"path",
";",
"}",
"throw",
"new",
"IOException",
"(",
"String",
".",
"format",
"(",
"\"Unable to create the h2 data directory '%s'\"",
",",
"(",
"path",
"==",
"null",
")",
"?",
"\"unknown\"",
":",
"path",
".",
"getAbsolutePath",
"(",
")",
")",
")",
";",
"}"
] |
Retrieves the H2 data directory - if the database has been moved to the
temp directory this method will return the temp directory.
@return the data directory to store data files
@throws java.io.IOException is thrown if an java.io.IOException occurs of
course...
|
[
"Retrieves",
"the",
"H2",
"data",
"directory",
"-",
"if",
"the",
"database",
"has",
"been",
"moved",
"to",
"the",
"temp",
"directory",
"this",
"method",
"will",
"return",
"the",
"temp",
"directory",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java#L1151-L1164
|
17,824
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java
|
Settings.getTempFile
|
public File getTempFile(@NotNull final String prefix, @NotNull final String extension) throws IOException {
final File dir = getTempDirectory();
final String tempFileName = String.format("%s%s.%s", prefix, UUID.randomUUID().toString(), extension);
final File tempFile = new File(dir, tempFileName);
if (tempFile.exists()) {
return getTempFile(prefix, extension);
}
return tempFile;
}
|
java
|
public File getTempFile(@NotNull final String prefix, @NotNull final String extension) throws IOException {
final File dir = getTempDirectory();
final String tempFileName = String.format("%s%s.%s", prefix, UUID.randomUUID().toString(), extension);
final File tempFile = new File(dir, tempFileName);
if (tempFile.exists()) {
return getTempFile(prefix, extension);
}
return tempFile;
}
|
[
"public",
"File",
"getTempFile",
"(",
"@",
"NotNull",
"final",
"String",
"prefix",
",",
"@",
"NotNull",
"final",
"String",
"extension",
")",
"throws",
"IOException",
"{",
"final",
"File",
"dir",
"=",
"getTempDirectory",
"(",
")",
";",
"final",
"String",
"tempFileName",
"=",
"String",
".",
"format",
"(",
"\"%s%s.%s\"",
",",
"prefix",
",",
"UUID",
".",
"randomUUID",
"(",
")",
".",
"toString",
"(",
")",
",",
"extension",
")",
";",
"final",
"File",
"tempFile",
"=",
"new",
"File",
"(",
"dir",
",",
"tempFileName",
")",
";",
"if",
"(",
"tempFile",
".",
"exists",
"(",
")",
")",
"{",
"return",
"getTempFile",
"(",
"prefix",
",",
"extension",
")",
";",
"}",
"return",
"tempFile",
";",
"}"
] |
Generates a new temporary file name that is guaranteed to be unique.
@param prefix the prefix for the file name to generate
@param extension the extension of the generated file name
@return a temporary File
@throws java.io.IOException if any.
|
[
"Generates",
"a",
"new",
"temporary",
"file",
"name",
"that",
"is",
"guaranteed",
"to",
"be",
"unique",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Settings.java#L1174-L1182
|
17,825
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/FileNameAnalyzer.java
|
FileNameAnalyzer.analyzeDependency
|
@Override
protected void analyzeDependency(Dependency dependency, Engine engine) throws AnalysisException {
//strip any path information that may get added by ArchiveAnalyzer, etc.
final File f = dependency.getActualFile();
final String fileName = FilenameUtils.removeExtension(f.getName());
final String ext = FilenameUtils.getExtension(f.getName());
if (!IGNORED_FILES.accept(f) && !"js".equals(ext)) {
//add version evidence
final DependencyVersion version = DependencyVersionUtil.parseVersion(fileName);
final String packageName = DependencyVersionUtil.parsePreVersion(fileName);
if (version != null) {
// If the version number is just a number like 2 or 23, reduce the confidence
// a shade. This should hopefully correct for cases like log4j.jar or
// struts2-core.jar
if (version.getVersionParts() == null || version.getVersionParts().size() < 2) {
dependency.addEvidence(EvidenceType.VERSION, "file", "version", version.toString(), Confidence.MEDIUM);
} else {
dependency.addEvidence(EvidenceType.VERSION, "file", "version", version.toString(), Confidence.HIGHEST);
}
dependency.addEvidence(EvidenceType.VERSION, "file", "name", packageName, Confidence.MEDIUM);
}
dependency.addEvidence(EvidenceType.PRODUCT, "file", "name", packageName, Confidence.HIGH);
dependency.addEvidence(EvidenceType.VENDOR, "file", "name", packageName, Confidence.HIGH);
}
}
|
java
|
@Override
protected void analyzeDependency(Dependency dependency, Engine engine) throws AnalysisException {
//strip any path information that may get added by ArchiveAnalyzer, etc.
final File f = dependency.getActualFile();
final String fileName = FilenameUtils.removeExtension(f.getName());
final String ext = FilenameUtils.getExtension(f.getName());
if (!IGNORED_FILES.accept(f) && !"js".equals(ext)) {
//add version evidence
final DependencyVersion version = DependencyVersionUtil.parseVersion(fileName);
final String packageName = DependencyVersionUtil.parsePreVersion(fileName);
if (version != null) {
// If the version number is just a number like 2 or 23, reduce the confidence
// a shade. This should hopefully correct for cases like log4j.jar or
// struts2-core.jar
if (version.getVersionParts() == null || version.getVersionParts().size() < 2) {
dependency.addEvidence(EvidenceType.VERSION, "file", "version", version.toString(), Confidence.MEDIUM);
} else {
dependency.addEvidence(EvidenceType.VERSION, "file", "version", version.toString(), Confidence.HIGHEST);
}
dependency.addEvidence(EvidenceType.VERSION, "file", "name", packageName, Confidence.MEDIUM);
}
dependency.addEvidence(EvidenceType.PRODUCT, "file", "name", packageName, Confidence.HIGH);
dependency.addEvidence(EvidenceType.VENDOR, "file", "name", packageName, Confidence.HIGH);
}
}
|
[
"@",
"Override",
"protected",
"void",
"analyzeDependency",
"(",
"Dependency",
"dependency",
",",
"Engine",
"engine",
")",
"throws",
"AnalysisException",
"{",
"//strip any path information that may get added by ArchiveAnalyzer, etc.",
"final",
"File",
"f",
"=",
"dependency",
".",
"getActualFile",
"(",
")",
";",
"final",
"String",
"fileName",
"=",
"FilenameUtils",
".",
"removeExtension",
"(",
"f",
".",
"getName",
"(",
")",
")",
";",
"final",
"String",
"ext",
"=",
"FilenameUtils",
".",
"getExtension",
"(",
"f",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"!",
"IGNORED_FILES",
".",
"accept",
"(",
"f",
")",
"&&",
"!",
"\"js\"",
".",
"equals",
"(",
"ext",
")",
")",
"{",
"//add version evidence",
"final",
"DependencyVersion",
"version",
"=",
"DependencyVersionUtil",
".",
"parseVersion",
"(",
"fileName",
")",
";",
"final",
"String",
"packageName",
"=",
"DependencyVersionUtil",
".",
"parsePreVersion",
"(",
"fileName",
")",
";",
"if",
"(",
"version",
"!=",
"null",
")",
"{",
"// If the version number is just a number like 2 or 23, reduce the confidence",
"// a shade. This should hopefully correct for cases like log4j.jar or",
"// struts2-core.jar",
"if",
"(",
"version",
".",
"getVersionParts",
"(",
")",
"==",
"null",
"||",
"version",
".",
"getVersionParts",
"(",
")",
".",
"size",
"(",
")",
"<",
"2",
")",
"{",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VERSION",
",",
"\"file\"",
",",
"\"version\"",
",",
"version",
".",
"toString",
"(",
")",
",",
"Confidence",
".",
"MEDIUM",
")",
";",
"}",
"else",
"{",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VERSION",
",",
"\"file\"",
",",
"\"version\"",
",",
"version",
".",
"toString",
"(",
")",
",",
"Confidence",
".",
"HIGHEST",
")",
";",
"}",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VERSION",
",",
"\"file\"",
",",
"\"name\"",
",",
"packageName",
",",
"Confidence",
".",
"MEDIUM",
")",
";",
"}",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"PRODUCT",
",",
"\"file\"",
",",
"\"name\"",
",",
"packageName",
",",
"Confidence",
".",
"HIGH",
")",
";",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VENDOR",
",",
"\"file\"",
",",
"\"name\"",
",",
"packageName",
",",
"Confidence",
".",
"HIGH",
")",
";",
"}",
"}"
] |
Collects information about the file name.
@param dependency the dependency to analyze.
@param engine the engine that is scanning the dependencies
@throws AnalysisException is thrown if there is an error reading the JAR
file.
|
[
"Collects",
"information",
"about",
"the",
"file",
"name",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/FileNameAnalyzer.java#L114-L140
|
17,826
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/ArtifactoryAnalyzer.java
|
ArtifactoryAnalyzer.supportsParallelProcessing
|
@Override
public boolean supportsParallelProcessing() {
try {
return getSettings().getBoolean(Settings.KEYS.ANALYZER_ARTIFACTORY_PARALLEL_ANALYSIS, true);
} catch (InvalidSettingException ex) {
LOGGER.debug("Invalid setting for analyzer.artifactory.parallel.analysis; using true.");
}
return true;
}
|
java
|
@Override
public boolean supportsParallelProcessing() {
try {
return getSettings().getBoolean(Settings.KEYS.ANALYZER_ARTIFACTORY_PARALLEL_ANALYSIS, true);
} catch (InvalidSettingException ex) {
LOGGER.debug("Invalid setting for analyzer.artifactory.parallel.analysis; using true.");
}
return true;
}
|
[
"@",
"Override",
"public",
"boolean",
"supportsParallelProcessing",
"(",
")",
"{",
"try",
"{",
"return",
"getSettings",
"(",
")",
".",
"getBoolean",
"(",
"Settings",
".",
"KEYS",
".",
"ANALYZER_ARTIFACTORY_PARALLEL_ANALYSIS",
",",
"true",
")",
";",
"}",
"catch",
"(",
"InvalidSettingException",
"ex",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Invalid setting for analyzer.artifactory.parallel.analysis; using true.\"",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Whether the analyzer is configured to support parallel processing.
@return true if configured to support parallel processing; otherwise
false
|
[
"Whether",
"the",
"analyzer",
"is",
"configured",
"to",
"support",
"parallel",
"processing",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/ArtifactoryAnalyzer.java#L104-L112
|
17,827
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/ArtifactoryAnalyzer.java
|
ArtifactoryAnalyzer.processPom
|
private void processPom(Dependency dependency, MavenArtifact ma) throws IOException, AnalysisException {
File pomFile = null;
try {
final File baseDir = getSettings().getTempDirectory();
pomFile = File.createTempFile("pom", ".xml", baseDir);
Files.delete(pomFile.toPath());
LOGGER.debug("Downloading {}", ma.getPomUrl());
final Downloader downloader = new Downloader(getSettings());
downloader.fetchFile(new URL(ma.getPomUrl()), pomFile);
PomUtils.analyzePOM(dependency, pomFile);
} catch (DownloadFailedException ex) {
LOGGER.warn("Unable to download pom.xml for {} from Artifactory; "
+ "this could result in undetected CPE/CVEs.", dependency.getFileName());
} finally {
if (pomFile != null && pomFile.exists() && !FileUtils.deleteQuietly(pomFile)) {
LOGGER.debug("Failed to delete temporary pom file {}", pomFile);
pomFile.deleteOnExit();
}
}
}
|
java
|
private void processPom(Dependency dependency, MavenArtifact ma) throws IOException, AnalysisException {
File pomFile = null;
try {
final File baseDir = getSettings().getTempDirectory();
pomFile = File.createTempFile("pom", ".xml", baseDir);
Files.delete(pomFile.toPath());
LOGGER.debug("Downloading {}", ma.getPomUrl());
final Downloader downloader = new Downloader(getSettings());
downloader.fetchFile(new URL(ma.getPomUrl()), pomFile);
PomUtils.analyzePOM(dependency, pomFile);
} catch (DownloadFailedException ex) {
LOGGER.warn("Unable to download pom.xml for {} from Artifactory; "
+ "this could result in undetected CPE/CVEs.", dependency.getFileName());
} finally {
if (pomFile != null && pomFile.exists() && !FileUtils.deleteQuietly(pomFile)) {
LOGGER.debug("Failed to delete temporary pom file {}", pomFile);
pomFile.deleteOnExit();
}
}
}
|
[
"private",
"void",
"processPom",
"(",
"Dependency",
"dependency",
",",
"MavenArtifact",
"ma",
")",
"throws",
"IOException",
",",
"AnalysisException",
"{",
"File",
"pomFile",
"=",
"null",
";",
"try",
"{",
"final",
"File",
"baseDir",
"=",
"getSettings",
"(",
")",
".",
"getTempDirectory",
"(",
")",
";",
"pomFile",
"=",
"File",
".",
"createTempFile",
"(",
"\"pom\"",
",",
"\".xml\"",
",",
"baseDir",
")",
";",
"Files",
".",
"delete",
"(",
"pomFile",
".",
"toPath",
"(",
")",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"Downloading {}\"",
",",
"ma",
".",
"getPomUrl",
"(",
")",
")",
";",
"final",
"Downloader",
"downloader",
"=",
"new",
"Downloader",
"(",
"getSettings",
"(",
")",
")",
";",
"downloader",
".",
"fetchFile",
"(",
"new",
"URL",
"(",
"ma",
".",
"getPomUrl",
"(",
")",
")",
",",
"pomFile",
")",
";",
"PomUtils",
".",
"analyzePOM",
"(",
"dependency",
",",
"pomFile",
")",
";",
"}",
"catch",
"(",
"DownloadFailedException",
"ex",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Unable to download pom.xml for {} from Artifactory; \"",
"+",
"\"this could result in undetected CPE/CVEs.\"",
",",
"dependency",
".",
"getFileName",
"(",
")",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"pomFile",
"!=",
"null",
"&&",
"pomFile",
".",
"exists",
"(",
")",
"&&",
"!",
"FileUtils",
".",
"deleteQuietly",
"(",
"pomFile",
")",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Failed to delete temporary pom file {}\"",
",",
"pomFile",
")",
";",
"pomFile",
".",
"deleteOnExit",
"(",
")",
";",
"}",
"}",
"}"
] |
If necessary, downloads the pom.xml from Central and adds the evidence to
the dependency.
@param dependency the dependency to download and process the pom.xml
@param ma the Maven artifact coordinates
@throws IOException thrown if there is an I/O error
@throws AnalysisException thrown if there is an error analyzing the pom
|
[
"If",
"necessary",
"downloads",
"the",
"pom",
".",
"xml",
"from",
"Central",
"and",
"adds",
"the",
"evidence",
"to",
"the",
"dependency",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/ArtifactoryAnalyzer.java#L232-L252
|
17,828
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Downloader.java
|
Downloader.fetchContent
|
public String fetchContent(URL url, boolean useProxy) throws DownloadFailedException {
try (HttpResourceConnection conn = new HttpResourceConnection(settings, useProxy);
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
final InputStream in = conn.fetch(url);
IOUtils.copy(in, out);
return out.toString(UTF8);
} catch (IOException ex) {
final String msg = format("Download failed, unable to retrieve '%s'", url.toString());
throw new DownloadFailedException(msg, ex);
}
}
|
java
|
public String fetchContent(URL url, boolean useProxy) throws DownloadFailedException {
try (HttpResourceConnection conn = new HttpResourceConnection(settings, useProxy);
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
final InputStream in = conn.fetch(url);
IOUtils.copy(in, out);
return out.toString(UTF8);
} catch (IOException ex) {
final String msg = format("Download failed, unable to retrieve '%s'", url.toString());
throw new DownloadFailedException(msg, ex);
}
}
|
[
"public",
"String",
"fetchContent",
"(",
"URL",
"url",
",",
"boolean",
"useProxy",
")",
"throws",
"DownloadFailedException",
"{",
"try",
"(",
"HttpResourceConnection",
"conn",
"=",
"new",
"HttpResourceConnection",
"(",
"settings",
",",
"useProxy",
")",
";",
"ByteArrayOutputStream",
"out",
"=",
"new",
"ByteArrayOutputStream",
"(",
")",
")",
"{",
"final",
"InputStream",
"in",
"=",
"conn",
".",
"fetch",
"(",
"url",
")",
";",
"IOUtils",
".",
"copy",
"(",
"in",
",",
"out",
")",
";",
"return",
"out",
".",
"toString",
"(",
"UTF8",
")",
";",
"}",
"catch",
"(",
"IOException",
"ex",
")",
"{",
"final",
"String",
"msg",
"=",
"format",
"(",
"\"Download failed, unable to retrieve '%s'\"",
",",
"url",
".",
"toString",
"(",
")",
")",
";",
"throw",
"new",
"DownloadFailedException",
"(",
"msg",
",",
"ex",
")",
";",
"}",
"}"
] |
Retrieves a file from a given URL and returns the contents.
@param url the URL of the file to download
@param useProxy whether to use the configured proxy when downloading
files
@return the content of the file
@throws DownloadFailedException is thrown if there is an error
downloading the file
|
[
"Retrieves",
"a",
"file",
"from",
"a",
"given",
"URL",
"and",
"returns",
"the",
"contents",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Downloader.java#L100-L110
|
17,829
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/cwe/App.java
|
App.readCweData
|
private static Map<String, String> readCweData(String[] files) {
try {
final SAXParserFactory factory = SAXParserFactory.newInstance();
final SAXParser saxParser = factory.newSAXParser();
final CweHandler handler = new CweHandler();
for (String f : files) {
final File in = new File(f);
if (!in.isFile()) {
System.err.println(String.format("File not found %s", in));
}
System.out.println(String.format("Parsing %s", in));
saxParser.parse(in, handler);
}
return handler.getCwe();
} catch (SAXException | IOException | ParserConfigurationException ex) {
System.err.println(String.format("Error generating serialized data: %s", ex.getMessage()));
}
return null;
}
|
java
|
private static Map<String, String> readCweData(String[] files) {
try {
final SAXParserFactory factory = SAXParserFactory.newInstance();
final SAXParser saxParser = factory.newSAXParser();
final CweHandler handler = new CweHandler();
for (String f : files) {
final File in = new File(f);
if (!in.isFile()) {
System.err.println(String.format("File not found %s", in));
}
System.out.println(String.format("Parsing %s", in));
saxParser.parse(in, handler);
}
return handler.getCwe();
} catch (SAXException | IOException | ParserConfigurationException ex) {
System.err.println(String.format("Error generating serialized data: %s", ex.getMessage()));
}
return null;
}
|
[
"private",
"static",
"Map",
"<",
"String",
",",
"String",
">",
"readCweData",
"(",
"String",
"[",
"]",
"files",
")",
"{",
"try",
"{",
"final",
"SAXParserFactory",
"factory",
"=",
"SAXParserFactory",
".",
"newInstance",
"(",
")",
";",
"final",
"SAXParser",
"saxParser",
"=",
"factory",
".",
"newSAXParser",
"(",
")",
";",
"final",
"CweHandler",
"handler",
"=",
"new",
"CweHandler",
"(",
")",
";",
"for",
"(",
"String",
"f",
":",
"files",
")",
"{",
"final",
"File",
"in",
"=",
"new",
"File",
"(",
"f",
")",
";",
"if",
"(",
"!",
"in",
".",
"isFile",
"(",
")",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"String",
".",
"format",
"(",
"\"File not found %s\"",
",",
"in",
")",
")",
";",
"}",
"System",
".",
"out",
".",
"println",
"(",
"String",
".",
"format",
"(",
"\"Parsing %s\"",
",",
"in",
")",
")",
";",
"saxParser",
".",
"parse",
"(",
"in",
",",
"handler",
")",
";",
"}",
"return",
"handler",
".",
"getCwe",
"(",
")",
";",
"}",
"catch",
"(",
"SAXException",
"|",
"IOException",
"|",
"ParserConfigurationException",
"ex",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"String",
".",
"format",
"(",
"\"Error generating serialized data: %s\"",
",",
"ex",
".",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Reads the CWE data from the array of files.
@param files the array of files to parse
@return a map of the CWE data
|
[
"Reads",
"the",
"CWE",
"data",
"from",
"the",
"array",
"of",
"files",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/cwe/App.java#L75-L93
|
17,830
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/cwe/App.java
|
App.serializeCweData
|
private static void serializeCweData(Map<String, String> cwe, File out) {
try (FileOutputStream fout = new FileOutputStream(out);
ObjectOutputStream objOut = new ObjectOutputStream(fout);) {
System.out.println("Writing " + cwe.size() + " cwe entries.");
objOut.writeObject(cwe);
System.out.println(String.format("Serialized CWE data written to %s", out.getCanonicalPath()));
System.out.println("To update the ODC CWE data copy the serialized file to 'src/main/resources/data/cwe.hashmap.serialized'");
} catch (IOException ex) {
System.err.println(String.format("Error generating serialized data: %s", ex.getMessage()));
}
}
|
java
|
private static void serializeCweData(Map<String, String> cwe, File out) {
try (FileOutputStream fout = new FileOutputStream(out);
ObjectOutputStream objOut = new ObjectOutputStream(fout);) {
System.out.println("Writing " + cwe.size() + " cwe entries.");
objOut.writeObject(cwe);
System.out.println(String.format("Serialized CWE data written to %s", out.getCanonicalPath()));
System.out.println("To update the ODC CWE data copy the serialized file to 'src/main/resources/data/cwe.hashmap.serialized'");
} catch (IOException ex) {
System.err.println(String.format("Error generating serialized data: %s", ex.getMessage()));
}
}
|
[
"private",
"static",
"void",
"serializeCweData",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"cwe",
",",
"File",
"out",
")",
"{",
"try",
"(",
"FileOutputStream",
"fout",
"=",
"new",
"FileOutputStream",
"(",
"out",
")",
";",
"ObjectOutputStream",
"objOut",
"=",
"new",
"ObjectOutputStream",
"(",
"fout",
")",
";",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Writing \"",
"+",
"cwe",
".",
"size",
"(",
")",
"+",
"\" cwe entries.\"",
")",
";",
"objOut",
".",
"writeObject",
"(",
"cwe",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"String",
".",
"format",
"(",
"\"Serialized CWE data written to %s\"",
",",
"out",
".",
"getCanonicalPath",
"(",
")",
")",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"\"To update the ODC CWE data copy the serialized file to 'src/main/resources/data/cwe.hashmap.serialized'\"",
")",
";",
"}",
"catch",
"(",
"IOException",
"ex",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"String",
".",
"format",
"(",
"\"Error generating serialized data: %s\"",
",",
"ex",
".",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"}"
] |
Writes the map of CWE data to disk.
@param cwe the CWE data
@param out the file output location
|
[
"Writes",
"the",
"map",
"of",
"CWE",
"data",
"to",
"disk",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/cwe/App.java#L101-L111
|
17,831
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/update/NvdCveUpdater.java
|
NvdCveUpdater.isUpdateConfiguredFalse
|
private boolean isUpdateConfiguredFalse() {
try {
if (!settings.getBoolean(Settings.KEYS.UPDATE_NVDCVE_ENABLED, true)) {
return true;
}
} catch (InvalidSettingException ex) {
LOGGER.trace("invalid setting UPDATE_NVDCVE_ENABLED", ex);
}
boolean autoUpdate = true;
try {
autoUpdate = settings.getBoolean(Settings.KEYS.AUTO_UPDATE);
} catch (InvalidSettingException ex) {
LOGGER.debug("Invalid setting for auto-update; using true.");
}
return !autoUpdate;
}
|
java
|
private boolean isUpdateConfiguredFalse() {
try {
if (!settings.getBoolean(Settings.KEYS.UPDATE_NVDCVE_ENABLED, true)) {
return true;
}
} catch (InvalidSettingException ex) {
LOGGER.trace("invalid setting UPDATE_NVDCVE_ENABLED", ex);
}
boolean autoUpdate = true;
try {
autoUpdate = settings.getBoolean(Settings.KEYS.AUTO_UPDATE);
} catch (InvalidSettingException ex) {
LOGGER.debug("Invalid setting for auto-update; using true.");
}
return !autoUpdate;
}
|
[
"private",
"boolean",
"isUpdateConfiguredFalse",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"settings",
".",
"getBoolean",
"(",
"Settings",
".",
"KEYS",
".",
"UPDATE_NVDCVE_ENABLED",
",",
"true",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"catch",
"(",
"InvalidSettingException",
"ex",
")",
"{",
"LOGGER",
".",
"trace",
"(",
"\"invalid setting UPDATE_NVDCVE_ENABLED\"",
",",
"ex",
")",
";",
"}",
"boolean",
"autoUpdate",
"=",
"true",
";",
"try",
"{",
"autoUpdate",
"=",
"settings",
".",
"getBoolean",
"(",
"Settings",
".",
"KEYS",
".",
"AUTO_UPDATE",
")",
";",
"}",
"catch",
"(",
"InvalidSettingException",
"ex",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Invalid setting for auto-update; using true.\"",
")",
";",
"}",
"return",
"!",
"autoUpdate",
";",
"}"
] |
Checks if the system is configured NOT to update.
@return false if the system is configured to perform an update; otherwise
true
|
[
"Checks",
"if",
"the",
"system",
"is",
"configured",
"NOT",
"to",
"update",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/update/NvdCveUpdater.java#L156-L171
|
17,832
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/update/NvdCveUpdater.java
|
NvdCveUpdater.initializeExecutorServices
|
protected void initializeExecutorServices() {
final int downloadPoolSize;
final int max = settings.getInt(Settings.KEYS.MAX_DOWNLOAD_THREAD_POOL_SIZE, 3);
if (DOWNLOAD_THREAD_POOL_SIZE > max) {
downloadPoolSize = max;
} else {
downloadPoolSize = DOWNLOAD_THREAD_POOL_SIZE;
}
downloadExecutorService = Executors.newFixedThreadPool(downloadPoolSize);
processingExecutorService = Executors.newFixedThreadPool(PROCESSING_THREAD_POOL_SIZE);
LOGGER.debug("#download threads: {}", downloadPoolSize);
LOGGER.debug("#processing threads: {}", PROCESSING_THREAD_POOL_SIZE);
}
|
java
|
protected void initializeExecutorServices() {
final int downloadPoolSize;
final int max = settings.getInt(Settings.KEYS.MAX_DOWNLOAD_THREAD_POOL_SIZE, 3);
if (DOWNLOAD_THREAD_POOL_SIZE > max) {
downloadPoolSize = max;
} else {
downloadPoolSize = DOWNLOAD_THREAD_POOL_SIZE;
}
downloadExecutorService = Executors.newFixedThreadPool(downloadPoolSize);
processingExecutorService = Executors.newFixedThreadPool(PROCESSING_THREAD_POOL_SIZE);
LOGGER.debug("#download threads: {}", downloadPoolSize);
LOGGER.debug("#processing threads: {}", PROCESSING_THREAD_POOL_SIZE);
}
|
[
"protected",
"void",
"initializeExecutorServices",
"(",
")",
"{",
"final",
"int",
"downloadPoolSize",
";",
"final",
"int",
"max",
"=",
"settings",
".",
"getInt",
"(",
"Settings",
".",
"KEYS",
".",
"MAX_DOWNLOAD_THREAD_POOL_SIZE",
",",
"3",
")",
";",
"if",
"(",
"DOWNLOAD_THREAD_POOL_SIZE",
">",
"max",
")",
"{",
"downloadPoolSize",
"=",
"max",
";",
"}",
"else",
"{",
"downloadPoolSize",
"=",
"DOWNLOAD_THREAD_POOL_SIZE",
";",
"}",
"downloadExecutorService",
"=",
"Executors",
".",
"newFixedThreadPool",
"(",
"downloadPoolSize",
")",
";",
"processingExecutorService",
"=",
"Executors",
".",
"newFixedThreadPool",
"(",
"PROCESSING_THREAD_POOL_SIZE",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"#download threads: {}\"",
",",
"downloadPoolSize",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"#processing threads: {}\"",
",",
"PROCESSING_THREAD_POOL_SIZE",
")",
";",
"}"
] |
Initialize the executor services for download and processing of the NVD
CVE XML data.
|
[
"Initialize",
"the",
"executor",
"services",
"for",
"download",
"and",
"processing",
"of",
"the",
"NVD",
"CVE",
"XML",
"data",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/update/NvdCveUpdater.java#L177-L189
|
17,833
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/update/NvdCveUpdater.java
|
NvdCveUpdater.checkUpdate
|
private boolean checkUpdate() throws UpdateException {
boolean proceed = true;
// If the valid setting has not been specified, then we proceed to check...
final int validForHours = settings.getInt(Settings.KEYS.CVE_CHECK_VALID_FOR_HOURS, 0);
if (dataExists() && 0 < validForHours) {
// ms Valid = valid (hours) x 60 min/hour x 60 sec/min x 1000 ms/sec
final long msValid = validForHours * 60L * 60L * 1000L;
final long lastChecked = Long.parseLong(dbProperties.getProperty(DatabaseProperties.LAST_CHECKED, "0"));
final long now = System.currentTimeMillis();
proceed = (now - lastChecked) > msValid;
if (!proceed) {
LOGGER.info("Skipping NVD check since last check was within {} hours.", validForHours);
LOGGER.debug("Last NVD was at {}, and now {} is within {} ms.", lastChecked, now, msValid);
}
}
return proceed;
}
|
java
|
private boolean checkUpdate() throws UpdateException {
boolean proceed = true;
// If the valid setting has not been specified, then we proceed to check...
final int validForHours = settings.getInt(Settings.KEYS.CVE_CHECK_VALID_FOR_HOURS, 0);
if (dataExists() && 0 < validForHours) {
// ms Valid = valid (hours) x 60 min/hour x 60 sec/min x 1000 ms/sec
final long msValid = validForHours * 60L * 60L * 1000L;
final long lastChecked = Long.parseLong(dbProperties.getProperty(DatabaseProperties.LAST_CHECKED, "0"));
final long now = System.currentTimeMillis();
proceed = (now - lastChecked) > msValid;
if (!proceed) {
LOGGER.info("Skipping NVD check since last check was within {} hours.", validForHours);
LOGGER.debug("Last NVD was at {}, and now {} is within {} ms.", lastChecked, now, msValid);
}
}
return proceed;
}
|
[
"private",
"boolean",
"checkUpdate",
"(",
")",
"throws",
"UpdateException",
"{",
"boolean",
"proceed",
"=",
"true",
";",
"// If the valid setting has not been specified, then we proceed to check...",
"final",
"int",
"validForHours",
"=",
"settings",
".",
"getInt",
"(",
"Settings",
".",
"KEYS",
".",
"CVE_CHECK_VALID_FOR_HOURS",
",",
"0",
")",
";",
"if",
"(",
"dataExists",
"(",
")",
"&&",
"0",
"<",
"validForHours",
")",
"{",
"// ms Valid = valid (hours) x 60 min/hour x 60 sec/min x 1000 ms/sec",
"final",
"long",
"msValid",
"=",
"validForHours",
"*",
"60L",
"*",
"60L",
"*",
"1000L",
";",
"final",
"long",
"lastChecked",
"=",
"Long",
".",
"parseLong",
"(",
"dbProperties",
".",
"getProperty",
"(",
"DatabaseProperties",
".",
"LAST_CHECKED",
",",
"\"0\"",
")",
")",
";",
"final",
"long",
"now",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"proceed",
"=",
"(",
"now",
"-",
"lastChecked",
")",
">",
"msValid",
";",
"if",
"(",
"!",
"proceed",
")",
"{",
"LOGGER",
".",
"info",
"(",
"\"Skipping NVD check since last check was within {} hours.\"",
",",
"validForHours",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"Last NVD was at {}, and now {} is within {} ms.\"",
",",
"lastChecked",
",",
"now",
",",
"msValid",
")",
";",
"}",
"}",
"return",
"proceed",
";",
"}"
] |
Checks if the NVD CVE XML files were last checked recently. As an
optimization, we can avoid repetitive checks against the NVD. Setting
CVE_CHECK_VALID_FOR_HOURS determines the duration since last check before
checking again. A database property stores the timestamp of the last
check.
@return true to proceed with the check, or false to skip
@throws UpdateException thrown when there is an issue checking for
updates
|
[
"Checks",
"if",
"the",
"NVD",
"CVE",
"XML",
"files",
"were",
"last",
"checked",
"recently",
".",
"As",
"an",
"optimization",
"we",
"can",
"avoid",
"repetitive",
"checks",
"against",
"the",
"NVD",
".",
"Setting",
"CVE_CHECK_VALID_FOR_HOURS",
"determines",
"the",
"duration",
"since",
"last",
"check",
"before",
"checking",
"again",
".",
"A",
"database",
"property",
"stores",
"the",
"timestamp",
"of",
"the",
"last",
"check",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/update/NvdCveUpdater.java#L214-L230
|
17,834
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/update/NvdCveUpdater.java
|
NvdCveUpdater.getMetaFile
|
protected final MetaProperties getMetaFile(String url) throws UpdateException {
try {
final String metaUrl = url.substring(0, url.length() - 7) + "meta";
final URL u = new URL(metaUrl);
final Downloader d = new Downloader(settings);
final String content = d.fetchContent(u, true);
return new MetaProperties(content);
} catch (MalformedURLException ex) {
throw new UpdateException("Meta file url is invalid: " + url, ex);
} catch (InvalidDataException ex) {
throw new UpdateException("Meta file content is invalid: " + url, ex);
} catch (DownloadFailedException ex) {
throw new UpdateException("Unable to download meta file: " + url, ex);
}
}
|
java
|
protected final MetaProperties getMetaFile(String url) throws UpdateException {
try {
final String metaUrl = url.substring(0, url.length() - 7) + "meta";
final URL u = new URL(metaUrl);
final Downloader d = new Downloader(settings);
final String content = d.fetchContent(u, true);
return new MetaProperties(content);
} catch (MalformedURLException ex) {
throw new UpdateException("Meta file url is invalid: " + url, ex);
} catch (InvalidDataException ex) {
throw new UpdateException("Meta file content is invalid: " + url, ex);
} catch (DownloadFailedException ex) {
throw new UpdateException("Unable to download meta file: " + url, ex);
}
}
|
[
"protected",
"final",
"MetaProperties",
"getMetaFile",
"(",
"String",
"url",
")",
"throws",
"UpdateException",
"{",
"try",
"{",
"final",
"String",
"metaUrl",
"=",
"url",
".",
"substring",
"(",
"0",
",",
"url",
".",
"length",
"(",
")",
"-",
"7",
")",
"+",
"\"meta\"",
";",
"final",
"URL",
"u",
"=",
"new",
"URL",
"(",
"metaUrl",
")",
";",
"final",
"Downloader",
"d",
"=",
"new",
"Downloader",
"(",
"settings",
")",
";",
"final",
"String",
"content",
"=",
"d",
".",
"fetchContent",
"(",
"u",
",",
"true",
")",
";",
"return",
"new",
"MetaProperties",
"(",
"content",
")",
";",
"}",
"catch",
"(",
"MalformedURLException",
"ex",
")",
"{",
"throw",
"new",
"UpdateException",
"(",
"\"Meta file url is invalid: \"",
"+",
"url",
",",
"ex",
")",
";",
"}",
"catch",
"(",
"InvalidDataException",
"ex",
")",
"{",
"throw",
"new",
"UpdateException",
"(",
"\"Meta file content is invalid: \"",
"+",
"url",
",",
"ex",
")",
";",
"}",
"catch",
"(",
"DownloadFailedException",
"ex",
")",
"{",
"throw",
"new",
"UpdateException",
"(",
"\"Unable to download meta file: \"",
"+",
"url",
",",
"ex",
")",
";",
"}",
"}"
] |
Downloads the NVD CVE Meta file properties.
@param url the URL to the NVD CVE JSON file
@return the meta file properties
@throws UpdateException thrown if the meta file could not be downloaded
|
[
"Downloads",
"the",
"NVD",
"CVE",
"Meta",
"file",
"properties",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/update/NvdCveUpdater.java#L350-L364
|
17,835
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/update/NvdCveUpdater.java
|
NvdCveUpdater.getUpdatesNeeded
|
protected final UpdateableNvdCve getUpdatesNeeded() throws MalformedURLException, DownloadFailedException, UpdateException {
LOGGER.debug("starting getUpdatesNeeded() ...");
final UpdateableNvdCve updates = new UpdateableNvdCve();
if (dbProperties != null && !dbProperties.isEmpty()) {
try {
final int startYear = settings.getInt(Settings.KEYS.CVE_START_YEAR, 2002);
final int endYear = Calendar.getInstance().get(Calendar.YEAR);
boolean needsFullUpdate = false;
for (int y = startYear; y <= endYear; y++) {
final long val = Long.parseLong(dbProperties.getProperty(DatabaseProperties.LAST_UPDATED_BASE + y, "0"));
if (val == 0) {
needsFullUpdate = true;
break;
}
}
final long lastUpdated = Long.parseLong(dbProperties.getProperty(DatabaseProperties.LAST_UPDATED, "0"));
final long now = System.currentTimeMillis();
final int days = settings.getInt(Settings.KEYS.CVE_MODIFIED_VALID_FOR_DAYS, 7);
String url = settings.getString(Settings.KEYS.CVE_MODIFIED_JSON);
MetaProperties modified = getMetaFile(url);
if (!needsFullUpdate && lastUpdated == modified.getLastModifiedDate()) {
return updates;
} else {
updates.add(MODIFIED, url, modified.getLastModifiedDate(), true);
if (needsFullUpdate || !DateUtil.withinDateRange(lastUpdated, now, days)) {
final int start = settings.getInt(Settings.KEYS.CVE_START_YEAR);
final int end = Calendar.getInstance().get(Calendar.YEAR);
final String baseUrl = settings.getString(Settings.KEYS.CVE_BASE_JSON);
for (int i = start; i <= end; i++) {
url = String.format(baseUrl, i);
MetaProperties meta = getMetaFile(url);
long currentTimestamp = 0;
try {
currentTimestamp = Long.parseLong(dbProperties.getProperty(DatabaseProperties.LAST_UPDATED_BASE
+ i, "0"));
} catch (NumberFormatException ex) {
LOGGER.debug("Error parsing '{}' '{}' from nvdcve.lastupdated",
DatabaseProperties.LAST_UPDATED_BASE, i, ex);
}
if (currentTimestamp < meta.getLastModifiedDate()) {
updates.add(Integer.toString(i), url, meta.getLastModifiedDate(), true);
}
}
}
}
} catch (NumberFormatException ex) {
LOGGER.warn("An invalid schema version or timestamp exists in the data.properties file.");
LOGGER.debug("", ex);
} catch (InvalidSettingException ex) {
throw new UpdateException("The NVD CVE start year property is set to an invalid value", ex);
}
}
return updates;
}
|
java
|
protected final UpdateableNvdCve getUpdatesNeeded() throws MalformedURLException, DownloadFailedException, UpdateException {
LOGGER.debug("starting getUpdatesNeeded() ...");
final UpdateableNvdCve updates = new UpdateableNvdCve();
if (dbProperties != null && !dbProperties.isEmpty()) {
try {
final int startYear = settings.getInt(Settings.KEYS.CVE_START_YEAR, 2002);
final int endYear = Calendar.getInstance().get(Calendar.YEAR);
boolean needsFullUpdate = false;
for (int y = startYear; y <= endYear; y++) {
final long val = Long.parseLong(dbProperties.getProperty(DatabaseProperties.LAST_UPDATED_BASE + y, "0"));
if (val == 0) {
needsFullUpdate = true;
break;
}
}
final long lastUpdated = Long.parseLong(dbProperties.getProperty(DatabaseProperties.LAST_UPDATED, "0"));
final long now = System.currentTimeMillis();
final int days = settings.getInt(Settings.KEYS.CVE_MODIFIED_VALID_FOR_DAYS, 7);
String url = settings.getString(Settings.KEYS.CVE_MODIFIED_JSON);
MetaProperties modified = getMetaFile(url);
if (!needsFullUpdate && lastUpdated == modified.getLastModifiedDate()) {
return updates;
} else {
updates.add(MODIFIED, url, modified.getLastModifiedDate(), true);
if (needsFullUpdate || !DateUtil.withinDateRange(lastUpdated, now, days)) {
final int start = settings.getInt(Settings.KEYS.CVE_START_YEAR);
final int end = Calendar.getInstance().get(Calendar.YEAR);
final String baseUrl = settings.getString(Settings.KEYS.CVE_BASE_JSON);
for (int i = start; i <= end; i++) {
url = String.format(baseUrl, i);
MetaProperties meta = getMetaFile(url);
long currentTimestamp = 0;
try {
currentTimestamp = Long.parseLong(dbProperties.getProperty(DatabaseProperties.LAST_UPDATED_BASE
+ i, "0"));
} catch (NumberFormatException ex) {
LOGGER.debug("Error parsing '{}' '{}' from nvdcve.lastupdated",
DatabaseProperties.LAST_UPDATED_BASE, i, ex);
}
if (currentTimestamp < meta.getLastModifiedDate()) {
updates.add(Integer.toString(i), url, meta.getLastModifiedDate(), true);
}
}
}
}
} catch (NumberFormatException ex) {
LOGGER.warn("An invalid schema version or timestamp exists in the data.properties file.");
LOGGER.debug("", ex);
} catch (InvalidSettingException ex) {
throw new UpdateException("The NVD CVE start year property is set to an invalid value", ex);
}
}
return updates;
}
|
[
"protected",
"final",
"UpdateableNvdCve",
"getUpdatesNeeded",
"(",
")",
"throws",
"MalformedURLException",
",",
"DownloadFailedException",
",",
"UpdateException",
"{",
"LOGGER",
".",
"debug",
"(",
"\"starting getUpdatesNeeded() ...\"",
")",
";",
"final",
"UpdateableNvdCve",
"updates",
"=",
"new",
"UpdateableNvdCve",
"(",
")",
";",
"if",
"(",
"dbProperties",
"!=",
"null",
"&&",
"!",
"dbProperties",
".",
"isEmpty",
"(",
")",
")",
"{",
"try",
"{",
"final",
"int",
"startYear",
"=",
"settings",
".",
"getInt",
"(",
"Settings",
".",
"KEYS",
".",
"CVE_START_YEAR",
",",
"2002",
")",
";",
"final",
"int",
"endYear",
"=",
"Calendar",
".",
"getInstance",
"(",
")",
".",
"get",
"(",
"Calendar",
".",
"YEAR",
")",
";",
"boolean",
"needsFullUpdate",
"=",
"false",
";",
"for",
"(",
"int",
"y",
"=",
"startYear",
";",
"y",
"<=",
"endYear",
";",
"y",
"++",
")",
"{",
"final",
"long",
"val",
"=",
"Long",
".",
"parseLong",
"(",
"dbProperties",
".",
"getProperty",
"(",
"DatabaseProperties",
".",
"LAST_UPDATED_BASE",
"+",
"y",
",",
"\"0\"",
")",
")",
";",
"if",
"(",
"val",
"==",
"0",
")",
"{",
"needsFullUpdate",
"=",
"true",
";",
"break",
";",
"}",
"}",
"final",
"long",
"lastUpdated",
"=",
"Long",
".",
"parseLong",
"(",
"dbProperties",
".",
"getProperty",
"(",
"DatabaseProperties",
".",
"LAST_UPDATED",
",",
"\"0\"",
")",
")",
";",
"final",
"long",
"now",
"=",
"System",
".",
"currentTimeMillis",
"(",
")",
";",
"final",
"int",
"days",
"=",
"settings",
".",
"getInt",
"(",
"Settings",
".",
"KEYS",
".",
"CVE_MODIFIED_VALID_FOR_DAYS",
",",
"7",
")",
";",
"String",
"url",
"=",
"settings",
".",
"getString",
"(",
"Settings",
".",
"KEYS",
".",
"CVE_MODIFIED_JSON",
")",
";",
"MetaProperties",
"modified",
"=",
"getMetaFile",
"(",
"url",
")",
";",
"if",
"(",
"!",
"needsFullUpdate",
"&&",
"lastUpdated",
"==",
"modified",
".",
"getLastModifiedDate",
"(",
")",
")",
"{",
"return",
"updates",
";",
"}",
"else",
"{",
"updates",
".",
"add",
"(",
"MODIFIED",
",",
"url",
",",
"modified",
".",
"getLastModifiedDate",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"needsFullUpdate",
"||",
"!",
"DateUtil",
".",
"withinDateRange",
"(",
"lastUpdated",
",",
"now",
",",
"days",
")",
")",
"{",
"final",
"int",
"start",
"=",
"settings",
".",
"getInt",
"(",
"Settings",
".",
"KEYS",
".",
"CVE_START_YEAR",
")",
";",
"final",
"int",
"end",
"=",
"Calendar",
".",
"getInstance",
"(",
")",
".",
"get",
"(",
"Calendar",
".",
"YEAR",
")",
";",
"final",
"String",
"baseUrl",
"=",
"settings",
".",
"getString",
"(",
"Settings",
".",
"KEYS",
".",
"CVE_BASE_JSON",
")",
";",
"for",
"(",
"int",
"i",
"=",
"start",
";",
"i",
"<=",
"end",
";",
"i",
"++",
")",
"{",
"url",
"=",
"String",
".",
"format",
"(",
"baseUrl",
",",
"i",
")",
";",
"MetaProperties",
"meta",
"=",
"getMetaFile",
"(",
"url",
")",
";",
"long",
"currentTimestamp",
"=",
"0",
";",
"try",
"{",
"currentTimestamp",
"=",
"Long",
".",
"parseLong",
"(",
"dbProperties",
".",
"getProperty",
"(",
"DatabaseProperties",
".",
"LAST_UPDATED_BASE",
"+",
"i",
",",
"\"0\"",
")",
")",
";",
"}",
"catch",
"(",
"NumberFormatException",
"ex",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Error parsing '{}' '{}' from nvdcve.lastupdated\"",
",",
"DatabaseProperties",
".",
"LAST_UPDATED_BASE",
",",
"i",
",",
"ex",
")",
";",
"}",
"if",
"(",
"currentTimestamp",
"<",
"meta",
".",
"getLastModifiedDate",
"(",
")",
")",
"{",
"updates",
".",
"add",
"(",
"Integer",
".",
"toString",
"(",
"i",
")",
",",
"url",
",",
"meta",
".",
"getLastModifiedDate",
"(",
")",
",",
"true",
")",
";",
"}",
"}",
"}",
"}",
"}",
"catch",
"(",
"NumberFormatException",
"ex",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"An invalid schema version or timestamp exists in the data.properties file.\"",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"\"",
",",
"ex",
")",
";",
"}",
"catch",
"(",
"InvalidSettingException",
"ex",
")",
"{",
"throw",
"new",
"UpdateException",
"(",
"\"The NVD CVE start year property is set to an invalid value\"",
",",
"ex",
")",
";",
"}",
"}",
"return",
"updates",
";",
"}"
] |
Determines if the index needs to be updated. This is done by fetching the
NVD CVE meta data and checking the last update date. If the data needs to
be refreshed this method will return the NvdCveUrl for the files that
need to be updated.
@return the collection of files that need to be updated
@throws MalformedURLException is thrown if the URL for the NVD CVE Meta
data is incorrect
@throws DownloadFailedException is thrown if there is an error.
downloading the NVD CVE download data file
@throws UpdateException Is thrown if there is an issue with the last
updated properties file
|
[
"Determines",
"if",
"the",
"index",
"needs",
"to",
"be",
"updated",
".",
"This",
"is",
"done",
"by",
"fetching",
"the",
"NVD",
"CVE",
"meta",
"data",
"and",
"checking",
"the",
"last",
"update",
"date",
".",
"If",
"the",
"data",
"needs",
"to",
"be",
"refreshed",
"this",
"method",
"will",
"return",
"the",
"NvdCveUrl",
"for",
"the",
"files",
"that",
"need",
"to",
"be",
"updated",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/update/NvdCveUpdater.java#L380-L436
|
17,836
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/AutoconfAnalyzer.java
|
AutoconfAnalyzer.extractConfigureScriptEvidence
|
private void extractConfigureScriptEvidence(Dependency dependency,
final String name, final String contents) {
final Matcher matcher = PACKAGE_VAR.matcher(contents);
while (matcher.find()) {
final String variable = matcher.group(1);
final String value = matcher.group(2);
if (!value.isEmpty()) {
if (variable.endsWith("NAME")) {
dependency.addEvidence(EvidenceType.PRODUCT, name, variable, value, Confidence.HIGHEST);
} else if ("VERSION".equals(variable)) {
dependency.addEvidence(EvidenceType.VERSION, name, variable, value, Confidence.HIGHEST);
} else if ("BUGREPORT".equals(variable)) {
dependency.addEvidence(EvidenceType.VENDOR, name, variable, value, Confidence.HIGH);
} else if ("URL".equals(variable)) {
dependency.addEvidence(EvidenceType.VENDOR, name, variable, value, Confidence.HIGH);
}
}
}
}
|
java
|
private void extractConfigureScriptEvidence(Dependency dependency,
final String name, final String contents) {
final Matcher matcher = PACKAGE_VAR.matcher(contents);
while (matcher.find()) {
final String variable = matcher.group(1);
final String value = matcher.group(2);
if (!value.isEmpty()) {
if (variable.endsWith("NAME")) {
dependency.addEvidence(EvidenceType.PRODUCT, name, variable, value, Confidence.HIGHEST);
} else if ("VERSION".equals(variable)) {
dependency.addEvidence(EvidenceType.VERSION, name, variable, value, Confidence.HIGHEST);
} else if ("BUGREPORT".equals(variable)) {
dependency.addEvidence(EvidenceType.VENDOR, name, variable, value, Confidence.HIGH);
} else if ("URL".equals(variable)) {
dependency.addEvidence(EvidenceType.VENDOR, name, variable, value, Confidence.HIGH);
}
}
}
}
|
[
"private",
"void",
"extractConfigureScriptEvidence",
"(",
"Dependency",
"dependency",
",",
"final",
"String",
"name",
",",
"final",
"String",
"contents",
")",
"{",
"final",
"Matcher",
"matcher",
"=",
"PACKAGE_VAR",
".",
"matcher",
"(",
"contents",
")",
";",
"while",
"(",
"matcher",
".",
"find",
"(",
")",
")",
"{",
"final",
"String",
"variable",
"=",
"matcher",
".",
"group",
"(",
"1",
")",
";",
"final",
"String",
"value",
"=",
"matcher",
".",
"group",
"(",
"2",
")",
";",
"if",
"(",
"!",
"value",
".",
"isEmpty",
"(",
")",
")",
"{",
"if",
"(",
"variable",
".",
"endsWith",
"(",
"\"NAME\"",
")",
")",
"{",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"PRODUCT",
",",
"name",
",",
"variable",
",",
"value",
",",
"Confidence",
".",
"HIGHEST",
")",
";",
"}",
"else",
"if",
"(",
"\"VERSION\"",
".",
"equals",
"(",
"variable",
")",
")",
"{",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VERSION",
",",
"name",
",",
"variable",
",",
"value",
",",
"Confidence",
".",
"HIGHEST",
")",
";",
"}",
"else",
"if",
"(",
"\"BUGREPORT\"",
".",
"equals",
"(",
"variable",
")",
")",
"{",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VENDOR",
",",
"name",
",",
"variable",
",",
"value",
",",
"Confidence",
".",
"HIGH",
")",
";",
"}",
"else",
"if",
"(",
"\"URL\"",
".",
"equals",
"(",
"variable",
")",
")",
"{",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VENDOR",
",",
"name",
",",
"variable",
",",
"value",
",",
"Confidence",
".",
"HIGH",
")",
";",
"}",
"}",
"}",
"}"
] |
Extracts evidence from the configuration.
@param dependency the dependency being analyzed
@param name the name of the source of evidence
@param contents the contents to analyze for evidence
|
[
"Extracts",
"evidence",
"from",
"the",
"configuration",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/AutoconfAnalyzer.java#L189-L207
|
17,837
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/AutoconfAnalyzer.java
|
AutoconfAnalyzer.gatherEvidence
|
private void gatherEvidence(Dependency dependency, final String name,
String contents) {
final Matcher matcher = AC_INIT_PATTERN.matcher(contents);
if (matcher.find()) {
dependency.addEvidence(EvidenceType.PRODUCT, name, "Package", matcher.group(1), Confidence.HIGHEST);
dependency.addEvidence(EvidenceType.VERSION, name, "Package Version", matcher.group(2), Confidence.HIGHEST);
if (null != matcher.group(3)) {
dependency.addEvidence(EvidenceType.VENDOR, name, "Bug report address", matcher.group(4), Confidence.HIGH);
}
if (null != matcher.group(5)) {
dependency.addEvidence(EvidenceType.PRODUCT, name, "Tarname", matcher.group(6), Confidence.HIGH);
}
if (null != matcher.group(7)) {
final String url = matcher.group(8);
if (UrlStringUtils.isUrl(url)) {
dependency.addEvidence(EvidenceType.VENDOR, name, "URL", url, Confidence.HIGH);
}
}
}
}
|
java
|
private void gatherEvidence(Dependency dependency, final String name,
String contents) {
final Matcher matcher = AC_INIT_PATTERN.matcher(contents);
if (matcher.find()) {
dependency.addEvidence(EvidenceType.PRODUCT, name, "Package", matcher.group(1), Confidence.HIGHEST);
dependency.addEvidence(EvidenceType.VERSION, name, "Package Version", matcher.group(2), Confidence.HIGHEST);
if (null != matcher.group(3)) {
dependency.addEvidence(EvidenceType.VENDOR, name, "Bug report address", matcher.group(4), Confidence.HIGH);
}
if (null != matcher.group(5)) {
dependency.addEvidence(EvidenceType.PRODUCT, name, "Tarname", matcher.group(6), Confidence.HIGH);
}
if (null != matcher.group(7)) {
final String url = matcher.group(8);
if (UrlStringUtils.isUrl(url)) {
dependency.addEvidence(EvidenceType.VENDOR, name, "URL", url, Confidence.HIGH);
}
}
}
}
|
[
"private",
"void",
"gatherEvidence",
"(",
"Dependency",
"dependency",
",",
"final",
"String",
"name",
",",
"String",
"contents",
")",
"{",
"final",
"Matcher",
"matcher",
"=",
"AC_INIT_PATTERN",
".",
"matcher",
"(",
"contents",
")",
";",
"if",
"(",
"matcher",
".",
"find",
"(",
")",
")",
"{",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"PRODUCT",
",",
"name",
",",
"\"Package\"",
",",
"matcher",
".",
"group",
"(",
"1",
")",
",",
"Confidence",
".",
"HIGHEST",
")",
";",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VERSION",
",",
"name",
",",
"\"Package Version\"",
",",
"matcher",
".",
"group",
"(",
"2",
")",
",",
"Confidence",
".",
"HIGHEST",
")",
";",
"if",
"(",
"null",
"!=",
"matcher",
".",
"group",
"(",
"3",
")",
")",
"{",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VENDOR",
",",
"name",
",",
"\"Bug report address\"",
",",
"matcher",
".",
"group",
"(",
"4",
")",
",",
"Confidence",
".",
"HIGH",
")",
";",
"}",
"if",
"(",
"null",
"!=",
"matcher",
".",
"group",
"(",
"5",
")",
")",
"{",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"PRODUCT",
",",
"name",
",",
"\"Tarname\"",
",",
"matcher",
".",
"group",
"(",
"6",
")",
",",
"Confidence",
".",
"HIGH",
")",
";",
"}",
"if",
"(",
"null",
"!=",
"matcher",
".",
"group",
"(",
"7",
")",
")",
"{",
"final",
"String",
"url",
"=",
"matcher",
".",
"group",
"(",
"8",
")",
";",
"if",
"(",
"UrlStringUtils",
".",
"isUrl",
"(",
"url",
")",
")",
"{",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VENDOR",
",",
"name",
",",
"\"URL\"",
",",
"url",
",",
"Confidence",
".",
"HIGH",
")",
";",
"}",
"}",
"}",
"}"
] |
Gathers evidence from a given file
@param dependency the dependency to add evidence to
@param name the source of the evidence
@param contents the evidence to analyze
|
[
"Gathers",
"evidence",
"from",
"a",
"given",
"file"
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/AutoconfAnalyzer.java#L233-L253
|
17,838
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractFileTypeAnalyzer.java
|
AbstractFileTypeAnalyzer.prepareAnalyzer
|
@Override
protected final void prepareAnalyzer(Engine engine) throws InitializationException {
if (filesMatched) {
prepareFileTypeAnalyzer(engine);
} else {
this.setEnabled(false);
}
}
|
java
|
@Override
protected final void prepareAnalyzer(Engine engine) throws InitializationException {
if (filesMatched) {
prepareFileTypeAnalyzer(engine);
} else {
this.setEnabled(false);
}
}
|
[
"@",
"Override",
"protected",
"final",
"void",
"prepareAnalyzer",
"(",
"Engine",
"engine",
")",
"throws",
"InitializationException",
"{",
"if",
"(",
"filesMatched",
")",
"{",
"prepareFileTypeAnalyzer",
"(",
"engine",
")",
";",
"}",
"else",
"{",
"this",
".",
"setEnabled",
"(",
"false",
")",
";",
"}",
"}"
] |
Initializes the analyzer.
@param engine a reference to the dependency-check engine
@throws InitializationException thrown if there is an exception during
initialization
|
[
"Initializes",
"the",
"analyzer",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractFileTypeAnalyzer.java#L80-L87
|
17,839
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/CocoaPodsAnalyzer.java
|
CocoaPodsAnalyzer.analyzePodfileLockDependencies
|
private void analyzePodfileLockDependencies(Dependency podfileLock, Engine engine)
throws AnalysisException {
engine.removeDependency(podfileLock);
final String contents;
try {
contents = FileUtils.readFileToString(podfileLock.getActualFile(), Charset.defaultCharset());
} catch (IOException e) {
throw new AnalysisException(
"Problem occurred while reading dependency file.", e);
}
final Matcher matcher = PODFILE_LOCK_DEPENDENCY_PATTERN.matcher(contents);
while (matcher.find()) {
final String name = matcher.group(1);
final String version = matcher.group(2);
final Dependency dependency = new Dependency(podfileLock.getActualFile(), true);
dependency.setEcosystem(DEPENDENCY_ECOSYSTEM);
dependency.setName(name);
dependency.setVersion(version);
final String packagePath = String.format("%s:%s", name, version);
dependency.setPackagePath(packagePath);
dependency.setDisplayFileName(packagePath);
dependency.setSha1sum(Checksum.getSHA1Checksum(packagePath));
dependency.setSha256sum(Checksum.getSHA256Checksum(packagePath));
dependency.setMd5sum(Checksum.getMD5Checksum(packagePath));
dependency.addEvidence(EvidenceType.VENDOR, PODFILE_LOCK, "name", name, Confidence.HIGHEST);
dependency.addEvidence(EvidenceType.PRODUCT, PODFILE_LOCK, "name", name, Confidence.HIGHEST);
dependency.addEvidence(EvidenceType.VERSION, PODFILE_LOCK, "version", version, Confidence.HIGHEST);
engine.addDependency(dependency);
}
}
|
java
|
private void analyzePodfileLockDependencies(Dependency podfileLock, Engine engine)
throws AnalysisException {
engine.removeDependency(podfileLock);
final String contents;
try {
contents = FileUtils.readFileToString(podfileLock.getActualFile(), Charset.defaultCharset());
} catch (IOException e) {
throw new AnalysisException(
"Problem occurred while reading dependency file.", e);
}
final Matcher matcher = PODFILE_LOCK_DEPENDENCY_PATTERN.matcher(contents);
while (matcher.find()) {
final String name = matcher.group(1);
final String version = matcher.group(2);
final Dependency dependency = new Dependency(podfileLock.getActualFile(), true);
dependency.setEcosystem(DEPENDENCY_ECOSYSTEM);
dependency.setName(name);
dependency.setVersion(version);
final String packagePath = String.format("%s:%s", name, version);
dependency.setPackagePath(packagePath);
dependency.setDisplayFileName(packagePath);
dependency.setSha1sum(Checksum.getSHA1Checksum(packagePath));
dependency.setSha256sum(Checksum.getSHA256Checksum(packagePath));
dependency.setMd5sum(Checksum.getMD5Checksum(packagePath));
dependency.addEvidence(EvidenceType.VENDOR, PODFILE_LOCK, "name", name, Confidence.HIGHEST);
dependency.addEvidence(EvidenceType.PRODUCT, PODFILE_LOCK, "name", name, Confidence.HIGHEST);
dependency.addEvidence(EvidenceType.VERSION, PODFILE_LOCK, "version", version, Confidence.HIGHEST);
engine.addDependency(dependency);
}
}
|
[
"private",
"void",
"analyzePodfileLockDependencies",
"(",
"Dependency",
"podfileLock",
",",
"Engine",
"engine",
")",
"throws",
"AnalysisException",
"{",
"engine",
".",
"removeDependency",
"(",
"podfileLock",
")",
";",
"final",
"String",
"contents",
";",
"try",
"{",
"contents",
"=",
"FileUtils",
".",
"readFileToString",
"(",
"podfileLock",
".",
"getActualFile",
"(",
")",
",",
"Charset",
".",
"defaultCharset",
"(",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"AnalysisException",
"(",
"\"Problem occurred while reading dependency file.\"",
",",
"e",
")",
";",
"}",
"final",
"Matcher",
"matcher",
"=",
"PODFILE_LOCK_DEPENDENCY_PATTERN",
".",
"matcher",
"(",
"contents",
")",
";",
"while",
"(",
"matcher",
".",
"find",
"(",
")",
")",
"{",
"final",
"String",
"name",
"=",
"matcher",
".",
"group",
"(",
"1",
")",
";",
"final",
"String",
"version",
"=",
"matcher",
".",
"group",
"(",
"2",
")",
";",
"final",
"Dependency",
"dependency",
"=",
"new",
"Dependency",
"(",
"podfileLock",
".",
"getActualFile",
"(",
")",
",",
"true",
")",
";",
"dependency",
".",
"setEcosystem",
"(",
"DEPENDENCY_ECOSYSTEM",
")",
";",
"dependency",
".",
"setName",
"(",
"name",
")",
";",
"dependency",
".",
"setVersion",
"(",
"version",
")",
";",
"final",
"String",
"packagePath",
"=",
"String",
".",
"format",
"(",
"\"%s:%s\"",
",",
"name",
",",
"version",
")",
";",
"dependency",
".",
"setPackagePath",
"(",
"packagePath",
")",
";",
"dependency",
".",
"setDisplayFileName",
"(",
"packagePath",
")",
";",
"dependency",
".",
"setSha1sum",
"(",
"Checksum",
".",
"getSHA1Checksum",
"(",
"packagePath",
")",
")",
";",
"dependency",
".",
"setSha256sum",
"(",
"Checksum",
".",
"getSHA256Checksum",
"(",
"packagePath",
")",
")",
";",
"dependency",
".",
"setMd5sum",
"(",
"Checksum",
".",
"getMD5Checksum",
"(",
"packagePath",
")",
")",
";",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VENDOR",
",",
"PODFILE_LOCK",
",",
"\"name\"",
",",
"name",
",",
"Confidence",
".",
"HIGHEST",
")",
";",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"PRODUCT",
",",
"PODFILE_LOCK",
",",
"\"name\"",
",",
"name",
",",
"Confidence",
".",
"HIGHEST",
")",
";",
"dependency",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VERSION",
",",
"PODFILE_LOCK",
",",
"\"version\"",
",",
"version",
",",
"Confidence",
".",
"HIGHEST",
")",
";",
"engine",
".",
"addDependency",
"(",
"dependency",
")",
";",
"}",
"}"
] |
Analyzes the podfile.lock file to extract evidence for the dependency.
@param podfileLock the dependency to analyze
@param engine the analysis engine
@throws AnalysisException thrown if there is an error analyzing the
dependency
|
[
"Analyzes",
"the",
"podfile",
".",
"lock",
"file",
"to",
"extract",
"evidence",
"for",
"the",
"dependency",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/CocoaPodsAnalyzer.java#L165-L197
|
17,840
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/CocoaPodsAnalyzer.java
|
CocoaPodsAnalyzer.determineEvidence
|
private String determineEvidence(String contents, String blockVariable, String fieldPattern) {
String value = "";
//capture array value between [ ]
final Matcher arrayMatcher = Pattern.compile(
String.format("\\s*?%s\\.%s\\s*?=\\s*?\\{\\s*?(.*?)\\s*?\\}", blockVariable, fieldPattern),
Pattern.CASE_INSENSITIVE).matcher(contents);
if (arrayMatcher.find()) {
value = arrayMatcher.group(1);
} else { //capture single value between quotes
final Matcher matcher = Pattern.compile(
String.format("\\s*?%s\\.%s\\s*?=\\s*?(['\"])(.*?)\\1", blockVariable, fieldPattern),
Pattern.CASE_INSENSITIVE).matcher(contents);
if (matcher.find()) {
value = matcher.group(2);
}
}
return value;
}
|
java
|
private String determineEvidence(String contents, String blockVariable, String fieldPattern) {
String value = "";
//capture array value between [ ]
final Matcher arrayMatcher = Pattern.compile(
String.format("\\s*?%s\\.%s\\s*?=\\s*?\\{\\s*?(.*?)\\s*?\\}", blockVariable, fieldPattern),
Pattern.CASE_INSENSITIVE).matcher(contents);
if (arrayMatcher.find()) {
value = arrayMatcher.group(1);
} else { //capture single value between quotes
final Matcher matcher = Pattern.compile(
String.format("\\s*?%s\\.%s\\s*?=\\s*?(['\"])(.*?)\\1", blockVariable, fieldPattern),
Pattern.CASE_INSENSITIVE).matcher(contents);
if (matcher.find()) {
value = matcher.group(2);
}
}
return value;
}
|
[
"private",
"String",
"determineEvidence",
"(",
"String",
"contents",
",",
"String",
"blockVariable",
",",
"String",
"fieldPattern",
")",
"{",
"String",
"value",
"=",
"\"\"",
";",
"//capture array value between [ ]",
"final",
"Matcher",
"arrayMatcher",
"=",
"Pattern",
".",
"compile",
"(",
"String",
".",
"format",
"(",
"\"\\\\s*?%s\\\\.%s\\\\s*?=\\\\s*?\\\\{\\\\s*?(.*?)\\\\s*?\\\\}\"",
",",
"blockVariable",
",",
"fieldPattern",
")",
",",
"Pattern",
".",
"CASE_INSENSITIVE",
")",
".",
"matcher",
"(",
"contents",
")",
";",
"if",
"(",
"arrayMatcher",
".",
"find",
"(",
")",
")",
"{",
"value",
"=",
"arrayMatcher",
".",
"group",
"(",
"1",
")",
";",
"}",
"else",
"{",
"//capture single value between quotes",
"final",
"Matcher",
"matcher",
"=",
"Pattern",
".",
"compile",
"(",
"String",
".",
"format",
"(",
"\"\\\\s*?%s\\\\.%s\\\\s*?=\\\\s*?(['\\\"])(.*?)\\\\1\"",
",",
"blockVariable",
",",
"fieldPattern",
")",
",",
"Pattern",
".",
"CASE_INSENSITIVE",
")",
".",
"matcher",
"(",
"contents",
")",
";",
"if",
"(",
"matcher",
".",
"find",
"(",
")",
")",
"{",
"value",
"=",
"matcher",
".",
"group",
"(",
"2",
")",
";",
"}",
"}",
"return",
"value",
";",
"}"
] |
Extracts evidence from the contents and adds it to the given evidence
collection.
@param contents the text to extract evidence from
@param blockVariable the block variable within the content to search for
@param fieldPattern the field pattern within the contents to search for
@return the evidence
|
[
"Extracts",
"evidence",
"from",
"the",
"contents",
"and",
"adds",
"it",
"to",
"the",
"given",
"evidence",
"collection",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/CocoaPodsAnalyzer.java#L290-L308
|
17,841
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/CocoaPodsAnalyzer.java
|
CocoaPodsAnalyzer.setPackagePath
|
private void setPackagePath(Dependency dep) {
final File file = new File(dep.getFilePath());
final String parent = file.getParent();
if (parent != null) {
dep.setPackagePath(parent);
}
}
|
java
|
private void setPackagePath(Dependency dep) {
final File file = new File(dep.getFilePath());
final String parent = file.getParent();
if (parent != null) {
dep.setPackagePath(parent);
}
}
|
[
"private",
"void",
"setPackagePath",
"(",
"Dependency",
"dep",
")",
"{",
"final",
"File",
"file",
"=",
"new",
"File",
"(",
"dep",
".",
"getFilePath",
"(",
")",
")",
";",
"final",
"String",
"parent",
"=",
"file",
".",
"getParent",
"(",
")",
";",
"if",
"(",
"parent",
"!=",
"null",
")",
"{",
"dep",
".",
"setPackagePath",
"(",
"parent",
")",
";",
"}",
"}"
] |
Sets the package path on the given dependency.
@param dep the dependency to update
|
[
"Sets",
"the",
"package",
"path",
"on",
"the",
"given",
"dependency",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/CocoaPodsAnalyzer.java#L315-L321
|
17,842
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/AnalysisTask.java
|
AnalysisTask.call
|
@Override
public Void call() {
if (shouldAnalyze()) {
LOGGER.debug("Begin Analysis of '{}' ({})", dependency.getActualFilePath(), analyzer.getName());
try {
analyzer.analyze(dependency, engine);
} catch (AnalysisException ex) {
LOGGER.warn("An error occurred while analyzing '{}' ({}).", dependency.getActualFilePath(), analyzer.getName());
LOGGER.debug("", ex);
exceptions.add(ex);
} catch (Throwable ex) {
LOGGER.warn("An unexpected error occurred during analysis of '{}' ({}): {}",
dependency.getActualFilePath(), analyzer.getName(), ex.getMessage());
LOGGER.error("", ex);
exceptions.add(ex);
}
}
return null;
}
|
java
|
@Override
public Void call() {
if (shouldAnalyze()) {
LOGGER.debug("Begin Analysis of '{}' ({})", dependency.getActualFilePath(), analyzer.getName());
try {
analyzer.analyze(dependency, engine);
} catch (AnalysisException ex) {
LOGGER.warn("An error occurred while analyzing '{}' ({}).", dependency.getActualFilePath(), analyzer.getName());
LOGGER.debug("", ex);
exceptions.add(ex);
} catch (Throwable ex) {
LOGGER.warn("An unexpected error occurred during analysis of '{}' ({}): {}",
dependency.getActualFilePath(), analyzer.getName(), ex.getMessage());
LOGGER.error("", ex);
exceptions.add(ex);
}
}
return null;
}
|
[
"@",
"Override",
"public",
"Void",
"call",
"(",
")",
"{",
"if",
"(",
"shouldAnalyze",
"(",
")",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Begin Analysis of '{}' ({})\"",
",",
"dependency",
".",
"getActualFilePath",
"(",
")",
",",
"analyzer",
".",
"getName",
"(",
")",
")",
";",
"try",
"{",
"analyzer",
".",
"analyze",
"(",
"dependency",
",",
"engine",
")",
";",
"}",
"catch",
"(",
"AnalysisException",
"ex",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"An error occurred while analyzing '{}' ({}).\"",
",",
"dependency",
".",
"getActualFilePath",
"(",
")",
",",
"analyzer",
".",
"getName",
"(",
")",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"\"",
",",
"ex",
")",
";",
"exceptions",
".",
"add",
"(",
"ex",
")",
";",
"}",
"catch",
"(",
"Throwable",
"ex",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"An unexpected error occurred during analysis of '{}' ({}): {}\"",
",",
"dependency",
".",
"getActualFilePath",
"(",
")",
",",
"analyzer",
".",
"getName",
"(",
")",
",",
"ex",
".",
"getMessage",
"(",
")",
")",
";",
"LOGGER",
".",
"error",
"(",
"\"\"",
",",
"ex",
")",
";",
"exceptions",
".",
"add",
"(",
"ex",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Executes the analysis task.
@return null
|
[
"Executes",
"the",
"analysis",
"task",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/AnalysisTask.java#L83-L101
|
17,843
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/AnalysisTask.java
|
AnalysisTask.shouldAnalyze
|
protected boolean shouldAnalyze() {
if (analyzer instanceof FileTypeAnalyzer) {
final FileTypeAnalyzer fileTypeAnalyzer = (FileTypeAnalyzer) analyzer;
return fileTypeAnalyzer.accept(dependency.getActualFile());
}
return true;
}
|
java
|
protected boolean shouldAnalyze() {
if (analyzer instanceof FileTypeAnalyzer) {
final FileTypeAnalyzer fileTypeAnalyzer = (FileTypeAnalyzer) analyzer;
return fileTypeAnalyzer.accept(dependency.getActualFile());
}
return true;
}
|
[
"protected",
"boolean",
"shouldAnalyze",
"(",
")",
"{",
"if",
"(",
"analyzer",
"instanceof",
"FileTypeAnalyzer",
")",
"{",
"final",
"FileTypeAnalyzer",
"fileTypeAnalyzer",
"=",
"(",
"FileTypeAnalyzer",
")",
"analyzer",
";",
"return",
"fileTypeAnalyzer",
".",
"accept",
"(",
"dependency",
".",
"getActualFile",
"(",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Determines if the analyzer can analyze the given dependency.
@return whether or not the analyzer can analyze the dependency
|
[
"Determines",
"if",
"the",
"analyzer",
"can",
"analyze",
"the",
"given",
"dependency",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/AnalysisTask.java#L108-L114
|
17,844
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java
|
Checksum.getMD5Checksum
|
public static String getMD5Checksum(File file) throws IOException, NoSuchAlgorithmException {
final byte[] b = getChecksum(MD5, file);
return getHex(b);
}
|
java
|
public static String getMD5Checksum(File file) throws IOException, NoSuchAlgorithmException {
final byte[] b = getChecksum(MD5, file);
return getHex(b);
}
|
[
"public",
"static",
"String",
"getMD5Checksum",
"(",
"File",
"file",
")",
"throws",
"IOException",
",",
"NoSuchAlgorithmException",
"{",
"final",
"byte",
"[",
"]",
"b",
"=",
"getChecksum",
"(",
"MD5",
",",
"file",
")",
";",
"return",
"getHex",
"(",
"b",
")",
";",
"}"
] |
Calculates the MD5 checksum of a specified file.
@param file the file to generate the MD5 checksum
@return the hex representation of the MD5 hash
@throws java.io.IOException when the file passed in does not exist
@throws java.security.NoSuchAlgorithmException when the MD5 algorithm is not available
|
[
"Calculates",
"the",
"MD5",
"checksum",
"of",
"a",
"specified",
"file",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java#L107-L110
|
17,845
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java
|
Checksum.getSHA1Checksum
|
public static String getSHA1Checksum(File file) throws IOException, NoSuchAlgorithmException {
final byte[] b = getChecksum(SHA1, file);
return getHex(b);
}
|
java
|
public static String getSHA1Checksum(File file) throws IOException, NoSuchAlgorithmException {
final byte[] b = getChecksum(SHA1, file);
return getHex(b);
}
|
[
"public",
"static",
"String",
"getSHA1Checksum",
"(",
"File",
"file",
")",
"throws",
"IOException",
",",
"NoSuchAlgorithmException",
"{",
"final",
"byte",
"[",
"]",
"b",
"=",
"getChecksum",
"(",
"SHA1",
",",
"file",
")",
";",
"return",
"getHex",
"(",
"b",
")",
";",
"}"
] |
Calculates the SHA1 checksum of a specified file.
@param file the file to generate the MD5 checksum
@return the hex representation of the SHA1 hash
@throws java.io.IOException when the file passed in does not exist
@throws java.security.NoSuchAlgorithmException when the SHA1 algorithm is not available
|
[
"Calculates",
"the",
"SHA1",
"checksum",
"of",
"a",
"specified",
"file",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java#L120-L123
|
17,846
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java
|
Checksum.getSHA256Checksum
|
public static String getSHA256Checksum(File file) throws IOException, NoSuchAlgorithmException {
final byte[] b = getChecksum(SHA256, file);
return getHex(b);
}
|
java
|
public static String getSHA256Checksum(File file) throws IOException, NoSuchAlgorithmException {
final byte[] b = getChecksum(SHA256, file);
return getHex(b);
}
|
[
"public",
"static",
"String",
"getSHA256Checksum",
"(",
"File",
"file",
")",
"throws",
"IOException",
",",
"NoSuchAlgorithmException",
"{",
"final",
"byte",
"[",
"]",
"b",
"=",
"getChecksum",
"(",
"SHA256",
",",
"file",
")",
";",
"return",
"getHex",
"(",
"b",
")",
";",
"}"
] |
Calculates the SH256 checksum of a specified file.
@param file the file to generate the MD5 checksum
@return the hex representation of the SHA1 hash
@throws java.io.IOException when the file passed in does not exist
@throws java.security.NoSuchAlgorithmException when the SHA1 algorithm is not available
|
[
"Calculates",
"the",
"SH256",
"checksum",
"of",
"a",
"specified",
"file",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java#L133-L136
|
17,847
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java
|
Checksum.getChecksum
|
public static String getChecksum(String algorithm, byte[] bytes) {
final MessageDigest digest = getMessageDigest(algorithm);
final byte[] b = digest.digest(bytes);
return getHex(b);
}
|
java
|
public static String getChecksum(String algorithm, byte[] bytes) {
final MessageDigest digest = getMessageDigest(algorithm);
final byte[] b = digest.digest(bytes);
return getHex(b);
}
|
[
"public",
"static",
"String",
"getChecksum",
"(",
"String",
"algorithm",
",",
"byte",
"[",
"]",
"bytes",
")",
"{",
"final",
"MessageDigest",
"digest",
"=",
"getMessageDigest",
"(",
"algorithm",
")",
";",
"final",
"byte",
"[",
"]",
"b",
"=",
"digest",
".",
"digest",
"(",
"bytes",
")",
";",
"return",
"getHex",
"(",
"b",
")",
";",
"}"
] |
Calculates the MD5 checksum of a specified bytes.
@param algorithm the algorithm to use (md5, sha1, etc.) to calculate the
message digest
@param bytes the bytes to generate the MD5 checksum
@return the hex representation of the MD5 hash
|
[
"Calculates",
"the",
"MD5",
"checksum",
"of",
"a",
"specified",
"bytes",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java#L146-L150
|
17,848
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java
|
Checksum.getMD5Checksum
|
public static String getMD5Checksum(String text) {
final byte[] data = stringToBytes(text);
return getChecksum(MD5, data);
}
|
java
|
public static String getMD5Checksum(String text) {
final byte[] data = stringToBytes(text);
return getChecksum(MD5, data);
}
|
[
"public",
"static",
"String",
"getMD5Checksum",
"(",
"String",
"text",
")",
"{",
"final",
"byte",
"[",
"]",
"data",
"=",
"stringToBytes",
"(",
"text",
")",
";",
"return",
"getChecksum",
"(",
"MD5",
",",
"data",
")",
";",
"}"
] |
Calculates the MD5 checksum of the specified text.
@param text the text to generate the MD5 checksum
@return the hex representation of the MD5
|
[
"Calculates",
"the",
"MD5",
"checksum",
"of",
"the",
"specified",
"text",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java#L158-L161
|
17,849
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java
|
Checksum.stringToBytes
|
private static byte[] stringToBytes(String text) {
byte[] data;
try {
data = text.getBytes(Charset.forName(StandardCharsets.UTF_8.name()));
} catch (UnsupportedCharsetException ex) {
data = text.getBytes(Charset.defaultCharset());
}
return data;
}
|
java
|
private static byte[] stringToBytes(String text) {
byte[] data;
try {
data = text.getBytes(Charset.forName(StandardCharsets.UTF_8.name()));
} catch (UnsupportedCharsetException ex) {
data = text.getBytes(Charset.defaultCharset());
}
return data;
}
|
[
"private",
"static",
"byte",
"[",
"]",
"stringToBytes",
"(",
"String",
"text",
")",
"{",
"byte",
"[",
"]",
"data",
";",
"try",
"{",
"data",
"=",
"text",
".",
"getBytes",
"(",
"Charset",
".",
"forName",
"(",
"StandardCharsets",
".",
"UTF_8",
".",
"name",
"(",
")",
")",
")",
";",
"}",
"catch",
"(",
"UnsupportedCharsetException",
"ex",
")",
"{",
"data",
"=",
"text",
".",
"getBytes",
"(",
"Charset",
".",
"defaultCharset",
"(",
")",
")",
";",
"}",
"return",
"data",
";",
"}"
] |
Converts the given text into bytes.
@param text the text to convert
@return the bytes
|
[
"Converts",
"the",
"given",
"text",
"into",
"bytes",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java#L191-L199
|
17,850
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java
|
Checksum.getMessageDigest
|
private static MessageDigest getMessageDigest(String algorithm) {
try {
return MessageDigest.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
LOGGER.error(e.getMessage());
final String msg = String.format("Failed to obtain the %s message digest.", algorithm);
throw new IllegalStateException(msg, e);
}
}
|
java
|
private static MessageDigest getMessageDigest(String algorithm) {
try {
return MessageDigest.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
LOGGER.error(e.getMessage());
final String msg = String.format("Failed to obtain the %s message digest.", algorithm);
throw new IllegalStateException(msg, e);
}
}
|
[
"private",
"static",
"MessageDigest",
"getMessageDigest",
"(",
"String",
"algorithm",
")",
"{",
"try",
"{",
"return",
"MessageDigest",
".",
"getInstance",
"(",
"algorithm",
")",
";",
"}",
"catch",
"(",
"NoSuchAlgorithmException",
"e",
")",
"{",
"LOGGER",
".",
"error",
"(",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"final",
"String",
"msg",
"=",
"String",
".",
"format",
"(",
"\"Failed to obtain the %s message digest.\"",
",",
"algorithm",
")",
";",
"throw",
"new",
"IllegalStateException",
"(",
"msg",
",",
"e",
")",
";",
"}",
"}"
] |
Returns the message digest.
@param algorithm the algorithm for the message digest
@return the message digest
|
[
"Returns",
"the",
"message",
"digest",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/Checksum.java#L229-L237
|
17,851
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/xml/suppression/SuppressionHandler.java
|
SuppressionHandler.processPropertyType
|
private PropertyType processPropertyType() {
final PropertyType pt = new PropertyType();
pt.setValue(currentText.toString());
if (currentAttributes != null && currentAttributes.getLength() > 0) {
final String regex = currentAttributes.getValue("regex");
if (regex != null) {
pt.setRegex(Boolean.parseBoolean(regex));
}
final String caseSensitive = currentAttributes.getValue("caseSensitive");
if (caseSensitive != null) {
pt.setCaseSensitive(Boolean.parseBoolean(caseSensitive));
}
}
return pt;
}
|
java
|
private PropertyType processPropertyType() {
final PropertyType pt = new PropertyType();
pt.setValue(currentText.toString());
if (currentAttributes != null && currentAttributes.getLength() > 0) {
final String regex = currentAttributes.getValue("regex");
if (regex != null) {
pt.setRegex(Boolean.parseBoolean(regex));
}
final String caseSensitive = currentAttributes.getValue("caseSensitive");
if (caseSensitive != null) {
pt.setCaseSensitive(Boolean.parseBoolean(caseSensitive));
}
}
return pt;
}
|
[
"private",
"PropertyType",
"processPropertyType",
"(",
")",
"{",
"final",
"PropertyType",
"pt",
"=",
"new",
"PropertyType",
"(",
")",
";",
"pt",
".",
"setValue",
"(",
"currentText",
".",
"toString",
"(",
")",
")",
";",
"if",
"(",
"currentAttributes",
"!=",
"null",
"&&",
"currentAttributes",
".",
"getLength",
"(",
")",
">",
"0",
")",
"{",
"final",
"String",
"regex",
"=",
"currentAttributes",
".",
"getValue",
"(",
"\"regex\"",
")",
";",
"if",
"(",
"regex",
"!=",
"null",
")",
"{",
"pt",
".",
"setRegex",
"(",
"Boolean",
".",
"parseBoolean",
"(",
"regex",
")",
")",
";",
"}",
"final",
"String",
"caseSensitive",
"=",
"currentAttributes",
".",
"getValue",
"(",
"\"caseSensitive\"",
")",
";",
"if",
"(",
"caseSensitive",
"!=",
"null",
")",
"{",
"pt",
".",
"setCaseSensitive",
"(",
"Boolean",
".",
"parseBoolean",
"(",
"caseSensitive",
")",
")",
";",
"}",
"}",
"return",
"pt",
";",
"}"
] |
Processes field members that have been collected during the characters
and startElement method to construct a PropertyType object.
@return a PropertyType object
|
[
"Processes",
"field",
"members",
"that",
"have",
"been",
"collected",
"during",
"the",
"characters",
"and",
"startElement",
"method",
"to",
"construct",
"a",
"PropertyType",
"object",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/xml/suppression/SuppressionHandler.java#L212-L226
|
17,852
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/nodeaudit/SanitizePackage.java
|
SanitizePackage.sanitize
|
public static JsonObject sanitize(JsonObject packageJson) {
final JsonObjectBuilder payloadBuilder = Json.createObjectBuilder();
final String projectName = packageJson.getString("name", "");
final String projectVersion = packageJson.getString("version", "");
if (!projectName.isEmpty()) {
payloadBuilder.add("name", projectName);
}
if (!projectVersion.isEmpty()) {
payloadBuilder.add("version", projectVersion);
}
// In most package-lock.json files, 'requires' is a boolean, however, NPM Audit expects
// 'requires' to be an object containing key/value pairs corresponding to the module
// name (key) and version (value).
final JsonValue jsonValue = packageJson.get("requires");
if (jsonValue.getValueType() != JsonValue.ValueType.OBJECT) {
final JsonObjectBuilder requiresBuilder = Json.createObjectBuilder();
final JsonObject dependencies = packageJson.getJsonObject("dependencies");
for (String moduleName: dependencies.keySet()) {
final JsonObject module = dependencies.getJsonObject(moduleName);
final String version = module.getString("version");
requiresBuilder.add(moduleName, version);
}
payloadBuilder.add("requires", requiresBuilder.build());
}
payloadBuilder.add("dependencies", packageJson.getJsonObject("dependencies"));
payloadBuilder.add("install", Json.createArrayBuilder().build());
payloadBuilder.add("remove", Json.createArrayBuilder().build());
payloadBuilder.add("metadata", Json.createObjectBuilder()
.add("npm_version", "6.1.0")
.add("node_version", "v10.5.0")
.add("platform", "linux")
);
// Create a new 'package-lock.json' object
return payloadBuilder.build();
}
|
java
|
public static JsonObject sanitize(JsonObject packageJson) {
final JsonObjectBuilder payloadBuilder = Json.createObjectBuilder();
final String projectName = packageJson.getString("name", "");
final String projectVersion = packageJson.getString("version", "");
if (!projectName.isEmpty()) {
payloadBuilder.add("name", projectName);
}
if (!projectVersion.isEmpty()) {
payloadBuilder.add("version", projectVersion);
}
// In most package-lock.json files, 'requires' is a boolean, however, NPM Audit expects
// 'requires' to be an object containing key/value pairs corresponding to the module
// name (key) and version (value).
final JsonValue jsonValue = packageJson.get("requires");
if (jsonValue.getValueType() != JsonValue.ValueType.OBJECT) {
final JsonObjectBuilder requiresBuilder = Json.createObjectBuilder();
final JsonObject dependencies = packageJson.getJsonObject("dependencies");
for (String moduleName: dependencies.keySet()) {
final JsonObject module = dependencies.getJsonObject(moduleName);
final String version = module.getString("version");
requiresBuilder.add(moduleName, version);
}
payloadBuilder.add("requires", requiresBuilder.build());
}
payloadBuilder.add("dependencies", packageJson.getJsonObject("dependencies"));
payloadBuilder.add("install", Json.createArrayBuilder().build());
payloadBuilder.add("remove", Json.createArrayBuilder().build());
payloadBuilder.add("metadata", Json.createObjectBuilder()
.add("npm_version", "6.1.0")
.add("node_version", "v10.5.0")
.add("platform", "linux")
);
// Create a new 'package-lock.json' object
return payloadBuilder.build();
}
|
[
"public",
"static",
"JsonObject",
"sanitize",
"(",
"JsonObject",
"packageJson",
")",
"{",
"final",
"JsonObjectBuilder",
"payloadBuilder",
"=",
"Json",
".",
"createObjectBuilder",
"(",
")",
";",
"final",
"String",
"projectName",
"=",
"packageJson",
".",
"getString",
"(",
"\"name\"",
",",
"\"\"",
")",
";",
"final",
"String",
"projectVersion",
"=",
"packageJson",
".",
"getString",
"(",
"\"version\"",
",",
"\"\"",
")",
";",
"if",
"(",
"!",
"projectName",
".",
"isEmpty",
"(",
")",
")",
"{",
"payloadBuilder",
".",
"add",
"(",
"\"name\"",
",",
"projectName",
")",
";",
"}",
"if",
"(",
"!",
"projectVersion",
".",
"isEmpty",
"(",
")",
")",
"{",
"payloadBuilder",
".",
"add",
"(",
"\"version\"",
",",
"projectVersion",
")",
";",
"}",
"// In most package-lock.json files, 'requires' is a boolean, however, NPM Audit expects",
"// 'requires' to be an object containing key/value pairs corresponding to the module",
"// name (key) and version (value).",
"final",
"JsonValue",
"jsonValue",
"=",
"packageJson",
".",
"get",
"(",
"\"requires\"",
")",
";",
"if",
"(",
"jsonValue",
".",
"getValueType",
"(",
")",
"!=",
"JsonValue",
".",
"ValueType",
".",
"OBJECT",
")",
"{",
"final",
"JsonObjectBuilder",
"requiresBuilder",
"=",
"Json",
".",
"createObjectBuilder",
"(",
")",
";",
"final",
"JsonObject",
"dependencies",
"=",
"packageJson",
".",
"getJsonObject",
"(",
"\"dependencies\"",
")",
";",
"for",
"(",
"String",
"moduleName",
":",
"dependencies",
".",
"keySet",
"(",
")",
")",
"{",
"final",
"JsonObject",
"module",
"=",
"dependencies",
".",
"getJsonObject",
"(",
"moduleName",
")",
";",
"final",
"String",
"version",
"=",
"module",
".",
"getString",
"(",
"\"version\"",
")",
";",
"requiresBuilder",
".",
"add",
"(",
"moduleName",
",",
"version",
")",
";",
"}",
"payloadBuilder",
".",
"add",
"(",
"\"requires\"",
",",
"requiresBuilder",
".",
"build",
"(",
")",
")",
";",
"}",
"payloadBuilder",
".",
"add",
"(",
"\"dependencies\"",
",",
"packageJson",
".",
"getJsonObject",
"(",
"\"dependencies\"",
")",
")",
";",
"payloadBuilder",
".",
"add",
"(",
"\"install\"",
",",
"Json",
".",
"createArrayBuilder",
"(",
")",
".",
"build",
"(",
")",
")",
";",
"payloadBuilder",
".",
"add",
"(",
"\"remove\"",
",",
"Json",
".",
"createArrayBuilder",
"(",
")",
".",
"build",
"(",
")",
")",
";",
"payloadBuilder",
".",
"add",
"(",
"\"metadata\"",
",",
"Json",
".",
"createObjectBuilder",
"(",
")",
".",
"add",
"(",
"\"npm_version\"",
",",
"\"6.1.0\"",
")",
".",
"add",
"(",
"\"node_version\"",
",",
"\"v10.5.0\"",
")",
".",
"add",
"(",
"\"platform\"",
",",
"\"linux\"",
")",
")",
";",
"// Create a new 'package-lock.json' object",
"return",
"payloadBuilder",
".",
"build",
"(",
")",
";",
"}"
] |
The NPM Audit API only accepts a modified version of package-lock.json.
This method will make the necessary modifications in-memory, sanitizing
non-public dependencies by omitting them, and returns a new 'sanitized'
version.
@param packageJson a raw package-lock.json file
@return a modified/sanitized version of the package-lock.json file
|
[
"The",
"NPM",
"Audit",
"API",
"only",
"accepts",
"a",
"modified",
"version",
"of",
"package",
"-",
"lock",
".",
"json",
".",
"This",
"method",
"will",
"make",
"the",
"necessary",
"modifications",
"in",
"-",
"memory",
"sanitizing",
"non",
"-",
"public",
"dependencies",
"by",
"omitting",
"them",
"and",
"returns",
"a",
"new",
"sanitized",
"version",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/nodeaudit/SanitizePackage.java#L51-L88
|
17,853
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/update/nvd/DownloadTask.java
|
DownloadTask.cleanup
|
public void cleanup() {
if (file != null && file.exists() && !file.delete()) {
LOGGER.debug("Failed to delete first temporary file {}", file.toString());
file.deleteOnExit();
}
}
|
java
|
public void cleanup() {
if (file != null && file.exists() && !file.delete()) {
LOGGER.debug("Failed to delete first temporary file {}", file.toString());
file.deleteOnExit();
}
}
|
[
"public",
"void",
"cleanup",
"(",
")",
"{",
"if",
"(",
"file",
"!=",
"null",
"&&",
"file",
".",
"exists",
"(",
")",
"&&",
"!",
"file",
".",
"delete",
"(",
")",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Failed to delete first temporary file {}\"",
",",
"file",
".",
"toString",
"(",
")",
")",
";",
"file",
".",
"deleteOnExit",
"(",
")",
";",
"}",
"}"
] |
Attempts to delete the files that were downloaded.
|
[
"Attempts",
"to",
"delete",
"the",
"files",
"that",
"were",
"downloaded",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/update/nvd/DownloadTask.java#L158-L163
|
17,854
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/nodeaudit/NodeAuditSearch.java
|
NodeAuditSearch.submitPackage
|
public List<Advisory> submitPackage(JsonObject packageJson) throws SearchException, IOException {
try {
final byte[] packageDatabytes = packageJson.toString().getBytes(StandardCharsets.UTF_8);
final URLConnectionFactory factory = new URLConnectionFactory(settings);
final HttpURLConnection conn = factory.createHttpURLConnection(nodeAuditUrl, useProxy);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("user-agent", "npm/6.1.0 node/v10.5.0 linux x64");
conn.setRequestProperty("npm-in-ci", "false");
conn.setRequestProperty("npm-scope", "");
conn.setRequestProperty("npm-session", generateRandomSession());
conn.setRequestProperty("content-type", "application/json");
conn.setRequestProperty("Content-Length", Integer.toString(packageDatabytes.length));
conn.connect();
try (OutputStream os = new BufferedOutputStream(conn.getOutputStream())) {
os.write(packageDatabytes);
os.flush();
}
switch (conn.getResponseCode()) {
case 200:
try (InputStream in = new BufferedInputStream(conn.getInputStream());
JsonReader jsonReader = Json.createReader(in)) {
final JSONObject jsonResponse = new JSONObject(jsonReader.readObject().toString());
final NpmAuditParser parser = new NpmAuditParser();
return parser.parse(jsonResponse);
}
case 400:
LOGGER.debug("Invalid payload submitted to Node Audit API. Received response code: {} {}",
conn.getResponseCode(), conn.getResponseMessage());
throw new SearchException("Could not perform Node Audit analysis. Invalid payload submitted to Node Audit API.");
default:
LOGGER.debug("Could not connect to Node Audit API. Received response code: {} {}",
conn.getResponseCode(), conn.getResponseMessage());
throw new IOException("Could not connect to Node Audit API");
}
} catch (IOException ex) {
if (ex instanceof javax.net.ssl.SSLHandshakeException
&& ex.getMessage().contains("unable to find valid certification path to requested target")) {
final String msg = String.format("Unable to connect to '%s' - the Java trust store does not contain a trusted root for the cert. "
+ " Please see https://github.com/jeremylong/InstallCert for one method of updating the trusted certificates.", nodeAuditUrl);
throw new URLConnectionFailureException(msg, ex);
}
throw ex;
}
}
|
java
|
public List<Advisory> submitPackage(JsonObject packageJson) throws SearchException, IOException {
try {
final byte[] packageDatabytes = packageJson.toString().getBytes(StandardCharsets.UTF_8);
final URLConnectionFactory factory = new URLConnectionFactory(settings);
final HttpURLConnection conn = factory.createHttpURLConnection(nodeAuditUrl, useProxy);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("user-agent", "npm/6.1.0 node/v10.5.0 linux x64");
conn.setRequestProperty("npm-in-ci", "false");
conn.setRequestProperty("npm-scope", "");
conn.setRequestProperty("npm-session", generateRandomSession());
conn.setRequestProperty("content-type", "application/json");
conn.setRequestProperty("Content-Length", Integer.toString(packageDatabytes.length));
conn.connect();
try (OutputStream os = new BufferedOutputStream(conn.getOutputStream())) {
os.write(packageDatabytes);
os.flush();
}
switch (conn.getResponseCode()) {
case 200:
try (InputStream in = new BufferedInputStream(conn.getInputStream());
JsonReader jsonReader = Json.createReader(in)) {
final JSONObject jsonResponse = new JSONObject(jsonReader.readObject().toString());
final NpmAuditParser parser = new NpmAuditParser();
return parser.parse(jsonResponse);
}
case 400:
LOGGER.debug("Invalid payload submitted to Node Audit API. Received response code: {} {}",
conn.getResponseCode(), conn.getResponseMessage());
throw new SearchException("Could not perform Node Audit analysis. Invalid payload submitted to Node Audit API.");
default:
LOGGER.debug("Could not connect to Node Audit API. Received response code: {} {}",
conn.getResponseCode(), conn.getResponseMessage());
throw new IOException("Could not connect to Node Audit API");
}
} catch (IOException ex) {
if (ex instanceof javax.net.ssl.SSLHandshakeException
&& ex.getMessage().contains("unable to find valid certification path to requested target")) {
final String msg = String.format("Unable to connect to '%s' - the Java trust store does not contain a trusted root for the cert. "
+ " Please see https://github.com/jeremylong/InstallCert for one method of updating the trusted certificates.", nodeAuditUrl);
throw new URLConnectionFailureException(msg, ex);
}
throw ex;
}
}
|
[
"public",
"List",
"<",
"Advisory",
">",
"submitPackage",
"(",
"JsonObject",
"packageJson",
")",
"throws",
"SearchException",
",",
"IOException",
"{",
"try",
"{",
"final",
"byte",
"[",
"]",
"packageDatabytes",
"=",
"packageJson",
".",
"toString",
"(",
")",
".",
"getBytes",
"(",
"StandardCharsets",
".",
"UTF_8",
")",
";",
"final",
"URLConnectionFactory",
"factory",
"=",
"new",
"URLConnectionFactory",
"(",
"settings",
")",
";",
"final",
"HttpURLConnection",
"conn",
"=",
"factory",
".",
"createHttpURLConnection",
"(",
"nodeAuditUrl",
",",
"useProxy",
")",
";",
"conn",
".",
"setDoOutput",
"(",
"true",
")",
";",
"conn",
".",
"setDoInput",
"(",
"true",
")",
";",
"conn",
".",
"setRequestMethod",
"(",
"\"POST\"",
")",
";",
"conn",
".",
"setRequestProperty",
"(",
"\"user-agent\"",
",",
"\"npm/6.1.0 node/v10.5.0 linux x64\"",
")",
";",
"conn",
".",
"setRequestProperty",
"(",
"\"npm-in-ci\"",
",",
"\"false\"",
")",
";",
"conn",
".",
"setRequestProperty",
"(",
"\"npm-scope\"",
",",
"\"\"",
")",
";",
"conn",
".",
"setRequestProperty",
"(",
"\"npm-session\"",
",",
"generateRandomSession",
"(",
")",
")",
";",
"conn",
".",
"setRequestProperty",
"(",
"\"content-type\"",
",",
"\"application/json\"",
")",
";",
"conn",
".",
"setRequestProperty",
"(",
"\"Content-Length\"",
",",
"Integer",
".",
"toString",
"(",
"packageDatabytes",
".",
"length",
")",
")",
";",
"conn",
".",
"connect",
"(",
")",
";",
"try",
"(",
"OutputStream",
"os",
"=",
"new",
"BufferedOutputStream",
"(",
"conn",
".",
"getOutputStream",
"(",
")",
")",
")",
"{",
"os",
".",
"write",
"(",
"packageDatabytes",
")",
";",
"os",
".",
"flush",
"(",
")",
";",
"}",
"switch",
"(",
"conn",
".",
"getResponseCode",
"(",
")",
")",
"{",
"case",
"200",
":",
"try",
"(",
"InputStream",
"in",
"=",
"new",
"BufferedInputStream",
"(",
"conn",
".",
"getInputStream",
"(",
")",
")",
";",
"JsonReader",
"jsonReader",
"=",
"Json",
".",
"createReader",
"(",
"in",
")",
")",
"{",
"final",
"JSONObject",
"jsonResponse",
"=",
"new",
"JSONObject",
"(",
"jsonReader",
".",
"readObject",
"(",
")",
".",
"toString",
"(",
")",
")",
";",
"final",
"NpmAuditParser",
"parser",
"=",
"new",
"NpmAuditParser",
"(",
")",
";",
"return",
"parser",
".",
"parse",
"(",
"jsonResponse",
")",
";",
"}",
"case",
"400",
":",
"LOGGER",
".",
"debug",
"(",
"\"Invalid payload submitted to Node Audit API. Received response code: {} {}\"",
",",
"conn",
".",
"getResponseCode",
"(",
")",
",",
"conn",
".",
"getResponseMessage",
"(",
")",
")",
";",
"throw",
"new",
"SearchException",
"(",
"\"Could not perform Node Audit analysis. Invalid payload submitted to Node Audit API.\"",
")",
";",
"default",
":",
"LOGGER",
".",
"debug",
"(",
"\"Could not connect to Node Audit API. Received response code: {} {}\"",
",",
"conn",
".",
"getResponseCode",
"(",
")",
",",
"conn",
".",
"getResponseMessage",
"(",
")",
")",
";",
"throw",
"new",
"IOException",
"(",
"\"Could not connect to Node Audit API\"",
")",
";",
"}",
"}",
"catch",
"(",
"IOException",
"ex",
")",
"{",
"if",
"(",
"ex",
"instanceof",
"javax",
".",
"net",
".",
"ssl",
".",
"SSLHandshakeException",
"&&",
"ex",
".",
"getMessage",
"(",
")",
".",
"contains",
"(",
"\"unable to find valid certification path to requested target\"",
")",
")",
"{",
"final",
"String",
"msg",
"=",
"String",
".",
"format",
"(",
"\"Unable to connect to '%s' - the Java trust store does not contain a trusted root for the cert. \"",
"+",
"\" Please see https://github.com/jeremylong/InstallCert for one method of updating the trusted certificates.\"",
",",
"nodeAuditUrl",
")",
";",
"throw",
"new",
"URLConnectionFailureException",
"(",
"msg",
",",
"ex",
")",
";",
"}",
"throw",
"ex",
";",
"}",
"}"
] |
Submits the package.json file to the Node Audit API and returns a list of
zero or more Advisories.
@param packageJson the package.json file retrieved from the Dependency
@return a List of zero or more Advisory object
@throws SearchException if Node Audit API is unable to analyze the
package
@throws IOException if it's unable to connect to Node Audit API
|
[
"Submits",
"the",
"package",
".",
"json",
"file",
"to",
"the",
"Node",
"Audit",
"API",
"and",
"returns",
"a",
"list",
"of",
"zero",
"or",
"more",
"Advisories",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/nodeaudit/NodeAuditSearch.java#L101-L148
|
17,855
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/nodeaudit/NodeAuditSearch.java
|
NodeAuditSearch.generateRandomSession
|
private String generateRandomSession() {
final int length = 16;
final SecureRandom r = new SecureRandom();
final StringBuilder sb = new StringBuilder();
while (sb.length() < length) {
sb.append(Integer.toHexString(r.nextInt()));
}
return sb.toString().substring(0, length);
}
|
java
|
private String generateRandomSession() {
final int length = 16;
final SecureRandom r = new SecureRandom();
final StringBuilder sb = new StringBuilder();
while (sb.length() < length) {
sb.append(Integer.toHexString(r.nextInt()));
}
return sb.toString().substring(0, length);
}
|
[
"private",
"String",
"generateRandomSession",
"(",
")",
"{",
"final",
"int",
"length",
"=",
"16",
";",
"final",
"SecureRandom",
"r",
"=",
"new",
"SecureRandom",
"(",
")",
";",
"final",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"while",
"(",
"sb",
".",
"length",
"(",
")",
"<",
"length",
")",
"{",
"sb",
".",
"append",
"(",
"Integer",
".",
"toHexString",
"(",
"r",
".",
"nextInt",
"(",
")",
")",
")",
";",
"}",
"return",
"sb",
".",
"toString",
"(",
")",
".",
"substring",
"(",
"0",
",",
"length",
")",
";",
"}"
] |
Generates a random 16 character lower-case hex string.
@return a random 16 character lower-case hex string
|
[
"Generates",
"a",
"random",
"16",
"character",
"lower",
"-",
"case",
"hex",
"string",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/nodeaudit/NodeAuditSearch.java#L155-L163
|
17,856
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/lucene/LuceneUtils.java
|
LuceneUtils.appendEscapedLuceneQuery
|
@SuppressWarnings("fallthrough")
@SuppressFBWarnings(justification = "As this is an encoding method the fallthrough is intentional", value = {"SF_SWITCH_NO_DEFAULT"})
public static void appendEscapedLuceneQuery(StringBuilder buf,
final CharSequence text) {
if (text == null || buf == null) {
return;
}
for (int i = 0; i < text.length(); i++) {
final char c = text.charAt(i);
switch (c) {
case '+':
case '-':
case '&':
case '|':
case '!':
case '(':
case ')':
case '{':
case '}':
case '[':
case ']':
case '^':
case '"':
case '~':
case '*':
case '?':
case ':':
case '/':
case '\\': //it is supposed to fall through here
buf.append('\\');
default:
buf.append(c);
break;
}
}
}
|
java
|
@SuppressWarnings("fallthrough")
@SuppressFBWarnings(justification = "As this is an encoding method the fallthrough is intentional", value = {"SF_SWITCH_NO_DEFAULT"})
public static void appendEscapedLuceneQuery(StringBuilder buf,
final CharSequence text) {
if (text == null || buf == null) {
return;
}
for (int i = 0; i < text.length(); i++) {
final char c = text.charAt(i);
switch (c) {
case '+':
case '-':
case '&':
case '|':
case '!':
case '(':
case ')':
case '{':
case '}':
case '[':
case ']':
case '^':
case '"':
case '~':
case '*':
case '?':
case ':':
case '/':
case '\\': //it is supposed to fall through here
buf.append('\\');
default:
buf.append(c);
break;
}
}
}
|
[
"@",
"SuppressWarnings",
"(",
"\"fallthrough\"",
")",
"@",
"SuppressFBWarnings",
"(",
"justification",
"=",
"\"As this is an encoding method the fallthrough is intentional\"",
",",
"value",
"=",
"{",
"\"SF_SWITCH_NO_DEFAULT\"",
"}",
")",
"public",
"static",
"void",
"appendEscapedLuceneQuery",
"(",
"StringBuilder",
"buf",
",",
"final",
"CharSequence",
"text",
")",
"{",
"if",
"(",
"text",
"==",
"null",
"||",
"buf",
"==",
"null",
")",
"{",
"return",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"text",
".",
"length",
"(",
")",
";",
"i",
"++",
")",
"{",
"final",
"char",
"c",
"=",
"text",
".",
"charAt",
"(",
"i",
")",
";",
"switch",
"(",
"c",
")",
"{",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"case",
"'",
"'",
":",
"//it is supposed to fall through here",
"buf",
".",
"append",
"(",
"'",
"'",
")",
";",
"default",
":",
"buf",
".",
"append",
"(",
"c",
")",
";",
"break",
";",
"}",
"}",
"}"
] |
Appends the text to the supplied StringBuilder escaping Lucene control
characters in the process.
@param buf a StringBuilder to append the escaped text to
@param text the data to be escaped
|
[
"Appends",
"the",
"text",
"to",
"the",
"supplied",
"StringBuilder",
"escaping",
"Lucene",
"control",
"characters",
"in",
"the",
"process",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/lucene/LuceneUtils.java#L68-L105
|
17,857
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/lucene/LuceneUtils.java
|
LuceneUtils.escapeLuceneQuery
|
public static String escapeLuceneQuery(final CharSequence text) {
if (text == null) {
return null;
}
final int size = text.length() << 1;
final StringBuilder buf = new StringBuilder(size);
appendEscapedLuceneQuery(buf, text);
return buf.toString();
}
|
java
|
public static String escapeLuceneQuery(final CharSequence text) {
if (text == null) {
return null;
}
final int size = text.length() << 1;
final StringBuilder buf = new StringBuilder(size);
appendEscapedLuceneQuery(buf, text);
return buf.toString();
}
|
[
"public",
"static",
"String",
"escapeLuceneQuery",
"(",
"final",
"CharSequence",
"text",
")",
"{",
"if",
"(",
"text",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"final",
"int",
"size",
"=",
"text",
".",
"length",
"(",
")",
"<<",
"1",
";",
"final",
"StringBuilder",
"buf",
"=",
"new",
"StringBuilder",
"(",
"size",
")",
";",
"appendEscapedLuceneQuery",
"(",
"buf",
",",
"text",
")",
";",
"return",
"buf",
".",
"toString",
"(",
")",
";",
"}"
] |
Escapes the text passed in so that it is treated as data instead of
control characters.
@param text data to be escaped
@return the escaped text.
|
[
"Escapes",
"the",
"text",
"passed",
"in",
"so",
"that",
"it",
"is",
"treated",
"as",
"data",
"instead",
"of",
"control",
"characters",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/lucene/LuceneUtils.java#L114-L122
|
17,858
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/SwiftPackageManagerAnalyzer.java
|
SwiftPackageManagerAnalyzer.addStringEvidence
|
private String addStringEvidence(Dependency dependency, EvidenceType type,
String packageDescription, String field, String fieldPattern, Confidence confidence) {
String value = "";
final Matcher matcher = Pattern.compile(
String.format("%s *:\\s*\"([^\"]*)", fieldPattern), Pattern.DOTALL).matcher(packageDescription);
if (matcher.find()) {
value = matcher.group(1);
}
if (value != null) {
value = value.trim();
if (value.length() > 0) {
dependency.addEvidence(type, SPM_FILE_NAME, field, value, confidence);
}
}
return value;
}
|
java
|
private String addStringEvidence(Dependency dependency, EvidenceType type,
String packageDescription, String field, String fieldPattern, Confidence confidence) {
String value = "";
final Matcher matcher = Pattern.compile(
String.format("%s *:\\s*\"([^\"]*)", fieldPattern), Pattern.DOTALL).matcher(packageDescription);
if (matcher.find()) {
value = matcher.group(1);
}
if (value != null) {
value = value.trim();
if (value.length() > 0) {
dependency.addEvidence(type, SPM_FILE_NAME, field, value, confidence);
}
}
return value;
}
|
[
"private",
"String",
"addStringEvidence",
"(",
"Dependency",
"dependency",
",",
"EvidenceType",
"type",
",",
"String",
"packageDescription",
",",
"String",
"field",
",",
"String",
"fieldPattern",
",",
"Confidence",
"confidence",
")",
"{",
"String",
"value",
"=",
"\"\"",
";",
"final",
"Matcher",
"matcher",
"=",
"Pattern",
".",
"compile",
"(",
"String",
".",
"format",
"(",
"\"%s *:\\\\s*\\\"([^\\\"]*)\"",
",",
"fieldPattern",
")",
",",
"Pattern",
".",
"DOTALL",
")",
".",
"matcher",
"(",
"packageDescription",
")",
";",
"if",
"(",
"matcher",
".",
"find",
"(",
")",
")",
"{",
"value",
"=",
"matcher",
".",
"group",
"(",
"1",
")",
";",
"}",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"value",
"=",
"value",
".",
"trim",
"(",
")",
";",
"if",
"(",
"value",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"dependency",
".",
"addEvidence",
"(",
"type",
",",
"SPM_FILE_NAME",
",",
"field",
",",
"value",
",",
"confidence",
")",
";",
"}",
"}",
"return",
"value",
";",
"}"
] |
Extracts evidence from the package description and adds it to the given
evidence collection.
@param dependency the dependency being analyzed
@param type the type of evidence to add
@param packageDescription the text to extract evidence from
@param field the name of the field being searched for
@param fieldPattern the field pattern within the contents to search for
@param confidence the confidence level of the evidence if found
@return the string that was added as evidence
|
[
"Extracts",
"evidence",
"from",
"the",
"package",
"description",
"and",
"adds",
"it",
"to",
"the",
"given",
"evidence",
"collection",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/SwiftPackageManagerAnalyzer.java#L210-L227
|
17,859
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/composer/ComposerLockParser.java
|
ComposerLockParser.process
|
public void process() {
LOGGER.debug("Beginning Composer lock processing");
try {
final JsonObject composer = jsonReader.readObject();
if (composer.containsKey("packages")) {
LOGGER.debug("Found packages");
final JsonArray packages = composer.getJsonArray("packages");
for (JsonObject pkg : packages.getValuesAs(JsonObject.class)) {
if (pkg.containsKey("name")) {
final String groupName = pkg.getString("name");
if (groupName.indexOf('/') >= 0 && groupName.indexOf('/') <= groupName.length() - 1) {
if (pkg.containsKey("version")) {
final String group = groupName.substring(0, groupName.indexOf('/'));
final String project = groupName.substring(groupName.indexOf('/') + 1);
String version = pkg.getString("version");
// Some version numbers begin with v - which doesn't end up matching CPE's
if (version.startsWith("v")) {
version = version.substring(1);
}
LOGGER.debug("Got package {}/{}/{}", group, project, version);
composerDependencies.add(new ComposerDependency(group, project, version));
} else {
LOGGER.debug("Group/package {} does not have a version", groupName);
}
} else {
LOGGER.debug("Got a dependency with no name");
}
}
}
}
} catch (JsonParsingException jsonpe) {
throw new ComposerException("Error parsing stream", jsonpe);
} catch (JsonException jsone) {
throw new ComposerException("Error reading stream", jsone);
} catch (IllegalStateException ise) {
throw new ComposerException("Illegal state in composer stream", ise);
} catch (ClassCastException cce) {
throw new ComposerException("Not exactly composer lock", cce);
}
}
|
java
|
public void process() {
LOGGER.debug("Beginning Composer lock processing");
try {
final JsonObject composer = jsonReader.readObject();
if (composer.containsKey("packages")) {
LOGGER.debug("Found packages");
final JsonArray packages = composer.getJsonArray("packages");
for (JsonObject pkg : packages.getValuesAs(JsonObject.class)) {
if (pkg.containsKey("name")) {
final String groupName = pkg.getString("name");
if (groupName.indexOf('/') >= 0 && groupName.indexOf('/') <= groupName.length() - 1) {
if (pkg.containsKey("version")) {
final String group = groupName.substring(0, groupName.indexOf('/'));
final String project = groupName.substring(groupName.indexOf('/') + 1);
String version = pkg.getString("version");
// Some version numbers begin with v - which doesn't end up matching CPE's
if (version.startsWith("v")) {
version = version.substring(1);
}
LOGGER.debug("Got package {}/{}/{}", group, project, version);
composerDependencies.add(new ComposerDependency(group, project, version));
} else {
LOGGER.debug("Group/package {} does not have a version", groupName);
}
} else {
LOGGER.debug("Got a dependency with no name");
}
}
}
}
} catch (JsonParsingException jsonpe) {
throw new ComposerException("Error parsing stream", jsonpe);
} catch (JsonException jsone) {
throw new ComposerException("Error reading stream", jsone);
} catch (IllegalStateException ise) {
throw new ComposerException("Illegal state in composer stream", ise);
} catch (ClassCastException cce) {
throw new ComposerException("Not exactly composer lock", cce);
}
}
|
[
"public",
"void",
"process",
"(",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Beginning Composer lock processing\"",
")",
";",
"try",
"{",
"final",
"JsonObject",
"composer",
"=",
"jsonReader",
".",
"readObject",
"(",
")",
";",
"if",
"(",
"composer",
".",
"containsKey",
"(",
"\"packages\"",
")",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Found packages\"",
")",
";",
"final",
"JsonArray",
"packages",
"=",
"composer",
".",
"getJsonArray",
"(",
"\"packages\"",
")",
";",
"for",
"(",
"JsonObject",
"pkg",
":",
"packages",
".",
"getValuesAs",
"(",
"JsonObject",
".",
"class",
")",
")",
"{",
"if",
"(",
"pkg",
".",
"containsKey",
"(",
"\"name\"",
")",
")",
"{",
"final",
"String",
"groupName",
"=",
"pkg",
".",
"getString",
"(",
"\"name\"",
")",
";",
"if",
"(",
"groupName",
".",
"indexOf",
"(",
"'",
"'",
")",
">=",
"0",
"&&",
"groupName",
".",
"indexOf",
"(",
"'",
"'",
")",
"<=",
"groupName",
".",
"length",
"(",
")",
"-",
"1",
")",
"{",
"if",
"(",
"pkg",
".",
"containsKey",
"(",
"\"version\"",
")",
")",
"{",
"final",
"String",
"group",
"=",
"groupName",
".",
"substring",
"(",
"0",
",",
"groupName",
".",
"indexOf",
"(",
"'",
"'",
")",
")",
";",
"final",
"String",
"project",
"=",
"groupName",
".",
"substring",
"(",
"groupName",
".",
"indexOf",
"(",
"'",
"'",
")",
"+",
"1",
")",
";",
"String",
"version",
"=",
"pkg",
".",
"getString",
"(",
"\"version\"",
")",
";",
"// Some version numbers begin with v - which doesn't end up matching CPE's",
"if",
"(",
"version",
".",
"startsWith",
"(",
"\"v\"",
")",
")",
"{",
"version",
"=",
"version",
".",
"substring",
"(",
"1",
")",
";",
"}",
"LOGGER",
".",
"debug",
"(",
"\"Got package {}/{}/{}\"",
",",
"group",
",",
"project",
",",
"version",
")",
";",
"composerDependencies",
".",
"add",
"(",
"new",
"ComposerDependency",
"(",
"group",
",",
"project",
",",
"version",
")",
")",
";",
"}",
"else",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Group/package {} does not have a version\"",
",",
"groupName",
")",
";",
"}",
"}",
"else",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Got a dependency with no name\"",
")",
";",
"}",
"}",
"}",
"}",
"}",
"catch",
"(",
"JsonParsingException",
"jsonpe",
")",
"{",
"throw",
"new",
"ComposerException",
"(",
"\"Error parsing stream\"",
",",
"jsonpe",
")",
";",
"}",
"catch",
"(",
"JsonException",
"jsone",
")",
"{",
"throw",
"new",
"ComposerException",
"(",
"\"Error reading stream\"",
",",
"jsone",
")",
";",
"}",
"catch",
"(",
"IllegalStateException",
"ise",
")",
"{",
"throw",
"new",
"ComposerException",
"(",
"\"Illegal state in composer stream\"",
",",
"ise",
")",
";",
"}",
"catch",
"(",
"ClassCastException",
"cce",
")",
"{",
"throw",
"new",
"ComposerException",
"(",
"\"Not exactly composer lock\"",
",",
"cce",
")",
";",
"}",
"}"
] |
Process the input stream to create the list of dependencies.
|
[
"Process",
"the",
"input",
"stream",
"to",
"create",
"the",
"list",
"of",
"dependencies",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/composer/ComposerLockParser.java#L71-L110
|
17,860
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/cwe/CweDB.java
|
CweDB.loadData
|
@SuppressWarnings("unchecked")
private static Map<String, String> loadData() {
final String filePath = "data/cwe.hashmap.serialized";
try (InputStream input = FileUtils.getResourceAsStream(filePath);
ObjectInputStream oin = new ObjectInputStream(input)) {
return (HashMap<String, String>) oin.readObject();
} catch (ClassNotFoundException ex) {
LOGGER.warn("Unable to load CWE data. This should not be an issue.");
LOGGER.debug("", ex);
} catch (IOException ex) {
LOGGER.warn("Unable to load CWE data due to an IO Error. This should not be an issue.");
LOGGER.debug("", ex);
}
return null;
}
|
java
|
@SuppressWarnings("unchecked")
private static Map<String, String> loadData() {
final String filePath = "data/cwe.hashmap.serialized";
try (InputStream input = FileUtils.getResourceAsStream(filePath);
ObjectInputStream oin = new ObjectInputStream(input)) {
return (HashMap<String, String>) oin.readObject();
} catch (ClassNotFoundException ex) {
LOGGER.warn("Unable to load CWE data. This should not be an issue.");
LOGGER.debug("", ex);
} catch (IOException ex) {
LOGGER.warn("Unable to load CWE data due to an IO Error. This should not be an issue.");
LOGGER.debug("", ex);
}
return null;
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"private",
"static",
"Map",
"<",
"String",
",",
"String",
">",
"loadData",
"(",
")",
"{",
"final",
"String",
"filePath",
"=",
"\"data/cwe.hashmap.serialized\"",
";",
"try",
"(",
"InputStream",
"input",
"=",
"FileUtils",
".",
"getResourceAsStream",
"(",
"filePath",
")",
";",
"ObjectInputStream",
"oin",
"=",
"new",
"ObjectInputStream",
"(",
"input",
")",
")",
"{",
"return",
"(",
"HashMap",
"<",
"String",
",",
"String",
">",
")",
"oin",
".",
"readObject",
"(",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"ex",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Unable to load CWE data. This should not be an issue.\"",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"\"",
",",
"ex",
")",
";",
"}",
"catch",
"(",
"IOException",
"ex",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Unable to load CWE data due to an IO Error. This should not be an issue.\"",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"\"",
",",
"ex",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Loads a HashMap containing the CWE data from a resource found in the jar.
@return a HashMap of CWE data
|
[
"Loads",
"a",
"HashMap",
"containing",
"the",
"CWE",
"data",
"from",
"a",
"resource",
"found",
"in",
"the",
"jar",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/cwe/CweDB.java#L59-L73
|
17,861
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/CMakeAnalyzer.java
|
CMakeAnalyzer.analyzeSetVersionCommand
|
private void analyzeSetVersionCommand(Dependency dependency, Engine engine, String contents) {
Dependency currentDep = dependency;
final Matcher m = SET_VERSION.matcher(contents);
int count = 0;
while (m.find()) {
count++;
LOGGER.debug("Found project command match with {} groups: {}",
m.groupCount(), m.group(0));
String product = m.group(1);
final String version = m.group(2);
LOGGER.debug("Group 1: {}", product);
LOGGER.debug("Group 2: {}", version);
final String aliasPrefix = "ALIASOF_";
if (product.startsWith(aliasPrefix)) {
product = product.replaceFirst(aliasPrefix, "");
}
if (count > 1) {
//TODO - refactor so we do not assign to the parameter (checkstyle)
currentDep = new Dependency(dependency.getActualFile());
currentDep.setEcosystem(DEPENDENCY_ECOSYSTEM);
final String filePath = String.format("%s:%s", dependency.getFilePath(), product);
currentDep.setFilePath(filePath);
currentDep.setSha1sum(Checksum.getSHA1Checksum(filePath));
currentDep.setSha256sum(Checksum.getSHA256Checksum(filePath));
currentDep.setMd5sum(Checksum.getMD5Checksum(filePath));
engine.addDependency(currentDep);
}
final String source = currentDep.getFileName();
currentDep.addEvidence(EvidenceType.PRODUCT, source, "Product", product, Confidence.MEDIUM);
currentDep.addEvidence(EvidenceType.VENDOR, source, "Vendor", product, Confidence.MEDIUM);
currentDep.addEvidence(EvidenceType.VERSION, source, "Version", version, Confidence.MEDIUM);
currentDep.setName(product);
currentDep.setVersion(version);
}
LOGGER.debug("Found {} matches.", count);
}
|
java
|
private void analyzeSetVersionCommand(Dependency dependency, Engine engine, String contents) {
Dependency currentDep = dependency;
final Matcher m = SET_VERSION.matcher(contents);
int count = 0;
while (m.find()) {
count++;
LOGGER.debug("Found project command match with {} groups: {}",
m.groupCount(), m.group(0));
String product = m.group(1);
final String version = m.group(2);
LOGGER.debug("Group 1: {}", product);
LOGGER.debug("Group 2: {}", version);
final String aliasPrefix = "ALIASOF_";
if (product.startsWith(aliasPrefix)) {
product = product.replaceFirst(aliasPrefix, "");
}
if (count > 1) {
//TODO - refactor so we do not assign to the parameter (checkstyle)
currentDep = new Dependency(dependency.getActualFile());
currentDep.setEcosystem(DEPENDENCY_ECOSYSTEM);
final String filePath = String.format("%s:%s", dependency.getFilePath(), product);
currentDep.setFilePath(filePath);
currentDep.setSha1sum(Checksum.getSHA1Checksum(filePath));
currentDep.setSha256sum(Checksum.getSHA256Checksum(filePath));
currentDep.setMd5sum(Checksum.getMD5Checksum(filePath));
engine.addDependency(currentDep);
}
final String source = currentDep.getFileName();
currentDep.addEvidence(EvidenceType.PRODUCT, source, "Product", product, Confidence.MEDIUM);
currentDep.addEvidence(EvidenceType.VENDOR, source, "Vendor", product, Confidence.MEDIUM);
currentDep.addEvidence(EvidenceType.VERSION, source, "Version", version, Confidence.MEDIUM);
currentDep.setName(product);
currentDep.setVersion(version);
}
LOGGER.debug("Found {} matches.", count);
}
|
[
"private",
"void",
"analyzeSetVersionCommand",
"(",
"Dependency",
"dependency",
",",
"Engine",
"engine",
",",
"String",
"contents",
")",
"{",
"Dependency",
"currentDep",
"=",
"dependency",
";",
"final",
"Matcher",
"m",
"=",
"SET_VERSION",
".",
"matcher",
"(",
"contents",
")",
";",
"int",
"count",
"=",
"0",
";",
"while",
"(",
"m",
".",
"find",
"(",
")",
")",
"{",
"count",
"++",
";",
"LOGGER",
".",
"debug",
"(",
"\"Found project command match with {} groups: {}\"",
",",
"m",
".",
"groupCount",
"(",
")",
",",
"m",
".",
"group",
"(",
"0",
")",
")",
";",
"String",
"product",
"=",
"m",
".",
"group",
"(",
"1",
")",
";",
"final",
"String",
"version",
"=",
"m",
".",
"group",
"(",
"2",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"Group 1: {}\"",
",",
"product",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"Group 2: {}\"",
",",
"version",
")",
";",
"final",
"String",
"aliasPrefix",
"=",
"\"ALIASOF_\"",
";",
"if",
"(",
"product",
".",
"startsWith",
"(",
"aliasPrefix",
")",
")",
"{",
"product",
"=",
"product",
".",
"replaceFirst",
"(",
"aliasPrefix",
",",
"\"\"",
")",
";",
"}",
"if",
"(",
"count",
">",
"1",
")",
"{",
"//TODO - refactor so we do not assign to the parameter (checkstyle)",
"currentDep",
"=",
"new",
"Dependency",
"(",
"dependency",
".",
"getActualFile",
"(",
")",
")",
";",
"currentDep",
".",
"setEcosystem",
"(",
"DEPENDENCY_ECOSYSTEM",
")",
";",
"final",
"String",
"filePath",
"=",
"String",
".",
"format",
"(",
"\"%s:%s\"",
",",
"dependency",
".",
"getFilePath",
"(",
")",
",",
"product",
")",
";",
"currentDep",
".",
"setFilePath",
"(",
"filePath",
")",
";",
"currentDep",
".",
"setSha1sum",
"(",
"Checksum",
".",
"getSHA1Checksum",
"(",
"filePath",
")",
")",
";",
"currentDep",
".",
"setSha256sum",
"(",
"Checksum",
".",
"getSHA256Checksum",
"(",
"filePath",
")",
")",
";",
"currentDep",
".",
"setMd5sum",
"(",
"Checksum",
".",
"getMD5Checksum",
"(",
"filePath",
")",
")",
";",
"engine",
".",
"addDependency",
"(",
"currentDep",
")",
";",
"}",
"final",
"String",
"source",
"=",
"currentDep",
".",
"getFileName",
"(",
")",
";",
"currentDep",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"PRODUCT",
",",
"source",
",",
"\"Product\"",
",",
"product",
",",
"Confidence",
".",
"MEDIUM",
")",
";",
"currentDep",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VENDOR",
",",
"source",
",",
"\"Vendor\"",
",",
"product",
",",
"Confidence",
".",
"MEDIUM",
")",
";",
"currentDep",
".",
"addEvidence",
"(",
"EvidenceType",
".",
"VERSION",
",",
"source",
",",
"\"Version\"",
",",
"version",
",",
"Confidence",
".",
"MEDIUM",
")",
";",
"currentDep",
".",
"setName",
"(",
"product",
")",
";",
"currentDep",
".",
"setVersion",
"(",
"version",
")",
";",
"}",
"LOGGER",
".",
"debug",
"(",
"\"Found {} matches.\"",
",",
"count",
")",
";",
"}"
] |
Extracts the version information from the contents. If more then one
version is found additional dependencies are added to the dependency
list.
@param dependency the dependency being analyzed
@param engine the dependency-check engine
@param contents the version information
|
[
"Extracts",
"the",
"version",
"information",
"from",
"the",
"contents",
".",
"If",
"more",
"then",
"one",
"version",
"is",
"found",
"additional",
"dependencies",
"are",
"added",
"to",
"the",
"dependency",
"list",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/CMakeAnalyzer.java#L186-L223
|
17,862
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.parse
|
public void parse(String[] args) throws FileNotFoundException, ParseException {
line = parseArgs(args);
if (line != null) {
validateArgs();
}
}
|
java
|
public void parse(String[] args) throws FileNotFoundException, ParseException {
line = parseArgs(args);
if (line != null) {
validateArgs();
}
}
|
[
"public",
"void",
"parse",
"(",
"String",
"[",
"]",
"args",
")",
"throws",
"FileNotFoundException",
",",
"ParseException",
"{",
"line",
"=",
"parseArgs",
"(",
"args",
")",
";",
"if",
"(",
"line",
"!=",
"null",
")",
"{",
"validateArgs",
"(",
")",
";",
"}",
"}"
] |
Parses the arguments passed in and captures the results for later use.
@param args the command line arguments
@throws FileNotFoundException is thrown when a 'file' argument does not
point to a file that exists.
@throws ParseException is thrown when a Parse Exception occurs.
|
[
"Parses",
"the",
"arguments",
"passed",
"in",
"and",
"captures",
"the",
"results",
"for",
"later",
"use",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L83-L89
|
17,863
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.validateArgs
|
private void validateArgs() throws FileNotFoundException, ParseException {
if (isUpdateOnly() || isRunScan()) {
final String value = line.getOptionValue(ARGUMENT.CVE_VALID_FOR_HOURS);
if (value != null) {
try {
final int i = Integer.parseInt(value);
if (i < 0) {
throw new ParseException("Invalid Setting: cveValidForHours must be a number greater than or equal to 0.");
}
} catch (NumberFormatException ex) {
throw new ParseException("Invalid Setting: cveValidForHours must be a number greater than or equal to 0.");
}
}
}
if (isRunScan()) {
validatePathExists(getScanFiles(), ARGUMENT.SCAN);
validatePathExists(getReportDirectory(), ARGUMENT.OUT);
if (getPathToCore() != null) {
validatePathExists(getPathToCore(), ARGUMENT.PATH_TO_CORE);
}
if (line.hasOption(ARGUMENT.OUTPUT_FORMAT)) {
final String format = line.getOptionValue(ARGUMENT.OUTPUT_FORMAT);
try {
Format.valueOf(format);
} catch (IllegalArgumentException ex) {
final String msg = String.format("An invalid 'format' of '%s' was specified. "
+ "Supported output formats are " + SUPPORTED_FORMATS, format);
throw new ParseException(msg);
}
}
if ((getBaseCveUrl() != null && getModifiedCveUrl() == null) || (getBaseCveUrl() == null && getModifiedCveUrl() != null)) {
final String msg = "If one of the CVE URLs is specified they must all be specified; please add the missing CVE URL.";
throw new ParseException(msg);
}
if (line.hasOption(ARGUMENT.SYM_LINK_DEPTH)) {
try {
final int i = Integer.parseInt(line.getOptionValue(ARGUMENT.SYM_LINK_DEPTH));
if (i < 0) {
throw new ParseException("Symbolic Link Depth (symLink) must be greater than zero.");
}
} catch (NumberFormatException ex) {
throw new ParseException("Symbolic Link Depth (symLink) is not a number.");
}
}
}
}
|
java
|
private void validateArgs() throws FileNotFoundException, ParseException {
if (isUpdateOnly() || isRunScan()) {
final String value = line.getOptionValue(ARGUMENT.CVE_VALID_FOR_HOURS);
if (value != null) {
try {
final int i = Integer.parseInt(value);
if (i < 0) {
throw new ParseException("Invalid Setting: cveValidForHours must be a number greater than or equal to 0.");
}
} catch (NumberFormatException ex) {
throw new ParseException("Invalid Setting: cveValidForHours must be a number greater than or equal to 0.");
}
}
}
if (isRunScan()) {
validatePathExists(getScanFiles(), ARGUMENT.SCAN);
validatePathExists(getReportDirectory(), ARGUMENT.OUT);
if (getPathToCore() != null) {
validatePathExists(getPathToCore(), ARGUMENT.PATH_TO_CORE);
}
if (line.hasOption(ARGUMENT.OUTPUT_FORMAT)) {
final String format = line.getOptionValue(ARGUMENT.OUTPUT_FORMAT);
try {
Format.valueOf(format);
} catch (IllegalArgumentException ex) {
final String msg = String.format("An invalid 'format' of '%s' was specified. "
+ "Supported output formats are " + SUPPORTED_FORMATS, format);
throw new ParseException(msg);
}
}
if ((getBaseCveUrl() != null && getModifiedCveUrl() == null) || (getBaseCveUrl() == null && getModifiedCveUrl() != null)) {
final String msg = "If one of the CVE URLs is specified they must all be specified; please add the missing CVE URL.";
throw new ParseException(msg);
}
if (line.hasOption(ARGUMENT.SYM_LINK_DEPTH)) {
try {
final int i = Integer.parseInt(line.getOptionValue(ARGUMENT.SYM_LINK_DEPTH));
if (i < 0) {
throw new ParseException("Symbolic Link Depth (symLink) must be greater than zero.");
}
} catch (NumberFormatException ex) {
throw new ParseException("Symbolic Link Depth (symLink) is not a number.");
}
}
}
}
|
[
"private",
"void",
"validateArgs",
"(",
")",
"throws",
"FileNotFoundException",
",",
"ParseException",
"{",
"if",
"(",
"isUpdateOnly",
"(",
")",
"||",
"isRunScan",
"(",
")",
")",
"{",
"final",
"String",
"value",
"=",
"line",
".",
"getOptionValue",
"(",
"ARGUMENT",
".",
"CVE_VALID_FOR_HOURS",
")",
";",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"try",
"{",
"final",
"int",
"i",
"=",
"Integer",
".",
"parseInt",
"(",
"value",
")",
";",
"if",
"(",
"i",
"<",
"0",
")",
"{",
"throw",
"new",
"ParseException",
"(",
"\"Invalid Setting: cveValidForHours must be a number greater than or equal to 0.\"",
")",
";",
"}",
"}",
"catch",
"(",
"NumberFormatException",
"ex",
")",
"{",
"throw",
"new",
"ParseException",
"(",
"\"Invalid Setting: cveValidForHours must be a number greater than or equal to 0.\"",
")",
";",
"}",
"}",
"}",
"if",
"(",
"isRunScan",
"(",
")",
")",
"{",
"validatePathExists",
"(",
"getScanFiles",
"(",
")",
",",
"ARGUMENT",
".",
"SCAN",
")",
";",
"validatePathExists",
"(",
"getReportDirectory",
"(",
")",
",",
"ARGUMENT",
".",
"OUT",
")",
";",
"if",
"(",
"getPathToCore",
"(",
")",
"!=",
"null",
")",
"{",
"validatePathExists",
"(",
"getPathToCore",
"(",
")",
",",
"ARGUMENT",
".",
"PATH_TO_CORE",
")",
";",
"}",
"if",
"(",
"line",
".",
"hasOption",
"(",
"ARGUMENT",
".",
"OUTPUT_FORMAT",
")",
")",
"{",
"final",
"String",
"format",
"=",
"line",
".",
"getOptionValue",
"(",
"ARGUMENT",
".",
"OUTPUT_FORMAT",
")",
";",
"try",
"{",
"Format",
".",
"valueOf",
"(",
"format",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"ex",
")",
"{",
"final",
"String",
"msg",
"=",
"String",
".",
"format",
"(",
"\"An invalid 'format' of '%s' was specified. \"",
"+",
"\"Supported output formats are \"",
"+",
"SUPPORTED_FORMATS",
",",
"format",
")",
";",
"throw",
"new",
"ParseException",
"(",
"msg",
")",
";",
"}",
"}",
"if",
"(",
"(",
"getBaseCveUrl",
"(",
")",
"!=",
"null",
"&&",
"getModifiedCveUrl",
"(",
")",
"==",
"null",
")",
"||",
"(",
"getBaseCveUrl",
"(",
")",
"==",
"null",
"&&",
"getModifiedCveUrl",
"(",
")",
"!=",
"null",
")",
")",
"{",
"final",
"String",
"msg",
"=",
"\"If one of the CVE URLs is specified they must all be specified; please add the missing CVE URL.\"",
";",
"throw",
"new",
"ParseException",
"(",
"msg",
")",
";",
"}",
"if",
"(",
"line",
".",
"hasOption",
"(",
"ARGUMENT",
".",
"SYM_LINK_DEPTH",
")",
")",
"{",
"try",
"{",
"final",
"int",
"i",
"=",
"Integer",
".",
"parseInt",
"(",
"line",
".",
"getOptionValue",
"(",
"ARGUMENT",
".",
"SYM_LINK_DEPTH",
")",
")",
";",
"if",
"(",
"i",
"<",
"0",
")",
"{",
"throw",
"new",
"ParseException",
"(",
"\"Symbolic Link Depth (symLink) must be greater than zero.\"",
")",
";",
"}",
"}",
"catch",
"(",
"NumberFormatException",
"ex",
")",
"{",
"throw",
"new",
"ParseException",
"(",
"\"Symbolic Link Depth (symLink) is not a number.\"",
")",
";",
"}",
"}",
"}",
"}"
] |
Validates that the command line arguments are valid.
@throws FileNotFoundException if there is a file specified by either the
SCAN or CPE command line arguments that does not exist.
@throws ParseException is thrown if there is an exception parsing the
command line.
|
[
"Validates",
"that",
"the",
"command",
"line",
"arguments",
"are",
"valid",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L112-L157
|
17,864
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.validatePathExists
|
private void validatePathExists(String path, String argumentName) throws FileNotFoundException {
if (path == null) {
isValid = false;
final String msg = String.format("Invalid '%s' argument: null", argumentName);
throw new FileNotFoundException(msg);
} else if (!path.contains("*") && !path.contains("?")) {
File f = new File(path);
if ("o".equalsIgnoreCase(argumentName.substring(0, 1)) && !"ALL".equalsIgnoreCase(this.getReportFormat())) {
final String checkPath = path.toLowerCase();
if (checkPath.endsWith(".html") || checkPath.endsWith(".xml") || checkPath.endsWith(".htm")) {
if (f.getParentFile() == null) {
f = new File(".", path);
}
if (!f.getParentFile().isDirectory()) {
isValid = false;
final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
throw new FileNotFoundException(msg);
}
}
} else if (!f.exists()) {
isValid = false;
final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
throw new FileNotFoundException(msg);
}
// } else if (path.startsWith("//") || path.startsWith("\\\\")) {
// isValid = false;
// final String msg = String.format("Invalid '%s' argument: '%s'%nUnable to scan paths that start with '//'.", argumentName, path);
// throw new FileNotFoundException(msg);
} else if ((path.endsWith("/*") && !path.endsWith("**/*")) || (path.endsWith("\\*") && path.endsWith("**\\*"))) {
LOGGER.warn("Possibly incorrect path '{}' from argument '{}' because it ends with a slash star; "
+ "dependency-check uses ant-style paths", path, argumentName);
}
}
|
java
|
private void validatePathExists(String path, String argumentName) throws FileNotFoundException {
if (path == null) {
isValid = false;
final String msg = String.format("Invalid '%s' argument: null", argumentName);
throw new FileNotFoundException(msg);
} else if (!path.contains("*") && !path.contains("?")) {
File f = new File(path);
if ("o".equalsIgnoreCase(argumentName.substring(0, 1)) && !"ALL".equalsIgnoreCase(this.getReportFormat())) {
final String checkPath = path.toLowerCase();
if (checkPath.endsWith(".html") || checkPath.endsWith(".xml") || checkPath.endsWith(".htm")) {
if (f.getParentFile() == null) {
f = new File(".", path);
}
if (!f.getParentFile().isDirectory()) {
isValid = false;
final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
throw new FileNotFoundException(msg);
}
}
} else if (!f.exists()) {
isValid = false;
final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
throw new FileNotFoundException(msg);
}
// } else if (path.startsWith("//") || path.startsWith("\\\\")) {
// isValid = false;
// final String msg = String.format("Invalid '%s' argument: '%s'%nUnable to scan paths that start with '//'.", argumentName, path);
// throw new FileNotFoundException(msg);
} else if ((path.endsWith("/*") && !path.endsWith("**/*")) || (path.endsWith("\\*") && path.endsWith("**\\*"))) {
LOGGER.warn("Possibly incorrect path '{}' from argument '{}' because it ends with a slash star; "
+ "dependency-check uses ant-style paths", path, argumentName);
}
}
|
[
"private",
"void",
"validatePathExists",
"(",
"String",
"path",
",",
"String",
"argumentName",
")",
"throws",
"FileNotFoundException",
"{",
"if",
"(",
"path",
"==",
"null",
")",
"{",
"isValid",
"=",
"false",
";",
"final",
"String",
"msg",
"=",
"String",
".",
"format",
"(",
"\"Invalid '%s' argument: null\"",
",",
"argumentName",
")",
";",
"throw",
"new",
"FileNotFoundException",
"(",
"msg",
")",
";",
"}",
"else",
"if",
"(",
"!",
"path",
".",
"contains",
"(",
"\"*\"",
")",
"&&",
"!",
"path",
".",
"contains",
"(",
"\"?\"",
")",
")",
"{",
"File",
"f",
"=",
"new",
"File",
"(",
"path",
")",
";",
"if",
"(",
"\"o\"",
".",
"equalsIgnoreCase",
"(",
"argumentName",
".",
"substring",
"(",
"0",
",",
"1",
")",
")",
"&&",
"!",
"\"ALL\"",
".",
"equalsIgnoreCase",
"(",
"this",
".",
"getReportFormat",
"(",
")",
")",
")",
"{",
"final",
"String",
"checkPath",
"=",
"path",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"checkPath",
".",
"endsWith",
"(",
"\".html\"",
")",
"||",
"checkPath",
".",
"endsWith",
"(",
"\".xml\"",
")",
"||",
"checkPath",
".",
"endsWith",
"(",
"\".htm\"",
")",
")",
"{",
"if",
"(",
"f",
".",
"getParentFile",
"(",
")",
"==",
"null",
")",
"{",
"f",
"=",
"new",
"File",
"(",
"\".\"",
",",
"path",
")",
";",
"}",
"if",
"(",
"!",
"f",
".",
"getParentFile",
"(",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"isValid",
"=",
"false",
";",
"final",
"String",
"msg",
"=",
"String",
".",
"format",
"(",
"\"Invalid '%s' argument: '%s'\"",
",",
"argumentName",
",",
"path",
")",
";",
"throw",
"new",
"FileNotFoundException",
"(",
"msg",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"!",
"f",
".",
"exists",
"(",
")",
")",
"{",
"isValid",
"=",
"false",
";",
"final",
"String",
"msg",
"=",
"String",
".",
"format",
"(",
"\"Invalid '%s' argument: '%s'\"",
",",
"argumentName",
",",
"path",
")",
";",
"throw",
"new",
"FileNotFoundException",
"(",
"msg",
")",
";",
"}",
"// } else if (path.startsWith(\"//\") || path.startsWith(\"\\\\\\\\\")) {",
"// isValid = false;",
"// final String msg = String.format(\"Invalid '%s' argument: '%s'%nUnable to scan paths that start with '//'.\", argumentName, path);",
"// throw new FileNotFoundException(msg);",
"}",
"else",
"if",
"(",
"(",
"path",
".",
"endsWith",
"(",
"\"/*\"",
")",
"&&",
"!",
"path",
".",
"endsWith",
"(",
"\"**/*\"",
")",
")",
"||",
"(",
"path",
".",
"endsWith",
"(",
"\"\\\\*\"",
")",
"&&",
"path",
".",
"endsWith",
"(",
"\"**\\\\*\"",
")",
")",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Possibly incorrect path '{}' from argument '{}' because it ends with a slash star; \"",
"+",
"\"dependency-check uses ant-style paths\"",
",",
"path",
",",
"argumentName",
")",
";",
"}",
"}"
] |
Validates whether or not the path points at a file that exists; if the
path does not point to an existing file a FileNotFoundException is
thrown.
@param path the paths to validate if they exists
@param argumentName the argument being validated (e.g. scan, out, etc.)
@throws FileNotFoundException is thrown if the path being validated does
not exist.
|
[
"Validates",
"whether",
"or",
"not",
"the",
"path",
"points",
"at",
"a",
"file",
"that",
"exists",
";",
"if",
"the",
"path",
"does",
"not",
"point",
"to",
"an",
"existing",
"file",
"a",
"FileNotFoundException",
"is",
"thrown",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L185-L217
|
17,865
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.createCommandLineOptions
|
@SuppressWarnings("static-access")
private Options createCommandLineOptions() {
final Options options = new Options();
addStandardOptions(options);
addAdvancedOptions(options);
addDeprecatedOptions(options);
return options;
}
|
java
|
@SuppressWarnings("static-access")
private Options createCommandLineOptions() {
final Options options = new Options();
addStandardOptions(options);
addAdvancedOptions(options);
addDeprecatedOptions(options);
return options;
}
|
[
"@",
"SuppressWarnings",
"(",
"\"static-access\"",
")",
"private",
"Options",
"createCommandLineOptions",
"(",
")",
"{",
"final",
"Options",
"options",
"=",
"new",
"Options",
"(",
")",
";",
"addStandardOptions",
"(",
"options",
")",
";",
"addAdvancedOptions",
"(",
"options",
")",
";",
"addDeprecatedOptions",
"(",
"options",
")",
";",
"return",
"options",
";",
"}"
] |
Generates an Options collection that is used to parse the command line
and to display the help message.
@return the command line options used for parsing the command line
|
[
"Generates",
"an",
"Options",
"collection",
"that",
"is",
"used",
"to",
"parse",
"the",
"command",
"line",
"and",
"to",
"display",
"the",
"help",
"message",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L225-L232
|
17,866
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.hasDisableOption
|
private boolean hasDisableOption(String argument, String setting) {
if (line == null || !line.hasOption(argument)) {
try {
return !settings.getBoolean(setting);
} catch (InvalidSettingException ise) {
LOGGER.warn("Invalid property setting '{}' defaulting to false", setting);
return false;
}
} else {
return true;
}
}
|
java
|
private boolean hasDisableOption(String argument, String setting) {
if (line == null || !line.hasOption(argument)) {
try {
return !settings.getBoolean(setting);
} catch (InvalidSettingException ise) {
LOGGER.warn("Invalid property setting '{}' defaulting to false", setting);
return false;
}
} else {
return true;
}
}
|
[
"private",
"boolean",
"hasDisableOption",
"(",
"String",
"argument",
",",
"String",
"setting",
")",
"{",
"if",
"(",
"line",
"==",
"null",
"||",
"!",
"line",
".",
"hasOption",
"(",
"argument",
")",
")",
"{",
"try",
"{",
"return",
"!",
"settings",
".",
"getBoolean",
"(",
"setting",
")",
";",
"}",
"catch",
"(",
"InvalidSettingException",
"ise",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Invalid property setting '{}' defaulting to false\"",
",",
"setting",
")",
";",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
] |
Utility method to determine if one of the disable options has been set.
If not set, this method will check the currently configured settings for
the current value to return.
Example given `--disableArchive` on the command line would cause this
method to return true for the disable archive setting.
@param argument the command line argument
@param setting the corresponding settings key
@return true if the disable option was set, if not set the currently
configured value will be returned
|
[
"Utility",
"method",
"to",
"determine",
"if",
"one",
"of",
"the",
"disable",
"options",
"has",
"been",
"set",
".",
"If",
"not",
"set",
"this",
"method",
"will",
"check",
"the",
"currently",
"configured",
"settings",
"for",
"the",
"current",
"value",
"to",
"return",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L589-L600
|
17,867
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.isNodeAuditDisabled
|
public boolean isNodeAuditDisabled() {
if (hasDisableOption("disableNSP", Settings.KEYS.ANALYZER_NODE_AUDIT_ENABLED)) {
LOGGER.error("The disableNSP argument has been deprecated and replaced by disableNodeAudit");
LOGGER.error("The disableNSP argument will be removed in the next version");
return true;
}
return hasDisableOption(ARGUMENT.DISABLE_NODE_AUDIT, Settings.KEYS.ANALYZER_NODE_AUDIT_ENABLED);
}
|
java
|
public boolean isNodeAuditDisabled() {
if (hasDisableOption("disableNSP", Settings.KEYS.ANALYZER_NODE_AUDIT_ENABLED)) {
LOGGER.error("The disableNSP argument has been deprecated and replaced by disableNodeAudit");
LOGGER.error("The disableNSP argument will be removed in the next version");
return true;
}
return hasDisableOption(ARGUMENT.DISABLE_NODE_AUDIT, Settings.KEYS.ANALYZER_NODE_AUDIT_ENABLED);
}
|
[
"public",
"boolean",
"isNodeAuditDisabled",
"(",
")",
"{",
"if",
"(",
"hasDisableOption",
"(",
"\"disableNSP\"",
",",
"Settings",
".",
"KEYS",
".",
"ANALYZER_NODE_AUDIT_ENABLED",
")",
")",
"{",
"LOGGER",
".",
"error",
"(",
"\"The disableNSP argument has been deprecated and replaced by disableNodeAudit\"",
")",
";",
"LOGGER",
".",
"error",
"(",
"\"The disableNSP argument will be removed in the next version\"",
")",
";",
"return",
"true",
";",
"}",
"return",
"hasDisableOption",
"(",
"ARGUMENT",
".",
"DISABLE_NODE_AUDIT",
",",
"Settings",
".",
"KEYS",
".",
"ANALYZER_NODE_AUDIT_ENABLED",
")",
";",
"}"
] |
Returns true if the disableNodeAudit command line argument was specified.
@return true if the disableNodeAudit command line argument was specified;
otherwise false
|
[
"Returns",
"true",
"if",
"the",
"disableNodeAudit",
"command",
"line",
"argument",
"was",
"specified",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L766-L773
|
17,868
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.getNexusUrl
|
public String getNexusUrl() {
if (line == null || !line.hasOption(ARGUMENT.NEXUS_URL)) {
return null;
} else {
return line.getOptionValue(ARGUMENT.NEXUS_URL);
}
}
|
java
|
public String getNexusUrl() {
if (line == null || !line.hasOption(ARGUMENT.NEXUS_URL)) {
return null;
} else {
return line.getOptionValue(ARGUMENT.NEXUS_URL);
}
}
|
[
"public",
"String",
"getNexusUrl",
"(",
")",
"{",
"if",
"(",
"line",
"==",
"null",
"||",
"!",
"line",
".",
"hasOption",
"(",
"ARGUMENT",
".",
"NEXUS_URL",
")",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"return",
"line",
".",
"getOptionValue",
"(",
"ARGUMENT",
".",
"NEXUS_URL",
")",
";",
"}",
"}"
] |
Returns the url to the nexus server if one was specified.
@return the url to the nexus server; if none was specified this will
return null;
|
[
"Returns",
"the",
"url",
"to",
"the",
"nexus",
"server",
"if",
"one",
"was",
"specified",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L823-L829
|
17,869
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.isNexusUsesProxy
|
public boolean isNexusUsesProxy() {
// If they didn't specify whether Nexus needs to use the proxy, we should
// still honor the property if it's set.
if (line == null || !line.hasOption(ARGUMENT.NEXUS_USES_PROXY)) {
try {
return settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_USES_PROXY);
} catch (InvalidSettingException ise) {
return true;
}
} else {
return Boolean.parseBoolean(line.getOptionValue(ARGUMENT.NEXUS_USES_PROXY));
}
}
|
java
|
public boolean isNexusUsesProxy() {
// If they didn't specify whether Nexus needs to use the proxy, we should
// still honor the property if it's set.
if (line == null || !line.hasOption(ARGUMENT.NEXUS_USES_PROXY)) {
try {
return settings.getBoolean(Settings.KEYS.ANALYZER_NEXUS_USES_PROXY);
} catch (InvalidSettingException ise) {
return true;
}
} else {
return Boolean.parseBoolean(line.getOptionValue(ARGUMENT.NEXUS_USES_PROXY));
}
}
|
[
"public",
"boolean",
"isNexusUsesProxy",
"(",
")",
"{",
"// If they didn't specify whether Nexus needs to use the proxy, we should",
"// still honor the property if it's set.",
"if",
"(",
"line",
"==",
"null",
"||",
"!",
"line",
".",
"hasOption",
"(",
"ARGUMENT",
".",
"NEXUS_USES_PROXY",
")",
")",
"{",
"try",
"{",
"return",
"settings",
".",
"getBoolean",
"(",
"Settings",
".",
"KEYS",
".",
"ANALYZER_NEXUS_USES_PROXY",
")",
";",
"}",
"catch",
"(",
"InvalidSettingException",
"ise",
")",
"{",
"return",
"true",
";",
"}",
"}",
"else",
"{",
"return",
"Boolean",
".",
"parseBoolean",
"(",
"line",
".",
"getOptionValue",
"(",
"ARGUMENT",
".",
"NEXUS_USES_PROXY",
")",
")",
";",
"}",
"}"
] |
Returns true if the Nexus Analyzer should use the configured proxy to
connect to Nexus; otherwise false is returned.
@return true if the Nexus Analyzer should use the configured proxy to
connect to Nexus; otherwise false
|
[
"Returns",
"true",
"if",
"the",
"Nexus",
"Analyzer",
"should",
"use",
"the",
"configured",
"proxy",
"to",
"connect",
"to",
"Nexus",
";",
"otherwise",
"false",
"is",
"returned",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L860-L872
|
17,870
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.getBooleanArgument
|
@SuppressFBWarnings(justification = "Accepting that this is a bad practice - used a Boolean as we needed three states",
value = {"NP_BOOLEAN_RETURN_NULL"})
public Boolean getBooleanArgument(String argument) {
if (line != null && line.hasOption(argument)) {
final String value = line.getOptionValue(argument);
if (value != null) {
return Boolean.parseBoolean(value);
}
}
return null;
}
|
java
|
@SuppressFBWarnings(justification = "Accepting that this is a bad practice - used a Boolean as we needed three states",
value = {"NP_BOOLEAN_RETURN_NULL"})
public Boolean getBooleanArgument(String argument) {
if (line != null && line.hasOption(argument)) {
final String value = line.getOptionValue(argument);
if (value != null) {
return Boolean.parseBoolean(value);
}
}
return null;
}
|
[
"@",
"SuppressFBWarnings",
"(",
"justification",
"=",
"\"Accepting that this is a bad practice - used a Boolean as we needed three states\"",
",",
"value",
"=",
"{",
"\"NP_BOOLEAN_RETURN_NULL\"",
"}",
")",
"public",
"Boolean",
"getBooleanArgument",
"(",
"String",
"argument",
")",
"{",
"if",
"(",
"line",
"!=",
"null",
"&&",
"line",
".",
"hasOption",
"(",
"argument",
")",
")",
"{",
"final",
"String",
"value",
"=",
"line",
".",
"getOptionValue",
"(",
"argument",
")",
";",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"return",
"Boolean",
".",
"parseBoolean",
"(",
"value",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Returns the argument boolean value.
@param argument the argument
@return the argument boolean value
|
[
"Returns",
"the",
"argument",
"boolean",
"value",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L890-L900
|
17,871
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.getStringArgument
|
public String getStringArgument(String argument) {
if (line != null && line.hasOption(argument)) {
return line.getOptionValue(argument);
}
return null;
}
|
java
|
public String getStringArgument(String argument) {
if (line != null && line.hasOption(argument)) {
return line.getOptionValue(argument);
}
return null;
}
|
[
"public",
"String",
"getStringArgument",
"(",
"String",
"argument",
")",
"{",
"if",
"(",
"line",
"!=",
"null",
"&&",
"line",
".",
"hasOption",
"(",
"argument",
")",
")",
"{",
"return",
"line",
".",
"getOptionValue",
"(",
"argument",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the argument value.
@param argument the argument
@return the value of the argument
|
[
"Returns",
"the",
"argument",
"value",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L908-L913
|
17,872
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.printHelp
|
public void printHelp() {
final HelpFormatter formatter = new HelpFormatter();
final Options options = new Options();
addStandardOptions(options);
if (line != null && line.hasOption(ARGUMENT.ADVANCED_HELP)) {
addAdvancedOptions(options);
}
final String helpMsg = String.format("%n%s"
+ " can be used to identify if there are any known CVE vulnerabilities in libraries utilized by an application. "
+ "%s will automatically update required data from the Internet, such as the CVE and CPE data files from nvd.nist.gov.%n%n",
settings.getString("application.name", "DependencyCheck"),
settings.getString("application.name", "DependencyCheck"));
formatter.printHelp(settings.getString("application.name", "DependencyCheck"),
helpMsg,
options,
"",
true);
}
|
java
|
public void printHelp() {
final HelpFormatter formatter = new HelpFormatter();
final Options options = new Options();
addStandardOptions(options);
if (line != null && line.hasOption(ARGUMENT.ADVANCED_HELP)) {
addAdvancedOptions(options);
}
final String helpMsg = String.format("%n%s"
+ " can be used to identify if there are any known CVE vulnerabilities in libraries utilized by an application. "
+ "%s will automatically update required data from the Internet, such as the CVE and CPE data files from nvd.nist.gov.%n%n",
settings.getString("application.name", "DependencyCheck"),
settings.getString("application.name", "DependencyCheck"));
formatter.printHelp(settings.getString("application.name", "DependencyCheck"),
helpMsg,
options,
"",
true);
}
|
[
"public",
"void",
"printHelp",
"(",
")",
"{",
"final",
"HelpFormatter",
"formatter",
"=",
"new",
"HelpFormatter",
"(",
")",
";",
"final",
"Options",
"options",
"=",
"new",
"Options",
"(",
")",
";",
"addStandardOptions",
"(",
"options",
")",
";",
"if",
"(",
"line",
"!=",
"null",
"&&",
"line",
".",
"hasOption",
"(",
"ARGUMENT",
".",
"ADVANCED_HELP",
")",
")",
"{",
"addAdvancedOptions",
"(",
"options",
")",
";",
"}",
"final",
"String",
"helpMsg",
"=",
"String",
".",
"format",
"(",
"\"%n%s\"",
"+",
"\" can be used to identify if there are any known CVE vulnerabilities in libraries utilized by an application. \"",
"+",
"\"%s will automatically update required data from the Internet, such as the CVE and CPE data files from nvd.nist.gov.%n%n\"",
",",
"settings",
".",
"getString",
"(",
"\"application.name\"",
",",
"\"DependencyCheck\"",
")",
",",
"settings",
".",
"getString",
"(",
"\"application.name\"",
",",
"\"DependencyCheck\"",
")",
")",
";",
"formatter",
".",
"printHelp",
"(",
"settings",
".",
"getString",
"(",
"\"application.name\"",
",",
"\"DependencyCheck\"",
")",
",",
"helpMsg",
",",
"options",
",",
"\"\"",
",",
"true",
")",
";",
"}"
] |
Displays the command line help message to the standard output.
|
[
"Displays",
"the",
"command",
"line",
"help",
"message",
"to",
"the",
"standard",
"output",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L918-L936
|
17,873
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.isRetireJsFilterNonVulnerable
|
@SuppressFBWarnings(justification = "Accepting that this is a bad practice - but made more sense in this use case",
value = {"NP_BOOLEAN_RETURN_NULL"})
public Boolean isRetireJsFilterNonVulnerable() {
return (line != null && line.hasOption(ARGUMENT.RETIREJS_FILTER_NON_VULNERABLE)) ? true : null;
}
|
java
|
@SuppressFBWarnings(justification = "Accepting that this is a bad practice - but made more sense in this use case",
value = {"NP_BOOLEAN_RETURN_NULL"})
public Boolean isRetireJsFilterNonVulnerable() {
return (line != null && line.hasOption(ARGUMENT.RETIREJS_FILTER_NON_VULNERABLE)) ? true : null;
}
|
[
"@",
"SuppressFBWarnings",
"(",
"justification",
"=",
"\"Accepting that this is a bad practice - but made more sense in this use case\"",
",",
"value",
"=",
"{",
"\"NP_BOOLEAN_RETURN_NULL\"",
"}",
")",
"public",
"Boolean",
"isRetireJsFilterNonVulnerable",
"(",
")",
"{",
"return",
"(",
"line",
"!=",
"null",
"&&",
"line",
".",
"hasOption",
"(",
"ARGUMENT",
".",
"RETIREJS_FILTER_NON_VULNERABLE",
")",
")",
"?",
"true",
":",
"null",
";",
"}"
] |
Returns whether or not the retireJS analyzer should exclude
non-vulnerable JS from the report.
@return <code>true</code> if non-vulnerable JS should be filtered in the
RetireJS Analyzer; otherwise <code>null</code>
|
[
"Returns",
"whether",
"or",
"not",
"the",
"retireJS",
"analyzer",
"should",
"exclude",
"non",
"-",
"vulnerable",
"JS",
"from",
"the",
"report",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L982-L986
|
17,874
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.getProjectName
|
public String getProjectName() {
String name = line.getOptionValue(ARGUMENT.PROJECT);
if (name == null) {
name = "";
}
return name;
}
|
java
|
public String getProjectName() {
String name = line.getOptionValue(ARGUMENT.PROJECT);
if (name == null) {
name = "";
}
return name;
}
|
[
"public",
"String",
"getProjectName",
"(",
")",
"{",
"String",
"name",
"=",
"line",
".",
"getOptionValue",
"(",
"ARGUMENT",
".",
"PROJECT",
")",
";",
"if",
"(",
"name",
"==",
"null",
")",
"{",
"name",
"=",
"\"\"",
";",
"}",
"return",
"name",
";",
"}"
] |
Returns the application name specified on the command line.
@return the application name.
|
[
"Returns",
"the",
"application",
"name",
"specified",
"on",
"the",
"command",
"line",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L1031-L1037
|
17,875
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.getPropertiesFile
|
public File getPropertiesFile() {
final String path = line.getOptionValue(ARGUMENT.PROP);
if (path != null) {
return new File(path);
}
return null;
}
|
java
|
public File getPropertiesFile() {
final String path = line.getOptionValue(ARGUMENT.PROP);
if (path != null) {
return new File(path);
}
return null;
}
|
[
"public",
"File",
"getPropertiesFile",
"(",
")",
"{",
"final",
"String",
"path",
"=",
"line",
".",
"getOptionValue",
"(",
"ARGUMENT",
".",
"PROP",
")",
";",
"if",
"(",
"path",
"!=",
"null",
")",
"{",
"return",
"new",
"File",
"(",
"path",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the properties file specified on the command line.
@return the properties file specified on the command line
|
[
"Returns",
"the",
"properties",
"file",
"specified",
"on",
"the",
"command",
"line",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L1116-L1122
|
17,876
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.isAutoUpdate
|
@SuppressFBWarnings(justification = "Accepting that this is a bad practice - but made more sense in this use case",
value = {"NP_BOOLEAN_RETURN_NULL"})
public Boolean isAutoUpdate() {
return (line != null && line.hasOption(ARGUMENT.DISABLE_AUTO_UPDATE)) ? false : null;
}
|
java
|
@SuppressFBWarnings(justification = "Accepting that this is a bad practice - but made more sense in this use case",
value = {"NP_BOOLEAN_RETURN_NULL"})
public Boolean isAutoUpdate() {
return (line != null && line.hasOption(ARGUMENT.DISABLE_AUTO_UPDATE)) ? false : null;
}
|
[
"@",
"SuppressFBWarnings",
"(",
"justification",
"=",
"\"Accepting that this is a bad practice - but made more sense in this use case\"",
",",
"value",
"=",
"{",
"\"NP_BOOLEAN_RETURN_NULL\"",
"}",
")",
"public",
"Boolean",
"isAutoUpdate",
"(",
")",
"{",
"return",
"(",
"line",
"!=",
"null",
"&&",
"line",
".",
"hasOption",
"(",
"ARGUMENT",
".",
"DISABLE_AUTO_UPDATE",
")",
")",
"?",
"false",
":",
"null",
";",
"}"
] |
Checks if the auto update feature has been disabled. If it has been
disabled via the command line this will return false.
@return <code>true</code> if auto-update is allowed; otherwise
<code>null</code>
|
[
"Checks",
"if",
"the",
"auto",
"update",
"feature",
"has",
"been",
"disabled",
".",
"If",
"it",
"has",
"been",
"disabled",
"via",
"the",
"command",
"line",
"this",
"will",
"return",
"false",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L1171-L1175
|
17,877
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.getCveValidForHours
|
public Integer getCveValidForHours() {
final String v = line.getOptionValue(ARGUMENT.CVE_VALID_FOR_HOURS);
if (v != null) {
return Integer.parseInt(v);
}
return null;
}
|
java
|
public Integer getCveValidForHours() {
final String v = line.getOptionValue(ARGUMENT.CVE_VALID_FOR_HOURS);
if (v != null) {
return Integer.parseInt(v);
}
return null;
}
|
[
"public",
"Integer",
"getCveValidForHours",
"(",
")",
"{",
"final",
"String",
"v",
"=",
"line",
".",
"getOptionValue",
"(",
"ARGUMENT",
".",
"CVE_VALID_FOR_HOURS",
")",
";",
"if",
"(",
"v",
"!=",
"null",
")",
"{",
"return",
"Integer",
".",
"parseInt",
"(",
"v",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Get the value of cveValidForHours.
@return the value of cveValidForHours
|
[
"Get",
"the",
"value",
"of",
"cveValidForHours",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L1265-L1271
|
17,878
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.isExperimentalEnabled
|
@SuppressFBWarnings(justification = "Accepting that this is a bad practice - but made more sense in this use case",
value = {"NP_BOOLEAN_RETURN_NULL"})
public Boolean isExperimentalEnabled() {
return (line != null && line.hasOption(ARGUMENT.EXPERIMENTAL)) ? true : null;
}
|
java
|
@SuppressFBWarnings(justification = "Accepting that this is a bad practice - but made more sense in this use case",
value = {"NP_BOOLEAN_RETURN_NULL"})
public Boolean isExperimentalEnabled() {
return (line != null && line.hasOption(ARGUMENT.EXPERIMENTAL)) ? true : null;
}
|
[
"@",
"SuppressFBWarnings",
"(",
"justification",
"=",
"\"Accepting that this is a bad practice - but made more sense in this use case\"",
",",
"value",
"=",
"{",
"\"NP_BOOLEAN_RETURN_NULL\"",
"}",
")",
"public",
"Boolean",
"isExperimentalEnabled",
"(",
")",
"{",
"return",
"(",
"line",
"!=",
"null",
"&&",
"line",
".",
"hasOption",
"(",
"ARGUMENT",
".",
"EXPERIMENTAL",
")",
")",
"?",
"true",
":",
"null",
";",
"}"
] |
Returns true if the experimental analyzers are enabled.
@return true if the experimental analyzers are enabled; otherwise null
|
[
"Returns",
"true",
"if",
"the",
"experimental",
"analyzers",
"are",
"enabled",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L1278-L1282
|
17,879
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.isRetiredEnabled
|
@SuppressFBWarnings(justification = "Accepting that this is a bad practice - but made more sense in this use case",
value = {"NP_BOOLEAN_RETURN_NULL"})
public Boolean isRetiredEnabled() {
return (line != null && line.hasOption(ARGUMENT.RETIRED)) ? true : null;
}
|
java
|
@SuppressFBWarnings(justification = "Accepting that this is a bad practice - but made more sense in this use case",
value = {"NP_BOOLEAN_RETURN_NULL"})
public Boolean isRetiredEnabled() {
return (line != null && line.hasOption(ARGUMENT.RETIRED)) ? true : null;
}
|
[
"@",
"SuppressFBWarnings",
"(",
"justification",
"=",
"\"Accepting that this is a bad practice - but made more sense in this use case\"",
",",
"value",
"=",
"{",
"\"NP_BOOLEAN_RETURN_NULL\"",
"}",
")",
"public",
"Boolean",
"isRetiredEnabled",
"(",
")",
"{",
"return",
"(",
"line",
"!=",
"null",
"&&",
"line",
".",
"hasOption",
"(",
"ARGUMENT",
".",
"RETIRED",
")",
")",
"?",
"true",
":",
"null",
";",
"}"
] |
Returns true if the retired analyzers are enabled.
@return true if the retired analyzers are enabled; otherwise null
|
[
"Returns",
"true",
"if",
"the",
"retired",
"analyzers",
"are",
"enabled",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L1289-L1293
|
17,880
|
jeremylong/DependencyCheck
|
cli/src/main/java/org/owasp/dependencycheck/CliParser.java
|
CliParser.getFailOnCVSS
|
public int getFailOnCVSS() {
if (line.hasOption(ARGUMENT.FAIL_ON_CVSS)) {
final String value = line.getOptionValue(ARGUMENT.FAIL_ON_CVSS);
try {
return Integer.parseInt(value);
} catch (NumberFormatException nfe) {
return 11;
}
} else {
return 11;
}
}
|
java
|
public int getFailOnCVSS() {
if (line.hasOption(ARGUMENT.FAIL_ON_CVSS)) {
final String value = line.getOptionValue(ARGUMENT.FAIL_ON_CVSS);
try {
return Integer.parseInt(value);
} catch (NumberFormatException nfe) {
return 11;
}
} else {
return 11;
}
}
|
[
"public",
"int",
"getFailOnCVSS",
"(",
")",
"{",
"if",
"(",
"line",
".",
"hasOption",
"(",
"ARGUMENT",
".",
"FAIL_ON_CVSS",
")",
")",
"{",
"final",
"String",
"value",
"=",
"line",
".",
"getOptionValue",
"(",
"ARGUMENT",
".",
"FAIL_ON_CVSS",
")",
";",
"try",
"{",
"return",
"Integer",
".",
"parseInt",
"(",
"value",
")",
";",
"}",
"catch",
"(",
"NumberFormatException",
"nfe",
")",
"{",
"return",
"11",
";",
"}",
"}",
"else",
"{",
"return",
"11",
";",
"}",
"}"
] |
Returns the CVSS value to fail on.
@return 11 if nothing is set. Otherwise it returns the int passed from
the command line arg
|
[
"Returns",
"the",
"CVSS",
"value",
"to",
"fail",
"on",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/cli/src/main/java/org/owasp/dependencycheck/CliParser.java#L1302-L1313
|
17,881
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/agent/DependencyCheckScanAgent.java
|
DependencyCheckScanAgent.generateExternalReports
|
private void generateExternalReports(Engine engine, File outDirectory) throws ScanAgentException {
try {
engine.writeReports(applicationName, outDirectory, this.reportFormat.name());
} catch (ReportException ex) {
LOGGER.debug("Unexpected exception occurred during analysis; please see the verbose error log for more details.", ex);
throw new ScanAgentException("Error generating the report", ex);
}
}
|
java
|
private void generateExternalReports(Engine engine, File outDirectory) throws ScanAgentException {
try {
engine.writeReports(applicationName, outDirectory, this.reportFormat.name());
} catch (ReportException ex) {
LOGGER.debug("Unexpected exception occurred during analysis; please see the verbose error log for more details.", ex);
throw new ScanAgentException("Error generating the report", ex);
}
}
|
[
"private",
"void",
"generateExternalReports",
"(",
"Engine",
"engine",
",",
"File",
"outDirectory",
")",
"throws",
"ScanAgentException",
"{",
"try",
"{",
"engine",
".",
"writeReports",
"(",
"applicationName",
",",
"outDirectory",
",",
"this",
".",
"reportFormat",
".",
"name",
"(",
")",
")",
";",
"}",
"catch",
"(",
"ReportException",
"ex",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Unexpected exception occurred during analysis; please see the verbose error log for more details.\"",
",",
"ex",
")",
";",
"throw",
"new",
"ScanAgentException",
"(",
"\"Error generating the report\"",
",",
"ex",
")",
";",
"}",
"}"
] |
Generates the reports for a given dependency-check engine.
@param engine a dependency-check engine
@param outDirectory the directory to write the reports to
@throws ScanAgentException thrown if there is an error generating the
report
|
[
"Generates",
"the",
"reports",
"for",
"a",
"given",
"dependency",
"-",
"check",
"engine",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/agent/DependencyCheckScanAgent.java#L893-L900
|
17,882
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/agent/DependencyCheckScanAgent.java
|
DependencyCheckScanAgent.execute
|
public Engine execute() throws ScanAgentException {
Engine engine = null;
try {
engine = executeDependencyCheck();
if (!this.updateOnly) {
if (this.generateReport) {
generateExternalReports(engine, new File(this.reportOutputDirectory));
}
if (this.showSummary) {
showSummary(engine.getDependencies());
}
if (this.failBuildOnCVSS <= 10) {
checkForFailure(engine.getDependencies());
}
}
} catch (ExceptionCollection ex) {
if (ex.isFatal()) {
LOGGER.error("A fatal exception occurred during analysis; analysis has stopped. Please see the debug log for more details.");
LOGGER.debug("", ex);
}
throw new ScanAgentException("One or more exceptions occurred during analysis; please see the debug log for more details.", ex);
} finally {
settings.cleanup(true);
if (engine != null) {
engine.close();
}
}
return engine;
}
|
java
|
public Engine execute() throws ScanAgentException {
Engine engine = null;
try {
engine = executeDependencyCheck();
if (!this.updateOnly) {
if (this.generateReport) {
generateExternalReports(engine, new File(this.reportOutputDirectory));
}
if (this.showSummary) {
showSummary(engine.getDependencies());
}
if (this.failBuildOnCVSS <= 10) {
checkForFailure(engine.getDependencies());
}
}
} catch (ExceptionCollection ex) {
if (ex.isFatal()) {
LOGGER.error("A fatal exception occurred during analysis; analysis has stopped. Please see the debug log for more details.");
LOGGER.debug("", ex);
}
throw new ScanAgentException("One or more exceptions occurred during analysis; please see the debug log for more details.", ex);
} finally {
settings.cleanup(true);
if (engine != null) {
engine.close();
}
}
return engine;
}
|
[
"public",
"Engine",
"execute",
"(",
")",
"throws",
"ScanAgentException",
"{",
"Engine",
"engine",
"=",
"null",
";",
"try",
"{",
"engine",
"=",
"executeDependencyCheck",
"(",
")",
";",
"if",
"(",
"!",
"this",
".",
"updateOnly",
")",
"{",
"if",
"(",
"this",
".",
"generateReport",
")",
"{",
"generateExternalReports",
"(",
"engine",
",",
"new",
"File",
"(",
"this",
".",
"reportOutputDirectory",
")",
")",
";",
"}",
"if",
"(",
"this",
".",
"showSummary",
")",
"{",
"showSummary",
"(",
"engine",
".",
"getDependencies",
"(",
")",
")",
";",
"}",
"if",
"(",
"this",
".",
"failBuildOnCVSS",
"<=",
"10",
")",
"{",
"checkForFailure",
"(",
"engine",
".",
"getDependencies",
"(",
")",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"ExceptionCollection",
"ex",
")",
"{",
"if",
"(",
"ex",
".",
"isFatal",
"(",
")",
")",
"{",
"LOGGER",
".",
"error",
"(",
"\"A fatal exception occurred during analysis; analysis has stopped. Please see the debug log for more details.\"",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"\"",
",",
"ex",
")",
";",
"}",
"throw",
"new",
"ScanAgentException",
"(",
"\"One or more exceptions occurred during analysis; please see the debug log for more details.\"",
",",
"ex",
")",
";",
"}",
"finally",
"{",
"settings",
".",
"cleanup",
"(",
"true",
")",
";",
"if",
"(",
"engine",
"!=",
"null",
")",
"{",
"engine",
".",
"close",
"(",
")",
";",
"}",
"}",
"return",
"engine",
";",
"}"
] |
Executes the dependency-check and generates the report.
@return a reference to the engine used to perform the scan.
@throws org.owasp.dependencycheck.exception.ScanAgentException thrown if
there is an exception executing the scan.
|
[
"Executes",
"the",
"dependency",
"-",
"check",
"and",
"generates",
"the",
"report",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/agent/DependencyCheckScanAgent.java#L959-L987
|
17,883
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/lucene/AbstractTokenizingFilter.java
|
AbstractTokenizingFilter.addTerm
|
protected boolean addTerm() {
final boolean termAdded = !tokens.isEmpty();
if (termAdded) {
final String term = tokens.pop();
clearAttributes();
termAtt.append(term);
}
return termAdded;
}
|
java
|
protected boolean addTerm() {
final boolean termAdded = !tokens.isEmpty();
if (termAdded) {
final String term = tokens.pop();
clearAttributes();
termAtt.append(term);
}
return termAdded;
}
|
[
"protected",
"boolean",
"addTerm",
"(",
")",
"{",
"final",
"boolean",
"termAdded",
"=",
"!",
"tokens",
".",
"isEmpty",
"(",
")",
";",
"if",
"(",
"termAdded",
")",
"{",
"final",
"String",
"term",
"=",
"tokens",
".",
"pop",
"(",
")",
";",
"clearAttributes",
"(",
")",
";",
"termAtt",
".",
"append",
"(",
"term",
")",
";",
"}",
"return",
"termAdded",
";",
"}"
] |
Adds a term, if one exists, from the tokens collection.
@return whether or not a new term was added
|
[
"Adds",
"a",
"term",
"if",
"one",
"exists",
"from",
"the",
"tokens",
"collection",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/lucene/AbstractTokenizingFilter.java#L88-L96
|
17,884
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/update/nvd/UpdateableNvdCve.java
|
UpdateableNvdCve.add
|
public void add(String id, String url, long timestamp, boolean needsUpdate) {
final NvdCveInfo item = new NvdCveInfo();
item.setNeedsUpdate(needsUpdate); //the others default to true, to make life easier later this should default to false.
item.setId(id);
item.setUrl(url);
item.setTimestamp(timestamp);
collection.put(id, item);
}
|
java
|
public void add(String id, String url, long timestamp, boolean needsUpdate) {
final NvdCveInfo item = new NvdCveInfo();
item.setNeedsUpdate(needsUpdate); //the others default to true, to make life easier later this should default to false.
item.setId(id);
item.setUrl(url);
item.setTimestamp(timestamp);
collection.put(id, item);
}
|
[
"public",
"void",
"add",
"(",
"String",
"id",
",",
"String",
"url",
",",
"long",
"timestamp",
",",
"boolean",
"needsUpdate",
")",
"{",
"final",
"NvdCveInfo",
"item",
"=",
"new",
"NvdCveInfo",
"(",
")",
";",
"item",
".",
"setNeedsUpdate",
"(",
"needsUpdate",
")",
";",
"//the others default to true, to make life easier later this should default to false.",
"item",
".",
"setId",
"(",
"id",
")",
";",
"item",
".",
"setUrl",
"(",
"url",
")",
";",
"item",
".",
"setTimestamp",
"(",
"timestamp",
")",
";",
"collection",
".",
"put",
"(",
"id",
",",
"item",
")",
";",
"}"
] |
Adds a new entry of updateable information to the contained collection.
@param id the key for the item to be added
@param url the URL to download the item
@param timestamp the last modified date of the downloaded item
@param needsUpdate whether or not the data needs to be updated
|
[
"Adds",
"a",
"new",
"entry",
"of",
"updateable",
"information",
"to",
"the",
"contained",
"collection",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/update/nvd/UpdateableNvdCve.java#L77-L84
|
17,885
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/RubyGemspecAnalyzer.java
|
RubyGemspecAnalyzer.addStringEvidence
|
private String addStringEvidence(Dependency dependency, EvidenceType type, String contents,
String blockVariable, String field, String fieldPattern, Confidence confidence) {
String value = "";
//capture array value between [ ]
final Matcher arrayMatcher = Pattern.compile(
String.format("\\s*?%s\\.%s\\s*?=\\s*?\\[(.*?)\\]", blockVariable, fieldPattern), Pattern.CASE_INSENSITIVE).matcher(contents);
if (arrayMatcher.find()) {
final String arrayValue = arrayMatcher.group(1);
value = arrayValue.replaceAll("['\"]", "").trim(); //strip quotes
} else { //capture single value between quotes
final Matcher matcher = Pattern.compile(
String.format("\\s*?%s\\.%s\\s*?=\\s*?(['\"])(.*?)\\1", blockVariable, fieldPattern), Pattern.CASE_INSENSITIVE).matcher(contents);
if (matcher.find()) {
value = matcher.group(2);
}
}
if (value.length() > 0) {
dependency.addEvidence(type, GEMSPEC, field, value, confidence);
}
return value;
}
|
java
|
private String addStringEvidence(Dependency dependency, EvidenceType type, String contents,
String blockVariable, String field, String fieldPattern, Confidence confidence) {
String value = "";
//capture array value between [ ]
final Matcher arrayMatcher = Pattern.compile(
String.format("\\s*?%s\\.%s\\s*?=\\s*?\\[(.*?)\\]", blockVariable, fieldPattern), Pattern.CASE_INSENSITIVE).matcher(contents);
if (arrayMatcher.find()) {
final String arrayValue = arrayMatcher.group(1);
value = arrayValue.replaceAll("['\"]", "").trim(); //strip quotes
} else { //capture single value between quotes
final Matcher matcher = Pattern.compile(
String.format("\\s*?%s\\.%s\\s*?=\\s*?(['\"])(.*?)\\1", blockVariable, fieldPattern), Pattern.CASE_INSENSITIVE).matcher(contents);
if (matcher.find()) {
value = matcher.group(2);
}
}
if (value.length() > 0) {
dependency.addEvidence(type, GEMSPEC, field, value, confidence);
}
return value;
}
|
[
"private",
"String",
"addStringEvidence",
"(",
"Dependency",
"dependency",
",",
"EvidenceType",
"type",
",",
"String",
"contents",
",",
"String",
"blockVariable",
",",
"String",
"field",
",",
"String",
"fieldPattern",
",",
"Confidence",
"confidence",
")",
"{",
"String",
"value",
"=",
"\"\"",
";",
"//capture array value between [ ]",
"final",
"Matcher",
"arrayMatcher",
"=",
"Pattern",
".",
"compile",
"(",
"String",
".",
"format",
"(",
"\"\\\\s*?%s\\\\.%s\\\\s*?=\\\\s*?\\\\[(.*?)\\\\]\"",
",",
"blockVariable",
",",
"fieldPattern",
")",
",",
"Pattern",
".",
"CASE_INSENSITIVE",
")",
".",
"matcher",
"(",
"contents",
")",
";",
"if",
"(",
"arrayMatcher",
".",
"find",
"(",
")",
")",
"{",
"final",
"String",
"arrayValue",
"=",
"arrayMatcher",
".",
"group",
"(",
"1",
")",
";",
"value",
"=",
"arrayValue",
".",
"replaceAll",
"(",
"\"['\\\"]\"",
",",
"\"\"",
")",
".",
"trim",
"(",
")",
";",
"//strip quotes",
"}",
"else",
"{",
"//capture single value between quotes",
"final",
"Matcher",
"matcher",
"=",
"Pattern",
".",
"compile",
"(",
"String",
".",
"format",
"(",
"\"\\\\s*?%s\\\\.%s\\\\s*?=\\\\s*?(['\\\"])(.*?)\\\\1\"",
",",
"blockVariable",
",",
"fieldPattern",
")",
",",
"Pattern",
".",
"CASE_INSENSITIVE",
")",
".",
"matcher",
"(",
"contents",
")",
";",
"if",
"(",
"matcher",
".",
"find",
"(",
")",
")",
"{",
"value",
"=",
"matcher",
".",
"group",
"(",
"2",
")",
";",
"}",
"}",
"if",
"(",
"value",
".",
"length",
"(",
")",
">",
"0",
")",
"{",
"dependency",
".",
"addEvidence",
"(",
"type",
",",
"GEMSPEC",
",",
"field",
",",
"value",
",",
"confidence",
")",
";",
"}",
"return",
"value",
";",
"}"
] |
Adds the specified evidence to the given evidence collection.
@param dependency the dependency being analyzed
@param type the type of evidence to add
@param contents the evidence contents
@param blockVariable the variable
@param field the field
@param fieldPattern the field pattern
@param confidence the confidence of the evidence
@return the evidence string value added
|
[
"Adds",
"the",
"specified",
"evidence",
"to",
"the",
"given",
"evidence",
"collection",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/RubyGemspecAnalyzer.java#L225-L247
|
17,886
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/RubyGemspecAnalyzer.java
|
RubyGemspecAnalyzer.addEvidenceFromVersionFile
|
private String addEvidenceFromVersionFile(Dependency dependency, EvidenceType type, File dependencyFile) {
final File parentDir = dependencyFile.getParentFile();
String version = null;
int versionCount = 0;
if (parentDir != null) {
final File[] matchingFiles = parentDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.contains(VERSION_FILE_NAME);
}
});
if (matchingFiles == null) {
return null;
}
for (File f : matchingFiles) {
try {
final List<String> lines = FileUtils.readLines(f, Charset.defaultCharset());
if (lines.size() == 1) { //TODO other checking?
final String value = lines.get(0).trim();
if (version == null || !version.equals(value)) {
version = value;
versionCount++;
}
dependency.addEvidence(type, GEMSPEC, "version", value, Confidence.HIGH);
}
} catch (IOException e) {
LOGGER.debug("Error reading gemspec", e);
}
}
}
if (versionCount == 1) {
return version;
}
return null;
}
|
java
|
private String addEvidenceFromVersionFile(Dependency dependency, EvidenceType type, File dependencyFile) {
final File parentDir = dependencyFile.getParentFile();
String version = null;
int versionCount = 0;
if (parentDir != null) {
final File[] matchingFiles = parentDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.contains(VERSION_FILE_NAME);
}
});
if (matchingFiles == null) {
return null;
}
for (File f : matchingFiles) {
try {
final List<String> lines = FileUtils.readLines(f, Charset.defaultCharset());
if (lines.size() == 1) { //TODO other checking?
final String value = lines.get(0).trim();
if (version == null || !version.equals(value)) {
version = value;
versionCount++;
}
dependency.addEvidence(type, GEMSPEC, "version", value, Confidence.HIGH);
}
} catch (IOException e) {
LOGGER.debug("Error reading gemspec", e);
}
}
}
if (versionCount == 1) {
return version;
}
return null;
}
|
[
"private",
"String",
"addEvidenceFromVersionFile",
"(",
"Dependency",
"dependency",
",",
"EvidenceType",
"type",
",",
"File",
"dependencyFile",
")",
"{",
"final",
"File",
"parentDir",
"=",
"dependencyFile",
".",
"getParentFile",
"(",
")",
";",
"String",
"version",
"=",
"null",
";",
"int",
"versionCount",
"=",
"0",
";",
"if",
"(",
"parentDir",
"!=",
"null",
")",
"{",
"final",
"File",
"[",
"]",
"matchingFiles",
"=",
"parentDir",
".",
"listFiles",
"(",
"new",
"FilenameFilter",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"accept",
"(",
"File",
"dir",
",",
"String",
"name",
")",
"{",
"return",
"name",
".",
"contains",
"(",
"VERSION_FILE_NAME",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"matchingFiles",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"for",
"(",
"File",
"f",
":",
"matchingFiles",
")",
"{",
"try",
"{",
"final",
"List",
"<",
"String",
">",
"lines",
"=",
"FileUtils",
".",
"readLines",
"(",
"f",
",",
"Charset",
".",
"defaultCharset",
"(",
")",
")",
";",
"if",
"(",
"lines",
".",
"size",
"(",
")",
"==",
"1",
")",
"{",
"//TODO other checking?",
"final",
"String",
"value",
"=",
"lines",
".",
"get",
"(",
"0",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"version",
"==",
"null",
"||",
"!",
"version",
".",
"equals",
"(",
"value",
")",
")",
"{",
"version",
"=",
"value",
";",
"versionCount",
"++",
";",
"}",
"dependency",
".",
"addEvidence",
"(",
"type",
",",
"GEMSPEC",
",",
"\"version\"",
",",
"value",
",",
"Confidence",
".",
"HIGH",
")",
";",
"}",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Error reading gemspec\"",
",",
"e",
")",
";",
"}",
"}",
"}",
"if",
"(",
"versionCount",
"==",
"1",
")",
"{",
"return",
"version",
";",
"}",
"return",
"null",
";",
"}"
] |
Adds evidence from the version file.
@param dependency the dependency being analyzed
@param type the type of evidence to add
@param dependencyFile the dependency being analyzed
@return the version number added
|
[
"Adds",
"evidence",
"from",
"the",
"version",
"file",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/RubyGemspecAnalyzer.java#L257-L292
|
17,887
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/utils/FileFilterBuilder.java
|
FileFilterBuilder.addExtensions
|
public FileFilterBuilder addExtensions(Iterable<String> extensions) {
for (String extension : extensions) {
// Ultimately, SuffixFileFilter will be used, and the "." needs to be explicit.
this.extensions.add(extension.startsWith(".") ? extension : "." + extension);
}
return this;
}
|
java
|
public FileFilterBuilder addExtensions(Iterable<String> extensions) {
for (String extension : extensions) {
// Ultimately, SuffixFileFilter will be used, and the "." needs to be explicit.
this.extensions.add(extension.startsWith(".") ? extension : "." + extension);
}
return this;
}
|
[
"public",
"FileFilterBuilder",
"addExtensions",
"(",
"Iterable",
"<",
"String",
">",
"extensions",
")",
"{",
"for",
"(",
"String",
"extension",
":",
"extensions",
")",
"{",
"// Ultimately, SuffixFileFilter will be used, and the \".\" needs to be explicit.",
"this",
".",
"extensions",
".",
"add",
"(",
"extension",
".",
"startsWith",
"(",
"\".\"",
")",
"?",
"extension",
":",
"\".\"",
"+",
"extension",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Add to the set of file extensions to accept for analysis. Case-insensitivity is assumed.
@param extensions one or more file extensions to accept for analysis
@return this builder
|
[
"Add",
"to",
"the",
"set",
"of",
"file",
"extensions",
"to",
"accept",
"for",
"analysis",
".",
"Case",
"-",
"insensitivity",
"is",
"assumed",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/utils/FileFilterBuilder.java#L99-L105
|
17,888
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/utils/FileFilterBuilder.java
|
FileFilterBuilder.build
|
public FileFilter build() {
if (filenames.isEmpty() && extensions.isEmpty() && fileFilters.isEmpty()) {
throw new IllegalStateException("May only be invoked after at least one add... method has been invoked.");
}
final OrFileFilter filter = new OrFileFilter();
if (!filenames.isEmpty()) {
filter.addFileFilter(new NameFileFilter(new ArrayList<>(filenames)));
}
if (!extensions.isEmpty()) {
filter.addFileFilter(new SuffixFileFilter(new ArrayList<>(extensions), IOCase.INSENSITIVE));
}
for (IOFileFilter iof : fileFilters) {
filter.addFileFilter(iof);
}
return filter;
}
|
java
|
public FileFilter build() {
if (filenames.isEmpty() && extensions.isEmpty() && fileFilters.isEmpty()) {
throw new IllegalStateException("May only be invoked after at least one add... method has been invoked.");
}
final OrFileFilter filter = new OrFileFilter();
if (!filenames.isEmpty()) {
filter.addFileFilter(new NameFileFilter(new ArrayList<>(filenames)));
}
if (!extensions.isEmpty()) {
filter.addFileFilter(new SuffixFileFilter(new ArrayList<>(extensions), IOCase.INSENSITIVE));
}
for (IOFileFilter iof : fileFilters) {
filter.addFileFilter(iof);
}
return filter;
}
|
[
"public",
"FileFilter",
"build",
"(",
")",
"{",
"if",
"(",
"filenames",
".",
"isEmpty",
"(",
")",
"&&",
"extensions",
".",
"isEmpty",
"(",
")",
"&&",
"fileFilters",
".",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"May only be invoked after at least one add... method has been invoked.\"",
")",
";",
"}",
"final",
"OrFileFilter",
"filter",
"=",
"new",
"OrFileFilter",
"(",
")",
";",
"if",
"(",
"!",
"filenames",
".",
"isEmpty",
"(",
")",
")",
"{",
"filter",
".",
"addFileFilter",
"(",
"new",
"NameFileFilter",
"(",
"new",
"ArrayList",
"<>",
"(",
"filenames",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"extensions",
".",
"isEmpty",
"(",
")",
")",
"{",
"filter",
".",
"addFileFilter",
"(",
"new",
"SuffixFileFilter",
"(",
"new",
"ArrayList",
"<>",
"(",
"extensions",
")",
",",
"IOCase",
".",
"INSENSITIVE",
")",
")",
";",
"}",
"for",
"(",
"IOFileFilter",
"iof",
":",
"fileFilters",
")",
"{",
"filter",
".",
"addFileFilter",
"(",
"iof",
")",
";",
"}",
"return",
"filter",
";",
"}"
] |
Builds the filter and returns it.
@return a filter that is the logical OR of all the conditions provided by the add... methods
@throws IllegalStateException if no add... method has been called with one or more arguments
|
[
"Builds",
"the",
"filter",
"and",
"returns",
"it",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/utils/FileFilterBuilder.java#L124-L139
|
17,889
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/xml/XmlEntity.java
|
XmlEntity.fromNamedReference
|
public static String fromNamedReference(CharSequence s) {
if (s == null) {
return null;
}
final Integer code = SPECIALS.get(s.toString());
if (code != null) {
return "&#" + code + ";";
}
return null;
}
|
java
|
public static String fromNamedReference(CharSequence s) {
if (s == null) {
return null;
}
final Integer code = SPECIALS.get(s.toString());
if (code != null) {
return "&#" + code + ";";
}
return null;
}
|
[
"public",
"static",
"String",
"fromNamedReference",
"(",
"CharSequence",
"s",
")",
"{",
"if",
"(",
"s",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"final",
"Integer",
"code",
"=",
"SPECIALS",
".",
"get",
"(",
"s",
".",
"toString",
"(",
")",
")",
";",
"if",
"(",
"code",
"!=",
"null",
")",
"{",
"return",
"\"&#\"",
"+",
"code",
"+",
"\";\"",
";",
"}",
"return",
"null",
";",
"}"
] |
Converts a named XML entity into its HTML encoded Unicode code point.
@param s the named entity (note, this should not include the leading
'&' or trailing ';'
@return the HTML encoded Unicode code point representation of the named
entity
|
[
"Converts",
"a",
"named",
"XML",
"entity",
"into",
"its",
"HTML",
"encoded",
"Unicode",
"code",
"point",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/xml/XmlEntity.java#L303-L312
|
17,890
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java
|
URLConnectionFactory.createHttpURLConnection
|
@SuppressFBWarnings(justification = "yes, there is a redundant null check in the catch - to suppress warnings we are leaving the null check",
value = {"RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"})
public HttpURLConnection createHttpURLConnection(URL url) throws URLConnectionFailureException {
HttpURLConnection conn = null;
final String proxyHost = settings.getString(Settings.KEYS.PROXY_SERVER);
try {
if (proxyHost != null && !matchNonProxy(url)) {
final int proxyPort = settings.getInt(Settings.KEYS.PROXY_PORT);
final SocketAddress address = new InetSocketAddress(proxyHost, proxyPort);
final String username = settings.getString(Settings.KEYS.PROXY_USERNAME);
final String password = settings.getString(Settings.KEYS.PROXY_PASSWORD);
if (username != null && password != null) {
final Authenticator auth = new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
if (proxyHost.equals(getRequestingHost()) || getRequestorType().equals(Authenticator.RequestorType.PROXY)) {
LOGGER.debug("Using the configured proxy username and password");
try {
if (settings.getBoolean(Settings.KEYS.PROXY_DISABLE_SCHEMAS, true)) {
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
}
} catch (InvalidSettingException ex) {
LOGGER.trace("This exception can be ignored", ex);
}
return new PasswordAuthentication(username, password.toCharArray());
}
return super.getPasswordAuthentication();
}
};
Authenticator.setDefault(auth);
}
final Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
conn = (HttpURLConnection) url.openConnection(proxy);
} else {
conn = (HttpURLConnection) url.openConnection();
}
final int connectionTimeout = settings.getInt(Settings.KEYS.CONNECTION_TIMEOUT, 10000);
conn.setConnectTimeout(connectionTimeout);
conn.setInstanceFollowRedirects(true);
} catch (IOException ex) {
if (conn != null) {
try {
conn.disconnect();
} finally {
conn = null;
}
}
throw new URLConnectionFailureException("Error getting connection.", ex);
}
//conn.setRequestProperty("user-agent",
// "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
configureTLS(url, conn);
return conn;
}
|
java
|
@SuppressFBWarnings(justification = "yes, there is a redundant null check in the catch - to suppress warnings we are leaving the null check",
value = {"RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE"})
public HttpURLConnection createHttpURLConnection(URL url) throws URLConnectionFailureException {
HttpURLConnection conn = null;
final String proxyHost = settings.getString(Settings.KEYS.PROXY_SERVER);
try {
if (proxyHost != null && !matchNonProxy(url)) {
final int proxyPort = settings.getInt(Settings.KEYS.PROXY_PORT);
final SocketAddress address = new InetSocketAddress(proxyHost, proxyPort);
final String username = settings.getString(Settings.KEYS.PROXY_USERNAME);
final String password = settings.getString(Settings.KEYS.PROXY_PASSWORD);
if (username != null && password != null) {
final Authenticator auth = new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
if (proxyHost.equals(getRequestingHost()) || getRequestorType().equals(Authenticator.RequestorType.PROXY)) {
LOGGER.debug("Using the configured proxy username and password");
try {
if (settings.getBoolean(Settings.KEYS.PROXY_DISABLE_SCHEMAS, true)) {
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
}
} catch (InvalidSettingException ex) {
LOGGER.trace("This exception can be ignored", ex);
}
return new PasswordAuthentication(username, password.toCharArray());
}
return super.getPasswordAuthentication();
}
};
Authenticator.setDefault(auth);
}
final Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
conn = (HttpURLConnection) url.openConnection(proxy);
} else {
conn = (HttpURLConnection) url.openConnection();
}
final int connectionTimeout = settings.getInt(Settings.KEYS.CONNECTION_TIMEOUT, 10000);
conn.setConnectTimeout(connectionTimeout);
conn.setInstanceFollowRedirects(true);
} catch (IOException ex) {
if (conn != null) {
try {
conn.disconnect();
} finally {
conn = null;
}
}
throw new URLConnectionFailureException("Error getting connection.", ex);
}
//conn.setRequestProperty("user-agent",
// "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
configureTLS(url, conn);
return conn;
}
|
[
"@",
"SuppressFBWarnings",
"(",
"justification",
"=",
"\"yes, there is a redundant null check in the catch - to suppress warnings we are leaving the null check\"",
",",
"value",
"=",
"{",
"\"RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE\"",
"}",
")",
"public",
"HttpURLConnection",
"createHttpURLConnection",
"(",
"URL",
"url",
")",
"throws",
"URLConnectionFailureException",
"{",
"HttpURLConnection",
"conn",
"=",
"null",
";",
"final",
"String",
"proxyHost",
"=",
"settings",
".",
"getString",
"(",
"Settings",
".",
"KEYS",
".",
"PROXY_SERVER",
")",
";",
"try",
"{",
"if",
"(",
"proxyHost",
"!=",
"null",
"&&",
"!",
"matchNonProxy",
"(",
"url",
")",
")",
"{",
"final",
"int",
"proxyPort",
"=",
"settings",
".",
"getInt",
"(",
"Settings",
".",
"KEYS",
".",
"PROXY_PORT",
")",
";",
"final",
"SocketAddress",
"address",
"=",
"new",
"InetSocketAddress",
"(",
"proxyHost",
",",
"proxyPort",
")",
";",
"final",
"String",
"username",
"=",
"settings",
".",
"getString",
"(",
"Settings",
".",
"KEYS",
".",
"PROXY_USERNAME",
")",
";",
"final",
"String",
"password",
"=",
"settings",
".",
"getString",
"(",
"Settings",
".",
"KEYS",
".",
"PROXY_PASSWORD",
")",
";",
"if",
"(",
"username",
"!=",
"null",
"&&",
"password",
"!=",
"null",
")",
"{",
"final",
"Authenticator",
"auth",
"=",
"new",
"Authenticator",
"(",
")",
"{",
"@",
"Override",
"public",
"PasswordAuthentication",
"getPasswordAuthentication",
"(",
")",
"{",
"if",
"(",
"proxyHost",
".",
"equals",
"(",
"getRequestingHost",
"(",
")",
")",
"||",
"getRequestorType",
"(",
")",
".",
"equals",
"(",
"Authenticator",
".",
"RequestorType",
".",
"PROXY",
")",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Using the configured proxy username and password\"",
")",
";",
"try",
"{",
"if",
"(",
"settings",
".",
"getBoolean",
"(",
"Settings",
".",
"KEYS",
".",
"PROXY_DISABLE_SCHEMAS",
",",
"true",
")",
")",
"{",
"System",
".",
"setProperty",
"(",
"\"jdk.http.auth.tunneling.disabledSchemes\"",
",",
"\"\"",
")",
";",
"}",
"}",
"catch",
"(",
"InvalidSettingException",
"ex",
")",
"{",
"LOGGER",
".",
"trace",
"(",
"\"This exception can be ignored\"",
",",
"ex",
")",
";",
"}",
"return",
"new",
"PasswordAuthentication",
"(",
"username",
",",
"password",
".",
"toCharArray",
"(",
")",
")",
";",
"}",
"return",
"super",
".",
"getPasswordAuthentication",
"(",
")",
";",
"}",
"}",
";",
"Authenticator",
".",
"setDefault",
"(",
"auth",
")",
";",
"}",
"final",
"Proxy",
"proxy",
"=",
"new",
"Proxy",
"(",
"Proxy",
".",
"Type",
".",
"HTTP",
",",
"address",
")",
";",
"conn",
"=",
"(",
"HttpURLConnection",
")",
"url",
".",
"openConnection",
"(",
"proxy",
")",
";",
"}",
"else",
"{",
"conn",
"=",
"(",
"HttpURLConnection",
")",
"url",
".",
"openConnection",
"(",
")",
";",
"}",
"final",
"int",
"connectionTimeout",
"=",
"settings",
".",
"getInt",
"(",
"Settings",
".",
"KEYS",
".",
"CONNECTION_TIMEOUT",
",",
"10000",
")",
";",
"conn",
".",
"setConnectTimeout",
"(",
"connectionTimeout",
")",
";",
"conn",
".",
"setInstanceFollowRedirects",
"(",
"true",
")",
";",
"}",
"catch",
"(",
"IOException",
"ex",
")",
"{",
"if",
"(",
"conn",
"!=",
"null",
")",
"{",
"try",
"{",
"conn",
".",
"disconnect",
"(",
")",
";",
"}",
"finally",
"{",
"conn",
"=",
"null",
";",
"}",
"}",
"throw",
"new",
"URLConnectionFailureException",
"(",
"\"Error getting connection.\"",
",",
"ex",
")",
";",
"}",
"//conn.setRequestProperty(\"user-agent\",",
"// \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36\");",
"configureTLS",
"(",
"url",
",",
"conn",
")",
";",
"return",
"conn",
";",
"}"
] |
Utility method to create an HttpURLConnection. If the application is
configured to use a proxy this method will retrieve the proxy settings
and use them when setting up the connection.
@param url the URL to connect to
@return an HttpURLConnection
@throws org.owasp.dependencycheck.utils.URLConnectionFailureException
thrown if there is an exception
|
[
"Utility",
"method",
"to",
"create",
"an",
"HttpURLConnection",
".",
"If",
"the",
"application",
"is",
"configured",
"to",
"use",
"a",
"proxy",
"this",
"method",
"will",
"retrieve",
"the",
"proxy",
"settings",
"and",
"use",
"them",
"when",
"setting",
"up",
"the",
"connection",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java#L75-L132
|
17,891
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java
|
URLConnectionFactory.matchNonProxy
|
@SuppressWarnings("StringSplitter")
private boolean matchNonProxy(final URL url) {
final String host = url.getHost();
// code partially from org.apache.maven.plugins.site.AbstractDeployMojo#getProxyInfo
final String nonProxyHosts = settings.getString(Settings.KEYS.PROXY_NON_PROXY_HOSTS);
if (null != nonProxyHosts) {
final String[] nonProxies = nonProxyHosts.split("(,)|(;)|(\\|)");
for (final String nonProxyHost : nonProxies) {
//if ( StringUtils.contains( nonProxyHost, "*" ) )
if (null != nonProxyHost && nonProxyHost.contains("*")) {
// Handle wildcard at the end, beginning or middle of the nonProxyHost
final int pos = nonProxyHost.indexOf('*');
final String nonProxyHostPrefix = nonProxyHost.substring(0, pos);
final String nonProxyHostSuffix = nonProxyHost.substring(pos + 1);
// prefix*
if (!StringUtils.isEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix) && StringUtils.isEmpty(nonProxyHostSuffix)) {
return true;
}
// *suffix
if (StringUtils.isEmpty(nonProxyHostPrefix) && !StringUtils.isEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) {
return true;
}
// prefix*suffix
if (!StringUtils.isEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix) && !StringUtils.isEmpty(nonProxyHostSuffix)
&& host.endsWith(nonProxyHostSuffix)) {
return true;
}
} else if (host.equals(nonProxyHost)) {
return true;
}
}
}
return false;
}
|
java
|
@SuppressWarnings("StringSplitter")
private boolean matchNonProxy(final URL url) {
final String host = url.getHost();
// code partially from org.apache.maven.plugins.site.AbstractDeployMojo#getProxyInfo
final String nonProxyHosts = settings.getString(Settings.KEYS.PROXY_NON_PROXY_HOSTS);
if (null != nonProxyHosts) {
final String[] nonProxies = nonProxyHosts.split("(,)|(;)|(\\|)");
for (final String nonProxyHost : nonProxies) {
//if ( StringUtils.contains( nonProxyHost, "*" ) )
if (null != nonProxyHost && nonProxyHost.contains("*")) {
// Handle wildcard at the end, beginning or middle of the nonProxyHost
final int pos = nonProxyHost.indexOf('*');
final String nonProxyHostPrefix = nonProxyHost.substring(0, pos);
final String nonProxyHostSuffix = nonProxyHost.substring(pos + 1);
// prefix*
if (!StringUtils.isEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix) && StringUtils.isEmpty(nonProxyHostSuffix)) {
return true;
}
// *suffix
if (StringUtils.isEmpty(nonProxyHostPrefix) && !StringUtils.isEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) {
return true;
}
// prefix*suffix
if (!StringUtils.isEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix) && !StringUtils.isEmpty(nonProxyHostSuffix)
&& host.endsWith(nonProxyHostSuffix)) {
return true;
}
} else if (host.equals(nonProxyHost)) {
return true;
}
}
}
return false;
}
|
[
"@",
"SuppressWarnings",
"(",
"\"StringSplitter\"",
")",
"private",
"boolean",
"matchNonProxy",
"(",
"final",
"URL",
"url",
")",
"{",
"final",
"String",
"host",
"=",
"url",
".",
"getHost",
"(",
")",
";",
"// code partially from org.apache.maven.plugins.site.AbstractDeployMojo#getProxyInfo",
"final",
"String",
"nonProxyHosts",
"=",
"settings",
".",
"getString",
"(",
"Settings",
".",
"KEYS",
".",
"PROXY_NON_PROXY_HOSTS",
")",
";",
"if",
"(",
"null",
"!=",
"nonProxyHosts",
")",
"{",
"final",
"String",
"[",
"]",
"nonProxies",
"=",
"nonProxyHosts",
".",
"split",
"(",
"\"(,)|(;)|(\\\\|)\"",
")",
";",
"for",
"(",
"final",
"String",
"nonProxyHost",
":",
"nonProxies",
")",
"{",
"//if ( StringUtils.contains( nonProxyHost, \"*\" ) )",
"if",
"(",
"null",
"!=",
"nonProxyHost",
"&&",
"nonProxyHost",
".",
"contains",
"(",
"\"*\"",
")",
")",
"{",
"// Handle wildcard at the end, beginning or middle of the nonProxyHost",
"final",
"int",
"pos",
"=",
"nonProxyHost",
".",
"indexOf",
"(",
"'",
"'",
")",
";",
"final",
"String",
"nonProxyHostPrefix",
"=",
"nonProxyHost",
".",
"substring",
"(",
"0",
",",
"pos",
")",
";",
"final",
"String",
"nonProxyHostSuffix",
"=",
"nonProxyHost",
".",
"substring",
"(",
"pos",
"+",
"1",
")",
";",
"// prefix*",
"if",
"(",
"!",
"StringUtils",
".",
"isEmpty",
"(",
"nonProxyHostPrefix",
")",
"&&",
"host",
".",
"startsWith",
"(",
"nonProxyHostPrefix",
")",
"&&",
"StringUtils",
".",
"isEmpty",
"(",
"nonProxyHostSuffix",
")",
")",
"{",
"return",
"true",
";",
"}",
"// *suffix",
"if",
"(",
"StringUtils",
".",
"isEmpty",
"(",
"nonProxyHostPrefix",
")",
"&&",
"!",
"StringUtils",
".",
"isEmpty",
"(",
"nonProxyHostSuffix",
")",
"&&",
"host",
".",
"endsWith",
"(",
"nonProxyHostSuffix",
")",
")",
"{",
"return",
"true",
";",
"}",
"// prefix*suffix",
"if",
"(",
"!",
"StringUtils",
".",
"isEmpty",
"(",
"nonProxyHostPrefix",
")",
"&&",
"host",
".",
"startsWith",
"(",
"nonProxyHostPrefix",
")",
"&&",
"!",
"StringUtils",
".",
"isEmpty",
"(",
"nonProxyHostSuffix",
")",
"&&",
"host",
".",
"endsWith",
"(",
"nonProxyHostSuffix",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"host",
".",
"equals",
"(",
"nonProxyHost",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check if host name matches nonProxy settings
@param url the URL to connect to
@return matching result. true: match nonProxy
|
[
"Check",
"if",
"host",
"name",
"matches",
"nonProxy",
"settings"
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java#L140-L174
|
17,892
|
jeremylong/DependencyCheck
|
utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java
|
URLConnectionFactory.configureTLS
|
private void configureTLS(URL url, URLConnection conn) {
if ("https".equals(url.getProtocol())) {
try {
final HttpsURLConnection secCon = (HttpsURLConnection) conn;
final SSLSocketFactoryEx factory = new SSLSocketFactoryEx(settings);
secCon.setSSLSocketFactory(factory);
} catch (NoSuchAlgorithmException ex) {
LOGGER.debug("Unsupported algorithm in SSLSocketFactoryEx", ex);
} catch (KeyManagementException ex) {
LOGGER.debug("Key management exception in SSLSocketFactoryEx", ex);
}
}
}
|
java
|
private void configureTLS(URL url, URLConnection conn) {
if ("https".equals(url.getProtocol())) {
try {
final HttpsURLConnection secCon = (HttpsURLConnection) conn;
final SSLSocketFactoryEx factory = new SSLSocketFactoryEx(settings);
secCon.setSSLSocketFactory(factory);
} catch (NoSuchAlgorithmException ex) {
LOGGER.debug("Unsupported algorithm in SSLSocketFactoryEx", ex);
} catch (KeyManagementException ex) {
LOGGER.debug("Key management exception in SSLSocketFactoryEx", ex);
}
}
}
|
[
"private",
"void",
"configureTLS",
"(",
"URL",
"url",
",",
"URLConnection",
"conn",
")",
"{",
"if",
"(",
"\"https\"",
".",
"equals",
"(",
"url",
".",
"getProtocol",
"(",
")",
")",
")",
"{",
"try",
"{",
"final",
"HttpsURLConnection",
"secCon",
"=",
"(",
"HttpsURLConnection",
")",
"conn",
";",
"final",
"SSLSocketFactoryEx",
"factory",
"=",
"new",
"SSLSocketFactoryEx",
"(",
"settings",
")",
";",
"secCon",
".",
"setSSLSocketFactory",
"(",
"factory",
")",
";",
"}",
"catch",
"(",
"NoSuchAlgorithmException",
"ex",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Unsupported algorithm in SSLSocketFactoryEx\"",
",",
"ex",
")",
";",
"}",
"catch",
"(",
"KeyManagementException",
"ex",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Key management exception in SSLSocketFactoryEx\"",
",",
"ex",
")",
";",
"}",
"}",
"}"
] |
If the protocol is HTTPS, this will configure the cipher suites so that
connections can be made to the NVD, and others, using older versions of
Java.
@param url the URL
@param conn the connection
|
[
"If",
"the",
"protocol",
"is",
"HTTPS",
"this",
"will",
"configure",
"the",
"cipher",
"suites",
"so",
"that",
"connections",
"can",
"be",
"made",
"to",
"the",
"NVD",
"and",
"others",
"using",
"older",
"versions",
"of",
"Java",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/utils/src/main/java/org/owasp/dependencycheck/utils/URLConnectionFactory.java#L213-L225
|
17,893
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractDependencyComparingAnalyzer.java
|
AbstractDependencyComparingAnalyzer.analyzeDependency
|
@Override
protected synchronized void analyzeDependency(Dependency ignore, Engine engine) throws AnalysisException {
if (!analyzed) {
analyzed = true;
final Set<Dependency> dependenciesToRemove = new HashSet<>();
final Dependency[] dependencies = engine.getDependencies();
if (dependencies.length < 2) {
return;
}
for (int x = 0; x < dependencies.length - 1; x++) {
final Dependency dependency = dependencies[x];
if (!dependenciesToRemove.contains(dependency)) {
for (int y = x + 1; y < dependencies.length; y++) {
final Dependency nextDependency = dependencies[y];
if (evaluateDependencies(dependency, nextDependency, dependenciesToRemove)) {
break;
}
}
}
}
dependenciesToRemove.forEach((d) -> {
engine.removeDependency(d);
});
}
|
java
|
@Override
protected synchronized void analyzeDependency(Dependency ignore, Engine engine) throws AnalysisException {
if (!analyzed) {
analyzed = true;
final Set<Dependency> dependenciesToRemove = new HashSet<>();
final Dependency[] dependencies = engine.getDependencies();
if (dependencies.length < 2) {
return;
}
for (int x = 0; x < dependencies.length - 1; x++) {
final Dependency dependency = dependencies[x];
if (!dependenciesToRemove.contains(dependency)) {
for (int y = x + 1; y < dependencies.length; y++) {
final Dependency nextDependency = dependencies[y];
if (evaluateDependencies(dependency, nextDependency, dependenciesToRemove)) {
break;
}
}
}
}
dependenciesToRemove.forEach((d) -> {
engine.removeDependency(d);
});
}
|
[
"@",
"Override",
"protected",
"synchronized",
"void",
"analyzeDependency",
"(",
"Dependency",
"ignore",
",",
"Engine",
"engine",
")",
"throws",
"AnalysisException",
"{",
"if",
"(",
"!",
"analyzed",
")",
"{",
"analyzed",
"=",
"true",
";",
"final",
"Set",
"<",
"Dependency",
">",
"dependenciesToRemove",
"=",
"new",
"HashSet",
"<>",
"(",
")",
";",
"final",
"Dependency",
"[",
"]",
"dependencies",
"=",
"engine",
".",
"getDependencies",
"(",
")",
";",
"if",
"(",
"dependencies",
".",
"length",
"<",
"2",
")",
"{",
"return",
";",
"}",
"for",
"(",
"int",
"x",
"=",
"0",
";",
"x",
"<",
"dependencies",
".",
"length",
"-",
"1",
";",
"x",
"++",
")",
"{",
"final",
"Dependency",
"dependency",
"=",
"dependencies",
"[",
"x",
"]",
";",
"if",
"(",
"!",
"dependenciesToRemove",
".",
"contains",
"(",
"dependency",
")",
")",
"{",
"for",
"(",
"int",
"y",
"=",
"x",
"+",
"1",
";",
"y",
"<",
"dependencies",
".",
"length",
";",
"y",
"++",
")",
"{",
"final",
"Dependency",
"nextDependency",
"=",
"dependencies",
"[",
"y",
"]",
";",
"if",
"(",
"evaluateDependencies",
"(",
"dependency",
",",
"nextDependency",
",",
"dependenciesToRemove",
")",
")",
"{",
"break",
";",
"}",
"}",
"}",
"}",
"dependenciesToRemove",
".",
"forEach",
"(",
"(",
"d",
")",
"-",
">",
"{",
"engine",
".",
"removeDependency",
"(",
"d",
")",
"",
";",
"}",
")",
";",
"}"
] |
Analyzes a set of dependencies. If they have been found to have the same
base path and the same set of identifiers they are likely related. The
related dependencies are bundled into a single reportable item.
@param ignore this analyzer ignores the dependency being analyzed
@param engine the engine that is scanning the dependencies
@throws AnalysisException is thrown if there is an error reading the JAR
file.
|
[
"Analyzes",
"a",
"set",
"of",
"dependencies",
".",
"If",
"they",
"have",
"been",
"found",
"to",
"have",
"the",
"same",
"base",
"path",
"and",
"the",
"same",
"set",
"of",
"identifiers",
"they",
"are",
"likely",
"related",
".",
"The",
"related",
"dependencies",
"are",
"bundled",
"into",
"a",
"single",
"reportable",
"item",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/AbstractDependencyComparingAnalyzer.java#L88-L112
|
17,894
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/utils/H2DBShutdownHookFactory.java
|
H2DBShutdownHookFactory.getHook
|
public static H2DBShutdownHook getHook(Settings settings) {
try {
final String className = settings.getString(Settings.KEYS.H2DB_SHUTDOWN_HOOK, "org.owasp.dependencycheck.utils.H2DBCleanupHook");
final Class<?> type = Class.forName(className);
return (H2DBShutdownHook) type.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException ex) {
LOGGER.debug("Failed to instantiate {}, using default shutdown hook instead", ex);
return new H2DBCleanupHook();
}
}
|
java
|
public static H2DBShutdownHook getHook(Settings settings) {
try {
final String className = settings.getString(Settings.KEYS.H2DB_SHUTDOWN_HOOK, "org.owasp.dependencycheck.utils.H2DBCleanupHook");
final Class<?> type = Class.forName(className);
return (H2DBShutdownHook) type.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException ex) {
LOGGER.debug("Failed to instantiate {}, using default shutdown hook instead", ex);
return new H2DBCleanupHook();
}
}
|
[
"public",
"static",
"H2DBShutdownHook",
"getHook",
"(",
"Settings",
"settings",
")",
"{",
"try",
"{",
"final",
"String",
"className",
"=",
"settings",
".",
"getString",
"(",
"Settings",
".",
"KEYS",
".",
"H2DB_SHUTDOWN_HOOK",
",",
"\"org.owasp.dependencycheck.utils.H2DBCleanupHook\"",
")",
";",
"final",
"Class",
"<",
"?",
">",
"type",
"=",
"Class",
".",
"forName",
"(",
"className",
")",
";",
"return",
"(",
"H2DBShutdownHook",
")",
"type",
".",
"getDeclaredConstructor",
"(",
")",
".",
"newInstance",
"(",
")",
";",
"}",
"catch",
"(",
"ClassNotFoundException",
"|",
"InstantiationException",
"|",
"IllegalAccessException",
"|",
"NoSuchMethodException",
"|",
"SecurityException",
"|",
"IllegalArgumentException",
"|",
"InvocationTargetException",
"ex",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Failed to instantiate {}, using default shutdown hook instead\"",
",",
"ex",
")",
";",
"return",
"new",
"H2DBCleanupHook",
"(",
")",
";",
"}",
"}"
] |
Creates a new H2DB Shutdown Hook.
@param settings the configured settings
@return the H2DB Shutdown Hook
|
[
"Creates",
"a",
"new",
"H2DB",
"Shutdown",
"Hook",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/utils/H2DBShutdownHookFactory.java#L49-L59
|
17,895
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/PythonPackageAnalyzer.java
|
PythonPackageAnalyzer.compileAssignPattern
|
private static Pattern compileAssignPattern(String name) {
return Pattern.compile(
String.format("\\b(__)?%s(__)?\\b *= *(['\"]+)(.*?)\\3", name),
REGEX_OPTIONS);
}
|
java
|
private static Pattern compileAssignPattern(String name) {
return Pattern.compile(
String.format("\\b(__)?%s(__)?\\b *= *(['\"]+)(.*?)\\3", name),
REGEX_OPTIONS);
}
|
[
"private",
"static",
"Pattern",
"compileAssignPattern",
"(",
"String",
"name",
")",
"{",
"return",
"Pattern",
".",
"compile",
"(",
"String",
".",
"format",
"(",
"\"\\\\b(__)?%s(__)?\\\\b *= *(['\\\"]+)(.*?)\\\\3\"",
",",
"name",
")",
",",
"REGEX_OPTIONS",
")",
";",
"}"
] |
Utility function to create a regex pattern matcher.
@param name the value to use when constructing the assignment pattern
@return the compiled Pattern
|
[
"Utility",
"function",
"to",
"create",
"a",
"regex",
"pattern",
"matcher",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/PythonPackageAnalyzer.java#L187-L191
|
17,896
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/PythonPackageAnalyzer.java
|
PythonPackageAnalyzer.addSummaryInfo
|
private boolean addSummaryInfo(Dependency dependency, Pattern pattern,
int group, String contents, String source, String key) {
final Matcher matcher = pattern.matcher(contents);
final boolean found = matcher.find();
if (found) {
JarAnalyzer.addDescription(dependency, matcher.group(group),
source, key);
}
return found;
}
|
java
|
private boolean addSummaryInfo(Dependency dependency, Pattern pattern,
int group, String contents, String source, String key) {
final Matcher matcher = pattern.matcher(contents);
final boolean found = matcher.find();
if (found) {
JarAnalyzer.addDescription(dependency, matcher.group(group),
source, key);
}
return found;
}
|
[
"private",
"boolean",
"addSummaryInfo",
"(",
"Dependency",
"dependency",
",",
"Pattern",
"pattern",
",",
"int",
"group",
",",
"String",
"contents",
",",
"String",
"source",
",",
"String",
"key",
")",
"{",
"final",
"Matcher",
"matcher",
"=",
"pattern",
".",
"matcher",
"(",
"contents",
")",
";",
"final",
"boolean",
"found",
"=",
"matcher",
".",
"find",
"(",
")",
";",
"if",
"(",
"found",
")",
"{",
"JarAnalyzer",
".",
"addDescription",
"(",
"dependency",
",",
"matcher",
".",
"group",
"(",
"group",
")",
",",
"source",
",",
"key",
")",
";",
"}",
"return",
"found",
";",
"}"
] |
Adds summary information to the dependency
@param dependency the dependency being analyzed
@param pattern the pattern used to perform analysis
@param group the group from the pattern that indicates the data to use
@param contents the data being analyzed
@param source the source name to use when recording the evidence
@param key the key name to use when recording the evidence
@return true if evidence was collected; otherwise false
|
[
"Adds",
"summary",
"information",
"to",
"the",
"dependency"
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/PythonPackageAnalyzer.java#L297-L306
|
17,897
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/PythonPackageAnalyzer.java
|
PythonPackageAnalyzer.gatherHomePageEvidence
|
private boolean gatherHomePageEvidence(Dependency dependency, EvidenceType type, Pattern pattern,
String source, String name, String contents) {
final Matcher matcher = pattern.matcher(contents);
boolean found = false;
if (matcher.find()) {
final String url = matcher.group(4);
if (UrlStringUtils.isUrl(url)) {
found = true;
dependency.addEvidence(type, source, name, url, Confidence.MEDIUM);
}
}
return found;
}
|
java
|
private boolean gatherHomePageEvidence(Dependency dependency, EvidenceType type, Pattern pattern,
String source, String name, String contents) {
final Matcher matcher = pattern.matcher(contents);
boolean found = false;
if (matcher.find()) {
final String url = matcher.group(4);
if (UrlStringUtils.isUrl(url)) {
found = true;
dependency.addEvidence(type, source, name, url, Confidence.MEDIUM);
}
}
return found;
}
|
[
"private",
"boolean",
"gatherHomePageEvidence",
"(",
"Dependency",
"dependency",
",",
"EvidenceType",
"type",
",",
"Pattern",
"pattern",
",",
"String",
"source",
",",
"String",
"name",
",",
"String",
"contents",
")",
"{",
"final",
"Matcher",
"matcher",
"=",
"pattern",
".",
"matcher",
"(",
"contents",
")",
";",
"boolean",
"found",
"=",
"false",
";",
"if",
"(",
"matcher",
".",
"find",
"(",
")",
")",
"{",
"final",
"String",
"url",
"=",
"matcher",
".",
"group",
"(",
"4",
")",
";",
"if",
"(",
"UrlStringUtils",
".",
"isUrl",
"(",
"url",
")",
")",
"{",
"found",
"=",
"true",
";",
"dependency",
".",
"addEvidence",
"(",
"type",
",",
"source",
",",
"name",
",",
"url",
",",
"Confidence",
".",
"MEDIUM",
")",
";",
"}",
"}",
"return",
"found",
";",
"}"
] |
Collects evidence from the home page URL.
@param dependency the dependency that is being analyzed
@param type the type of evidence
@param pattern the pattern to match
@param source the source of the evidence
@param name the name of the evidence
@param contents the home page URL
@return true if evidence was collected; otherwise false
|
[
"Collects",
"evidence",
"from",
"the",
"home",
"page",
"URL",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/PythonPackageAnalyzer.java#L319-L331
|
17,898
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/analyzer/PythonPackageAnalyzer.java
|
PythonPackageAnalyzer.gatherEvidence
|
private boolean gatherEvidence(Dependency dependency, EvidenceType type, Pattern pattern, String contents,
String source, String name, Confidence confidence) {
final Matcher matcher = pattern.matcher(contents);
final boolean found = matcher.find();
if (found) {
dependency.addEvidence(type, source, name, matcher.group(4), confidence);
if (type == EvidenceType.VERSION) {
//TODO - this seems broken as we are cycling over py files and could be grabbing versions from multiple?
dependency.setVersion(matcher.group(4));
final String dispName = String.format("%s:%s", dependency.getName(), dependency.getVersion());
dependency.setDisplayFileName(dispName);
}
}
return found;
}
|
java
|
private boolean gatherEvidence(Dependency dependency, EvidenceType type, Pattern pattern, String contents,
String source, String name, Confidence confidence) {
final Matcher matcher = pattern.matcher(contents);
final boolean found = matcher.find();
if (found) {
dependency.addEvidence(type, source, name, matcher.group(4), confidence);
if (type == EvidenceType.VERSION) {
//TODO - this seems broken as we are cycling over py files and could be grabbing versions from multiple?
dependency.setVersion(matcher.group(4));
final String dispName = String.format("%s:%s", dependency.getName(), dependency.getVersion());
dependency.setDisplayFileName(dispName);
}
}
return found;
}
|
[
"private",
"boolean",
"gatherEvidence",
"(",
"Dependency",
"dependency",
",",
"EvidenceType",
"type",
",",
"Pattern",
"pattern",
",",
"String",
"contents",
",",
"String",
"source",
",",
"String",
"name",
",",
"Confidence",
"confidence",
")",
"{",
"final",
"Matcher",
"matcher",
"=",
"pattern",
".",
"matcher",
"(",
"contents",
")",
";",
"final",
"boolean",
"found",
"=",
"matcher",
".",
"find",
"(",
")",
";",
"if",
"(",
"found",
")",
"{",
"dependency",
".",
"addEvidence",
"(",
"type",
",",
"source",
",",
"name",
",",
"matcher",
".",
"group",
"(",
"4",
")",
",",
"confidence",
")",
";",
"if",
"(",
"type",
"==",
"EvidenceType",
".",
"VERSION",
")",
"{",
"//TODO - this seems broken as we are cycling over py files and could be grabbing versions from multiple?",
"dependency",
".",
"setVersion",
"(",
"matcher",
".",
"group",
"(",
"4",
")",
")",
";",
"final",
"String",
"dispName",
"=",
"String",
".",
"format",
"(",
"\"%s:%s\"",
",",
"dependency",
".",
"getName",
"(",
")",
",",
"dependency",
".",
"getVersion",
"(",
")",
")",
";",
"dependency",
".",
"setDisplayFileName",
"(",
"dispName",
")",
";",
"}",
"}",
"return",
"found",
";",
"}"
] |
Gather evidence from a Python source file using the given string
assignment regex pattern.
@param dependency the dependency that is being analyzed
@param type the type of evidence
@param pattern to scan contents with
@param contents of Python source file
@param source for storing evidence
@param name of evidence
@param confidence in evidence
@return whether evidence was found
|
[
"Gather",
"evidence",
"from",
"a",
"Python",
"source",
"file",
"using",
"the",
"given",
"string",
"assignment",
"regex",
"pattern",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/analyzer/PythonPackageAnalyzer.java#L346-L360
|
17,899
|
jeremylong/DependencyCheck
|
core/src/main/java/org/owasp/dependencycheck/data/nvdcve/ConnectionFactory.java
|
ConnectionFactory.cleanup
|
public synchronized void cleanup() {
if (driver != null) {
DriverLoader.cleanup(driver);
driver = null;
}
connectionString = null;
userName = null;
password = null;
}
|
java
|
public synchronized void cleanup() {
if (driver != null) {
DriverLoader.cleanup(driver);
driver = null;
}
connectionString = null;
userName = null;
password = null;
}
|
[
"public",
"synchronized",
"void",
"cleanup",
"(",
")",
"{",
"if",
"(",
"driver",
"!=",
"null",
")",
"{",
"DriverLoader",
".",
"cleanup",
"(",
"driver",
")",
";",
"driver",
"=",
"null",
";",
"}",
"connectionString",
"=",
"null",
";",
"userName",
"=",
"null",
";",
"password",
"=",
"null",
";",
"}"
] |
Cleans up resources and unloads any registered database drivers. This
needs to be called to ensure the driver is unregistered prior to the
finalize method being called as during shutdown the class loader used to
load the driver may be unloaded prior to the driver being de-registered.
|
[
"Cleans",
"up",
"resources",
"and",
"unloads",
"any",
"registered",
"database",
"drivers",
".",
"This",
"needs",
"to",
"be",
"called",
"to",
"ensure",
"the",
"driver",
"is",
"unregistered",
"prior",
"to",
"the",
"finalize",
"method",
"being",
"called",
"as",
"during",
"shutdown",
"the",
"class",
"loader",
"used",
"to",
"load",
"the",
"driver",
"may",
"be",
"unloaded",
"prior",
"to",
"the",
"driver",
"being",
"de",
"-",
"registered",
"."
] |
6cc7690ea12e4ca1454210ceaa2e9a5523f0926c
|
https://github.com/jeremylong/DependencyCheck/blob/6cc7690ea12e4ca1454210ceaa2e9a5523f0926c/core/src/main/java/org/owasp/dependencycheck/data/nvdcve/ConnectionFactory.java#L212-L220
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.