mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 07:04:24 +00:00
[chore] - fix import name clashes (#2143)
* fix import name clashes * fix missing var
This commit is contained in:
parent
e7ccfc2f4c
commit
52ffab1034
9 changed files with 44 additions and 44 deletions
|
@ -74,7 +74,7 @@ func main() {
|
||||||
selectedScanners := map[string]detectors.Detector{}
|
selectedScanners := map[string]detectors.Detector{}
|
||||||
allScanners := getAllScanners()
|
allScanners := getAllScanners()
|
||||||
|
|
||||||
decoders := decoders.DefaultDecoders()
|
allDecoders := decoders.DefaultDecoders()
|
||||||
|
|
||||||
input := strings.ToLower(*scanCmdDetector)
|
input := strings.ToLower(*scanCmdDetector)
|
||||||
if input == "all" {
|
if input == "all" {
|
||||||
|
@ -121,7 +121,7 @@ func main() {
|
||||||
|
|
||||||
for chunk := range chunksChan {
|
for chunk := range chunksChan {
|
||||||
for name, scanner := range selectedScanners {
|
for name, scanner := range selectedScanners {
|
||||||
for _, dec := range decoders {
|
for _, dec := range allDecoders {
|
||||||
decoded := dec.FromChunk(&sources.Chunk{Data: chunk.Data})
|
decoded := dec.FromChunk(&sources.Chunk{Data: chunk.Data})
|
||||||
if decoded != nil {
|
if decoded != nil {
|
||||||
foundKeyword := false
|
foundKeyword := false
|
||||||
|
|
6
main.go
6
main.go
|
@ -591,11 +591,11 @@ func printAverageDetectorTime(e *engine.Engine) {
|
||||||
|
|
||||||
// detectorTypeToSet is a helper function to convert a slice of detector IDs into a set.
|
// detectorTypeToSet is a helper function to convert a slice of detector IDs into a set.
|
||||||
func detectorTypeToSet(detectors []config.DetectorID) map[config.DetectorID]struct{} {
|
func detectorTypeToSet(detectors []config.DetectorID) map[config.DetectorID]struct{} {
|
||||||
output := make(map[config.DetectorID]struct{}, len(detectors))
|
out := make(map[config.DetectorID]struct{}, len(detectors))
|
||||||
for _, d := range detectors {
|
for _, d := range detectors {
|
||||||
output[d] = struct{}{}
|
out[d] = struct{}{}
|
||||||
}
|
}
|
||||||
return output
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// getWithDetectorID is a helper function to get a value from a map using a
|
// getWithDetectorID is a helper function to get a value from a map using a
|
||||||
|
|
|
@ -80,8 +80,8 @@ func (f *Filter) ShouldInclude(object string) bool {
|
||||||
// shouldIncludeFromExclude checks for explicitly excluded paths. This should
|
// shouldIncludeFromExclude checks for explicitly excluded paths. This should
|
||||||
// only be called when the include list is empty.
|
// only be called when the include list is empty.
|
||||||
func (f *Filter) shouldIncludeFromExclude(object string) bool {
|
func (f *Filter) shouldIncludeFromExclude(object string) bool {
|
||||||
for _, glob := range f.exclude {
|
for _, g := range f.exclude {
|
||||||
if glob.Match(object) {
|
if g.Match(object) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,8 +91,8 @@ func (f *Filter) shouldIncludeFromExclude(object string) bool {
|
||||||
// shouldIncludeFromInclude checks for explicitly included paths. This should
|
// shouldIncludeFromInclude checks for explicitly included paths. This should
|
||||||
// only be called when the exclude list is empty.
|
// only be called when the exclude list is empty.
|
||||||
func (f *Filter) shouldIncludeFromInclude(object string) bool {
|
func (f *Filter) shouldIncludeFromInclude(object string) bool {
|
||||||
for _, glob := range f.include {
|
for _, g := range f.include {
|
||||||
if glob.Match(object) {
|
if g.Match(object) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,14 +104,14 @@ func (f *Filter) shouldIncludeFromInclude(object string) bool {
|
||||||
func (f *Filter) shouldIncludeFromBoth(object string) (bool, error) {
|
func (f *Filter) shouldIncludeFromBoth(object string) (bool, error) {
|
||||||
// Exclude takes precedence. If we find the object in the exclude list,
|
// Exclude takes precedence. If we find the object in the exclude list,
|
||||||
// we should not match.
|
// we should not match.
|
||||||
for _, glob := range f.exclude {
|
for _, g := range f.exclude {
|
||||||
if glob.Match(object) {
|
if g.Match(object) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we find the object in the include list, we should match.
|
// If we find the object in the include list, we should match.
|
||||||
for _, glob := range f.include {
|
for _, g := range f.include {
|
||||||
if glob.Match(object) {
|
if g.Match(object) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,15 +31,15 @@ func NewYAML(input []byte) (*Config, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Convert the structured YAML into detectors.
|
// Convert the structured YAML into detectors.
|
||||||
var detectors []detectors.Detector
|
var d []detectors.Detector
|
||||||
for _, detectorConfig := range messages.Detectors {
|
for _, detectorConfig := range messages.Detectors {
|
||||||
detector, err := custom_detectors.NewWebhookCustomRegex(detectorConfig)
|
detector, err := custom_detectors.NewWebhookCustomRegex(detectorConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
detectors = append(detectors, detector)
|
d = append(d, detector)
|
||||||
}
|
}
|
||||||
return &Config{
|
return &Config{
|
||||||
Detectors: detectors,
|
Detectors: d,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,15 +66,15 @@ func ParseDetectors(input string) ([]DetectorID, error) {
|
||||||
if item == "" {
|
if item == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
detectors, ok := specialGroups[strings.ToLower(item)]
|
allDetectors, ok := specialGroups[strings.ToLower(item)]
|
||||||
if !ok {
|
if !ok {
|
||||||
var err error
|
var err error
|
||||||
detectors, err = asRange(item)
|
allDetectors, err = asRange(item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, d := range detectors {
|
for _, d := range allDetectors {
|
||||||
if _, ok := seenDetector[d]; ok {
|
if _, ok := seenDetector[d]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,14 +84,14 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
||||||
payload := strings.NewReader(stringPayload)
|
payload := strings.NewReader(stringPayload)
|
||||||
_bodyMD5 := md5.New()
|
_bodyMD5 := md5.New()
|
||||||
_bodyMD5.Write([]byte(stringPayload))
|
_bodyMD5.Write([]byte(stringPayload))
|
||||||
md5 := hex.EncodeToString(_bodyMD5.Sum(nil))
|
hash := hex.EncodeToString(_bodyMD5.Sum(nil))
|
||||||
|
|
||||||
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
|
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"auth_key": {reskeyMatch},
|
"auth_key": {reskeyMatch},
|
||||||
"auth_timestamp": {timestamp},
|
"auth_timestamp": {timestamp},
|
||||||
"auth_version": {auth_version},
|
"auth_version": {auth_version},
|
||||||
"body_md5": {md5},
|
"body_md5": {hash},
|
||||||
}
|
}
|
||||||
|
|
||||||
usecd, _ := url.QueryUnescape(params.Encode())
|
usecd, _ := url.QueryUnescape(params.Encode())
|
||||||
|
@ -99,7 +99,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
||||||
stringToSign := strings.Join([]string{method, path, usecd}, "\n")
|
stringToSign := strings.Join([]string{method, path, usecd}, "\n")
|
||||||
signature := hex.EncodeToString(hmacBytes([]byte(stringToSign), []byte(ressecretMatch)))
|
signature := hex.EncodeToString(hmacBytes([]byte(stringToSign), []byte(ressecretMatch)))
|
||||||
|
|
||||||
md5Str := "https://api-ap1.pusher.com/apps/" + resappMatch + "/events?auth_key=" + reskeyMatch + "&auth_signature=" + signature + "&auth_timestamp=" + timestamp + "&auth_version=1.0&body_md5=" + md5
|
md5Str := "https://api-ap1.pusher.com/apps/" + resappMatch + "/events?auth_key=" + reskeyMatch + "&auth_signature=" + signature + "&auth_timestamp=" + timestamp + "&auth_version=1.0&body_md5=" + hash
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, method, md5Str, payload)
|
req, err := http.NewRequestWithContext(ctx, method, md5Str, payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -181,13 +181,13 @@ func WithVerify(verify bool) Option {
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterDetectors(filterFunc func(detectors.Detector) bool, input []detectors.Detector) []detectors.Detector {
|
func filterDetectors(filterFunc func(detectors.Detector) bool, input []detectors.Detector) []detectors.Detector {
|
||||||
var output []detectors.Detector
|
var out []detectors.Detector
|
||||||
for _, detector := range input {
|
for _, detector := range input {
|
||||||
if filterFunc(detector) {
|
if filterFunc(detector) {
|
||||||
output = append(output, detector)
|
out = append(out, detector)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasFoundResults returns true if any results are found.
|
// HasFoundResults returns true if any results are found.
|
||||||
|
|
|
@ -98,20 +98,20 @@ func (s *Source) Init(aCtx context.Context, name string, jobId sources.JobID, so
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) Validate(ctx context.Context) []error {
|
func (s *Source) Validate(ctx context.Context) []error {
|
||||||
var errors []error
|
var errs []error
|
||||||
visitor := func(c context.Context, defaultRegionClient *s3.S3, roleArn string, buckets []string) {
|
visitor := func(c context.Context, defaultRegionClient *s3.S3, roleArn string, buckets []string) {
|
||||||
roleErrs := s.validateBucketAccess(c, defaultRegionClient, roleArn, buckets)
|
roleErrs := s.validateBucketAccess(c, defaultRegionClient, roleArn, buckets)
|
||||||
if len(roleErrs) > 0 {
|
if len(roleErrs) > 0 {
|
||||||
errors = append(errors, roleErrs...)
|
errs = append(errs, roleErrs...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := s.visitRoles(ctx, visitor)
|
err := s.visitRoles(ctx, visitor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors = append(errors, err)
|
errs = append(errs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
// setMaxObjectSize sets the maximum size of objects that will be scanned. If
|
// setMaxObjectSize sets the maximum size of objects that will be scanned. If
|
||||||
|
@ -421,16 +421,16 @@ func (s *Source) pageChunker(ctx context.Context, client *s3.S3, chunksChan chan
|
||||||
func (s *Source) validateBucketAccess(ctx context.Context, client *s3.S3, roleArn string, buckets []string) []error {
|
func (s *Source) validateBucketAccess(ctx context.Context, client *s3.S3, roleArn string, buckets []string) []error {
|
||||||
shouldHaveAccessToAllBuckets := roleArn == ""
|
shouldHaveAccessToAllBuckets := roleArn == ""
|
||||||
wasAbleToListAnyBucket := false
|
wasAbleToListAnyBucket := false
|
||||||
var errors []error
|
var errs []error
|
||||||
|
|
||||||
for _, bucket := range buckets {
|
for _, bucket := range buckets {
|
||||||
if common.IsDone(ctx) {
|
if common.IsDone(ctx) {
|
||||||
return append(errors, ctx.Err())
|
return append(errs, ctx.Err())
|
||||||
}
|
}
|
||||||
|
|
||||||
regionalClient, err := s.getRegionalClientForBucket(ctx, client, roleArn, bucket)
|
regionalClient, err := s.getRegionalClientForBucket(ctx, client, roleArn, bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors = append(errors, fmt.Errorf("could not get regional client for bucket %q: %w", bucket, err))
|
errs = append(errs, fmt.Errorf("could not get regional client for bucket %q: %w", bucket, err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,19 +439,19 @@ func (s *Source) validateBucketAccess(ctx context.Context, client *s3.S3, roleAr
|
||||||
if err == nil {
|
if err == nil {
|
||||||
wasAbleToListAnyBucket = true
|
wasAbleToListAnyBucket = true
|
||||||
} else if shouldHaveAccessToAllBuckets {
|
} else if shouldHaveAccessToAllBuckets {
|
||||||
errors = append(errors, fmt.Errorf("could not list objects in bucket %q: %w", bucket, err))
|
errs = append(errs, fmt.Errorf("could not list objects in bucket %q: %w", bucket, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !wasAbleToListAnyBucket {
|
if !wasAbleToListAnyBucket {
|
||||||
if roleArn == "" {
|
if roleArn == "" {
|
||||||
errors = append(errors, fmt.Errorf("could not list objects in any bucket"))
|
errs = append(errs, fmt.Errorf("could not list objects in any bucket"))
|
||||||
} else {
|
} else {
|
||||||
errors = append(errors, fmt.Errorf("role %q could not list objects in any bucket", roleArn))
|
errs = append(errs, fmt.Errorf("role %q could not list objects in any bucket", roleArn))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) visitRoles(ctx context.Context, f func(c context.Context, defaultRegionClient *s3.S3, roleArn string, buckets []string)) error {
|
func (s *Source) visitRoles(ctx context.Context, f func(c context.Context, defaultRegionClient *s3.S3, roleArn string, buckets []string)) error {
|
||||||
|
|
|
@ -65,14 +65,14 @@ func NewSyslog(sourceType sourcespb.SourceType, jobID sources.JobID, sourceID so
|
||||||
|
|
||||||
// Validate validates the configuration of the source.
|
// Validate validates the configuration of the source.
|
||||||
func (s *Source) Validate(ctx context.Context) []error {
|
func (s *Source) Validate(ctx context.Context) []error {
|
||||||
var errors []error
|
var errs []error
|
||||||
|
|
||||||
if s.conn.TlsCert != nilString || s.conn.TlsKey != nilString {
|
if s.conn.TlsCert != nilString || s.conn.TlsKey != nilString {
|
||||||
if s.conn.TlsCert == nilString || s.conn.TlsKey == nilString {
|
if s.conn.TlsCert == nilString || s.conn.TlsKey == nilString {
|
||||||
errors = append(errors, fmt.Errorf("tls cert and key must both be set"))
|
errs = append(errs, fmt.Errorf("tls cert and key must both be set"))
|
||||||
}
|
}
|
||||||
if _, err := tls.LoadX509KeyPair(s.conn.TlsCert, s.conn.TlsKey); err != nil {
|
if _, err := tls.LoadX509KeyPair(s.conn.TlsCert, s.conn.TlsKey); err != nil {
|
||||||
errors = append(errors, fmt.Errorf("error loading tls cert and key: %s", err))
|
errs = append(errs, fmt.Errorf("error loading tls cert and key: %s", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,24 +81,24 @@ func (s *Source) Validate(ctx context.Context) []error {
|
||||||
case "tcp":
|
case "tcp":
|
||||||
srv, err := net.Listen(s.conn.Protocol, s.conn.ListenAddress)
|
srv, err := net.Listen(s.conn.Protocol, s.conn.ListenAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors = append(errors, fmt.Errorf("error listening on tcp socket: %s", err))
|
errs = append(errs, fmt.Errorf("error listening on tcp socket: %s", err))
|
||||||
}
|
}
|
||||||
srv.Close()
|
srv.Close()
|
||||||
case "udp":
|
case "udp":
|
||||||
srv, err := net.ListenPacket(s.conn.Protocol, s.conn.ListenAddress)
|
srv, err := net.ListenPacket(s.conn.Protocol, s.conn.ListenAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors = append(errors, fmt.Errorf("error listening on udp socket: %s", err))
|
errs = append(errs, fmt.Errorf("error listening on udp socket: %s", err))
|
||||||
}
|
}
|
||||||
srv.Close()
|
srv.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if s.conn.Protocol != "tcp" && s.conn.Protocol != "udp" {
|
if s.conn.Protocol != "tcp" && s.conn.Protocol != "udp" {
|
||||||
errors = append(errors, fmt.Errorf("protocol must be 'tcp' or 'udp', got: %s", s.conn.Protocol))
|
errs = append(errs, fmt.Errorf("protocol must be 'tcp' or 'udp', got: %s", s.conn.Protocol))
|
||||||
}
|
}
|
||||||
if s.conn.Format != "rfc5424" && s.conn.Format != "rfc3164" {
|
if s.conn.Format != "rfc5424" && s.conn.Format != "rfc3164" {
|
||||||
errors = append(errors, fmt.Errorf("format must be 'rfc5424' or 'rfc3164', got: %s", s.conn.Format))
|
errs = append(errs, fmt.Errorf("format must be 'rfc5424' or 'rfc3164', got: %s", s.conn.Format))
|
||||||
}
|
}
|
||||||
return errors
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure the Source satisfies the interface at compile time.
|
// Ensure the Source satisfies the interface at compile time.
|
||||||
|
|
Loading…
Reference in a new issue