|
22 | 22 | )
|
23 | 23 | from cryptography.utils import _check_byteslike
|
24 | 24 | from cryptography.x509 import Certificate
|
| 25 | +from cryptography.x509.oid import ExtendedKeyUsageOID |
25 | 26 | from cryptography.x509.verification import (
|
26 | 27 | Criticality,
|
27 | 28 | ExtensionPolicy,
|
@@ -83,14 +84,14 @@ def _validate_basic_constraints(
|
83 | 84 | def _validate_key_usage(
|
84 | 85 | policy: Policy, cert: Certificate, ku: x509.KeyUsage | None
|
85 | 86 | ) -> None:
|
86 |
| - if ku is not None: |
87 |
| - # Content commitment used to be named non repudiation |
88 |
| - if not (ku.digital_signature or ku.content_commitment): |
89 |
| - raise ValueError( |
90 |
| - "Key Usage, if specified, must have at least one of the " |
91 |
| - "digital signature or content commitment (formerly non " |
92 |
| - "repudiation) bits set." |
93 |
| - ) |
| 87 | + if ku is not None and not ( |
| 88 | + ku.digital_signature or ku.content_commitment |
| 89 | + ): |
| 90 | + raise ValueError( |
| 91 | + "Key Usage, if specified, must have at least one of the " |
| 92 | + "digital signature or content commitment (formerly non " |
| 93 | + "repudiation) bits set." |
| 94 | + ) |
94 | 95 |
|
95 | 96 | def _validate_subject_alternative_name(
|
96 | 97 | policy: Policy,
|
@@ -125,14 +126,15 @@ def _validate_subject_alternative_name(
|
125 | 126 | def _validate_extended_key_usage(
|
126 | 127 | policy: Policy, cert: Certificate, eku: x509.ExtendedKeyUsage | None
|
127 | 128 | ) -> None:
|
128 |
| - if eku is not None: |
129 |
| - ep = x509.ExtendedKeyUsageOID.EMAIL_PROTECTION in eku # type: ignore[attr-defined] |
130 |
| - aeku = x509.ExtendedKeyUsageOID.ANY_EXTENDED_KEY_USAGE in eku # type: ignore[attr-defined] |
131 |
| - if not (ep or aeku): |
132 |
| - raise ValueError( |
133 |
| - "Extended Key Usage, if specified, must include " |
134 |
| - "emailProtection or anyExtendedKeyUsage." |
135 |
| - ) |
| 129 | + if ( |
| 130 | + eku is not None |
| 131 | + and ExtendedKeyUsageOID.EMAIL_PROTECTION not in eku |
| 132 | + and ExtendedKeyUsageOID.ANY_EXTENDED_KEY_USAGE not in eku |
| 133 | + ): |
| 134 | + raise ValueError( |
| 135 | + "Extended Key Usage, if specified, must include " |
| 136 | + "emailProtection or anyExtendedKeyUsage." |
| 137 | + ) |
136 | 138 |
|
137 | 139 | ee_policy = (
|
138 | 140 | ExtensionPolicy.webpki_defaults_ee()
|
|
0 commit comments