Skip to content

Commit d1f0e6a

Browse files
authored
Merge pull request #9 from trendmicro/update_to_latest_version_v1.1.1
update to latest version: v1.1.1
2 parents bd3544c + bb58192 commit d1f0e6a

File tree

6 files changed

+70
-14
lines changed

6 files changed

+70
-14
lines changed

CHANGELOG.md

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

3+
## 1.1.1 - 2024-04-04
4+
5+
* Fix bug in SPN smart feedback
6+
* Add tag flag to example tools
7+
38
## 1.1.0 - 2024-04-03
49

510
* Update protos

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ You can enable PML detection by calling the `SetPMLEnable` function:
136136
client.SetPMLEnable()
137137
```
138138

139+
### Enable SPN feedback
140+
141+
You can enable SPN feedback by calling the `SetFeedbackEnable` function:
142+
143+
```go
144+
client.SetFeedbackEnable()
145+
```
146+
139147
## Usage Examples
140148
As examples, you can find two important files in the `tools/` directory of the SDK package:
141149

@@ -182,6 +190,12 @@ API key for service authentication if authentication is enabled
182190
`-pml`
183191
Specify to enable PML (Predictive Machine Learning) detection
184192

193+
`-feedback`
194+
Specify to enable SPN feedback
195+
196+
`-tag <string>`
197+
Specify the tags to be used for scanning, separated by commas
198+
185199
### scanfiles
186200

187201
This is another program that uses the gRPC client library to communicate with our server. Depending on whether or not the `-good` flag is specified, and the scan result returned from the scan, the program will output result that shows the testing was successful or not.
@@ -214,6 +228,13 @@ API key for service authentication if authentication is enabled
214228
`-pml`
215229
Specify to enable PML (Predictive Machine Learning) detection
216230

231+
`-feedback`
232+
Specify to enable SPN feedback
233+
234+
`-tag <string>`
235+
Specify the tags to be used for scanning, separated by commas
236+
237+
217238
## Proxy Configuration
218239

219240
The cli tool loads the proxy configuration from the following set of optional environment variables

grpc.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ type AmaasClient struct {
234234
appName string
235235
archHandler AmaasClientArchiveHandler
236236
pml bool
237+
feedback bool
237238
}
238239

239-
func scanRun(ctx context.Context, cancel context.CancelFunc, c pb.ScanClient, dataReader AmaasClientReader, disableCache bool, tags []string, pml bool, bulk bool) (string, error) {
240+
func scanRun(ctx context.Context, cancel context.CancelFunc, c pb.ScanClient, dataReader AmaasClientReader, disableCache bool, tags []string, pml bool, bulk bool, feedback bool) (string, error) {
240241

241242
defer cancel()
242243

@@ -274,7 +275,7 @@ func scanRun(ctx context.Context, cancel context.CancelFunc, c pb.ScanClient, da
274275

275276
hashSha1, _ := dataReader.Hash("sha1")
276277

277-
if err = runInitRequest(stream, dataReader.Identifier(), uint64(size), hashSha256, hashSha1, tags, pml, bulk); err != nil {
278+
if err = runInitRequest(stream, dataReader.Identifier(), uint64(size), hashSha256, hashSha1, tags, pml, bulk, feedback); err != nil {
278279
return makeFailedScanJSONResp(), err
279280
}
280281

@@ -290,9 +291,9 @@ func scanRun(ctx context.Context, cancel context.CancelFunc, c pb.ScanClient, da
290291
return result, nil
291292
}
292293

293-
func runInitRequest(stream pb.Scan_RunClient, identifier string, dataSize uint64, hashSha256 string, hashSha1 string, tags []string, pml bool, bulk bool) error {
294+
func runInitRequest(stream pb.Scan_RunClient, identifier string, dataSize uint64, hashSha256 string, hashSha1 string, tags []string, pml bool, bulk bool, feedback bool) error {
294295
if err := stream.Send(&pb.C2S{Stage: pb.Stage_STAGE_INIT,
295-
FileName: identifier, RsSize: dataSize, FileSha256: hashSha256, FileSha1: hashSha1, Tags: tags, Trendx: pml, Bulk: bulk}); err != nil {
296+
FileName: identifier, RsSize: dataSize, FileSha256: hashSha256, FileSha1: hashSha1, Tags: tags, Trendx: pml, Bulk: bulk, SpnFeedback: feedback}); err != nil {
296297
err = sanitizeGRPCError(err)
297298
logMsg(LogLevelError, MSG("MSG_ID_ERR_INIT"), err)
298299
return err
@@ -409,7 +410,7 @@ func (ac *AmaasClient) bufferScanRun(buffer []byte, identifier string, tags []st
409410

410411
ctx = ac.buildAppNameContext(ctx)
411412

412-
return scanRun(ctx, cancel, pb.NewScanClient(ac.conn), bufferReader, ac.disableCache, tags, ac.pml, true)
413+
return scanRun(ctx, cancel, pb.NewScanClient(ac.conn), bufferReader, ac.disableCache, tags, ac.pml, true, ac.feedback)
413414
}
414415

415416
func (ac *AmaasClient) fileScanRun(fileName string, tags []string) (string, error) {
@@ -439,7 +440,7 @@ func (ac *AmaasClient) fileScanRunNormalFile(fileName string, tags []string) (st
439440

440441
ctx = ac.buildAppNameContext(ctx)
441442

442-
return scanRun(ctx, cancel, pb.NewScanClient(ac.conn), fileReader, ac.disableCache, tags, ac.pml, true)
443+
return scanRun(ctx, cancel, pb.NewScanClient(ac.conn), fileReader, ac.disableCache, tags, ac.pml, true, ac.feedback)
443444
}
444445

445446
func (ac *AmaasClient) setupComm() error {
@@ -1001,6 +1002,10 @@ func (ac *AmaasClient) SetPMLEnable() {
10011002
ac.pml = true
10021003
}
10031004

1005+
func (ac *AmaasClient) SetFeedbackEnable() {
1006+
ac.feedback = true
1007+
}
1008+
10041009
func validateTags(tags []string) error {
10051010
if len(tags) == 0 {
10061011
return errors.New("tags cannot be empty")

grpc_run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ func TestScanRunWithInvalidTags(t *testing.T) {
459459
ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(180))
460460

461461
// act
462-
_, err := scanRun(ctx, cancel, nil, nil, false, tt.tags, false, true)
462+
_, err := scanRun(ctx, cancel, nil, nil, false, tt.tags, false, true, false)
463463

464464
// assert
465465
assert.Equal(t, tt.expectedErr, err.Error())

tools/client/client.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"log"
66
"os"
7+
"strings"
78

89
amaasclient "github.com/trendmicro/tm-v1-fs-golang-sdk"
910
)
@@ -15,6 +16,8 @@ var (
1516
enableTLS = flag.Bool("tls", false, "enable TLS")
1617
region = flag.String("region", "", "the region to connect to")
1718
pml = flag.Bool("pml", false, "enable predictive machine learning detection")
19+
feedback = flag.Bool("feedback", false, "enable SPN feedback")
20+
tag = flag.String("tag", "", "tags to be used for scanning")
1821
)
1922

2023
func main() {
@@ -43,7 +46,16 @@ func main() {
4346
client.SetPMLEnable()
4447
}
4548

46-
result, err := client.ScanFile(*fileName, nil)
49+
if *feedback {
50+
client.SetFeedbackEnable()
51+
}
52+
53+
var tagsArray []string
54+
if *tag != "" {
55+
tagsArray = strings.Split(*tag, ",")
56+
}
57+
58+
result, err := client.ScanFile(*fileName, tagsArray)
4759
if err != nil {
4860
log.Fatalf(err.Error())
4961
}

tools/scanfiles/scanfiles.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func main() {
5252
var fileList []string
5353
var region string
5454
var pml bool
55+
var feedback bool
56+
var tag string
5557

5658
flag.StringVar(&path, "path", "", "Path of file or directory to scan.")
5759
flag.BoolVar(&scanGoodFiles, "good", false, "Specify if scanning good/non-malicious files.")
@@ -63,6 +65,8 @@ func main() {
6365
flag.BoolVar(&enableTLS, "tls", false, "Specify to enable server authentication by client for GRPC")
6466
flag.StringVar(&region, "region", "", "the region to connect to")
6567
flag.BoolVar(&pml, "pml", false, "enable predictive machine learning detection")
68+
flag.BoolVar(&feedback, "feedback", false, "enable SPN feedback")
69+
flag.StringVar(&tag, "tag", "", "tags to be used for scanning")
6670

6771
flag.Parse()
6872

@@ -98,6 +102,15 @@ func main() {
98102
ac.SetPMLEnable()
99103
}
100104

105+
if feedback {
106+
ac.SetFeedbackEnable()
107+
}
108+
109+
var tagsArray []string
110+
if tag != "" {
111+
tagsArray = strings.Split(tag, ",")
112+
}
113+
101114
if fileInfo.IsDir() {
102115

103116
files, err := ioutil.ReadDir(path)
@@ -125,9 +138,9 @@ func main() {
125138

126139
var tr OverallTestResult
127140
if scanInParallel {
128-
tr = scanFileListInParallel(fileList, scanGoodFiles, ac)
141+
tr = scanFileListInParallel(fileList, scanGoodFiles, ac, tagsArray)
129142
} else {
130-
tr = scanFileListInSequence(fileList, scanGoodFiles, ac)
143+
tr = scanFileListInSequence(fileList, scanGoodFiles, ac, tagsArray)
131144
}
132145

133146
jsonData, _ := json.Marshal(tr)
@@ -138,7 +151,7 @@ func main() {
138151
os.Exit(0)
139152
}
140153

141-
func scanFileListInSequence(fileList []string, scanGoodFiles bool, scanner *amaasclient.AmaasClient) OverallTestResult {
154+
func scanFileListInSequence(fileList []string, scanGoodFiles bool, scanner *amaasclient.AmaasClient, tags []string) OverallTestResult {
142155

143156
var tr OverallTestResult
144157
tr.Passed = true
@@ -153,7 +166,7 @@ func scanFileListInSequence(fileList []string, scanGoodFiles bool, scanner *amaa
153166

154167
sr.StartTime = time.Now()
155168

156-
jsonResult, err := scanner.ScanFile(fileList[i], nil)
169+
jsonResult, err := scanner.ScanFile(fileList[i], tags)
157170
if err != nil {
158171
log.Print(err.Error())
159172
}
@@ -173,7 +186,7 @@ func scanFileListInSequence(fileList []string, scanGoodFiles bool, scanner *amaa
173186
return tr
174187
}
175188

176-
func scanFileListInParallel(fileList []string, scanGoodFiles bool, scanner *amaasclient.AmaasClient) OverallTestResult {
189+
func scanFileListInParallel(fileList []string, scanGoodFiles bool, scanner *amaasclient.AmaasClient, tags []string) OverallTestResult {
177190

178191
var tr OverallTestResult
179192
tr.Passed = true
@@ -192,7 +205,7 @@ func scanFileListInParallel(fileList []string, scanGoodFiles bool, scanner *amaa
192205

193206
sr.StartTime = time.Now()
194207

195-
jsonResult, err := scanner.ScanFile(f, nil)
208+
jsonResult, err := scanner.ScanFile(f, tags)
196209
if err != nil {
197210
log.Print(err.Error())
198211
}

0 commit comments

Comments
 (0)