privatekey.go 897 B

12345678910111213141516171819202122232425262728293031
  1. package rules
  2. import (
  3. "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
  4. "github.com/zricethezav/gitleaks/v8/config"
  5. "github.com/zricethezav/gitleaks/v8/regexp"
  6. )
  7. func PrivateKey() *config.Rule {
  8. // define rule
  9. r := config.Rule{
  10. Description: "Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.",
  11. RuleID: "private-key",
  12. Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY(?: BLOCK)?-----[\s\S-]*?KEY(?: BLOCK)?-----`),
  13. Keywords: []string{"-----BEGIN"},
  14. }
  15. // validate
  16. tps := []string{`-----BEGIN PRIVATE KEY-----
  17. anything
  18. -----END PRIVATE KEY-----`,
  19. `-----BEGIN RSA PRIVATE KEY-----
  20. abcdefghijksmnopqrstuvwxyz
  21. -----END RSA PRIVATE KEY-----
  22. `,
  23. `-----BEGIN PRIVATE KEY BLOCK-----
  24. anything
  25. -----END PRIVATE KEY BLOCK-----`,
  26. } // gitleaks:allow
  27. return utils.Validate(r, tps, nil)
  28. }