diff --git a/CHANGELOG.md b/CHANGELOG.md index a405cb3..dd26571 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 1.1.1 - 2024-04-04 + +* Fix bug in SPN smart feedback +* Add tag flag to example tools + ## 1.1.0 - 2024-04-03 * Update protos diff --git a/README.md b/README.md index 15cd77a..6c6b3ea 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,14 @@ You can enable PML detection by calling the `SetPMLEnable` function: client.SetPMLEnable() ``` +### Enable SPN feedback + +You can enable SPN feedback by calling the `SetFeedbackEnable` function: + +```go +client.SetFeedbackEnable() +``` + ## Usage Examples As examples, you can find two important files in the `tools/` directory of the SDK package: @@ -182,6 +190,12 @@ API key for service authentication if authentication is enabled `-pml` Specify to enable PML (Predictive Machine Learning) detection +`-feedback` +Specify to enable SPN feedback + +`-tag ` +Specify the tags to be used for scanning, separated by commas + ### scanfiles 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 `-pml` Specify to enable PML (Predictive Machine Learning) detection +`-feedback` +Specify to enable SPN feedback + +`-tag ` +Specify the tags to be used for scanning, separated by commas + + ## Proxy Configuration The cli tool loads the proxy configuration from the following set of optional environment variables diff --git a/grpc.go b/grpc.go index c983099..322ff55 100644 --- a/grpc.go +++ b/grpc.go @@ -234,9 +234,10 @@ type AmaasClient struct { appName string archHandler AmaasClientArchiveHandler pml bool + feedback bool } -func scanRun(ctx context.Context, cancel context.CancelFunc, c pb.ScanClient, dataReader AmaasClientReader, disableCache bool, tags []string, pml bool, bulk bool) (string, error) { +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) { defer cancel() @@ -274,7 +275,7 @@ func scanRun(ctx context.Context, cancel context.CancelFunc, c pb.ScanClient, da hashSha1, _ := dataReader.Hash("sha1") - if err = runInitRequest(stream, dataReader.Identifier(), uint64(size), hashSha256, hashSha1, tags, pml, bulk); err != nil { + if err = runInitRequest(stream, dataReader.Identifier(), uint64(size), hashSha256, hashSha1, tags, pml, bulk, feedback); err != nil { return makeFailedScanJSONResp(), err } @@ -290,9 +291,9 @@ func scanRun(ctx context.Context, cancel context.CancelFunc, c pb.ScanClient, da return result, nil } -func runInitRequest(stream pb.Scan_RunClient, identifier string, dataSize uint64, hashSha256 string, hashSha1 string, tags []string, pml bool, bulk bool) error { +func runInitRequest(stream pb.Scan_RunClient, identifier string, dataSize uint64, hashSha256 string, hashSha1 string, tags []string, pml bool, bulk bool, feedback bool) error { if err := stream.Send(&pb.C2S{Stage: pb.Stage_STAGE_INIT, - FileName: identifier, RsSize: dataSize, FileSha256: hashSha256, FileSha1: hashSha1, Tags: tags, Trendx: pml, Bulk: bulk}); err != nil { + FileName: identifier, RsSize: dataSize, FileSha256: hashSha256, FileSha1: hashSha1, Tags: tags, Trendx: pml, Bulk: bulk, SpnFeedback: feedback}); err != nil { err = sanitizeGRPCError(err) logMsg(LogLevelError, MSG("MSG_ID_ERR_INIT"), err) return err @@ -409,7 +410,7 @@ func (ac *AmaasClient) bufferScanRun(buffer []byte, identifier string, tags []st ctx = ac.buildAppNameContext(ctx) - return scanRun(ctx, cancel, pb.NewScanClient(ac.conn), bufferReader, ac.disableCache, tags, ac.pml, true) + return scanRun(ctx, cancel, pb.NewScanClient(ac.conn), bufferReader, ac.disableCache, tags, ac.pml, true, ac.feedback) } func (ac *AmaasClient) fileScanRun(fileName string, tags []string) (string, error) { @@ -439,7 +440,7 @@ func (ac *AmaasClient) fileScanRunNormalFile(fileName string, tags []string) (st ctx = ac.buildAppNameContext(ctx) - return scanRun(ctx, cancel, pb.NewScanClient(ac.conn), fileReader, ac.disableCache, tags, ac.pml, true) + return scanRun(ctx, cancel, pb.NewScanClient(ac.conn), fileReader, ac.disableCache, tags, ac.pml, true, ac.feedback) } func (ac *AmaasClient) setupComm() error { @@ -1001,6 +1002,10 @@ func (ac *AmaasClient) SetPMLEnable() { ac.pml = true } +func (ac *AmaasClient) SetFeedbackEnable() { + ac.feedback = true +} + func validateTags(tags []string) error { if len(tags) == 0 { return errors.New("tags cannot be empty") diff --git a/grpc_run_test.go b/grpc_run_test.go index 8da5864..d01f1cb 100644 --- a/grpc_run_test.go +++ b/grpc_run_test.go @@ -459,7 +459,7 @@ func TestScanRunWithInvalidTags(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(180)) // act - _, err := scanRun(ctx, cancel, nil, nil, false, tt.tags, false, true) + _, err := scanRun(ctx, cancel, nil, nil, false, tt.tags, false, true, false) // assert assert.Equal(t, tt.expectedErr, err.Error()) diff --git a/tools/client/client.go b/tools/client/client.go index d1e192a..aaadc89 100644 --- a/tools/client/client.go +++ b/tools/client/client.go @@ -4,6 +4,7 @@ import ( "flag" "log" "os" + "strings" amaasclient "github.com/trendmicro/tm-v1-fs-golang-sdk" ) @@ -15,6 +16,8 @@ var ( enableTLS = flag.Bool("tls", false, "enable TLS") region = flag.String("region", "", "the region to connect to") pml = flag.Bool("pml", false, "enable predictive machine learning detection") + feedback = flag.Bool("feedback", false, "enable SPN feedback") + tag = flag.String("tag", "", "tags to be used for scanning") ) func main() { @@ -43,7 +46,16 @@ func main() { client.SetPMLEnable() } - result, err := client.ScanFile(*fileName, nil) + if *feedback { + client.SetFeedbackEnable() + } + + var tagsArray []string + if *tag != "" { + tagsArray = strings.Split(*tag, ",") + } + + result, err := client.ScanFile(*fileName, tagsArray) if err != nil { log.Fatalf(err.Error()) } diff --git a/tools/scanfiles/scanfiles.go b/tools/scanfiles/scanfiles.go index f69d62e..ae0d8bd 100644 --- a/tools/scanfiles/scanfiles.go +++ b/tools/scanfiles/scanfiles.go @@ -52,6 +52,8 @@ func main() { var fileList []string var region string var pml bool + var feedback bool + var tag string flag.StringVar(&path, "path", "", "Path of file or directory to scan.") flag.BoolVar(&scanGoodFiles, "good", false, "Specify if scanning good/non-malicious files.") @@ -63,6 +65,8 @@ func main() { flag.BoolVar(&enableTLS, "tls", false, "Specify to enable server authentication by client for GRPC") flag.StringVar(®ion, "region", "", "the region to connect to") flag.BoolVar(&pml, "pml", false, "enable predictive machine learning detection") + flag.BoolVar(&feedback, "feedback", false, "enable SPN feedback") + flag.StringVar(&tag, "tag", "", "tags to be used for scanning") flag.Parse() @@ -98,6 +102,15 @@ func main() { ac.SetPMLEnable() } + if feedback { + ac.SetFeedbackEnable() + } + + var tagsArray []string + if tag != "" { + tagsArray = strings.Split(tag, ",") + } + if fileInfo.IsDir() { files, err := ioutil.ReadDir(path) @@ -125,9 +138,9 @@ func main() { var tr OverallTestResult if scanInParallel { - tr = scanFileListInParallel(fileList, scanGoodFiles, ac) + tr = scanFileListInParallel(fileList, scanGoodFiles, ac, tagsArray) } else { - tr = scanFileListInSequence(fileList, scanGoodFiles, ac) + tr = scanFileListInSequence(fileList, scanGoodFiles, ac, tagsArray) } jsonData, _ := json.Marshal(tr) @@ -138,7 +151,7 @@ func main() { os.Exit(0) } -func scanFileListInSequence(fileList []string, scanGoodFiles bool, scanner *amaasclient.AmaasClient) OverallTestResult { +func scanFileListInSequence(fileList []string, scanGoodFiles bool, scanner *amaasclient.AmaasClient, tags []string) OverallTestResult { var tr OverallTestResult tr.Passed = true @@ -153,7 +166,7 @@ func scanFileListInSequence(fileList []string, scanGoodFiles bool, scanner *amaa sr.StartTime = time.Now() - jsonResult, err := scanner.ScanFile(fileList[i], nil) + jsonResult, err := scanner.ScanFile(fileList[i], tags) if err != nil { log.Print(err.Error()) } @@ -173,7 +186,7 @@ func scanFileListInSequence(fileList []string, scanGoodFiles bool, scanner *amaa return tr } -func scanFileListInParallel(fileList []string, scanGoodFiles bool, scanner *amaasclient.AmaasClient) OverallTestResult { +func scanFileListInParallel(fileList []string, scanGoodFiles bool, scanner *amaasclient.AmaasClient, tags []string) OverallTestResult { var tr OverallTestResult tr.Passed = true @@ -192,7 +205,7 @@ func scanFileListInParallel(fileList []string, scanGoodFiles bool, scanner *amaa sr.StartTime = time.Now() - jsonResult, err := scanner.ScanFile(f, nil) + jsonResult, err := scanner.ScanFile(f, tags) if err != nil { log.Print(err.Error()) }