main.go 1.7 KB

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