Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrav committed Feb 5, 2024
2 parents 54c8a65 + 135cc3e commit 57a2305
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,12 @@ status code, the secret is considered verified.
```yaml
# config.yaml
detectors:
- name: hog detector
- name: HogTokenDetector
keywords:
- hog
regex:
adjective: hogs are (\S+)
hogID: \b(HOG[0-9A-Z]{16})\b
hogToken: [^A-Za-z0-9+\/]{0,1}([A-Za-z0-9+\/]{40})[^A-Za-z0-9+\/]{0,1}
verify:
- endpoint: http://localhost:8000/
# unsafe must be set if the endpoint is HTTP
Expand All @@ -482,16 +483,27 @@ detectors:
- "Authorization: super secret authorization header"
```
```
$ trufflehog filesystem /tmp --config config.yaml --only-verified
🐷🔑🐷 TruffleHog. Unearth your secrets. 🐷🔑🐷

Found verified result 🐷🔑
Detector Type: CustomRegex
Decoder Type: PLAIN
Raw result: hogs are cool
Raw result: HOGAAIUNNWHAHJJWUQYR
File: /tmp/hog-facts.txt
```
Data structure sent to the custom verificaiton server:
```
{
"HogTokenDetector": {
"HogID": ["HOGAAIUNNWHAHJJWUQYR"],
"HogSecret": ["sD9vzqdSsAOxntjAJ/qZ9sw+8PvEYg0r7D1Hhh0C"],
}
}
```

## Verification Server Example (Python)

Expand Down Expand Up @@ -523,8 +535,8 @@ class Verifier(BaseHTTPRequestHandler):
request = json.loads(self.rfile.read(length))
self.log_message("%s", request)

# check the match
if request['hog detector']['adjective'][-1] == 'cool':
# check the match, you'll need to implement validateToken, which takes an array of ID's and Secrets
if not validateTokens(request['HogTokenDetector']['hogID'], request['HogTokenDetector']['hogSecret']):
self.send_response(200)
self.end_headers()
else:
Expand Down
21 changes: 16 additions & 5 deletions pkg/gitparse/gitparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,17 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan ch
)
var latestState = Initial

writer := c.contentWriter()
currentDiff := NewDiff(withCustomContentWriter(writer))
diff := func(opts ...diffOption) *Diff {
opts = append(opts, withCustomContentWriter(newBuffer()))
return NewDiff(opts...)
}
if c.useCustomContentWriter {
diff = func(opts ...diffOption) *Diff {
opts = append(opts, withCustomContentWriter(bufferedfilewriter.New()))
return NewDiff(opts...)
}
}
currentDiff := diff()

defer common.RecoverWithExit(ctx)
defer close(commitChan)
Expand Down Expand Up @@ -436,7 +445,8 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan ch
totalLogSize += currentCommit.Size
}
// Create a new currentDiff and currentCommit
currentDiff = NewDiff(withCustomContentWriter(c.contentWriter()))
currentCommit = &Commit{}
currentDiff = diff()
currentCommit = &Commit{Message: strings.Builder{}}
// Check that the commit line contains a hash and set it.
if len(line) >= 47 {
Expand Down Expand Up @@ -504,7 +514,8 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan ch
currentCommit.Message.WriteString(oldCommit.Message.String())
}
}
currentDiff = NewDiff(withCustomContentWriter(c.contentWriter()))
currentDiff = diff()
// currentDiff = NewDiff(withCustomContentWriter(c.contentWriter()))
case isModeLine(isStaged, latestState, line):
latestState = ModeLine
// NoOp
Expand Down Expand Up @@ -544,7 +555,7 @@ func (c *Parser) FromReader(ctx context.Context, stdOut io.Reader, commitChan ch
}
currentCommit.Diffs = append(currentCommit.Diffs, *currentDiff)
}
currentDiff = NewDiff(withCustomContentWriter(c.contentWriter()), withPathB(currentDiff.PathB))
currentDiff = diff(withPathB(currentDiff.PathB))

words := bytes.Split(line, []byte(" "))
if len(words) >= 3 {
Expand Down

0 comments on commit 57a2305

Please sign in to comment.