| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package etsi |
| 16 |
|
| 17 |
import ( |
| 18 |
"fmt" |
| 19 |
"strings" |
| 20 |
|
| 21 |
"github.com/zmap/zcrypto/encoding/asn1" |
| 22 |
"github.com/zmap/zcrypto/x509" |
| 23 |
"github.com/zmap/zlint/v3/lint" |
| 24 |
"github.com/zmap/zlint/v3/util" |
| 25 |
) |
| 26 |
|
| 27 |
type qcStatemQcPdsValid struct{} |
| 28 |
|
| 29 |
func init() { |
| 30 |
lint.RegisterCertificateLint(&lint.CertificateLint{ |
| 31 |
LintMetadata: lint.LintMetadata{ |
| 32 |
Name: "e_qcstatem_qcpds_valid", |
| 33 |
Description: "Checks that a QC Statement of the type id-etsi-qcs-QcPDS has the correct form", |
| 34 |
Citation: "ETSI EN 319 412 - 5 V2.2.1 (2017 - 11) / Section 4.3.4", |
| 35 |
Source: lint.EtsiEsi, |
| 36 |
EffectiveDate: util.EtsiEn319_412_5_V2_2_1_Date, |
| 37 |
}, |
| 38 |
Lint: NewQcStatemQcPdsValid, |
| 39 |
}) |
| 40 |
} |
| 41 |
|
| 42 |
func NewQcStatemQcPdsValid() lint.LintInterface { |
| 43 |
return &qcStatemQcPdsValid{} |
| 44 |
} |
| 45 |
|
| 46 |
func (this *qcStatemQcPdsValid) getStatementOid() *asn1.ObjectIdentifier { |
| 47 |
return &util.IdEtsiQcsQcEuPDS |
| 48 |
} |
| 49 |
|
| 50 |
func (l *qcStatemQcPdsValid) CheckApplies(c *x509.Certificate) bool { |
| 51 |
if !util.IsExtInCert(c, util.QcStateOid) { |
| 52 |
return false |
| 53 |
} |
| 54 |
if util.ParseQcStatem(util.GetExtFromCert(c, util.QcStateOid).Value, *l.getStatementOid()).IsPresent() { |
| 55 |
return true |
| 56 |
} |
| 57 |
return false |
| 58 |
} |
| 59 |
|
| 60 |
func isInList(s string, list []string) bool { |
| 61 |
for _, i := range list { |
| 62 |
if strings.Compare(i, s) == 0 { |
| 63 |
return true |
| 64 |
} |
| 65 |
} |
| 66 |
return false |
| 67 |
} |
| 68 |
|
| 69 |
func (l *qcStatemQcPdsValid) Execute(c *x509.Certificate) *lint.LintResult { |
| 70 |
errString := "" |
| 71 |
ext := util.GetExtFromCert(c, util.QcStateOid) |
| 72 |
s := util.ParseQcStatem(ext.Value, *l.getStatementOid()) |
| 73 |
errString += s.GetErrorInfo() |
| 74 |
if len(errString) == 0 { |
| 75 |
codeList := make([]string, 0) |
| 76 |
foundEn := false |
| 77 |
pds := s.(util.EtsiQcPds) |
| 78 |
if len(pds.PdsLocations) == 0 { |
| 79 |
util.AppendToStringSemicolonDelim(&errString, "PDS list is empty") |
| 80 |
} |
| 81 |
for i, loc := range pds.PdsLocations { |
| 82 |
if len(loc.Language) != 2 { |
| 83 |
util.AppendToStringSemicolonDelim(&errString, fmt.Sprintf("PDS location %d has a language code with an invalid length", i)) |
| 84 |
} |
| 85 |
if strings.Compare(strings.ToLower(loc.Language), "en") == 0 { |
| 86 |
foundEn = true |
| 87 |
} |
| 88 |
if isInList(strings.ToLower(loc.Language), codeList) { |
| 89 |
util.AppendToStringSemicolonDelim(&errString, "country code '"+loc.Language+"' appears multiple times") |
| 90 |
} |
| 91 |
codeList = append(codeList, loc.Language) |
| 92 |
|
| 93 |
} |
| 94 |
if !foundEn { |
| 95 |
util.AppendToStringSemicolonDelim(&errString, "no english PDS present") |
| 96 |
} |
| 97 |
} |
| 98 |
if len(errString) == 0 { |
| 99 |
return &lint.LintResult{Status: lint.Pass} |
| 100 |
} else { |
| 101 |
return &lint.LintResult{Status: lint.Error, Details: errString} |
| 102 |
} |
| 103 |
} |