Skip to content

Commit e3815e8

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

File tree

15 files changed

+184
-83
lines changed

15 files changed

+184
-83
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
11
# CHANGELOG
22

3+
## 1.4.0 - 2024-08-23
4+
5+
* Update README.md
6+
* Support digest calculation bypass
7+
8+
## 1.3.0 - 2024-08-21
9+
10+
* Update README.md
11+
* Support passing host address in an AMaasClient constructor
12+
* Support CA cert import
13+
314
## 1.2.0 - 2024-08-07
15+
416
* Support verbose scan result
517

618
## 1.1.1 - 2024-04-10
19+
720
* Update README.md
821
* Extend the scan default timeout to 300s
922

1023
## 1.1.0 - 2024-04-03
24+
1125
* Update protos
1226
* Enable PML (Predictive Machine Learning) detection and smart feedback
1327
* Enable bulk mode
1428
* Enable India region
1529
* Support for scanning large files (over 2GB)
1630

1731
## 1.0.1 - 2023-11-23
32+
1833
* Update to latest code
1934

2035
## 1.0.0 - 2023-11-21
36+
2137
* Initial release

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,20 @@ When malicious content is detected in the scanned object, `scanResult` will show
154154

155155
The AmaasClient class is the main class of the SDK and provides methods to use the AMaaS scanning services.
156156

157-
#### ```public AMaasClient(final String region, final String apiKey, final long timeoutInSecs, final boolean enabledTLS) throws AMaasException```
157+
#### ```public AMaasClient(final String region, final String host, final String apiKey, final long timeoutInSecs, final boolean enabledTLS, final string caCert) throws AMaasException```
158158

159159
Creates a new instance of the `AmaasClient` class, and provisions essential settings, including authentication/authorization credentials (API key), preferred service region, etc.
160160

161161
**_Parameters_**
162162

163163
| Parameter | Description |
164164
| ------------- | ---------------------------------------------------------------------------------------- |
165-
| region | The region you obtained your api key. Value provided must be one of the Vision One regions, e.g. `us-east-1`, `eu-central-1`, `ap-northeast-1`, `ap-southeast-2`, `ap-southeast-1`, `ap-south-1`, etc. |
165+
| region | The region you obtained your api key. Value provided must be one of the Vision One regions, e.g. `us-east-1`, `eu-central-1`, `ap-northeast-1`, `ap-southeast-2`, `ap-southeast-1`, `ap-south-1`, etc. If host is given, region will be ignored. |
166+
| host | The host ip address of self hosted AMaaS scanner. Ignore if to use Trend AMaaS service |
166167
| apikey | Your own Vision One API Key. |
167168
| timeoutInSecs | Timeout to cancel the connection to server in seconds. Valid value is 0, 1, 2, ... ; default to 300 seconds. |
168169
| enabledTLS | Enable or disable TLS. TLS should always be enabled when connecting to the AMaaS server. For more information, see the 'Ensuring Secure Communication with TLS' |
170+
| caCert | File path of the CA certificate for hosted AMaaS Scanner server. null if using Trend AMaaS service. |
169171

170172
**_Return_**
171173
An AmaasClient instance
@@ -211,6 +213,7 @@ Scan a file for malware, add a list of tags to the scan result and retrieves res
211213
| pml | A flag to indicate whether to enable predictive machine learning detection. |
212214
| feedback | A flag to indicate whether to enable Trend Micro Smart Protection Network's Smart Feedback. |
213215
| verbose | A flag to enable log verbose mode. |
216+
| digest | A flag to enable/disable calculation of digests for cache search and result lookup. |
214217

215218
**_Return_**
216219
String the scanned result in JSON format.
@@ -243,6 +246,7 @@ Scan a buffer for malware, add a list of tags to the scan result, and retrieves
243246
| pml | A flag to indicate whether to enable predictive machine learning detection. |
244247
| feedback | A flag to indicate whether to enable Trend Micro Smart Protection Network's Smart Feedback. |
245248
| verbose | A flag to enable log verbose mode. |
249+
| digest | A flag to enable/disable calculation of digests for cache search and result lookup. |
246250

247251
**_Return_**
248252
String the scanned result in JSON format.

VERSION

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

