main.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "fmt"
  4. _ "fmt"
  5. "go.uber.org/zap"
  6. _ "io/ioutil"
  7. "os"
  8. "regexp"
  9. _ "time"
  10. )
  11. const EXIT_CLEAN = 0
  12. const EXIT_FAILURE = 1
  13. const EXIT_LEAKS = 2
  14. // package globals
  15. var (
  16. regexes map[string]*regexp.Regexp
  17. stopWords []string
  18. base64Chars string
  19. hexChars string
  20. assignRegex *regexp.Regexp
  21. fileDiffRegex *regexp.Regexp
  22. logger *zap.Logger
  23. opts *Options
  24. )
  25. func init() {
  26. base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
  27. hexChars = "1234567890abcdefABCDEF"
  28. stopWords = []string{"setting", "info", "env", "environment"}
  29. fileDiffRegex = regexp.MustCompile("diff --git a.+b/")
  30. assignRegex = regexp.MustCompile(`(=|:|:=|<-)`)
  31. // TODO Externalize regex... this is tricky making it yml compliant
  32. regexes = map[string]*regexp.Regexp{
  33. "PKCS8": regexp.MustCompile("-----BEGIN PRIVATE KEY-----"),
  34. "RSA": regexp.MustCompile("-----BEGIN RSA PRIVATE KEY-----"),
  35. "SSH": regexp.MustCompile("-----BEGIN OPENSSH PRIVATE KEY-----"),
  36. "Facebook": regexp.MustCompile("(?i)facebook.*['|\"][0-9a-f]{32}['|\"]"),
  37. "Twitter": regexp.MustCompile("(?i)twitter.*['|\"][0-9a-zA-Z]{35,44}['|\"]"),
  38. "Github": regexp.MustCompile("(?i)github.*[['|\"]0-9a-zA-Z]{35,40}['|\"]"),
  39. "AWS": regexp.MustCompile("AKIA[0-9A-Z]{16}"),
  40. "Reddit": regexp.MustCompile("(?i)reddit.*['|\"][0-9a-zA-Z]{14}['|\"]"),
  41. "Heroku": regexp.MustCompile("(?i)heroku.*[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}"),
  42. }
  43. }
  44. func main() {
  45. args := os.Args[1:]
  46. opts = newOpts(args)
  47. owner := newOwner()
  48. os.Exit(owner.auditRepos())
  49. }
  50. func failF(format string, args ...interface{}) {
  51. fmt.Fprintf(os.Stderr, format, args...)
  52. os.Exit(EXIT_FAILURE)
  53. }