libp2p/go-openssl

PEM Regex seems questionable

aschmahmann opened this issue · 1 comments

go-openssl/pem.go

Lines 22 to 25 in 6d00a81

var pemSplit *regexp.Regexp = regexp.MustCompile(`(?sm)` +
`(^-----[\s-]*?BEGIN.*?-----[\s-]*?$` +
`.*?` +
`^-----[\s-]*?END.*?-----[\s-]*?$)`)

Allows for whitespace and dashes beyond what is allowed in the spec https://tools.ietf.org/html/rfc7468. We should clean this up.

To remedy this, the following more restrictive regex would also work from the CRLF line endings point of view:

var pemSplit *regexp.Regexp = regexp.MustCompile(`(?sm)` + 
	`(^-----[\s-]*?BEGIN.*?-----\r?$` +
	`.*?` +
	`^-----[\s-]*?END.*?-----\r?$)`)