@@ -71,30 +71,68 @@ def pkcs7_x509_extension_policies() -> tuple[ExtensionPolicy, ExtensionPolicy]:
71
71
"""
72
72
73
73
# CA policy - TODO: is there any?
74
- ca_policy = ExtensionPolicy .permit_all ()
74
+ ca_policy = ExtensionPolicy .webpki_defaults_ca ()
75
75
76
76
# EE policy
77
- def _validate_eku (
78
- policy : Policy , cert : Certificate , eku : x509 .ExtendedKeyUsage
79
- ):
80
- assert x509 .ExtendedKeyUsageOID .EMAIL_PROTECTION in eku # type: ignore[attr-defined]
81
-
82
- def _validate_ca (
83
- policy : Policy , cert : Certificate , bc : x509 .BasicConstraints
84
- ):
85
- assert not bc .ca
77
+ def _validate_basic_constraints (
78
+ policy : Policy , cert : Certificate , bc : x509 .BasicConstraints | None
79
+ ) -> None :
80
+ if bc is not None and bc .ca :
81
+ raise ValueError ("Basic Constraints CA must be False." )
82
+
83
+ def _validate_key_usage (
84
+ policy : Policy , cert : Certificate , ku : x509 .KeyUsage | None
85
+ ) -> 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
+ )
94
+
95
+ def _validate_subject_alternative_name (
96
+ policy : Policy ,
97
+ cert : Certificate ,
98
+ san : x509 .SubjectAlternativeName | None ,
99
+ ) -> None :
100
+ if san is not None :
101
+ pass
102
+
103
+ def _validate_extended_key_usage (
104
+ policy : Policy , cert : Certificate , eku : x509 .ExtendedKeyUsage | None
105
+ ) -> None :
106
+ if eku is not None :
107
+ ep = x509 .ExtendedKeyUsageOID .EMAIL_PROTECTION in eku # type: ignore[attr-defined]
108
+ aeku = x509 .ExtendedKeyUsageOID .ANY_EXTENDED_KEY_USAGE in eku # type: ignore[attr-defined]
109
+ if not (ep or aeku ):
110
+ raise ValueError (
111
+ "Extended Key Usage, if specified, must include "
112
+ "emailProtection or anyExtendedKeyUsage"
113
+ )
86
114
87
115
ee_policy = (
88
116
ExtensionPolicy .permit_all ()
89
- .require_present (
90
- x509 .ExtendedKeyUsage ,
117
+ .may_be_present (
118
+ x509 .BasicConstraints ,
91
119
Criticality .AGNOSTIC ,
92
- _validate_eku ,
120
+ _validate_basic_constraints ,
93
121
)
94
122
.may_be_present (
95
- x509 .BasicConstraints ,
123
+ x509 .KeyUsage ,
124
+ Criticality .CRITICAL ,
125
+ _validate_key_usage ,
126
+ )
127
+ .may_be_present (
128
+ x509 .SubjectAlternativeName ,
129
+ Criticality .AGNOSTIC ,
130
+ _validate_subject_alternative_name ,
131
+ )
132
+ .may_be_present (
133
+ x509 .ExtendedKeyUsage ,
96
134
Criticality .AGNOSTIC ,
97
- _validate_ca ,
135
+ _validate_extended_key_usage ,
98
136
)
99
137
)
100
138
0 commit comments