| 1 |
package privatekey |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/DefangLabs/secret-detector/pkg/detectors/helpers" |
| 5 |
"github.com/DefangLabs/secret-detector/pkg/secrets" |
| 6 |
) |
| 7 |
|
| 8 |
const ( |
| 9 |
Name = "pk" |
| 10 |
secretType = "Private Key" |
| 11 |
) |
| 12 |
|
| 13 |
func init() { |
| 14 |
secrets.GetDetectorFactory().Register(Name, NewDetector) |
| 15 |
} |
| 16 |
|
| 17 |
var privateKeysRegex = []string{ |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
".*PuTTY-User-Key-File-.*", |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
"(-*BEGIN[ \\S]+?PRIVATE KEY(?: BLOCK)?-*)([\\S\n]{4,}?)(-*END[ \\S]+?PRIVATE KEY(?: BLOCK)?-*)", |
| 36 |
} |
| 37 |
|
| 38 |
type detector struct { |
| 39 |
secrets.Detector |
| 40 |
} |
| 41 |
|
| 42 |
func NewDetector(config ...string) secrets.Detector { |
| 43 |
return &detector{ |
| 44 |
Detector: helpers.NewRegexDetectorBuilder(secretType, privateKeysRegex...).Build(), |
| 45 |
} |
| 46 |
} |