Skip to content

Commit 8c5e4ec

Browse files
su-amaasliangsengk-tm
authored andcommitted
update to latest version: v1.2.0
1 parent 3c0089f commit 8c5e4ec

File tree

20 files changed

+1186
-17
lines changed

20 files changed

+1186
-17
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CHANGELOG
22

3+
## 1.2.0 - 2024-08-07
4+
* Support verbose scan result
5+
36
## 1.1.1 - 2024-04-10
47
* Update README.md
58
* Extend the scan default timeout to 300s

README.md

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public static void main(String[] args) {
7575

7676
### Sample JSON Response
7777

78+
#### Concise Format
79+
7880
```json
7981
{
8082
"version": "1.0",
@@ -94,6 +96,58 @@ public static void main(String[] args) {
9496

9597
When malicious content is detected in the scanned object, `scanResult` will show a non-zero value. Otherwise, the value will be `null`. Moreover, when malware is detected, `foundMalwares` will be non-empty containing one or more name/value pairs of `fileName` and `malwareName`. `fileName` will be filename of malware detected while `malwareName` will be the name of the virus/malware found.
9698

99+
#### Verbose Format
100+
101+
```json
102+
{
103+
"scanType": "sdk",
104+
"objectType": "file",
105+
"timestamp": {
106+
"start": "2024-07-05T20:01:21.064Z",
107+
"end": "2024-07-05T20:01:21.069Z"
108+
},
109+
"schemaVersion": "1.0.0",
110+
"scannerVersion": "1.0.0-59",
111+
"fileName": "eicar.com",
112+
"rsSize": 68,
113+
"scanId": "40d7a38e-a1d3-400b-a09c-7aa9cd62658f",
114+
"accountId": "",
115+
"result": {
116+
"atse": {
117+
"elapsedTime": 4693,
118+
"fileType": 5,
119+
"fileSubType": 0,
120+
"version": {
121+
"engine": "23.57.0-1002",
122+
"lptvpn": 385,
123+
"ssaptn": 731,
124+
"tmblack": 253,
125+
"tmwhite": 239,
126+
"macvpn": 914
127+
},
128+
"malwareCount": 1,
129+
"malware": [
130+
{
131+
"name": "Eicar_test_file",
132+
"fileName": "eicar.com",
133+
"type": "",
134+
"fileType": 5,
135+
"fileSubType": 0,
136+
"fileTypeName": "COM",
137+
"fileSubTypeName": "VSDT_COM_DOS"
138+
}
139+
],
140+
"error": null,
141+
"fileTypeName": "COM",
142+
"fileSubTypeName": "VSDT_COM_DOS"
143+
}
144+
},
145+
"fileSHA1": "3395856ce81f2b7382dee72602f798b642f14140",
146+
"fileSHA256": "275a021bbfb6489e54d471899f7db9d1663fc695ec2fe2a2c4538aabf651fd0f",
147+
"appName": "V1FS"
148+
}
149+
```
150+
97151
## Java SDK API Reference
98152

99153
### ```AmaasClient```
@@ -144,7 +198,7 @@ Scan a file for malware and retrieves response data from the API.
144198
**_Return_**
145199
String the scanned result in JSON format.
146200

147-
#### ```public String scanFile(final String fileName, final String[] tagList, final boolean pml, final boolean feedback) throws AMaasException```
201+
#### ```public String scanFile(final String fileName, final String[] tagList, final boolean pml, final boolean feedback, final boolean verbose) throws AMaasException```
148202

149203
Scan a file for malware, add a list of tags to the scan result and retrieves response data from the API.
150204

@@ -156,6 +210,7 @@ Scan a file for malware, add a list of tags to the scan result and retrieves res
156210
| tagList | A list of strings to be used to tag the scan result. At most 8 tags with the maximum length of 63 characters. |
157211
| pml | A flag to indicate whether to enable predictive machine learning detection. |
158212
| feedback | A flag to indicate whether to enable Trend Micro Smart Protection Network's Smart Feedback. |
213+
| verbose | A flag to enable log verbose mode. |
159214

160215
**_Return_**
161216
String the scanned result in JSON format.
@@ -174,7 +229,7 @@ Scan a buffer for malware and retrieves response data from the API.
174229
**_Return_**
175230
String the scanned result in JSON format.
176231

177-
#### ```public String scanBuffer(final byte[] buffer, final String identifier, final String[] tagList, final boolean pml, final boolean feedback) throws AMaasException```
232+
#### ```public String scanBuffer(final byte[] buffer, final String identifier, final String[] tagList, final boolean pml, final boolean feedback, final boolean verbose) throws AMaasException```
178233

179234
Scan a buffer for malware, add a list of tags to the scan result, and retrieves response data from the API.
180235

@@ -187,6 +242,7 @@ Scan a buffer for malware, add a list of tags to the scan result, and retrieves
187242
| tagList | A list of strings to be used to tag the scan result. At most 8 tags with maximum length of 63 characters. |
188243
| pml | A flag to indicate whether to enable predictive machine learning detection. |
189244
| feedback | A flag to indicate whether to enable Trend Micro Smart Protection Network's Smart Feedback. |
245+
| verbose | A flag to enable log verbose mode. |
190246

191247
**_Return_**
192248
String the scanned result in JSON format.
@@ -207,7 +263,7 @@ public class AmaasScanResult {
207263
private String fileName: // Name of the file scanned
208264
private MalwareItem[] foundMalwares; // A list of malware names and the filenames found by AMaaS
209265

210-
// getter and seter methods for the above private variables.
266+
// getter and setter methods for the above private variables.
211267
}
212268
```
213269

@@ -223,7 +279,32 @@ public class MalwareItem {
223279
private String malwareName; // A detected Malware name
224280
private String fileName: // File name that the malware is detected.
225281

226-
// getter and seter methods for the above private variables.
282+
// getter and setter methods for the above private variables.
283+
}
284+
```
285+
286+
### ```AMaasScanResultVerbose```
287+
288+
The AMaasScanResultVerbose has the data elements of the response data in verbose mode that is retrieved from our API. The class has the following private members. There are getter and setter methods for each of the members. See javaDoc for the class of each data element.
289+
290+
```java
291+
public class AMaasScanResultVerbose {
292+
private String scanType; // Type of scan
293+
private String objectType; // Type of the object being scanned. e.g, file
294+
private StartEnd timestamp; // begin and end time strings in ISO 8601 format
295+
private String schemaVersion; // Version of the data schema
296+
private String scannerVersion; // Scanner version
297+
private String fileName; // Name of the file
298+
private long rsSize; // Size of the scanned file
299+
private String scanId; // ID of the scan
300+
private String accountId; // ID of the customer
301+
private ScanResult result; // Result for the current scan
302+
private String[] tags; // Tags used for this scan
303+
private String fileSha1; // Sha1 of the scanned file
304+
private String fileSha256; // Sha256 of the scanned file
305+
private String appName; // Name of the application
306+
307+
// getter and setter methods for the above private variables.
227308
}
228309
```
229310

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.1
1+
1.2.0

examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ There are 4 examples under the following sub-folders:
4646
--taglist a commas separated string of tags. e.g. dev,sdk
4747
--pml enable predictive machine language detection. default to false
4848
--feedback enable Smart Feedback of Trend Micro Smart Protection Network. default to false
49+
-v enable log verbose mode. default to false
4950
```
5051

5152
For example:

examples/filescan/App.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ private static String[] listFiles(final String pathName) {
3434
.collect(Collectors.toList()).toArray(new String[] {});
3535
}
3636

37-
static void scanFilesInSequential(final AMaasClient client, final String[] fList, final String[] tagList, final boolean pmlFlag, final boolean feedbackFlag) {
37+
static void scanFilesInSequential(final AMaasClient client, final String[] fList, final String[] tagList, final boolean pmlFlag, final boolean feedbackFlag, final boolean verbose) {
3838
for (String fileName: fList) {
3939
try {
4040
info("===============> Scanning file {0}", fileName);
4141
long startTS = System.currentTimeMillis();
42-
String scanResult = client.scanFile(fileName, tagList, pmlFlag, feedbackFlag);
42+
String scanResult = client.scanFile(fileName, tagList, pmlFlag, feedbackFlag, verbose);
4343
long endTS = System.currentTimeMillis();
4444
info("{0}", scanResult);
4545
info("===============> File scan time {0}", endTS - startTS);
@@ -58,6 +58,7 @@ private static Options getCmdOptions() {
5858
optionList.addOption(null, "taglist", true, "commas separated string of tags.e.g, sdk,dev");
5959
optionList.addOption(null, "pml", true, "Enable predictive machine language detection");
6060
optionList.addOption(null, "feedback", true, "Enable Trend Smart Protection Network's Smart Feedback");
61+
optionList.addOption("v", "verbose", true, "Enable log verbose mode");
6162
return optionList;
6263
}
6364

@@ -71,6 +72,7 @@ private static Options getCmdOptions() {
7172
* --taglist a commas separated string of tags. e.g. dev,sdk
7273
* --pml enable predictive machine language detection. default to false
7374
* --feedback enable Trend Micro Smart Protection Network's Smart Feedback. default to false
75+
* -v enable log verbose mode. default to false
7476
*/
7577
public static void main(final String[] args) {
7678
String pathname = "";
@@ -80,6 +82,7 @@ public static void main(final String[] args) {
8082
String tags = null;
8183
boolean pmlFlag = false;
8284
boolean feedbackFlag = false;
85+
boolean verbose = false;
8386

8487
DefaultParser parser = new DefaultParser();
8588
HelpFormatter helper = new HelpFormatter();
@@ -111,6 +114,11 @@ public static void main(final String[] args) {
111114
feedbackFlag = true;
112115
}
113116
}
117+
if (cmd.hasOption("v")) {
118+
if (cmd.getOptionValue("v").equals("true")) {
119+
verbose = true;
120+
}
121+
}
114122
String[] tagList = null;
115123
if (tags != null) {
116124
info("tags to used {0}", tags);
@@ -121,7 +129,7 @@ public static void main(final String[] args) {
121129
String[] listOfFiles = listFiles(pathname);
122130
long totalStartTs = System.currentTimeMillis();
123131

124-
scanFilesInSequential(client, listOfFiles, tagList, pmlFlag, feedbackFlag);
132+
scanFilesInSequential(client, listOfFiles, tagList, pmlFlag, feedbackFlag, verbose);
125133

126134
long totalEndTs = System.currentTimeMillis();
127135
info("*************** Total scan time {0}", totalEndTs - totalStartTs);

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.trend</groupId>
77
<artifactId>file-security-java-sdk</artifactId>
8-
<version>1.1.1</version>
8+
<version>1.2.0</version>
99

1010
<name>file-security-java-sdk</name>
1111
<url>https://github.com/trendmicro/tm-v1-fs-java-sdk</url>

protos/scan.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ message C2S {
2929
repeated string tags = 9;
3030
bool bulk = 10;
3131
bool spn_feedback = 11;
32+
bool verbose = 12;
3233
}
3334

3435
enum Command {

src/main/java/com/trend/cloudone/amaas/AMaasClient.java

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public AMaasClient(final String region, final String apiKey, final long timeoutI
5353
* @param region region we obtained your api key
5454
* @param apiKey api key to be used
5555
* @param timeoutInSecs number in seconds to wait for a scan. 0 default to 180 seconds.
56-
* @param enabledTLS boolean flag ro enable or disable TLS
56+
* @param enabledTLS boolean flag to enable or disable TLS
5757
* @param appName application name to use.
5858
* @throws AMaasException if an exception is detected, it will convert to AMassException.
5959
*
@@ -266,10 +266,11 @@ static AMaasException getTagListErrors(final String[] tagList) {
266266
* @param tagList List of tags.
267267
* @param pml flag to indicate whether to use predictive machine learning detection.
268268
* @param feedback flag to indicate whether to use Trend Micro Smart Protection Network's Smart Feedback.
269+
* @param verbose flag to enable log verbose mode
269270
* @return String the scanned result in JSON format.
270271
* @throws AMaasException if an exception is detected, it will convert to AMassException.
271272
*/
272-
private String scanRun(final AMaasReader reader, final String[] tagList, final boolean pml, final boolean feedback) throws AMaasException {
273+
private String scanRun(final AMaasReader reader, final String[] tagList, final boolean pml, final boolean feedback, final boolean verbose) throws AMaasException {
273274

274275
long fileSize = reader.getLength();
275276

@@ -282,7 +283,7 @@ private String scanRun(final AMaasReader reader, final String[] tagList, final b
282283
String sha1Str = reader.getHash(AMaasReader.HashType.HASH_SHA1);
283284
String sha256Str = reader.getHash(AMaasReader.HashType.HASH_SHA256);
284285

285-
ScanOuterClass.C2S.Builder builder = ScanOuterClass.C2S.newBuilder().setStage(Stage.STAGE_INIT).setFileName(reader.getIdentifier()).setRsSize(fileSize).setOffset(0).setFileSha1(sha1Str).setFileSha256(sha256Str).setTrendx(pml).setSpnFeedback(feedback).setBulk(this.bulk);
286+
ScanOuterClass.C2S.Builder builder = ScanOuterClass.C2S.newBuilder().setStage(Stage.STAGE_INIT).setFileName(reader.getIdentifier()).setRsSize(fileSize).setOffset(0).setFileSha1(sha1Str).setFileSha256(sha256Str).setTrendx(pml).setSpnFeedback(feedback).setBulk(this.bulk).setVerbose(verbose);
286287
if (tagList != null) {
287288
AMaasException except = getTagListErrors(tagList);
288289
if (except != null) {
@@ -308,22 +309,40 @@ private String scanRun(final AMaasReader reader, final String[] tagList, final b
308309
* @throws AMaasException if an exception is detected, it will convert to AMassException.
309310
*/
310311
public String scanFile(final String fileName) throws AMaasException {
311-
return this.scanFile(fileName, null, false, false);
312+
return this.scanFile(fileName, null, false, false, false);
312313
}
313314

314315
/**
315316
* Scan a file and return the scanned result.
316317
*
318+
* @deprecated
317319
* @param fileName Full path of a file to be scanned.
318320
* @param tagList List of tags.
319321
* @param pml flag to indicate whether to enable predictive machine learning detection.
320322
* @param feedback flag to indicate whether to use Trend Micro Smart Protection Network's Smart Feedback.
321323
* @return String the scanned result in JSON format.
322324
* @throws AMaasException if an exception is detected, it will convert to AMassException.
323325
*/
326+
@Deprecated
324327
public String scanFile(final String fileName, final String[] tagList, final boolean pml, final boolean feedback) throws AMaasException {
325328
AMaasFileReader fileReader = new AMaasFileReader(fileName);
326-
return this.scanRun(fileReader, tagList, pml, feedback);
329+
return this.scanRun(fileReader, tagList, pml, feedback, false);
330+
}
331+
332+
/**
333+
* Scan a file and return the scanned result.
334+
*
335+
* @param fileName Full path of a file to be scanned.
336+
* @param tagList List of tags.
337+
* @param pml flag to indicate whether to enable predictive machine learning detection.
338+
* @param feedback flag to indicate whether to use Trend Micro Smart Protection Network's Smart Feedback.
339+
* @param verbose flag to enable log verbose mode
340+
* @return String the scanned result in JSON format.
341+
* @throws AMaasException if an exception is detected, it will convert to AMassException.
342+
*/
343+
public String scanFile(final String fileName, final String[] tagList, final boolean pml, final boolean feedback, final boolean verbose) throws AMaasException {
344+
AMaasFileReader fileReader = new AMaasFileReader(fileName);
345+
return this.scanRun(fileReader, tagList, pml, feedback, verbose);
327346
}
328347

329348
/**
@@ -335,11 +354,11 @@ public String scanFile(final String fileName, final String[] tagList, final bool
335354
* @throws AMaasException if an exception is detected, it will convert to AMassException.
336355
*/
337356
public String scanBuffer(final byte[] buffer, final String identifier) throws AMaasException {
338-
return this.scanBuffer(buffer, identifier, null, false, false);
357+
return this.scanBuffer(buffer, identifier, null, false, false, false);
339358
}
340359

341360
/**
342-
* Scan a buffer and return the scanned result.
361+
* Scan a buffer and return the scanned result. (TBD: LSK remove this API).
343362
*
344363
* @param buffer the buffer to be scanned.
345364
* @param identifier A unique name to identify the buffer.
@@ -351,6 +370,23 @@ public String scanBuffer(final byte[] buffer, final String identifier) throws AM
351370
*/
352371
public String scanBuffer(final byte[] buffer, final String identifier, final String[] tagList, final boolean pml, final boolean feedback) throws AMaasException {
353372
AMaasBufferReader bufReader = new AMaasBufferReader(buffer, identifier);
354-
return this.scanRun(bufReader, tagList, pml, feedback);
373+
return this.scanRun(bufReader, tagList, pml, feedback, false);
374+
}
375+
376+
/**
377+
* Scan a buffer and return the scanned result.
378+
*
379+
* @param buffer the buffer to be scanned.
380+
* @param identifier A unique name to identify the buffer.
381+
* @param tagList List of tags.
382+
* @param pml flag to indicate whether to use predictive machine learning detection.
383+
* @param feedback flag to indicate whether to use Trend Micro Smart Protection Network's Smart Feedback.
384+
* @param verbose flag to enable log verbose mode
385+
* @return String the scanned result in JSON format.
386+
* @throws AMaasException if an exception is detected, it will convert to AMassException.
387+
*/
388+
public String scanBuffer(final byte[] buffer, final String identifier, final String[] tagList, final boolean pml, final boolean feedback, final boolean verbose) throws AMaasException {
389+
AMaasBufferReader bufReader = new AMaasBufferReader(buffer, identifier);
390+
return this.scanRun(bufReader, tagList, pml, feedback, verbose);
355391
}
356392
}

0 commit comments

Comments
 (0)