Skip to content

Commit 2620040

Browse files
su-amaas830d953e
authored andcommitted
update to latest version: v1.4.0
1 parent 02a74a2 commit 2620040

File tree

8 files changed

+75
-35
lines changed

8 files changed

+75
-35
lines changed

CHANGELOG.md

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

3+
## 1.4.0 - 2024-08-21
4+
5+
* Update README.md
6+
* Support digest calculation bypass
7+
8+
## 1.3.0 - 2024-08-20
9+
10+
* Update README.md
11+
* Support CA cert import
12+
313
## 1.2.0 - 2024-07-05
414

515
* Support verbose scan result

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ Creates a new instance of the grpc Channel, and provisions essential settings, i
200200
| 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. |
201201
| api_key | Your own Vision One API Key. |
202202
| enable_tls | 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' section. |
203-
| ca_cert | `Optional` CA certificate used to connect to AMaaS server. |
203+
| ca_cert | `Optional` CA certificate used to connect to self hosted AMaaS server. |
204204

205205
**_Return_**
206206
A grpc Channel instance
@@ -216,7 +216,7 @@ Creates a new instance of the grpc aio Channel, and provisions essential setting
216216
| 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. |
217217
| api_key | Your own Vision One API Key. |
218218
| enable_tls | 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' section. |
219-
| ca_cert | `Optional` CA certificate used to connect to AMaaS server. |
219+
| ca_cert | `Optional` CA certificate used to connect to self hosted AMaaS server. |
220220

221221
**_Return_**
222222
A grpc aio Channel instance
@@ -237,6 +237,7 @@ Scan a file for malware and retrieves response data from the API.
237237
| pml | Enable PML (Predictive Machine Learning) Detection. |
238238
| feedback | Enable SPN feedback for Predictive Machine Learning Detection |
239239
| verbose | Enable log verbose mode |
240+
| digest | Calculate digests for cache search and result lookup |
240241

241242
**_Return_**
242243
String the scanned result in JSON format.
@@ -255,6 +256,7 @@ AsyncIO Scan a file for malware and retrieves response data from the API.
255256
| pml | Enable PML (Predictive Machine Learning) Detection. |
256257
| feedback | Enable SPN feedback for Predictive Machine Learning Detection |
257258
| verbose | Enable log verbose mode |
259+
| digest | Calculate digests for cache search and result lookup |
258260

259261
**_Return_**
260262
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

amaas/grpc/__init__.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,19 @@ def quit(handle):
122122

123123

124124
def _scan_data(channel: grpc.Channel, data_reader: BinaryIO, size: int, identifier: str, tags: List[str],
125-
pml: bool, feedback: bool, verbose: bool) -> str:
125+
pml: bool, feedback: bool, verbose: bool, digest: bool) -> str:
126126
_validate_tags(tags)
127127
stub = scan_pb2_grpc.ScanStub(channel)
128128
pipeline = _Pipeline()
129129
stats = {}
130130
result = None
131131
bulk = True
132+
file_sha1 = ""
133+
file_sha256 = ""
134+
135+
if digest:
136+
file_sha1 = "sha1:" + _digest_hex(data_reader, "sha1")
137+
file_sha256 = "sha256:" + _digest_hex(data_reader, "sha256")
132138

133139
try:
134140
metadata = (
@@ -143,8 +149,8 @@ def _scan_data(channel: grpc.Channel, data_reader: BinaryIO, size: int, identifi
143149
chunk=None,
144150
trendx=pml,
145151
tags=tags,
146-
file_sha1="sha1:" + _digest_hex(data_reader, "sha1"),
147-
file_sha256="sha256:" + _digest_hex(data_reader, "sha256"),
152+
file_sha1=file_sha1,
153+
file_sha256=file_sha256,
148154
bulk=bulk,
149155
spn_feedback=feedback,
150156
verbose=verbose)
@@ -182,7 +188,7 @@ def _scan_data(channel: grpc.Channel, data_reader: BinaryIO, size: int, identifi
182188

183189

184190
def scan_file(channel: grpc.Channel, file_name: str, tags: List[str] = None,
185-
pml: bool = False, feedback: bool = False, verbose: bool = False) -> str:
191+
pml: bool = False, feedback: bool = False, verbose: bool = False, digest: bool = True) -> str:
186192
try:
187193
f = open(file_name, "rb")
188194
fid = os.path.basename(file_name)
@@ -194,10 +200,10 @@ def scan_file(channel: grpc.Channel, file_name: str, tags: List[str] = None,
194200
logger.debug("Permission error: " + str(err))
195201
raise AMaasException(AMaasErrorCode.MSG_ID_ERR_FILE_NO_PERMISSION, file_name)
196202

197-
return _scan_data(channel, f, n, fid, tags, pml, feedback, verbose)
203+
return _scan_data(channel, f, n, fid, tags, pml, feedback, verbose, digest)
198204

199205

200206
def scan_buffer(channel: grpc.Channel, bytes_buffer: bytes, uid: str, tags: List[str] = None,
201-
pml: bool = False, feedback: bool = False, verbose: bool = False) -> str:
207+
pml: bool = False, feedback: bool = False, verbose: bool = False, digest: bool = True) -> str:
202208
f = io.BytesIO(bytes_buffer)
203-
return _scan_data(channel, f, len(bytes_buffer), uid, tags, pml, feedback, verbose)
209+
return _scan_data(channel, f, len(bytes_buffer), uid, tags, pml, feedback, verbose, digest)

amaas/grpc/aio/__init__.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ async def quit(handle):
4040

4141

4242
async def _scan_data(channel: grpc.Channel, data_reader: BinaryIO, size: int, identifier: str, tags: List[str],
43-
pml: bool, feedback: bool, verbose: bool) -> str:
43+
pml: bool, feedback: bool, verbose: bool, digest: bool) -> str:
4444
_validate_tags(tags)
4545
stub = scan_pb2_grpc.ScanStub(channel)
4646
stats = {}
4747
result = None
4848
bulk = True
49+
file_sha1 = ""
50+
file_sha256 = ""
51+
52+
if digest:
53+
file_sha1 = "sha1:" + _digest_hex(data_reader, "sha1")
54+
file_sha256 = "sha256:" + _digest_hex(data_reader, "sha256")
4955

