Skip to content

Commit 08a9354

Browse files
Lint for CABF SMIME 7.1.2.3.h - subjectAlternativeName, all: SHALL be present (7.1.2.3.h) (#744)
* Lint for CABF SMIME 7.1.2.3.h - subjectAlternativeName, all: SHALL be present (7.1.2.3.h) * not exporting
1 parent 386a8dc commit 08a9354

File tree

4 files changed

+167
-0
lines changed

4 files changed

+167
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* ZLint Copyright 2023 Regents of the University of Michigan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy
6+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
11+
* implied. See the License for the specific language governing
12+
* permissions and limitations under the License.
13+
*/
14+
15+
package cabf_smime_br
16+
17+
import (
18+
"github.com/zmap/zcrypto/x509"
19+
"github.com/zmap/zlint/v3/lint"
20+
"github.com/zmap/zlint/v3/util"
21+
)
22+
23+
func init() {
24+
lint.RegisterLint(&lint.Lint{
25+
Name: "e_san_shall_be_present",
26+
Description: "Subject alternative name SHALL be present",
27+
Citation: "7.1.2.3.h",
28+
Source: lint.CABFSMIMEBaselineRequirements,
29+
EffectiveDate: util.CABF_SMIME_BRs_1_0_0_Date,
30+
Lint: NewSubjectAlternativeNameShallBePresent,
31+
})
32+
}
33+
34+
type subjectAlternativeNameShallBePresent struct{}
35+
36+
func NewSubjectAlternativeNameShallBePresent() lint.LintInterface {
37+
return &subjectAlternativeNameShallBePresent{}
38+
}
39+
40+
func (l *subjectAlternativeNameShallBePresent) CheckApplies(c *x509.Certificate) bool {
41+
return util.IsSubscriberCert(c)
42+
}
43+
44+
func (l *subjectAlternativeNameShallBePresent) Execute(c *x509.Certificate) *lint.LintResult {
45+
if !util.IsExtInCert(c, util.SubjectAlternateNameOID) {
46+
return &lint.LintResult{
47+
Status: lint.Error,
48+
Details: "SMIME certificate does not have a subject alternative name extension",
49+
}
50+
} else {
51+
return &lint.LintResult{Status: lint.Pass}
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cabf_smime_br
2+
3+
import (
4+
"testing"
5+
6+
"github.com/zmap/zlint/v3/lint"
7+
"github.com/zmap/zlint/v3/test"
8+
)
9+
10+
func TestSubscriberSubjectAlternativeNameShallBePresent(t *testing.T) {
11+
testCases := []struct {
12+
Name string
13+
InputFilename string
14+
ExpectedResult lint.LintStatus
15+
}{
16+
{
17+
Name: "pass - cert with SAN",
18+
InputFilename: "smime/with_subject_alternative_name.pem",
19+
ExpectedResult: lint.Pass,
20+
},
21+
{
22+
Name: "error - cert without SAN",
23+
InputFilename: "smime/without_subject_alternative_name.pem",
24+
ExpectedResult: lint.Error,
25+
},
26+
}
27+
for _, tc := range testCases {
28+
t.Run(tc.Name, func(t *testing.T) {
29+
result := test.TestLint("e_san_shall_be_present", tc.InputFilename)
30+
if result.Status != tc.ExpectedResult {
31+
t.Errorf("expected result %v was %v - details: %v", tc.ExpectedResult, result.Status, result.Details)
32+
}
33+
})
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Certificate:
2+
Data:
3+
Version: 3 (0x2)
4+
Serial Number: 3 (0x3)
5+
Signature Algorithm: ecdsa-with-SHA256
6+
Issuer:
7+
Validity
8+
Not Before: Sep 30 15:56:47 2023 GMT
9+
Not After : Nov 30 00:00:00 9998 GMT
10+
Subject:
11+
Subject Public Key Info:
12+
Public Key Algorithm: id-ecPublicKey
13+
Public-Key: (256 bit)
14+
pub:
15+
04:69:58:02:49:7d:98:10:6e:6d:f3:3f:8f:2b:9f:
16+
10:df:09:42:d6:c5:1c:22:9c:86:87:e6:1d:ed:ed:
17+
d5:98:1d:93:ce:ce:61:2a:8d:44:cb:73:59:90:06:
18+
bb:68:e4:7c:24:d0:47:6a:b9:a4:a3:c9:60:a7:4d:
19+
5e:c5:46:dd:bd
20+
ASN1 OID: prime256v1
21+
NIST CURVE: P-256
22+
X509v3 extensions:
23+
X509v3 Extended Key Usage:
24+
E-mail Protection
25+
X509v3 Subject Alternative Name:
26+
27+
Signature Algorithm: ecdsa-with-SHA256
28+
Signature Value:
29+
30:45:02:21:00:eb:30:e0:f2:cf:6f:a4:95:ca:6a:e0:a9:e7:
30+
06:ea:4d:b2:18:b7:bd:6e:69:4f:96:c0:07:86:3c:73:b2:2e:
31+
3f:02:20:6e:83:bb:ca:79:8f:91:43:22:08:02:b3:86:30:85:
32+
d7:1f:e7:ec:9c:0b:06:58:1b:47:15:08:25:26:99:c2:26
33+
-----BEGIN CERTIFICATE-----
34+
MIIBKjCB0aADAgECAgEDMAoGCCqGSM49BAMCMAAwIBcNMjMwOTMwMTU1NjQ3WhgP
35+
OTk5ODExMzAwMDAwMDBaMAAwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARpWAJJ
36+
fZgQbm3zP48rnxDfCULWxRwinIaH5h3t7dWYHZPOzmEqjUTLc1mQBrto5Hwk0Edq
37+
uaSjyWCnTV7FRt29ozowODATBgNVHSUEDDAKBggrBgEFBQcDBDAhBgNVHREEGjAY
38+
gRZjb29sZ3V5QGNvb2xwbGFjZS5jb21lMAoGCCqGSM49BAMCA0gAMEUCIQDrMODy
39+
z2+klcpq4KnnBupNshi3vW5pT5bAB4Y8c7IuPwIgboO7ynmPkUMiCAKzhjCF1x/n
40+
7JwLBlgbRxUIJSaZwiY=
41+
-----END CERTIFICATE-----
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Certificate:
2+
Data:
3+
Version: 3 (0x2)
4+
Serial Number: 3 (0x3)
5+
Signature Algorithm: ecdsa-with-SHA256
6+
Issuer:
7+
Validity
8+
Not Before: Sep 30 15:41:50 2023 GMT
9+
Not After : Nov 30 00:00:00 9998 GMT
10+
Subject:
11+
Subject Public Key Info:
12+
Public Key Algorithm: id-ecPublicKey
13+
Public-Key: (256 bit)
14+
pub:
15+
04:8b:93:b2:84:b1:56:f4:cc:df:55:3f:f4:07:2b:
16+
d1:5a:bc:52:10:41:aa:91:88:aa:25:ac:02:da:3e:
17+
0c:0e:af:3b:65:49:d5:22:f9:a5:80:f1:83:c6:bc:
18+
bb:8e:cf:d1:a6:b5:92:5d:85:6f:91:5e:31:1a:af:
19+
69:04:62:31:86
20+
ASN1 OID: prime256v1
21+
NIST CURVE: P-256
22+
X509v3 extensions:
23+
X509v3 Extended Key Usage:
24+
E-mail Protection
25+
Signature Algorithm: ecdsa-with-SHA256
26+
Signature Value:
27+
30:45:02:20:0f:4a:43:42:ff:8b:5a:b3:30:f0:c6:b2:63:1c:
28+
92:39:4d:17:5d:b0:15:70:e9:15:2e:9a:3f:a1:d6:12:c2:79:
29+
02:21:00:a6:91:19:20:11:17:8d:f1:65:e0:f1:33:89:38:42:
30+
24:a5:41:e5:33:6b:53:21:7f:1f:49:49:0f:57:d8:0a:f2
31+
-----BEGIN CERTIFICATE-----
32+
MIIBBzCBrqADAgECAgEDMAoGCCqGSM49BAMCMAAwIBcNMjMwOTMwMTU0MTUwWhgP
33+
OTk5ODExMzAwMDAwMDBaMAAwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASLk7KE
34+
sVb0zN9VP/QHK9FavFIQQaqRiKolrALaPgwOrztlSdUi+aWA8YPGvLuOz9GmtZJd
35+
hW+RXjEar2kEYjGGoxcwFTATBgNVHSUEDDAKBggrBgEFBQcDBDAKBggqhkjOPQQD
36+
AgNIADBFAiAPSkNC/4taszDwxrJjHJI5TRddsBVw6RUumj+h1hLCeQIhAKaRGSAR
37+
F43xZeDxM4k4QiSlQeUza1Mhfx9JSQ9X2Ary
38+
-----END CERTIFICATE-----

0 commit comments

Comments
 (0)