mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-26 19:30:55 +01:00
32 lines
897 B
Go
32 lines
897 B
Go
package rules
|
|
|
|
import (
|
|
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
|
"github.com/zricethezav/gitleaks/v8/config"
|
|
"github.com/zricethezav/gitleaks/v8/regexp"
|
|
)
|
|
|
|
func PrivateKey() *config.Rule {
|
|
// define rule
|
|
r := config.Rule{
|
|
Description: "Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.",
|
|
RuleID: "private-key",
|
|
Regex: regexp.MustCompile(`(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY(?: BLOCK)?-----[\s\S-]*?KEY(?: BLOCK)?-----`),
|
|
Keywords: []string{"-----BEGIN"},
|
|
}
|
|
|
|
// validate
|
|
tps := []string{`-----BEGIN PRIVATE KEY-----
|
|
anything
|
|
-----END PRIVATE KEY-----`,
|
|
`-----BEGIN RSA PRIVATE KEY-----
|
|
abcdefghijksmnopqrstuvwxyz
|
|
-----END RSA PRIVATE KEY-----
|
|
`,
|
|
`-----BEGIN PRIVATE KEY BLOCK-----
|
|
anything
|
|
-----END PRIVATE KEY BLOCK-----`,
|
|
} // gitleaks:allow
|
|
return utils.Validate(r, tps, nil)
|
|
}
|