| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package rfc |
| 16 |
|
| 17 |
import ( |
| 18 |
"fmt" |
| 19 |
"sort" |
| 20 |
"strings" |
| 21 |
|
| 22 |
"github.com/zmap/zcrypto/x509" |
| 23 |
"github.com/zmap/zlint/v3/lint" |
| 24 |
"github.com/zmap/zlint/v3/util" |
| 25 |
) |
| 26 |
|
| 27 |
type rsaAllowedKUEe struct{} |
| 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_rsa_allowed_ku_ee", |
| 45 |
Description: "Key usage values digitalSignature, nonRepudiation, keyEncipherment, and dataEncipherment may only be present in an end entity certificate with an RSA key", |
| 46 |
Citation: "RFC 3279: 2.3.1", |
| 47 |
Source: lint.RFC3279, |
| 48 |
EffectiveDate: util.RFC3279Date, |
| 49 |
}, |
| 50 |
Lint: NewRsaAllowedKUEe, |
| 51 |
}) |
| 52 |
} |
| 53 |
|
| 54 |
func NewRsaAllowedKUEe() lint.LintInterface { |
| 55 |
return &rsaAllowedKUEe{} |
| 56 |
} |
| 57 |
|
| 58 |
func (l *rsaAllowedKUEe) CheckApplies(c *x509.Certificate) bool { |
| 59 |
return c.PublicKeyAlgorithm == x509.RSA && util.HasKeyUsageOID(c) && util.IsSubscriberCert(c) |
| 60 |
} |
| 61 |
|
| 62 |
func (l *rsaAllowedKUEe) Execute(c *x509.Certificate) *lint.LintResult { |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
var invalidKUs []string |
| 75 |
|
| 76 |
disallowedKUs := [5]x509.KeyUsage{x509.KeyUsageKeyAgreement, x509.KeyUsageCertSign, x509.KeyUsageCRLSign, x509.KeyUsageEncipherOnly, x509.KeyUsageDecipherOnly} |
| 77 |
|
| 78 |
for _, disallowedKU := range disallowedKUs { |
| 79 |
if util.HasKeyUsage(c, disallowedKU) { |
| 80 |
invalidKUs = append(invalidKUs, util.KeyUsageToString[disallowedKU]) |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
if len(invalidKUs) > 0 { |
| 85 |
|
| 86 |
sort.Strings(invalidKUs) |
| 87 |
return &lint.LintResult{ |
| 88 |
Status: lint.Error, |
| 89 |
Details: fmt.Sprintf("Subscriber certificate with an RSA key contains invalid key usage(s): %s", strings.Join(invalidKUs, ", ")), |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
return &lint.LintResult{Status: lint.Pass} |
| 94 |
} |