| 1 |
package rfc |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
import ( |
| 18 |
"unicode/utf8" |
| 19 |
|
| 20 |
"github.com/zmap/zcrypto/x509" |
| 21 |
"github.com/zmap/zlint/v3/lint" |
| 22 |
"github.com/zmap/zlint/v3/util" |
| 23 |
) |
| 24 |
|
| 25 |
type subjectEmailMaxLength struct{} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
func init() { |
| 42 |
lint.RegisterCertificateLint(&lint.CertificateLint{ |
| 43 |
LintMetadata: lint.LintMetadata{ |
| 44 |
Name: "e_subject_email_max_length", |
| 45 |
Description: "The 'Email' field of the subject MUST be less than 256 characters", |
| 46 |
Citation: "RFC 5280: A.1", |
| 47 |
Source: lint.RFC5280, |
| 48 |
EffectiveDate: util.RFC2459Date, |
| 49 |
}, |
| 50 |
Lint: NewSubjectEmailMaxLength, |
| 51 |
}) |
| 52 |
} |
| 53 |
|
| 54 |
func NewSubjectEmailMaxLength() lint.LintInterface { |
| 55 |
return &subjectEmailMaxLength{} |
| 56 |
} |
| 57 |
|
| 58 |
func (l *subjectEmailMaxLength) CheckApplies(c *x509.Certificate) bool { |
| 59 |
return len(c.Subject.EmailAddress) > 0 |
| 60 |
} |
| 61 |
|
| 62 |
func (l *subjectEmailMaxLength) Execute(c *x509.Certificate) *lint.LintResult { |
| 63 |
for _, j := range c.Subject.EmailAddress { |
| 64 |
if utf8.RuneCountInString(j) > 255 { |
| 65 |
return &lint.LintResult{Status: lint.Error} |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
return &lint.LintResult{Status: lint.Pass} |
| 70 |
} |