main.go 1.7 KB

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