Merge remote-tracking branch 'origin/feature/SUPPORT-9156' into develop
# Conflicts: # src/main/java/ru/micord/av/service/service/FileScanService.java
This commit is contained in:
commit
11cd7856cc
1 changed files with 15 additions and 5 deletions
|
|
@ -26,6 +26,9 @@ import ru.micord.av.service.property.PasswordProtectedResultNamesProperty;
|
|||
public class FileScanService {
|
||||
private static final String KESL_CONTROL = "kesl-control";
|
||||
private static final String KESL_SCAN = "--scan-file";
|
||||
private static final int CLEAN_CODE = 0;
|
||||
private static final int INFECTED_CODE = 72;
|
||||
private static final int PASS_PROTECTED_CODE = 73;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FileScanService.class);
|
||||
private final String uploadDirectory;
|
||||
private final PasswordProtectedResultNamesProperty passwordProtectedResultNamesProperty;
|
||||
|
|
@ -77,16 +80,22 @@ public class FileScanService {
|
|||
String processOutput = processResult.outputUTF8();
|
||||
int exitCode = processResult.getExitValue();
|
||||
|
||||
if (exitCode != 0 && exitCode != 72) {
|
||||
if (exitCode != CLEAN_CODE && exitCode != INFECTED_CODE) {
|
||||
throw new AvException(
|
||||
"KESL error scanning file: " + originalFileName + ", exit code: " + exitCode);
|
||||
}
|
||||
checkScanResult(processOutput, originalFileName);
|
||||
|
||||
if (isPasswordProtectedFile(processOutput)) {
|
||||
LOGGER.warn("File: {} is identified as password protected. Please review the file.",
|
||||
originalFileName
|
||||
);
|
||||
exitCode = PASS_PROTECTED_CODE;
|
||||
}
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
private void checkScanResult(String result, String originalFileName) {
|
||||
private boolean isPasswordProtectedFile(String result) {
|
||||
boolean isResultNotContains = passwordProtectedResultNamesProperty.getNames().stream()
|
||||
.filter(result::contains)
|
||||
.toList()
|
||||
|
|
@ -108,10 +117,11 @@ public class FileScanService {
|
|||
.toList()
|
||||
.isEmpty();
|
||||
|
||||
if (isLinePartStartWith && Integer.parseInt(lineParts[1].trim()) > 0) {
|
||||
throw new AvException("Detected password-protected file: " + originalFileName);
|
||||
if (isLinePartStartWith) {
|
||||
return Integer.parseInt(lineParts[1].trim()) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue