Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug #191 #225

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.secnium.iast.core.EngineManager;
import com.secnium.iast.core.handler.vulscan.ReportConstant;
import com.secnium.iast.core.report.AssestReport;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -12,6 +13,8 @@
import java.util.HashSet;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import com.secnium.iast.log.DongTaiLog;
import org.json.JSONArray;
import org.json.JSONObject;

Expand Down Expand Up @@ -67,8 +70,12 @@ public static void scanForSCA(String packageFile, String internalClassName) {
thread = new ScaScanThread(packagePath, 1);
} else if (!scannedClassSet.contains(packageFile) && isLocalMavenRepo(packageFile)) {
scannedClassSet.add(packageFile);
thread = new ScaScanThread(packagePath, 3);
} else if (!isClassPath) {
thread = new ScaScanThread(packageFile, 3);
} else if (packageFile.endsWith(".jar") && !scannedClassSet.contains(packageFile)) {
scannedClassSet.add(packageFile);
thread = new ScaScanThread(packageFile, 3);
}
if (!isClassPath) {
isClassPath = true;
thread = new ScaScanThread(System.getProperty("java.class.path"), 4);
}
Expand Down Expand Up @@ -165,31 +172,29 @@ private void scanJarLib(String packagePath) {
try {
JarFile file = new JarFile(packagePath);
Enumeration<JarEntry> entries = file.entries();
file.close();
String entryName;
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
entryName = entry.getName();
if (!entryName.endsWith(".jar")) {
continue;
}
InputStream is = getJarInputStream(packagePath, entryName);
String signature = SignatureAlgorithm.getSignature(is, ScaScanner.ALGORITHM);
String packageName = entry.getName();
if (signature == null) {
continue;
if (entryName.endsWith(".jar")) {
InputStream is = getJarInputStream(packagePath, entryName);
String signature = SignatureAlgorithm.getSignature(is, ScaScanner.ALGORITHM);
String packageName = entry.getName();
if (signature == null) {
continue;
}
JSONObject packageObj = new JSONObject();
packageObj.put(ReportConstant.SCA_PACKAGE_PATH, "jar:file:" + packagePath + "!/" + entryName);
packageObj.put(ReportConstant.SCA_PACKAGE_NAME, packageName);
packageObj.put(ReportConstant.SCA_PACKAGE_SIGNATURE, signature);
packageObj.put(ReportConstant.SCA_PACKAGE_ALGORITHM, ScaScanner.ALGORITHM);
packages.put(packageObj);
}
JSONObject packageObj = new JSONObject();
packageObj.put(ReportConstant.SCA_PACKAGE_PATH, "jar:file:" + packagePath + "!/" + entryName);
packageObj.put(ReportConstant.SCA_PACKAGE_NAME, packageName);
packageObj.put(ReportConstant.SCA_PACKAGE_SIGNATURE, signature);
packageObj.put(ReportConstant.SCA_PACKAGE_ALGORITHM, ScaScanner.ALGORITHM);
packages.put(packageObj);
}
} catch (IOException e) {
e.printStackTrace();
DongTaiLog.error(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
DongTaiLog.error(e.getMessage());
}
}

Expand All @@ -203,7 +208,6 @@ private void scanJarLib(String packagePath) {
*
* @see #start()
* @see #stop()
* @see #Thread(ThreadGroup, Runnable, String)
*/
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public static String getSignature(InputStream is, String algorithm) {
while ((len = is.read(buffer)) > 0) {
digest.update(buffer, 0, len);
}
signature = new BigInteger(1, digest.digest()).toString(16);
BigInteger bigInteger = new BigInteger(1, digest.digest());
signature = String.format("%040x", bigInteger);
} catch (IOException e) {
DongTaiLog.error("calc jar signature error[IOException], msg: %s{}", e);
} catch (NoSuchAlgorithmException e) {
Expand Down