@@ -500,7 +500,7 @@ int x509v3_cache_extensions(X509 *x) {
500
500
x -> ex_flags |= EXFLAG_SI ;
501
501
// If SKID matches AKID also indicate self signed
502
502
if (X509_check_akid (x , x -> akid ) == X509_V_OK &&
503
- !ku_reject (x , KU_KEY_CERT_SIGN )) {
503
+ !ku_reject (x , X509v3_KU_KEY_CERT_SIGN )) {
504
504
x -> ex_flags |= EXFLAG_SS ;
505
505
}
506
506
}
@@ -539,7 +539,7 @@ int x509v3_cache_extensions(X509 *x) {
539
539
// otherwise.
540
540
static int check_ca (const X509 * x ) {
541
541
// keyUsage if present should allow cert signing
542
- if (ku_reject (x , KU_KEY_CERT_SIGN )) {
542
+ if (ku_reject (x , X509v3_KU_KEY_CERT_SIGN )) {
543
543
return 0 ;
544
544
}
545
545
// Version 1 certificates are considered CAs and don't have extensions.
@@ -566,7 +566,7 @@ static int check_purpose_ssl_client(const X509_PURPOSE *xp, const X509 *x,
566
566
return check_ca (x );
567
567
}
568
568
// We need to do digital signatures or key agreement
569
- if (ku_reject (x , KU_DIGITAL_SIGNATURE | KU_KEY_AGREEMENT )) {
569
+ if (ku_reject (x , X509v3_KU_DIGITAL_SIGNATURE | X509v3_KU_KEY_AGREEMENT )) {
570
570
return 0 ;
571
571
}
572
572
// nsCertType if present should allow SSL client use
@@ -579,7 +579,9 @@ static int check_purpose_ssl_client(const X509_PURPOSE *xp, const X509 *x,
579
579
// Key usage needed for TLS/SSL server: digital signature, encipherment or
580
580
// key agreement. The ssl code can check this more thoroughly for individual
581
581
// key types.
582
- #define KU_TLS (KU_DIGITAL_SIGNATURE | KU_KEY_ENCIPHERMENT | KU_KEY_AGREEMENT)
582
+ #define X509v3_KU_TLS \
583
+ (X509v3_KU_DIGITAL_SIGNATURE | X509v3_KU_KEY_ENCIPHERMENT | \
584
+ X509v3_KU_KEY_AGREEMENT)
583
585
584
586
static int check_purpose_ssl_server (const X509_PURPOSE * xp , const X509 * x ,
585
587
int ca ) {
@@ -593,7 +595,7 @@ static int check_purpose_ssl_server(const X509_PURPOSE *xp, const X509 *x,
593
595
if (ns_reject (x , NS_SSL_SERVER )) {
594
596
return 0 ;
595
597
}
596
- if (ku_reject (x , KU_TLS )) {
598
+ if (ku_reject (x , X509v3_KU_TLS )) {
597
599
return 0 ;
598
600
}
599
601
@@ -608,7 +610,7 @@ static int check_purpose_ns_ssl_server(const X509_PURPOSE *xp, const X509 *x,
608
610
return ret ;
609
611
}
610
612
// We need to encipher or Netscape complains
611
- if (ku_reject (x , KU_KEY_ENCIPHERMENT )) {
613
+ if (ku_reject (x , X509v3_KU_KEY_ENCIPHERMENT )) {
612
614
return 0 ;
613
615
}
614
616
return ret ;
@@ -641,7 +643,7 @@ static int check_purpose_smime_sign(const X509_PURPOSE *xp, const X509 *x,
641
643
if (!ret || ca ) {
642
644
return ret ;
643
645
}
644
- if (ku_reject (x , KU_DIGITAL_SIGNATURE | KU_NON_REPUDIATION )) {
646
+ if (ku_reject (x , X509v3_KU_DIGITAL_SIGNATURE | X509v3_KU_NON_REPUDIATION )) {
645
647
return 0 ;
646
648
}
647
649
return ret ;
@@ -654,7 +656,7 @@ static int check_purpose_smime_encrypt(const X509_PURPOSE *xp, const X509 *x,
654
656
if (!ret || ca ) {
655
657
return ret ;
656
658
}
657
- if (ku_reject (x , KU_KEY_ENCIPHERMENT )) {
659
+ if (ku_reject (x , X509v3_KU_KEY_ENCIPHERMENT )) {
658
660
return 0 ;
659
661
}
660
662
return ret ;
@@ -665,7 +667,7 @@ static int check_purpose_crl_sign(const X509_PURPOSE *xp, const X509 *x,
665
667
if (ca ) {
666
668
return check_ca (x );
667
669
}
668
- if (ku_reject (x , KU_CRL_SIGN )) {
670
+ if (ku_reject (x , X509v3_KU_CRL_SIGN )) {
669
671
return 0 ;
670
672
}
671
673
return 1 ;
@@ -696,8 +698,10 @@ static int check_purpose_timestamp_sign(const X509_PURPOSE *xp, const X509 *x,
696
698
// and/or nonRepudiation (other values are not consistent and shall
697
699
// be rejected).
698
700
if ((x -> ex_flags & EXFLAG_KUSAGE ) &&
699
- ((x -> ex_kusage & ~(KU_NON_REPUDIATION | KU_DIGITAL_SIGNATURE )) ||
700
- !(x -> ex_kusage & (KU_NON_REPUDIATION | KU_DIGITAL_SIGNATURE )))) {
701
+ ((x -> ex_kusage &
702
+ ~(X509v3_KU_NON_REPUDIATION | X509v3_KU_DIGITAL_SIGNATURE )) ||
703
+ !(x -> ex_kusage &
704
+ (X509v3_KU_NON_REPUDIATION | X509v3_KU_DIGITAL_SIGNATURE )))) {
701
705
return 0 ;
702
706
}
703
707
@@ -744,7 +748,7 @@ int X509_check_issued(X509 *issuer, X509 *subject) {
744
748
}
745
749
}
746
750
747
- if (ku_reject (issuer , KU_KEY_CERT_SIGN )) {
751
+ if (ku_reject (issuer , X509v3_KU_KEY_CERT_SIGN )) {
748
752
return X509_V_ERR_KEYUSAGE_NO_CERTSIGN ;
749
753
}
750
754
return X509_V_OK ;
@@ -803,6 +807,9 @@ uint32_t X509_get_key_usage(X509 *x) {
803
807
if (x -> ex_flags & EXFLAG_KUSAGE ) {
804
808
return x -> ex_kusage ;
805
809
}
810
+ // If there is no extension, key usage is unconstrained, so set all bits to
811
+ // one. Note that, although we use |UINT32_MAX|, |ex_kusage| only contains the
812
+ // first 16 bits when the extension is present.
806
813
return UINT32_MAX ;
807
814
}
808
815
@@ -813,6 +820,8 @@ uint32_t X509_get_extended_key_usage(X509 *x) {
813
820
if (x -> ex_flags & EXFLAG_XKUSAGE ) {
814
821
return x -> ex_xkusage ;
815
822
}
823
+ // If there is no extension, extended key usage is unconstrained, so set all
824
+ // bits to one.
816
825
return UINT32_MAX ;
817
826
}
818
827
0 commit comments