@@ -23,13 +23,12 @@ use cryptography_x509::{
23
23
name:: GeneralName ,
24
24
oid:: { NAME_CONSTRAINTS_OID , SUBJECT_ALTERNATIVE_NAME_OID } ,
25
25
} ;
26
- use types:: { RFC822Constraint , RFC822Name } ;
26
+ use types:: { DNSPattern , RFC822Constraint , RFC822Name } ;
27
27
28
28
use crate :: certificate:: cert_is_self_issued;
29
29
use crate :: ops:: { CryptoOps , VerificationCertificate } ;
30
30
use crate :: policy:: Policy ;
31
31
use crate :: trust_store:: Store ;
32
- use crate :: types:: DNSName ;
33
32
use crate :: types:: { DNSConstraint , IPAddress , IPConstraint } ;
34
33
use crate :: ApplyNameConstraintStatus :: { Applied , Skipped } ;
35
34
@@ -155,45 +154,53 @@ impl<'a, 'chain> NameChain<'a, 'chain> {
155
154
budget. name_constraint_check ( ) ?;
156
155
157
156
match ( constraint, san) {
158
- ( GeneralName :: DNSName ( pattern) , GeneralName :: DNSName ( name) ) => {
159
- match ( DNSConstraint :: new ( pattern. 0 ) , DNSName :: new ( name. 0 ) ) {
160
- ( Some ( pattern) , Some ( name) ) => Ok ( Applied ( pattern. matches ( & name) ) ) ,
157
+ ( GeneralName :: DNSName ( constraint) , GeneralName :: DNSName ( name) ) => {
158
+ // NOTE: A DNS SAN can be a wildcard pattern instead of a normal DNS name.
159
+ // These are handled by matching unconditionally on the inner name,
160
+ // since a NC of `foo.com` will match both `foo.com` and any arbitrarily deep
161
+ // subdomain of `foo.com`, where a wildcard SAN like `*.foo.com` will only
162
+ // match exactly one subdomain of `foo.com`. Therefore, the NC's matching
163
+ // set is a strict superset of any possible wildcard SAN pattern.
164
+ match ( DNSConstraint :: new ( constraint. 0 ) , DNSPattern :: new ( name. 0 ) ) {
165
+ ( Some ( constraint) , Some ( name) ) => {
166
+ Ok ( Applied ( constraint. matches ( name. inner_name ( ) ) ) )
167
+ }
161
168
( _, None ) => Err ( ValidationError :: new ( ValidationErrorKind :: Other ( format ! (
162
169
"unsatisfiable DNS name constraint: malformed SAN {}" ,
163
170
name. 0
164
171
) ) ) ) ,
165
172
( None , _) => Err ( ValidationError :: new ( ValidationErrorKind :: Other ( format ! (
166
173
"malformed DNS name constraint: {}" ,
167
- pattern . 0
174
+ constraint . 0
168
175
) ) ) ) ,
169
176
}
170
177
}
171
- ( GeneralName :: IPAddress ( pattern ) , GeneralName :: IPAddress ( name) ) => {
178
+ ( GeneralName :: IPAddress ( constraint ) , GeneralName :: IPAddress ( name) ) => {
172
179
match (
173
- IPConstraint :: from_bytes ( pattern ) ,
180
+ IPConstraint :: from_bytes ( constraint ) ,
174
181
IPAddress :: from_bytes ( name) ,
175
182
) {
176
- ( Some ( pattern ) , Some ( name) ) => Ok ( Applied ( pattern . matches ( & name) ) ) ,
183
+ ( Some ( constraint ) , Some ( name) ) => Ok ( Applied ( constraint . matches ( & name) ) ) ,
177
184
( _, None ) => Err ( ValidationError :: new ( ValidationErrorKind :: Other ( format ! (
178
185
"unsatisfiable IP name constraint: malformed SAN {:?}" ,
179
186
name,
180
187
) ) ) ) ,
181
188
( None , _) => Err ( ValidationError :: new ( ValidationErrorKind :: Other ( format ! (
182
189
"malformed IP name constraints: {:?}" ,
183
- pattern
190
+ constraint
184
191
) ) ) ) ,
185
192
}
186
193
}
187
- ( GeneralName :: RFC822Name ( pattern ) , GeneralName :: RFC822Name ( name) ) => {
188
- match ( RFC822Constraint :: new ( pattern . 0 ) , RFC822Name :: new ( name. 0 ) ) {
189
- ( Some ( pattern ) , Some ( name) ) => Ok ( Applied ( pattern . matches ( & name) ) ) ,
194
+ ( GeneralName :: RFC822Name ( constraint ) , GeneralName :: RFC822Name ( name) ) => {
195
+ match ( RFC822Constraint :: new ( constraint . 0 ) , RFC822Name :: new ( name. 0 ) ) {
196
+ ( Some ( constraint ) , Some ( name) ) => Ok ( Applied ( constraint . matches ( & name) ) ) ,
190
197
( _, None ) => Err ( ValidationError :: new ( ValidationErrorKind :: Other ( format ! (
191
198
"unsatisfiable RFC822 name constraint: malformed SAN {:?}" ,
192
199
name. 0 ,
193
200
) ) ) ) ,
194
201
( None , _) => Err ( ValidationError :: new ( ValidationErrorKind :: Other ( format ! (
195
202
"malformed RFC822 name constraints: {:?}" ,
196
- pattern . 0
203
+ constraint . 0
197
204
) ) ) ) ,
198
205
}
199
206
}
0 commit comments