-
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
Open
mtgag
wants to merge
43
commits into
zmap:master
Choose a base branch
from
mtgag:e_qcstatem_correct_national_scheme
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
6c23670
lint about the encoding of qcstatements for PSD2
4666bb7
Revert "lint about the encoding of qcstatements for PSD2"
01996c6
Merge https://github.com/zmap/zlint
28481cc
Merge https://github.com/zmap/zlint
749d896
Merge https://github.com/zmap/zlint
e56e2a0
util: gtld_map autopull updates for 2021-10-21T07:25:20 UTC
web-flow 8600050
Merge pull request #1 from mtgag/zlint-gtld-update
mtgag 30b096e
Merge https://github.com/zmap/zlint
mtgag 92e659c
always check and perform the operation in the execution
mtgag 351a379
Merge branch 'master' into master
christopher-henderson b52111b
Merge https://github.com/zmap/zlint
mtgag 526f9be
Merge https://github.com/zmap/zlint
mtgag 92902fc
Merge https://github.com/zmap/zlint
mtgag 1652cfa
synchronised with project
mtgag d4f2f9f
synchronised with project
mtgag 88c933e
Merge https://github.com/zmap/zlint
mtgag cee805f
Merge https://github.com/zmap/zlint
mtgag 2408543
synchronised with project
mtgag 67537e9
synchronised with project
mtgag e77fae1
synchronised with project
mtgag 51d498f
synchronised with project
mtgag 31e1845
Merge https://github.com/zmap/zlint
mtgag d10444e
Merge https://github.com/zmap/zlint
mtgag 53b911e
fixed merge error
mtgag f1a66db
Merge https://github.com/zmap/zlint
mtgag 795d206
Merge https://github.com/zmap/zlint
mtgag bad73ee
synchronised with project
mtgag 2cd7d08
synchronised with project
mtgag 63cf8e8
Revert "synchronised with project"
mtgag b3a86b3
Revert "synchronised with project"
mtgag 4d46729
Merge https://github.com/zmap/zlint
mtgag f0991f9
Merge https://github.com/zmap/zlint
mtgag 6662edf
Merge https://github.com/zmap/zlint
mtgag d5aec9b
synchronised with project
mtgag fdc1d36
synchronised with project
mtgag a694591
synchronised with project
mtgag b26ef71
added lint
mtgag 05f2372
added testdata
mtgag cd332f8
added missing date
mtgag 96060e5
with main project
mtgag e1e43ff
addressing review comments
mtgag 636623a
addressing review comments
mtgag 1036f73
addressing lint issues
mtgag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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{} | ||
| } | ||
|
|
||
| var re = regexp.MustCompile(`^[a-zA-Z]{2}:`) | ||
|
|
||
| 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 | ||
|
|
||
| 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) { | ||
| 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} | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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----- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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----- |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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
^.{2}:regex. Are you expecting both of these scenarios to also generate aPASS?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.
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.