Add decoder type to results. (#835)
This commit is contained in:
@@ -26,7 +26,9 @@ type Detector interface {
|
|||||||
type Result struct {
|
type Result struct {
|
||||||
// DetectorType is the type of Detector.
|
// DetectorType is the type of Detector.
|
||||||
DetectorType detectorspb.DetectorType
|
DetectorType detectorspb.DetectorType
|
||||||
Verified bool
|
// DecoderType is the type of Decoder.
|
||||||
|
DecoderType detectorspb.DecoderType
|
||||||
|
Verified bool
|
||||||
// Raw contains the raw secret identifier data. Prefer IDs over secrets since it is used for deduping after hashing.
|
// Raw contains the raw secret identifier data. Prefer IDs over secrets since it is used for deduping after hashing.
|
||||||
Raw []byte
|
Raw []byte
|
||||||
// RawV2 contains the raw secret identifier that is a combination of both the ID and the secret.
|
// RawV2 contains the raw secret identifier that is a combination of both the ID and the secret.
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
|
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
|
||||||
"github.com/trufflesecurity/trufflehog/v3/pkg/decoders"
|
"github.com/trufflesecurity/trufflehog/v3/pkg/decoders"
|
||||||
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
|
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
|
||||||
|
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
|
||||||
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
|
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
|
||||||
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
|
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
|
||||||
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
|
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
|
||||||
@@ -163,6 +164,16 @@ func (e *Engine) detectorWorker(ctx context.Context) {
|
|||||||
for chunk := range e.chunks {
|
for chunk := range e.chunks {
|
||||||
fragStart, mdLine := fragmentFirstLine(chunk)
|
fragStart, mdLine := fragmentFirstLine(chunk)
|
||||||
for _, decoder := range e.decoders {
|
for _, decoder := range e.decoders {
|
||||||
|
var decoderType detectorspb.DecoderType
|
||||||
|
switch decoder.(type) {
|
||||||
|
case *decoders.Plain:
|
||||||
|
decoderType = detectorspb.DecoderType_PLAIN
|
||||||
|
case *decoders.Base64:
|
||||||
|
decoderType = detectorspb.DecoderType_BASE64
|
||||||
|
default:
|
||||||
|
logrus.Warnf("unknown decoder type: %T", decoder)
|
||||||
|
decoderType = detectorspb.DecoderType_UNKNOWN
|
||||||
|
}
|
||||||
decoded := decoder.FromChunk(chunk)
|
decoded := decoder.FromChunk(chunk)
|
||||||
if decoded == nil {
|
if decoded == nil {
|
||||||
continue
|
continue
|
||||||
@@ -201,6 +212,7 @@ func (e *Engine) detectorWorker(ctx context.Context) {
|
|||||||
offset := FragmentLineOffset(chunk, &result)
|
offset := FragmentLineOffset(chunk, &result)
|
||||||
*mdLine = fragStart + offset
|
*mdLine = fragStart + offset
|
||||||
}
|
}
|
||||||
|
result.DecoderType = decoderType
|
||||||
e.results <- detectors.CopyMetadata(chunk, result)
|
e.results <- detectors.CopyMetadata(chunk, result)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
|
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
|
||||||
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
|
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
|
||||||
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
|
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
|
||||||
@@ -25,7 +26,9 @@ func PrintJSON(r *detectors.ResultWithMetadata) {
|
|||||||
DetectorType detectorspb.DetectorType
|
DetectorType detectorspb.DetectorType
|
||||||
// DetectorName is the string name of the DetectorType.
|
// DetectorName is the string name of the DetectorType.
|
||||||
DetectorName string
|
DetectorName string
|
||||||
Verified bool
|
// DecoderName is the string name of the DecoderType.
|
||||||
|
DecoderName string
|
||||||
|
Verified bool
|
||||||
// Raw contains the raw secret data.
|
// Raw contains the raw secret data.
|
||||||
Raw string
|
Raw string
|
||||||
// Redacted contains the redacted version of the raw secret identification data for display purposes.
|
// Redacted contains the redacted version of the raw secret identification data for display purposes.
|
||||||
@@ -40,6 +43,7 @@ func PrintJSON(r *detectors.ResultWithMetadata) {
|
|||||||
SourceName: r.SourceName,
|
SourceName: r.SourceName,
|
||||||
DetectorType: r.DetectorType,
|
DetectorType: r.DetectorType,
|
||||||
DetectorName: r.DetectorType.String(),
|
DetectorName: r.DetectorType.String(),
|
||||||
|
DecoderName: r.DecoderType.String(),
|
||||||
Verified: r.Verified,
|
Verified: r.Verified,
|
||||||
Raw: string(r.Raw),
|
Raw: string(r.Raw),
|
||||||
Redacted: r.Redacted,
|
Redacted: r.Redacted,
|
||||||
|
|||||||
+7
-3
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
|
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
|
||||||
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
|
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
|
||||||
)
|
)
|
||||||
@@ -20,6 +21,7 @@ var (
|
|||||||
func PrintPlainOutput(r *detectors.ResultWithMetadata) {
|
func PrintPlainOutput(r *detectors.ResultWithMetadata) {
|
||||||
out := outputFormat{
|
out := outputFormat{
|
||||||
DetectorType: r.Result.DetectorType.String(),
|
DetectorType: r.Result.DetectorType.String(),
|
||||||
|
DecoderType: r.Result.DecoderType.String(),
|
||||||
Verified: r.Result.Verified,
|
Verified: r.Result.Verified,
|
||||||
MetaData: r.SourceMetadata,
|
MetaData: r.SourceMetadata,
|
||||||
Raw: strings.TrimSpace(string(r.Result.Raw)),
|
Raw: strings.TrimSpace(string(r.Result.Raw)),
|
||||||
@@ -39,6 +41,7 @@ func PrintPlainOutput(r *detectors.ResultWithMetadata) {
|
|||||||
whitePrinter.Print("Found unverified result 🐷🔑❓\n")
|
whitePrinter.Print("Found unverified result 🐷🔑❓\n")
|
||||||
}
|
}
|
||||||
printer.Printf("Detector Type: %s\n", out.DetectorType)
|
printer.Printf("Detector Type: %s\n", out.DetectorType)
|
||||||
|
printer.Printf("Decoder Type: %s\n", out.DecoderType)
|
||||||
printer.Printf("Raw result: %s\n", whitePrinter.Sprint(out.Raw))
|
printer.Printf("Raw result: %s\n", whitePrinter.Sprint(out.Raw))
|
||||||
for _, data := range meta {
|
for _, data := range meta {
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
@@ -58,8 +61,9 @@ func structToMap(obj interface{}) (m map[string]map[string]interface{}, err erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
type outputFormat struct {
|
type outputFormat struct {
|
||||||
DetectorType string
|
DetectorType,
|
||||||
Verified bool
|
DecoderType string
|
||||||
Raw string
|
Verified bool
|
||||||
|
Raw string
|
||||||
*source_metadatapb.MetaData
|
*source_metadatapb.MetaData
|
||||||
}
|
}
|
||||||
|
|||||||
+1021
-955
File diff suppressed because it is too large
Load Diff
@@ -97,6 +97,8 @@ func (m *Result) validate(all bool) error {
|
|||||||
|
|
||||||
// no validation rules for HashV2
|
// no validation rules for HashV2
|
||||||
|
|
||||||
|
// no validation rules for Decoder
|
||||||
|
|
||||||
if len(errors) > 0 {
|
if len(errors) > 0 {
|
||||||
return ResultMultiError(errors)
|
return ResultMultiError(errors)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user