@@ -31,7 +31,8 @@ static int do_i2r_name_constraints(const X509V3_EXT_METHOD *method,
31
31
static int print_nc_ipadd (BIO * bp , ASN1_OCTET_STRING * ip );
32
32
33
33
static int nc_match (GENERAL_NAME * gen , NAME_CONSTRAINTS * nc );
34
- static int nc_match_single (GENERAL_NAME * sub , GENERAL_NAME * gen );
34
+ static int nc_match_single (int effective_type , GENERAL_NAME * sub ,
35
+ GENERAL_NAME * gen );
35
36
static int nc_dn (const X509_NAME * sub , const X509_NAME * nm );
36
37
static int nc_dns (ASN1_IA5STRING * sub , ASN1_IA5STRING * dns );
37
38
static int nc_email (ASN1_IA5STRING * sub , ASN1_IA5STRING * eml );
@@ -472,14 +473,17 @@ static int nc_match(GENERAL_NAME *gen, NAME_CONSTRAINTS *nc)
472
473
{
473
474
GENERAL_SUBTREE * sub ;
474
475
int i , r , match = 0 ;
476
+ int effective_type = gen -> type ;
477
+
475
478
/*
476
479
* We need to compare not gen->type field but an "effective" type because
477
480
* the otherName field may contain EAI email address treated specially
478
481
* according to RFC 8398, section 6
479
482
*/
480
- int effective_type = ((gen -> type == GEN_OTHERNAME ) &&
481
- (OBJ_obj2nid (gen -> d .otherName -> type_id ) ==
482
- NID_id_on_SmtpUTF8Mailbox )) ? GEN_EMAIL : gen -> type ;
483
+ if (effective_type == GEN_OTHERNAME &&
484
+ (OBJ_obj2nid (gen -> d .otherName -> type_id ) == NID_id_on_SmtpUTF8Mailbox )) {
485
+ effective_type = GEN_EMAIL ;
486
+ }
483
487
484
488
/*
485
489
* Permitted subtrees: if any subtrees exist of matching the type at
@@ -488,7 +492,10 @@ static int nc_match(GENERAL_NAME *gen, NAME_CONSTRAINTS *nc)
488
492
489
493
for (i = 0 ; i < sk_GENERAL_SUBTREE_num (nc -> permittedSubtrees ); i ++ ) {
490
494
sub = sk_GENERAL_SUBTREE_value (nc -> permittedSubtrees , i );
491
- if (effective_type != sub -> base -> type )
495
+ if (effective_type != sub -> base -> type
496
+ || (effective_type == GEN_OTHERNAME &&
497
+ OBJ_cmp (gen -> d .otherName -> type_id ,
498
+ sub -> base -> d .otherName -> type_id ) != 0 ))
492
499
continue ;
493
500
if (!nc_minmax_valid (sub ))
494
501
return X509_V_ERR_SUBTREE_MINMAX ;
@@ -497,7 +504,7 @@ static int nc_match(GENERAL_NAME *gen, NAME_CONSTRAINTS *nc)
497
504
continue ;
498
505
if (match == 0 )
499
506
match = 1 ;
500
- r = nc_match_single (gen , sub -> base );
507
+ r = nc_match_single (effective_type , gen , sub -> base );
501
508
if (r == X509_V_OK )
502
509
match = 2 ;
503
510
else if (r != X509_V_ERR_PERMITTED_VIOLATION )
@@ -511,12 +518,15 @@ static int nc_match(GENERAL_NAME *gen, NAME_CONSTRAINTS *nc)
511
518
512
519
for (i = 0 ; i < sk_GENERAL_SUBTREE_num (nc -> excludedSubtrees ); i ++ ) {
513
520
sub = sk_GENERAL_SUBTREE_value (nc -> excludedSubtrees , i );
514
- if (effective_type != sub -> base -> type )
521
+ if (effective_type != sub -> base -> type
522
+ || (effective_type == GEN_OTHERNAME &&
523
+ OBJ_cmp (gen -> d .otherName -> type_id ,
524
+ sub -> base -> d .otherName -> type_id ) != 0 ))
515
525
continue ;
516
526
if (!nc_minmax_valid (sub ))
517
527
return X509_V_ERR_SUBTREE_MINMAX ;
518
528
519
- r = nc_match_single (gen , sub -> base );
529
+ r = nc_match_single (effective_type , gen , sub -> base );
520
530
if (r == X509_V_OK )
521
531
return X509_V_ERR_EXCLUDED_VIOLATION ;
522
532
else if (r != X509_V_ERR_PERMITTED_VIOLATION )
@@ -528,15 +538,22 @@ static int nc_match(GENERAL_NAME *gen, NAME_CONSTRAINTS *nc)
528
538
529
539
}
530
540
531
- static int nc_match_single (GENERAL_NAME * gen , GENERAL_NAME * base )
541
+ static int nc_match_single (int effective_type , GENERAL_NAME * gen ,
542
+ GENERAL_NAME * base )
532
543
{
533
544
switch (gen -> type ) {
534
545
case GEN_OTHERNAME :
535
- /*
536
- * We are here only when we have SmtpUTF8 name,
537
- * so we match the value of othername with base->d.rfc822Name
538
- */
539
- return nc_email_eai (gen -> d .otherName -> value , base -> d .rfc822Name );
546
+ switch (effective_type ) {
547
+ case GEN_EMAIL :
548
+ /*
549
+ * We are here only when we have SmtpUTF8 name,
550
+ * so we match the value of othername with base->d.rfc822Name
551
+ */
552
+ return nc_email_eai (gen -> d .otherName -> value , base -> d .rfc822Name );
553
+
554
+ default :
555
+ return X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE ;
556
+ }
540
557
541
558
case GEN_DIRNAME :
542
559
return nc_dn (gen -> d .directoryName , base -> d .directoryName );
0 commit comments