-
Notifications
You must be signed in to change notification settings - Fork 118
E qcstatem correct national scheme #949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 40 commits
6c23670
4666bb7
01996c6
28481cc
749d896
e56e2a0
8600050
30b096e
92e659c
351a379
b52111b
526f9be
92902fc
1652cfa
d4f2f9f
88c933e
cee805f
2408543
67537e9
e77fae1
51d498f
31e1845
d10444e
53b911e
f1a66db
795d206
bad73ee
2cd7d08
63cf8e8
b3a86b3
4d46729
f0991f9
6662edf
d5aec9b
fdc1d36
a694591
b26ef71
05f2372
cd332f8
96060e5
e1e43ff
636623a
1036f73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| package etsi | ||
|
|
||
| /* | ||
| * ZLint Copyright 2025 Regents of the University of Michigan | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
| * implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "regexp" | ||
|
|
||
| "github.com/zmap/zcrypto/x509" | ||
| "github.com/zmap/zlint/v3/lint" | ||
| "github.com/zmap/zlint/v3/util" | ||
| ) | ||
|
|
||
| type qcStatemNationalScheme struct{} | ||
|
|
||
| /************************************************************************ | ||
| ETSI EN 319 412-2 V2.2.1 (2020-07) | ||
| https://www.etsi.org/deliver/etsi_en/319400_319499/31941202/02.02.01_60/en_31941202v020201p.pdf | ||
| 4.2.4 Certificates may include one or more semantics identifiers as specified in ETSI | ||
| EN 319 412-1 [i.4], clause 5 which defines the semantics for the organizationIdentifier attribute. | ||
|
|
||
| Certificates may include one or more semantics identifiers as specified in ETSI EN 319 412-1 [i.4], | ||
| clause 5 which define the semantics for the serialNumber attribute. | ||
|
|
||
| ETSI EN 319 412-1 V1.4.1 (2020-06) | ||
| https://www.etsi.org/deliver/etsi_en/319400_319499/31941201/01.04.01_60/en_31941201v010401p.pdf | ||
| 5.1.3 Natural person semantics identifier | ||
| The semantics of id-etsi-qcs-SemanticsId-Natural shall be as follows. | ||
| When the natural person semantics identifier is included, any present serialNumber attribute in the subject field shall | ||
| contain information using the following structure in the presented order: | ||
| The three initial characters shall have one of the following defined values: | ||
| 1) "PAS" for identification based on passport number. | ||
| 2) "IDC" for identification based on national identity card number. | ||
| 3) "PNO" for identification based on (national) personal number (national civic registration number). | ||
| 4) "TAX" for identification based on a personal tax reference number issued by a national tax authority. This | ||
| value is deprecated. The value "TIN" should be used instead. | ||
| 5) "TIN" Tax Identification Number according to the European Commission – Tax and Customs Union | ||
| (https://ec.europa.eu/taxation_customs/tin/tinByCountry.html). | ||
| 6) Two characters according to local definition within the specified country and name registration authority, | ||
| identifying a national scheme that is considered appropriate for national and European level, followed by the | ||
| character ":" (colon). | ||
|
|
||
| 5.1.4 Legal person semantics identifier | ||
| The semantics of id-etsi-qcs-SemanticsId-Legal shall be as follows. | ||
| When the legal person semantics identifier is included, any present organizationIdentifier attribute in the subject | ||
| field shall contain information using the following structure in the presented order: | ||
| • 3 character legal person identity type reference; | ||
| • 2 character ISO 3166 [2] country code; | ||
| • hyphen-minus "-" (0x2D (ASCII), U+002D (UTF-8)); and | ||
| • identifier (according to country and identity type reference). | ||
| The three initial characters shall have one of the following defined values: | ||
| 1) "VAT" for identification based on a national value added tax identification number. | ||
| 2) "NTR" for identification based on an identifier from a national trade register. | ||
| 3) "PSD" for identification based on national authorization number of a payment service provider under | ||
| Payments Services Directive (EU) 2015/2366 [i.13]. This shall use the extended structure as defined in ETSI | ||
| TS 119 495 [3], clause 5.2.1. | ||
| 4) "LEI" for a global Legal Entity Identifier as specified in ISO 17442 [4]. The 2 character ISO 3166 [2] country | ||
| code shall be set to 'XG'. | ||
| 5) Two characters according to local definition within the specified country and name registration authority, | ||
| identifying a national scheme that is considered appropriate for national and European level, followed by the | ||
| character ":" (colon) | ||
| *************************************************************************/ | ||
|
|
||
| func init() { | ||
| lint.RegisterCertificateLint(&lint.CertificateLint{ | ||
| LintMetadata: lint.LintMetadata{ | ||
| Name: "e_qcstatem_correct_national_scheme", | ||
| Description: "This lint checks that the national scheme is well-formed when used in the serialNumber or organizationIdentifier attribute in the subject field, provided that either the natural person semantics identifier or the legal person semantics identifier is present.", | ||
| Citation: "ETSI EN 319 412-1 V1.4.1, 5.1.3 Natural person semantics identifier and 5.1.4 Legal person semantics identifier", | ||
| Source: lint.EtsiEsi, | ||
| EffectiveDate: util.ETSI_EN_319_412_1_V1_4_1_DATE, | ||
| }, | ||
| Lint: NewQcStatemNationalScheme, | ||
| }) | ||
| } | ||
|
|
||
| func NewQcStatemNationalScheme() lint.LintInterface { | ||
| return &qcStatemNationalScheme{} | ||
| } | ||
|
|
||
| func (l *qcStatemNationalScheme) CheckApplies(c *x509.Certificate) bool { | ||
| _, isPresent := util.IsQcStatemPresent(c, &util.IdQcsPkixQCSyntaxV2) | ||
|
|
||
| if !isPresent { | ||
| return false | ||
| } | ||
|
|
||
| qcs2Generic := util.ParseQcStatem(util.GetQcStatemExtValue(c), util.IdQcsPkixQCSyntaxV2) | ||
|
|
||
| qcs2 := qcs2Generic.(util.DecodedQcS2) | ||
| semanticsId := qcs2.Decoded.SemanticsId | ||
| re := regexp.MustCompile(`^.{2}:`) | ||
|
|
||
| if semanticsId.Equal(util.IdEtsiQcsSemanticsIdNatural) { | ||
| serialNumber := c.Subject.SerialNumber | ||
| return re.MatchString(serialNumber) | ||
| } | ||
|
|
||
| if semanticsId.Equal(util.IdEtsiQcsSemanticsIdLegal) { | ||
| for _, orgId := range c.Subject.OrganizationIDs { | ||
| if re.MatchString(orgId) { | ||
| return true | ||
| } | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func (l *qcStatemNationalScheme) Execute(c *x509.Certificate) *lint.LintResult { | ||
|
|
||
| qcs2Generic := util.ParseQcStatem(util.GetQcStatemExtValue(c), util.IdQcsPkixQCSyntaxV2) | ||
|
|
||
| qcs2 := qcs2Generic.(util.DecodedQcS2) | ||
| semanticsId := qcs2.Decoded.SemanticsId | ||
|
|
||
| if semanticsId.Equal(util.IdEtsiQcsSemanticsIdNatural) { | ||
| serialNumber := c.Subject.SerialNumber | ||
| if !util.CheckNationalScheme(serialNumber) { | ||
| return &lint.LintResult{Status: lint.Error, Details: fmt.Sprintf("invalid format of subject:serialNumber %s for national scheme", serialNumber)} | ||
| } | ||
| } | ||
|
|
||
| if semanticsId.Equal(util.IdEtsiQcsSemanticsIdLegal) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am unsure of this block. The psuedo-code that describes it is... However, it will also succeed if there are simply no orgIDs or if none of the orgIDs that are present match the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The CheckApplies should cover this. If the certificate does not have any orgIDs or none of the orgIDs that are present match the regexp then it is an NA. |
||
| re := regexp.MustCompile(`^.{2}:`) | ||
|
||
| for _, orgId := range c.Subject.OrganizationIDs { | ||
| if re.MatchString(orgId) && !util.CheckNationalScheme(orgId) { | ||
| return &lint.LintResult{Status: lint.Error, Details: fmt.Sprintf("invalid format of subject:organizationIdentifier %s for national scheme", orgId)} | ||
| } | ||
| } | ||
| } | ||
| return &lint.LintResult{Status: lint.Pass} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package etsi | ||
|
|
||
| /* | ||
| * ZLint Copyright 2025 Regents of the University of Michigan | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
| * use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
| * implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/zmap/zlint/v3/lint" | ||
| "github.com/zmap/zlint/v3/test" | ||
| ) | ||
|
|
||
| func TestQcStatemNationalScheme(t *testing.T) { | ||
| testCases := []struct { | ||
| Name string | ||
| InputFilename string | ||
| ExpectedResult lint.LintStatus | ||
| }{ | ||
| { | ||
| Name: "NA - certificate has the natural person semantics identifier and no national scheme value", | ||
| InputFilename: "qcNaturalNoNationalScheme.pem", | ||
| ExpectedResult: lint.NA, | ||
| }, | ||
| { | ||
| Name: "Pass - certificate has the natural person semantics identifier and a correct national scheme value", | ||
| InputFilename: "qcNaturalCorrectNationalScheme.pem", | ||
| ExpectedResult: lint.Pass, | ||
| }, | ||
| { | ||
| Name: "Error - certificate has the natural person semantics identifier and a wrong national scheme value", | ||
| InputFilename: "qcNaturalNotCorrectScheme.pem", | ||
| ExpectedResult: lint.Error, | ||
| }, | ||
| { | ||
| Name: "NA - certificate has the legal person semantics identifier and no national scheme value", | ||
| InputFilename: "qcLegalNoNationalScheme.pem", | ||
| ExpectedResult: lint.NA, | ||
| }, | ||
| { | ||
| Name: "Pass - certificate has the legal person semantics identifier and a correct national scheme value", | ||
| InputFilename: "qcLegalCorrectNationalScheme.pem", | ||
| ExpectedResult: lint.Pass, | ||
| }, | ||
| { | ||
| Name: "Error - certificate has the legal person semantics identifier and a wrong national scheme value", | ||
| InputFilename: "qcLegalNotCorrectScheme.pem", | ||
| ExpectedResult: lint.Error, | ||
| }, | ||
| } | ||
| for _, tc := range testCases { | ||
| t.Run(tc.Name, func(t *testing.T) { | ||
| result := test.TestLint("e_qcstatem_correct_national_scheme", tc.InputFilename) | ||
| if result.Status != tc.ExpectedResult { | ||
| t.Errorf("expected result %v was %v - details: %v", tc.ExpectedResult, result.Status, result.Details) | ||
| } | ||
| }) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| Certificate: | ||
| Data: | ||
| Version: 3 (0x2) | ||
| Serial Number: | ||
| 3e:40:85:f1:1f:4f:d3:c8:50:3f:5b:dc | ||
| Signature Algorithm: ecdsa-with-SHA256 | ||
| Issuer: CN = Lint CA, O = Lint, C = DE | ||
| Validity | ||
| Not Before: Feb 18 00:00:00 2025 GMT | ||
| Not After : Feb 18 00:00:00 2026 GMT | ||
| Subject: organizationIdentifier = EI:SE-5567971433 | ||
| Subject Public Key Info: | ||
| Public Key Algorithm: id-ecPublicKey | ||
| Public-Key: (256 bit) | ||
| pub: | ||
| 04:8c:5e:3f:b1:9b:cb:61:f6:56:fe:06:f2:26:06: | ||
| 93:00:d4:6f:5a:ac:72:d7:3f:3c:f4:8e:72:73:71: | ||
| 6f:2e:e0:af:93:2f:57:42:58:50:ef:47:f4:b2:ab: | ||
| 58:d5:d5:7a:c9:d0:cd:46:1f:8e:b1:c5:19:28:5f: | ||
| ea:c1:d4:49:3e | ||
| ASN1 OID: prime256v1 | ||
| NIST CURVE: P-256 | ||
| X509v3 extensions: | ||
| qcStatements: | ||
| 0.0...+.......0.......I.. | ||
| Signature Algorithm: ecdsa-with-SHA256 | ||
| 30:44:02:20:49:36:0b:d5:cc:db:c9:d2:2a:81:19:3f:11:3a: | ||
| 01:e3:34:fd:66:65:c7:05:e2:76:2e:36:cf:17:bb:91:90:ca: | ||
| 02:20:4d:e5:9e:45:32:d5:c8:99:c3:0f:4d:aa:2b:b8:a0:34: | ||
| 2d:a6:d5:11:76:63:5a:09:3b:0d:7d:ad:ed:f4:14:ae | ||
| -----BEGIN CERTIFICATE----- | ||
| MIIBazCCARKgAwIBAgIMPkCF8R9P08hQP1vcMAoGCCqGSM49BAMCMC4xEDAOBgNV | ||
| BAMMB0xpbnQgQ0ExDTALBgNVBAoMBExpbnQxCzAJBgNVBAYTAkRFMB4XDTI1MDIx | ||
| ODAwMDAwMFoXDTI2MDIxODAwMDAwMFowGzEZMBcGA1UEYQwQRUk6U0UtNTU2Nzk3 | ||
| MTQzMzBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABIxeP7Gby2H2Vv4G8iYGkwDU | ||
| b1qsctc/PPSOcnNxby7gr5MvV0JYUO9H9LKrWNXVesnQzUYfjrHFGShf6sHUST6j | ||
| KTAnMCUGCCsGAQUFBwEDBBkwFzAVBggrBgEFBQcLAjAJBgcEAIvsSQECMAoGCCqG | ||
| SM49BAMCA0cAMEQCIEk2C9XM28nSKoEZPxE6AeM0/WZlxwXidi42zxe7kZDKAiBN | ||
| 5Z5FMtXImcMPTaoruKA0LabVEXZjWgk7DX2t7fQUrg== | ||
| -----END CERTIFICATE----- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| Certificate: | ||
| Data: | ||
| Version: 3 (0x2) | ||
| Serial Number: | ||
| 43:f4:da:2d:d7:7e:4f:67:7f:3c:0e:2a | ||
| Signature Algorithm: ecdsa-with-SHA256 | ||
| Issuer: CN = Lint CA, O = Lint, C = DE | ||
| Validity | ||
| Not Before: Feb 18 00:00:00 2025 GMT | ||
| Not After : Feb 18 00:00:00 2026 GMT | ||
| Subject: organizationIdentifier = PASSK-P3000180 | ||
| Subject Public Key Info: | ||
| Public Key Algorithm: id-ecPublicKey | ||
| Public-Key: (256 bit) | ||
| pub: | ||
| 04:8c:5e:3f:b1:9b:cb:61:f6:56:fe:06:f2:26:06: | ||
| 93:00:d4:6f:5a:ac:72:d7:3f:3c:f4:8e:72:73:71: | ||
| 6f:2e:e0:af:93:2f:57:42:58:50:ef:47:f4:b2:ab: | ||
| 58:d5:d5:7a:c9:d0:cd:46:1f:8e:b1:c5:19:28:5f: | ||
| ea:c1:d4:49:3e | ||
| ASN1 OID: prime256v1 | ||
| NIST CURVE: P-256 | ||
| X509v3 extensions: | ||
| qcStatements: | ||
| 0.0...+.......0.......I.. | ||
| Signature Algorithm: ecdsa-with-SHA256 | ||
| 30:44:02:20:35:22:18:10:bc:e0:55:ca:df:5d:c1:14:de:07: | ||
| 68:f0:70:59:22:23:99:da:0e:1a:15:df:d1:4b:f3:c4:36:16: | ||
| 02:20:24:40:37:4f:d7:b4:61:df:75:60:97:22:c2:63:d7:9d: | ||
| 88:4f:5f:be:5f:9b:88:27:80:3c:ab:60:e9:75:1d:25 | ||
| -----BEGIN CERTIFICATE----- | ||
| MIIBaTCCARCgAwIBAgIMQ/TaLdd+T2d/PA4qMAoGCCqGSM49BAMCMC4xEDAOBgNV | ||
| BAMMB0xpbnQgQ0ExDTALBgNVBAoMBExpbnQxCzAJBgNVBAYTAkRFMB4XDTI1MDIx | ||
| ODAwMDAwMFoXDTI2MDIxODAwMDAwMFowGTEXMBUGA1UEYQwOUEFTU0stUDMwMDAx | ||
| ODAwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASMXj+xm8th9lb+BvImBpMA1G9a | ||
| rHLXPzz0jnJzcW8u4K+TL1dCWFDvR/Syq1jV1XrJ0M1GH46xxRkoX+rB1Ek+oykw | ||
| JzAlBggrBgEFBQcBAwQZMBcwFQYIKwYBBQUHCwIwCQYHBACL7EkBAjAKBggqhkjO | ||
| PQQDAgNHADBEAiA1IhgQvOBVyt9dwRTeB2jwcFkiI5naDhoV39FL88Q2FgIgJEA3 | ||
| T9e0Yd91YJciwmPXnYhPX75fm4gngDyrYOl1HSU= | ||
| -----END CERTIFICATE----- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not 100% certain of this, but do at least consider making this a bit more precise (if possible).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good. Changed.