5056
try:
5157
metadata = (
@@ -60,8 +66,8 @@ async def _scan_data(channel: grpc.Channel, data_reader: BinaryIO, size: int, id
6066
chunk=None,
6167
tags=tags,
6268
trendx=pml,
63-
file_sha1="sha1:" + _digest_hex(data_reader, "sha1"),
64-
file_sha256="sha256:" + _digest_hex(data_reader, "sha256"),
69+
file_sha1=file_sha1,
70+
file_sha256=file_sha256,
6571
bulk=bulk,
6672
spn_feedback=feedback,
6773
verbose=verbose)
@@ -140,7 +146,7 @@ async def _scan_data(channel: grpc.Channel, data_reader: BinaryIO, size: int, id
140146

141147

142148
async def scan_file(channel: grpc.Channel, file_name: str, tags: List[str] = None,
143-
pml: bool = False, feedback: bool = False, verbose: bool = False) -> str:
149+
pml: bool = False, feedback: bool = False, verbose: bool = False, digest: bool = True) -> str:
144150
try:
145151
f = open(file_name, "rb")
146152
fid = os.path.basename(file_name)
@@ -151,10 +157,10 @@ async def scan_file(channel: grpc.Channel, file_name: str, tags: List[str] = Non
151157
except (PermissionError, IOError) as err:
152158
logger.debug("Permission error: " + str(err))
153159
raise AMaasException(AMaasErrorCode.MSG_ID_ERR_FILE_NO_PERMISSION, file_name)
154-
return await _scan_data(channel, f, n, fid, tags, pml, feedback, verbose)
160+
return await _scan_data(channel, f, n, fid, tags, pml, feedback, verbose, digest)
155161

156162

157163
async def scan_buffer(channel: grpc.Channel, bytes_buffer: bytes, uid: str, tags: List[str] = None,
158-
pml: bool = False, feedback: bool = False, verbose: bool = False) -> str:
164+
pml: bool = False, feedback: bool = False, verbose: bool = False, digest: bool = True) -> str:
159165
f = io.BytesIO(bytes_buffer)
160-
return await _scan_data(channel, f, len(bytes_buffer), uid, tags, pml, feedback, verbose)
166+
return await _scan_data(channel, f, len(bytes_buffer), uid, tags, pml, feedback, verbose, digest)

examples/README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,19 @@ If you plan on using a Trend Vision One region, be sure to pass in region parame
5252

5353
3. Current Python examples support following command line arguments
5454

55-
| Command Line Arguments | Value | Optional |
56-
|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
57-
| --region or -r | 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-southeast-1`, `ap-southeast-2`, `ap-northeast-1`, `ap-south-1` | Yes, either -r or -a |
58-
| --addr or -a | Trend Vision One File Security server, such as: antimalware.__REGION__.cloudone.trendmicro.com:443 | Yes, either -r or -a |
59-
| --api_key | Vision One API Key | No |
60-
| --filename or -f | File to be scanned | No |
61-
| --pml | Predictive Machine Learning | Yes |
62-
| --tags or -t | List of tags | Yes |
63-
| --verbose or -v | Log verbose mode | Yes |
55+
| Command Line Arguments | Value | Optional |
56+
|--------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
57+
| -f FILENAME, --filename FILENAME | File to be scanned | No |
58+
| -a ADDR, --addr ADDR | Trend Vision One File Security server | Yes, either -r or -a |
59+
| -r REGION, --region 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-southeast-1`, `ap-southeast-2`, `ap-northeast-1`, `ap-south-1` | Yes, either -r or -a |
60+
| --api_key API_KEY | Vision One API Key | Yes |
61+
| --tls, --no-tls | Enable or disable TLS | Yes |
62+
| --ca_cert CA_CERT | CA certificate used to connect to self hosted AMaaS | Yes |
63+
| --pml, --no-pml | Predictive Machine Learning | Yes |
64+
| -t TAGS [TAGS ...], --tags TAGS [TAGS ...] | List of tags | Yes |
65+
| --feedback, --no-feedback | Feedback for Predictive Machine Learning detection | Yes |
66+
| -v, --verbose, --no-verbose | Log verbose mode | Yes |
67+
| --digest, --no-digest | Calculate digests for cache search and result lookup | Yes |
6468

6569
4. Run one of the examples.
6670

examples/client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@
1717
parser.add_argument('--api_key', action='store',
1818
help='api key for authentication')
1919
parser.add_argument('--tls', action=argparse.BooleanOptionalAction, default=False,
20-
help='enable TLS gRPC ')
20+
help='enable/disable TLS gRPC ')
2121
parser.add_argument('--ca_cert', action='store',
2222
help='CA certificate')
2323
parser.add_argument('--pml', action=argparse.BooleanOptionalAction, default=False,
24-
help='enable predictive machine learning detection')
24+
help='enable/disable predictive machine learning detection')
2525
parser.add_argument('-t', '--tags', action='store', nargs='+',
2626
help='list of tags')
2727
parser.add_argument('--feedback', action=argparse.BooleanOptionalAction, default=False,
28-
help='enable feedback for predictive machine learning detection')
28+
help='enable/disable feedback for predictive machine learning detection')
2929
parser.add_argument('-v', '--verbose', action=argparse.BooleanOptionalAction, default=False,
30-
help='enable log verbose mode')
30+
help='enable/disable log verbose mode')
31+
parser.add_argument('--digest', action=argparse.BooleanOptionalAction, default=True,
32+
help='enable/disable digest calculation')
3133

