Skip to content

Commit 0852630

Browse files
committed
Document the implemented part of custom verification.
1 parent adc39ba commit 0852630

File tree

2 files changed

+119
-3
lines changed

2 files changed

+119
-3
lines changed

docs/spelling_wordlist.txt

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ unencrypted
140140
unicode
141141
unpadded
142142
unpadding
143+
validator
143144
Ventura
144145
verifier
145146
Verifier

docs/x509/verification.rst

+118-3
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,22 @@ the root of trust:
111111

112112
.. versionadded:: 43.0.0
113113

114-
.. attribute:: subjects
114+
.. versionchanged:: 44.0.0
115+
Renamed `subjects` to :attr:`sans`.
116+
Made `sans` optional, added :attr:`subject`.
115117

116-
:type: list of :class:`~cryptography.x509.GeneralName`
118+
.. attribute:: subject
119+
120+
:type: :class:`~cryptography.x509.Name`
121+
122+
The subject presented in the verified client's certificate.
123+
124+
.. attribute:: sans
125+
126+
:type: list of :class:`~cryptography.x509.GeneralName` or None
117127

118128
The subjects presented in the verified client's Subject Alternative Name
119-
extension.
129+
extension or `None` if the extension is not present.
120130

121131
.. attribute:: chain
122132

@@ -129,6 +139,8 @@ the root of trust:
129139
.. class:: ClientVerifier
130140

131141
.. versionadded:: 43.0.0
142+
.. versionchanged:: 44.0.0
143+
Added :attr:`eku`.
132144

133145
A ClientVerifier verifies client certificates.
134146

@@ -156,6 +168,18 @@ the root of trust:
156168
:type: :class:`Store`
157169

158170
The verifier's trust store.
171+
172+
.. attribute:: eku
173+
174+
:type: :class:`~cryptography.x509.ObjectIdentifier` or None
175+
176+
The value of the Extended Key Usage extension required by this verifier
177+
If the verifier was built using :meth:`PolicyBuilder.build_client_verifier`,
178+
this will always be :attr:`~cryptography.x509.oid.ExtendedKeyUsageOID.CLIENT_AUTH`.
179+
180+
:note:
181+
See :meth:`CustomPolicyBuilder.eku` documentation for how verification is affected
182+
when changing the required EKU or using a custom extension policy.
159183

160184
.. method:: verify(leaf, intermediates)
161185

@@ -212,6 +236,18 @@ the root of trust:
212236

213237
The verifier's trust store.
214238

239+
.. attribute:: eku
240+
241+
:type: :class:`~cryptography.x509.ObjectIdentifier`
242+
243+
The value of the Extended Key Usage extension required by this verifier
244+
If the verifier was built using :meth:`PolicyBuilder.build_server_verifier`,
245+
this will always be :attr:`~cryptography.x509.oid.ExtendedKeyUsageOID.SERVER_AUTH`.
246+
247+
:note:
248+
See :meth:`CustomPolicyBuilder.eku` documentation for how verification is affected
249+
when changing the required EKU or using a custom extension policy.
250+
215251
.. method:: verify(leaf, intermediates)
216252

217253
Performs path validation on ``leaf``, returning a valid path
@@ -294,3 +330,82 @@ the root of trust:
294330
for server verification.
295331

296332
:returns: An instance of :class:`ClientVerifier`
333+
334+
.. class:: CustomPolicyBuilder
335+
336+
.. versionadded:: 44.0.0
337+
338+
A CustomPolicyBuilder provides a builder-style interface for constructing a
339+
Verifier, but provides additional control over the verification policy compared to :class:`PolicyBuilder`.
340+
341+
.. method:: time(new_time)
342+
343+
Sets the verifier's verification time.
344+
345+
If not called explicitly, this is set to :meth:`datetime.datetime.now`
346+
when :meth:`build_server_verifier` or :meth:`build_client_verifier`
347+
is called.
348+
349+
:param new_time: The :class:`datetime.datetime` to use in the verifier
350+
351+
:returns: A new instance of :class:`PolicyBuilder`
352+
353+
.. method:: store(new_store)
354+
355+
Sets the verifier's trust store.
356+
357+
:param new_store: The :class:`Store` to use in the verifier
358+
359+
:returns: A new instance of :class:`PolicyBuilder`
360+
361+
.. method:: max_chain_depth(new_max_chain_depth)
362+
363+
Sets the verifier's maximum chain building depth.
364+
365+
This depth behaves tracks the length of the intermediate CA
366+
chain: a maximum depth of zero means that the leaf must be directly
367+
issued by a member of the store, a depth of one means no more than
368+
one intermediate CA, and so forth. Note that self-issued intermediates
369+
don't count against the chain depth, per RFC 5280.
370+
371+
:param new_max_chain_depth: The maximum depth to allow in the verifier
372+
373+
:returns: A new instance of :class:`PolicyBuilder`
374+
375+
.. method:: eku(new_eku)
376+
377+
Sets the Extended Key Usage required by the verifier's policy.
378+
379+
If this method is not called, the EKU defaults to :attr:`~cryptography.x509.oid.ExtendedKeyUsageOID.SERVER_AUTH`
380+
if :meth:`build_server_verifier` is called, and :attr:`~cryptography.x509.oid.ExtendedKeyUsageOID.CLIENT_AUTH` if
381+
:meth:`build_client_verifier` is called.
382+
383+
When using the default extension policies, only certificates
384+
with the Extended Key Usage extension containing the specified value
385+
will be accepted. To accept more than one EKU or any EKU, use an extension policy
386+
with a custom validator. The EKU set via this method is accessible to custom extension validator
387+
callbacks via the `policy` argument.
388+
389+
:param ~cryptography.x509.ObjectIdentifier new_eku:
390+
391+
:returns: A new instance of :class:`PolicyBuilder`
392+
393+
.. method:: build_server_verifier(subject)
394+
395+
Builds a verifier for verifying server certificates.
396+
397+
:param subject: A :class:`Subject` to use in the verifier
398+
399+
:returns: An instance of :class:`ServerVerifier`
400+
401+
.. method:: build_client_verifier()
402+
403+
Builds a verifier for verifying client certificates.
404+
405+
.. warning::
406+
407+
This API is not suitable for website (i.e. server) certificate
408+
verification. You **must** use :meth:`build_server_verifier`
409+
for server verification.
410+
411+
:returns: An instance of :class:`ClientVerifier`

0 commit comments

Comments
 (0)