checks.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package main
  2. import (
  3. "strings"
  4. "github.com/nbutton23/zxcvbn-go"
  5. )
  6. // check each line of a diff and see if there are any potential secrets
  7. // [1] https://people.eecs.berkeley.edu/~rohanpadhye/files/key_leaks-msr15.pdf
  8. func checkRegex(diff string) []string {
  9. var match string
  10. var results []string
  11. lines := strings.Split(diff, "\n")
  12. for _, line := range lines {
  13. // doubtful a leak would be on a line > 120 characters
  14. if len(line) == 0 || len(line) > 120 {
  15. continue
  16. }
  17. for _, re := range regexes {
  18. match = re.FindString(line)
  19. if len(match) == 0 {
  20. continue
  21. }
  22. results = append(results, line)
  23. }
  24. }
  25. return results
  26. }
  27. // checkEntropy determines whether target contains enough
  28. // entropy for a hash
  29. // TODO remove stop words:
  30. // setting(s), config(s), property(s), etc
  31. func checkEntropy(target string) bool {
  32. index := assignRegex.FindStringIndex(target)
  33. if len(index) == 0 {
  34. return false
  35. }
  36. // TODO check for stop words here
  37. target = strings.Trim(target[index[1]:], " ")
  38. if len(target) > 70 {
  39. return false
  40. }
  41. entropy := zxcvbn.PasswordStrength(target, nil).Entropy
  42. // tune this/make option
  43. return entropy > 70
  44. }