examples/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ There are 4 examples under the following sub-folders:
4242
-f a file or a directory to be scanned
4343
-k customer Vision One API key
4444
-r region where the Vision One API key was obtained. eg, us-east-1
45+
-a host ip address of self hosted AMaaS scanner. Ignore if to use Trend AMaaS service
4546
-t optional client maximum waiting time in seconds for a scan. 0 or missing will default to 180 seconds.
46-
--taglist a commas separated string of tags. e.g. dev,sdk
47+
--tags a commas separated string of tags. e.g. dev,sdk
4748
--pml enable predictive machine language detection. default to false
4849
--feedback enable Smart Feedback of Trend Micro Smart Protection Network. default to false
4950
-v enable log verbose mode. default to false
51+
--ca_cert File path of the CA certificate for hosted AMaaS Scanner server. ignore if using Trend AMaaS service.
52+
--digest Flag to enable/disable calculation of digests for cache search and result lookup.
5053
```
5154
5255
For example:

examples/filescan/App.java

Lines changed: 32 additions & 12 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, final boolean verbose) {
37+
static void scanFilesInSequential(final AMaasClient client, final String[] fList, final String[] tagList, final boolean pmlFlag, final boolean feedbackFlag, final boolean verbose, final boolean digest) {
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, verbose);
42+
String scanResult = client.scanFile(fileName, tagList, pmlFlag, feedbackFlag, verbose, digest);
4343
long endTS = System.currentTimeMillis();
4444
info("{0}", scanResult);
4545
info("===============> File scan time {0}", endTS - startTS);
@@ -53,12 +53,15 @@ private static Options getCmdOptions() {
5353
Options optionList = new Options();
5454
optionList.addRequiredOption("f", "filename", true, "File path or folder to be scanned");
5555
optionList.addRequiredOption("k", "apikey", true, "Cloud One API key");
56-
optionList.addRequiredOption("r", "region", true, "AMaaS service region");
56+
optionList.addRequiredOption("r", "region", true, "AMaaS service region to used. Ignore if self hosted.");
57+
optionList.addOption("a", "addr", true, "host ip address of self hosted AMaaS scanner. Ignore if to use Trend AMaaS service");
5758
optionList.addOption("t", "timeout", true, "Per scan timeout in seconds");
58-
optionList.addOption(null, "taglist", true, "commas separated string of tags.e.g, sdk,dev");
59+
optionList.addOption(null, "tags", true, "commas separated string of tags.e.g, sdk,dev");
5960
optionList.addOption(null, "pml", true, "Enable predictive machine language detection");
6061
optionList.addOption(null, "feedback", true, "Enable Trend Smart Protection Network's Smart Feedback");
6162
optionList.addOption("v", "verbose", true, "Enable log verbose mode");
63+
optionList.addOption(null, "ca_cert", true, "CA Certificate of hosted AMaaS Scanner server");
64+
optionList.addOption(null, "digest", true, "Enable/Disable calculation of digests for cache search and result lookup");
6265
return optionList;
6366
}
6467

@@ -67,22 +70,28 @@ private static Options getCmdOptions() {
6770
* @param args Input options:
6871
* -f a file or a directory to be scanned
6972
* -k the API key or bearer authentication token
70-
* -r region where the key/token was applied. eg, us-east-1
73+
* -r region where the Vision One API key was obtained. eg, us-east-1. If host is given, region value will be ignored.
74+
* -a host ip address of self hosted AMaaS scanner. Ignore if to use Trend AMaaS service.
7175
* -t optional client maximum waiting time in seconds for a scan. 0 or missing means default.
72-
* --taglist a commas separated string of tags. e.g. dev,sdk
76+
* --tags a commas separated string of tags. e.g. dev,sdk
7377
* --pml enable predictive machine language detection. default to false
7478
* --feedback enable Trend Micro Smart Protection Network's Smart Feedback. default to false
7579
* -v enable log verbose mode. default to false
80+
* --ca_cert CA certificate of self hosted AMaaS server
81+
* --digest Enable/Disable calculation of digests for cache search and result lookup
7682
*/
7783
public static void main(final String[] args) {
7884
String pathname = "";
7985
String apikey = null;
8086
String region = "";
87+
String addr = "";
8188
long timeout = 0;
8289
String tags = null;
8390
boolean pmlFlag = false;
8491
boolean feedbackFlag = false;
8592
boolean verbose = false;
93+
String caCertPath = null;
94+
boolean digest = true;
8695

8796
DefaultParser parser = new DefaultParser();
8897
HelpFormatter helper = new HelpFormatter();
@@ -92,17 +101,20 @@ public static void main(final String[] args) {
92101
if (cmd.hasOption("f")) {
93102
pathname = cmd.getOptionValue("f");
94103
}
95-
if (cmd.hasOption("r")) {
104+
if (cmd.hasOption("k")) {
96105
apikey = cmd.getOptionValue("k");
97106
}
98-
if (cmd.hasOption("k")) {
107+
if (cmd.hasOption("r")) {
99108
region = cmd.getOptionValue("r");
100109
}
110+
if (cmd.hasOption("a")) {
111+
addr = cmd.getOptionValue("a");
112+
}
101113
if (cmd.hasOption("t")) {
102114
timeout = Long.parseLong(cmd.getOptionValue("t"));
103115
}
104-
if (cmd.hasOption("taglist")) {
105-
tags = cmd.getOptionValue("taglist");
116+
if (cmd.hasOption("tags")) {
117+
tags = cmd.getOptionValue("tags");
106118
}
107119
if (cmd.hasOption("pml")) {
108120
if (cmd.getOptionValue("pml").equals("true")) {
@@ -119,17 +131,25 @@ public static void main(final String[] args) {
119131
verbose = true;
120132
}
121133
}
134+
if (cmd.hasOption("ca_cert")) {
135+
caCertPath = cmd.getOptionValue("ca_cert");
136+
}
137+
if (cmd.hasOption("digest")) {
138+
if (cmd.getOptionValue("digest").equals("false")) {
139+
digest = false;
140+
}
141+
}
122142
String[] tagList = null;
123143
if (tags != null) {
124144
info("tags to used {0}", tags);
125145
tagList = tags.split(",");
126146
}
127147

128-
AMaasClient client = new AMaasClient(region, apikey, timeout);
148+
AMaasClient client = new AMaasClient(region, addr, apikey, timeout, true, caCertPath);
129149
String[] listOfFiles = listFiles(pathname);
130150
long totalStartTs = System.currentTimeMillis();
131151

132-
scanFilesInSequential(client, listOfFiles, tagList, pmlFlag, feedbackFlag, verbose);
152+
scanFilesInSequential(client, listOfFiles, tagList, pmlFlag, feedbackFlag, verbose, digest);
133153

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

examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
</dependency>
6262
<dependency>
6363
<groupId>io.grpc</groupId>
64-
<artifactId>grpc-netty-shaded</artifactId>
64+
<artifactId>grpc-netty</artifactId>
6565
<version>1.56.0</version>
6666
</dependency>
6767
<dependency>

pom.xml

Lines changed: 2 additions & 2 deletions
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.2.0</version>
8+
<version>1.4.0</version>
99

1010
<name>file-security-java-sdk</name>
1111
<url>https://github.com/trendmicro/tm-v1-fs-java-sdk</url>
@@ -83,7 +83,7 @@
8383
</dependency>
8484
<dependency>
8585
<groupId>io.grpc</groupId>
86-
<artifactId>grpc-netty-shaded</artifactId>
86+
<artifactId>grpc-netty</artifactId>
8787
<version>1.56.0</version>
8888
</dependency>
8989
<dependency>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ private static String bytesToHex(final byte[] bytes) {
2424
public final String getHash(final HashType htype) {
2525
switch (htype) {
2626
case HASH_SHA1:
27-
return "sha1:" + bytesToHex(this.sha1);
27+
return (this.sha1 == null) ? "" : "sha1:" + bytesToHex(this.sha1);
2828
case HASH_SHA256:
29-
return "sha256:" + bytesToHex(this.sha256);
29+
return (this.sha256 == null) ? "" : "sha256:" + bytesToHex(this.sha256);
3030
default:
31-
return null;
31+
return "";
3232
}
3333
}
3434

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ final class AMaasBufferReader extends AMaasBaseReader {
1212
private String identifier;
1313
private byte[] readerBuf;
1414

15-
AMaasBufferReader(final byte[] byteBuf, final String identifier) throws AMaasException {
15+
AMaasBufferReader(final byte[] byteBuf, final String identifier, final boolean digest) throws AMaasException {
1616
this.readerBuf = byteBuf;
1717
this.identifier = identifier;
18-
try {
19-
MessageDigest md = MessageDigest.getInstance("SHA1");
20-
this.setHash(HashType.HASH_SHA1, md.digest(this.readerBuf));
21-
md = MessageDigest.getInstance("SHA-256");
22-
this.setHash(HashType.HASH_SHA256, md.digest(this.readerBuf));
23-
} catch (NoSuchAlgorithmException err) {
24-
// this exception is not possible as the algorithms are hard coded.
18+
if (digest) {
19+
try {
20+
MessageDigest md = MessageDigest.getInstance("SHA1");
21+
this.setHash(HashType.HASH_SHA1, md.digest(this.readerBuf));
22+
md = MessageDigest.getInstance("SHA-256");
23+
this.setHash(HashType.HASH_SHA256, md.digest(this.readerBuf));
24+
} catch (NoSuchAlgorithmException err) {
25+
// this exception is not possible as the algorithms are hard coded.
26+
}
2527
}
2628
}
2729

0 commit comments

Comments
 (0)