-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add syslog source * only load cert/key with tls * Cleanup * Linting Co-authored-by: Bill Rich <bill.rich@trufflesec.com>
- Loading branch information
Showing
12 changed files
with
1,048 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package engine | ||
|
||
import ( | ||
"context" | ||
"github.com/go-errors/errors" | ||
"github.com/sirupsen/logrus" | ||
"google.golang.org/protobuf/proto" | ||
"google.golang.org/protobuf/types/known/anypb" | ||
"os" | ||
|
||
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb" | ||
"github.com/trufflesecurity/trufflehog/v3/pkg/sources/syslog" | ||
) | ||
|
||
func (e *Engine) ScanSyslog(ctx context.Context, address, protocol, certPath, keyPath, format string, concurrency int) error { | ||
connection := &sourcespb.Syslog{ | ||
Protocol: protocol, | ||
ListenAddress: address, | ||
Format: format, | ||
} | ||
|
||
if certPath != "" && keyPath != "" { | ||
cert, err := os.ReadFile(certPath) | ||
if err != nil { | ||
return errors.WrapPrefix(err, "could not open TLS cert file", 0) | ||
} | ||
connection.TlsCert = string(cert) | ||
|
||
key, err := os.ReadFile(keyPath) | ||
if err != nil { | ||
return errors.WrapPrefix(err, "could not open TLS key file", 0) | ||
} | ||
connection.TlsKey = string(key) | ||
} | ||
|
||
var conn anypb.Any | ||
err := anypb.MarshalFrom(&conn, connection, proto.MarshalOptions{}) | ||
if err != nil { | ||
return errors.WrapPrefix(err, "error unmarshalling connection", 0) | ||
} | ||
source := syslog.Source{} | ||
err = source.Init(ctx, "trufflehog - syslog", 0, 0, false, &conn, concurrency) | ||
source.InjectConnection(connection) | ||
if err != nil { | ||
logrus.WithError(err).Error("failed to initialize syslog source") | ||
return err | ||
} | ||
|
||
go func() { | ||
err := source.Chunks(ctx, e.ChunksChan()) | ||
if err != nil { | ||
logrus.WithError(err).Fatal("could not scan syslog") | ||
} | ||
close(e.ChunksChan()) | ||
}() | ||
return nil | ||
} |
Oops, something went wrong.