3234
args = parser.parse_args()
3335

@@ -39,7 +41,9 @@
3941
s = time.perf_counter()
4042

4143
try:
42-
result = amaas.grpc.scan_file(handle, file_name=args.filename, pml=args.pml, tags=args.tags, feedback=args.feedback, verbose=args.verbose)
44+
result = amaas.grpc.scan_file(
45+
channel=handle, file_name=args.filename, pml=args.pml,
46+
tags=args.tags, feedback=args.feedback, verbose=args.verbose, digest=args.digest)
4347
elapsed = time.perf_counter() - s
4448
print(f"scan executed in {elapsed:0.2f} seconds.")
4549
print(result)

examples/client_aio.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ async def main(args):
1313

1414
tasks = set()
1515
for file_name in args.filename:
16-
task = asyncio.create_task(amaas.grpc.aio.scan_file(handle, file_name=file_name, pml=args.pml, tags=args.tags, feedback=args.feedback))
16+
task = asyncio.create_task(
17+
amaas.grpc.aio.scan_file(
18+
channel=handle, file_name=file_name, pml=args.pml,
19+
tags=args.tags, feedback=args.feedback, verbose=args.verbose, digest=args.digest)
20+
)
1721
tasks.add(task)
1822

1923
s = time.perf_counter()
@@ -41,15 +45,19 @@ async def main(args):
4145
parser.add_argument('--api_key', action='store',
4246
help='api key for authentication')
4347
parser.add_argument('--tls', action=argparse.BooleanOptionalAction, default=False,
44-
help='enable TLS gRPC ')
48+
help='enable/disable TLS gRPC ')
4549
parser.add_argument('--ca_cert', action='store',
4650
help='CA certificate')
4751
parser.add_argument('--pml', action=argparse.BooleanOptionalAction, default=False,
48-
help='enable predictive machine learning detection')
52+
help='enable/disable predictive machine learning detection')
4953
parser.add_argument('-t', '--tags', action='store', nargs='+',
5054
help='list of tags')
5155
parser.add_argument('--feedback', action=argparse.BooleanOptionalAction, default=False,
52-
help='enable feedback for predictive machine learning detection')
56+
help='enable/disable feedback for predictive machine learning detection')
57+
parser.add_argument('-v', '--verbose', action=argparse.BooleanOptionalAction, default=False,
58+
help='enable/disable log verbose mode')
59+
parser.add_argument('--digest', action=argparse.BooleanOptionalAction, default=True,
60+
help='enable/disable digest calculation')
5361

5462
arguments = parser.parse_args()
5563

0 commit comments

Comments
 (0)