Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[THOG-746] - Add decoder type to results. #835

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/detectors/detectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ type Detector interface {
type Result struct {
// DetectorType is the type of Detector.
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 []byte
// RawV2 contains the raw secret identifier that is a combination of both the ID and the secret.
Expand Down
12 changes: 12 additions & 0 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
"github.com/trufflesecurity/trufflehog/v3/pkg/decoders"
"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/sourcespb"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
Expand Down Expand Up @@ -163,6 +164,16 @@ func (e *Engine) detectorWorker(ctx context.Context) {
for chunk := range e.chunks {
fragStart, mdLine := fragmentFirstLine(chunk)
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)
if decoded == nil {
continue
Expand Down Expand Up @@ -201,6 +212,7 @@ func (e *Engine) detectorWorker(ctx context.Context) {
offset := FragmentLineOffset(chunk, &result)
*mdLine = fragStart + offset
}
result.DecoderType = decoderType
e.results <- detectors.CopyMetadata(chunk, result)

}
Expand Down
6 changes: 5 additions & 1 deletion pkg/output/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/sirupsen/logrus"

"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
Expand All @@ -25,7 +26,9 @@ func PrintJSON(r *detectors.ResultWithMetadata) {
DetectorType detectorspb.DetectorType
// DetectorName is the string name of the DetectorType.
DetectorName string
Verified bool
// DecoderName is the string name of the DecoderType.
DecoderName string
Verified bool
// Raw contains the raw secret data.
Raw string
// Redacted contains the redacted version of the raw secret identification data for display purposes.
Expand All @@ -40,6 +43,7 @@ func PrintJSON(r *detectors.ResultWithMetadata) {
SourceName: r.SourceName,
DetectorType: r.DetectorType,
DetectorName: r.DetectorType.String(),
DecoderName: r.DecoderType.String(),
Verified: r.Verified,
Raw: string(r.Raw),
Redacted: r.Redacted,
Expand Down
10 changes: 7 additions & 3 deletions pkg/output/plain.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/fatih/color"
"github.com/sirupsen/logrus"

"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
)
Expand All @@ -20,6 +21,7 @@ var (
func PrintPlainOutput(r *detectors.ResultWithMetadata) {
out := outputFormat{
DetectorType: r.Result.DetectorType.String(),
DecoderType: r.Result.DecoderType.String(),
Verified: r.Result.Verified,
MetaData: r.SourceMetadata,
Raw: strings.TrimSpace(string(r.Result.Raw)),
Expand All @@ -39,6 +41,7 @@ func PrintPlainOutput(r *detectors.ResultWithMetadata) {
whitePrinter.Print("Found unverified result 🐷🔑❓\n")
}
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))
for _, data := range meta {
for k, v := range data {
Expand All @@ -58,8 +61,9 @@ func structToMap(obj interface{}) (m map[string]map[string]interface{}, err erro
}

type outputFormat struct {
DetectorType string
Verified bool
Raw string
DetectorType,
DecoderType string
Verified bool
Raw string
*source_metadatapb.MetaData
}
Loading