Debian Codegraph @

jedi/third_party/typeshed/stdlib/ssl.pyi

raw symbols SCIP
1 import enum
2 import socket
3 import sys
4 from _ssl import (
5 _DEFAULT_CIPHERS as _DEFAULT_CIPHERS,
6 _OPENSSL_API_VERSION as _OPENSSL_API_VERSION,
7 HAS_ALPN as HAS_ALPN,
8 HAS_ECDH as HAS_ECDH,
9 HAS_NPN as HAS_NPN,
10 HAS_SNI as HAS_SNI,
11 OPENSSL_VERSION as OPENSSL_VERSION,
12 OPENSSL_VERSION_INFO as OPENSSL_VERSION_INFO,
13 OPENSSL_VERSION_NUMBER as OPENSSL_VERSION_NUMBER,
14 HAS_SSLv2 as HAS_SSLv2,
15 HAS_SSLv3 as HAS_SSLv3,
16 HAS_TLSv1 as HAS_TLSv1,
17 HAS_TLSv1_1 as HAS_TLSv1_1,
18 HAS_TLSv1_2 as HAS_TLSv1_2,
19 HAS_TLSv1_3 as HAS_TLSv1_3,
20 MemoryBIO as MemoryBIO,
21 RAND_add as RAND_add,
22 RAND_bytes as RAND_bytes,
23 RAND_status as RAND_status,
24 SSLSession as SSLSession,
25 _PasswordType as _PasswordType, # typeshed only, but re-export for other type stubs to use
26 _SSLContext,
27 )
28 from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer
29 from collections.abc import Callable, Iterable
30 from typing import Any, Final, Literal, NamedTuple, TypedDict, overload, type_check_only
31 from typing_extensions import Never, Self, TypeAlias, deprecated
32
33 if sys.version_info >= (3, 13):
34 from _ssl import HAS_PSK as HAS_PSK
35
36 if sys.version_info >= (3, 14):
37 from _ssl import HAS_PHA as HAS_PHA
38
39 if sys.version_info < (3, 12):
40 from _ssl import RAND_pseudo_bytes as RAND_pseudo_bytes
41
42 if sys.version_info < (3, 10):
43 from _ssl import RAND_egd as RAND_egd
44
45 if sys.platform == "win32":
46 from _ssl import enum_certificates as enum_certificates, enum_crls as enum_crls
47
48 _PCTRTT: TypeAlias = tuple[tuple[str, str], ...]
49 _PCTRTTT: TypeAlias = tuple[_PCTRTT, ...]
50 _PeerCertRetDictType: TypeAlias = dict[str, str | _PCTRTTT | _PCTRTT]
51 _PeerCertRetType: TypeAlias = _PeerCertRetDictType | bytes | None
52 _SrvnmeCbType: TypeAlias = Callable[[SSLSocket | SSLObject, str | None, SSLSocket], int | None]
53
54 socket_error = OSError
55
56 @type_check_only
57 class _Cipher(TypedDict):
58 aead: bool
59 alg_bits: int
60 auth: str
61 description: str
62 digest: str | None
63 id: int
64 kea: str
65 name: str
66 protocol: str
67 strength_bits: int
68 symmetric: str
69
70 class SSLError(OSError):
71 library: str
72 reason: str
73
74 class SSLZeroReturnError(SSLError): ...
75 class SSLWantReadError(SSLError): ...
76 class SSLWantWriteError(SSLError): ...
77 class SSLSyscallError(SSLError): ...
78 class SSLEOFError(SSLError): ...
79
80 class SSLCertVerificationError(SSLError, ValueError):
81 verify_code: int
82 verify_message: str
83
84 CertificateError = SSLCertVerificationError
85
86 class DefaultVerifyPaths(NamedTuple):
87 cafile: str
88 capath: str
89 openssl_cafile_env: str
90 openssl_cafile: str
91 openssl_capath_env: str
92 openssl_capath: str
93
94 def get_default_verify_paths() -> DefaultVerifyPaths: ...
95
96 class VerifyMode(enum.IntEnum):
97 CERT_NONE = 0
98 CERT_OPTIONAL = 1
99 CERT_REQUIRED = 2
100
101 CERT_NONE: Final = VerifyMode.CERT_NONE
102 CERT_OPTIONAL: Final = VerifyMode.CERT_OPTIONAL
103 CERT_REQUIRED: Final = VerifyMode.CERT_REQUIRED
104
105 class VerifyFlags(enum.IntFlag):
106 VERIFY_DEFAULT = 0x00
107 VERIFY_CRL_CHECK_LEAF = 0x04
108 VERIFY_CRL_CHECK_CHAIN = 0x0C
109 VERIFY_X509_STRICT = 0x20
110 VERIFY_X509_TRUSTED_FIRST = 0x8000
111 if sys.version_info >= (3, 10):
112 VERIFY_ALLOW_PROXY_CERTS = 0x40
113 VERIFY_X509_PARTIAL_CHAIN = 0x80000
114
115 VERIFY_DEFAULT: Final = VerifyFlags.VERIFY_DEFAULT
116 VERIFY_CRL_CHECK_LEAF: Final = VerifyFlags.VERIFY_CRL_CHECK_LEAF
117 VERIFY_CRL_CHECK_CHAIN: Final = VerifyFlags.VERIFY_CRL_CHECK_CHAIN
118 VERIFY_X509_STRICT: Final = VerifyFlags.VERIFY_X509_STRICT
119 VERIFY_X509_TRUSTED_FIRST: Final = VerifyFlags.VERIFY_X509_TRUSTED_FIRST
120
121 if sys.version_info >= (3, 10):
122 VERIFY_ALLOW_PROXY_CERTS: Final = VerifyFlags.VERIFY_ALLOW_PROXY_CERTS
123 VERIFY_X509_PARTIAL_CHAIN: Final = VerifyFlags.VERIFY_X509_PARTIAL_CHAIN
124
125 class _SSLMethod(enum.IntEnum):
126 PROTOCOL_SSLv23 = 2
127 PROTOCOL_SSLv2 = ...
128 PROTOCOL_SSLv3 = ...
129 PROTOCOL_TLSv1 = 3
130 PROTOCOL_TLSv1_1 = 4
131 PROTOCOL_TLSv1_2 = 5
132 PROTOCOL_TLS = 2
133 PROTOCOL_TLS_CLIENT = 16
134 PROTOCOL_TLS_SERVER = 17
135
136 PROTOCOL_SSLv23: Final = _SSLMethod.PROTOCOL_SSLv23
137 PROTOCOL_SSLv2: Final = _SSLMethod.PROTOCOL_SSLv2
138 PROTOCOL_SSLv3: Final = _SSLMethod.PROTOCOL_SSLv3
139 PROTOCOL_TLSv1: Final = _SSLMethod.PROTOCOL_TLSv1
140 PROTOCOL_TLSv1_1: Final = _SSLMethod.PROTOCOL_TLSv1_1
141 PROTOCOL_TLSv1_2: Final = _SSLMethod.PROTOCOL_TLSv1_2
142 PROTOCOL_TLS: Final = _SSLMethod.PROTOCOL_TLS
143 PROTOCOL_TLS_CLIENT: Final = _SSLMethod.PROTOCOL_TLS_CLIENT
144 PROTOCOL_TLS_SERVER: Final = _SSLMethod.PROTOCOL_TLS_SERVER
145
146 class Options(enum.IntFlag):
147 OP_ALL: int
148 OP_NO_SSLv2 = 0
149 OP_NO_SSLv3 = 33554432
150 OP_NO_TLSv1 = 67108864
151 OP_NO_TLSv1_1 = 268435456
152 OP_NO_TLSv1_2 = 134217728
153 OP_NO_TLSv1_3 = 536870912
154 OP_CIPHER_SERVER_PREFERENCE = 4194304
155 OP_SINGLE_DH_USE = 0
156 OP_SINGLE_ECDH_USE = 0
157 OP_NO_COMPRESSION = 131072
158 OP_NO_TICKET = 16384
159 OP_NO_RENEGOTIATION = 1073741824
160 OP_ENABLE_MIDDLEBOX_COMPAT = 1048576
161 if sys.version_info >= (3, 12):
162 OP_LEGACY_SERVER_CONNECT = 4
163 OP_ENABLE_KTLS = 8
164 if sys.version_info >= (3, 11) or sys.platform == "linux":
165 OP_IGNORE_UNEXPECTED_EOF = 128
166
167 OP_ALL: Final = Options.OP_ALL
168 OP_NO_SSLv2: Final = Options.OP_NO_SSLv2
169 OP_NO_SSLv3: Final = Options.OP_NO_SSLv3
170 OP_NO_TLSv1: Final = Options.OP_NO_TLSv1
171 OP_NO_TLSv1_1: Final = Options.OP_NO_TLSv1_1
172 OP_NO_TLSv1_2: Final = Options.OP_NO_TLSv1_2
173 OP_NO_TLSv1_3: Final = Options.OP_NO_TLSv1_3
174 OP_CIPHER_SERVER_PREFERENCE: Final = Options.OP_CIPHER_SERVER_PREFERENCE
175 OP_SINGLE_DH_USE: Final = Options.OP_SINGLE_DH_USE
176 OP_SINGLE_ECDH_USE: Final = Options.OP_SINGLE_ECDH_USE
177 OP_NO_COMPRESSION: Final = Options.OP_NO_COMPRESSION
178 OP_NO_TICKET: Final = Options.OP_NO_TICKET
179 OP_NO_RENEGOTIATION: Final = Options.OP_NO_RENEGOTIATION
180 OP_ENABLE_MIDDLEBOX_COMPAT: Final = Options.OP_ENABLE_MIDDLEBOX_COMPAT
181 if sys.version_info >= (3, 12):
182 OP_LEGACY_SERVER_CONNECT: Final = Options.OP_LEGACY_SERVER_CONNECT
183 OP_ENABLE_KTLS: Final = Options.OP_ENABLE_KTLS
184 if sys.version_info >= (3, 11) or sys.platform == "linux":
185 OP_IGNORE_UNEXPECTED_EOF: Final = Options.OP_IGNORE_UNEXPECTED_EOF
186
187 HAS_NEVER_CHECK_COMMON_NAME: Final[bool]
188
189 CHANNEL_BINDING_TYPES: Final[list[str]]
190
191 class AlertDescription(enum.IntEnum):
192 ALERT_DESCRIPTION_ACCESS_DENIED = 49
193 ALERT_DESCRIPTION_BAD_CERTIFICATE = 42
194 ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE = 114
195 ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE = 113
196 ALERT_DESCRIPTION_BAD_RECORD_MAC = 20
197 ALERT_DESCRIPTION_CERTIFICATE_EXPIRED = 45
198 ALERT_DESCRIPTION_CERTIFICATE_REVOKED = 44
199 ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN = 46
200 ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE = 111
201 ALERT_DESCRIPTION_CLOSE_NOTIFY = 0
202 ALERT_DESCRIPTION_DECODE_ERROR = 50
203 ALERT_DESCRIPTION_DECOMPRESSION_FAILURE = 30
204 ALERT_DESCRIPTION_DECRYPT_ERROR = 51
205 ALERT_DESCRIPTION_HANDSHAKE_FAILURE = 40
206 ALERT_DESCRIPTION_ILLEGAL_PARAMETER = 47
207 ALERT_DESCRIPTION_INSUFFICIENT_SECURITY = 71
208 ALERT_DESCRIPTION_INTERNAL_ERROR = 80
209 ALERT_DESCRIPTION_NO_RENEGOTIATION = 100
210 ALERT_DESCRIPTION_PROTOCOL_VERSION = 70
211 ALERT_DESCRIPTION_RECORD_OVERFLOW = 22
212 ALERT_DESCRIPTION_UNEXPECTED_MESSAGE = 10
213 ALERT_DESCRIPTION_UNKNOWN_CA = 48
214 ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY = 115
215 ALERT_DESCRIPTION_UNRECOGNIZED_NAME = 112
216 ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE = 43
217 ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION = 110
218 ALERT_DESCRIPTION_USER_CANCELLED = 90
219
220 ALERT_DESCRIPTION_HANDSHAKE_FAILURE: Final = AlertDescription.ALERT_DESCRIPTION_HANDSHAKE_FAILURE
221 ALERT_DESCRIPTION_INTERNAL_ERROR: Final = AlertDescription.ALERT_DESCRIPTION_INTERNAL_ERROR
222 ALERT_DESCRIPTION_ACCESS_DENIED: Final = AlertDescription.ALERT_DESCRIPTION_ACCESS_DENIED
223 ALERT_DESCRIPTION_BAD_CERTIFICATE: Final = AlertDescription.ALERT_DESCRIPTION_BAD_CERTIFICATE
224 ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE: Final = AlertDescription.ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE
225 ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE: Final = AlertDescription.ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE
226 ALERT_DESCRIPTION_BAD_RECORD_MAC: Final = AlertDescription.ALERT_DESCRIPTION_BAD_RECORD_MAC
227 ALERT_DESCRIPTION_CERTIFICATE_EXPIRED: Final = AlertDescription.ALERT_DESCRIPTION_CERTIFICATE_EXPIRED
228 ALERT_DESCRIPTION_CERTIFICATE_REVOKED: Final = AlertDescription.ALERT_DESCRIPTION_CERTIFICATE_REVOKED
229 ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN: Final = AlertDescription.ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN
230 ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE: Final = AlertDescription.ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE
231 ALERT_DESCRIPTION_CLOSE_NOTIFY: Final = AlertDescription.ALERT_DESCRIPTION_CLOSE_NOTIFY
232 ALERT_DESCRIPTION_DECODE_ERROR: Final = AlertDescription.ALERT_DESCRIPTION_DECODE_ERROR
233 ALERT_DESCRIPTION_DECOMPRESSION_FAILURE: Final = AlertDescription.ALERT_DESCRIPTION_DECOMPRESSION_FAILURE
234 ALERT_DESCRIPTION_DECRYPT_ERROR: Final = AlertDescription.ALERT_DESCRIPTION_DECRYPT_ERROR
235 ALERT_DESCRIPTION_ILLEGAL_PARAMETER: Final = AlertDescription.ALERT_DESCRIPTION_ILLEGAL_PARAMETER
236 ALERT_DESCRIPTION_INSUFFICIENT_SECURITY: Final = AlertDescription.ALERT_DESCRIPTION_INSUFFICIENT_SECURITY
237 ALERT_DESCRIPTION_NO_RENEGOTIATION: Final = AlertDescription.ALERT_DESCRIPTION_NO_RENEGOTIATION
238 ALERT_DESCRIPTION_PROTOCOL_VERSION: Final = AlertDescription.ALERT_DESCRIPTION_PROTOCOL_VERSION
239 ALERT_DESCRIPTION_RECORD_OVERFLOW: Final = AlertDescription.ALERT_DESCRIPTION_RECORD_OVERFLOW
240 ALERT_DESCRIPTION_UNEXPECTED_MESSAGE: Final = AlertDescription.ALERT_DESCRIPTION_UNEXPECTED_MESSAGE
241 ALERT_DESCRIPTION_UNKNOWN_CA: Final = AlertDescription.ALERT_DESCRIPTION_UNKNOWN_CA
242 ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY: Final = AlertDescription.ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY
243 ALERT_DESCRIPTION_UNRECOGNIZED_NAME: Final = AlertDescription.ALERT_DESCRIPTION_UNRECOGNIZED_NAME
244 ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: Final = AlertDescription.ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE
245 ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: Final = AlertDescription.ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION
246 ALERT_DESCRIPTION_USER_CANCELLED: Final = AlertDescription.ALERT_DESCRIPTION_USER_CANCELLED
247
248 # This class is not exposed. It calls itself ssl._ASN1Object.
249 @type_check_only
250 class _ASN1ObjectBase(NamedTuple):
251 nid: int
252 shortname: str
253 longname: str
254 oid: str
255
256 class _ASN1Object(_ASN1ObjectBase):
257 def __new__(cls, oid: str) -> Self: ...
258 @classmethod
259 def fromnid(cls, nid: int) -> Self: ...
260 @classmethod
261 def fromname(cls, name: str) -> Self: ...
262
263 class Purpose(_ASN1Object, enum.Enum):
264 # Normally this class would inherit __new__ from _ASN1Object, but
265 # because this is an enum, the inherited __new__ is replaced at runtime with
266 # Enum.__new__.
267 def __new__(cls, value: object) -> Self: ...
268 SERVER_AUTH = (129, "serverAuth", "TLS Web Server Authentication", "1.3.6.1.5.5.7.3.2") # pyright: ignore[reportCallIssue]
269 CLIENT_AUTH = (130, "clientAuth", "TLS Web Client Authentication", "1.3.6.1.5.5.7.3.1") # pyright: ignore[reportCallIssue]
270
271 class SSLSocket(socket.socket):
272 context: SSLContext
273 server_side: bool
274 server_hostname: str | None
275 session: SSLSession | None
276 @property
277 def session_reused(self) -> bool | None: ...
278 def __init__(self, *args: Any, **kwargs: Any) -> None: ...
279 def connect(self, addr: socket._Address) -> None: ...
280 def connect_ex(self, addr: socket._Address) -> int: ...
281 def recv(self, buflen: int = 1024, flags: int = 0) -> bytes: ...
282 def recv_into(self, buffer: WriteableBuffer, nbytes: int | None = None, flags: int = 0) -> int: ...
283 def recvfrom(self, buflen: int = 1024, flags: int = 0) -> tuple[bytes, socket._RetAddress]: ...
284 def recvfrom_into(
285 self, buffer: WriteableBuffer, nbytes: int | None = None, flags: int = 0
286 ) -> tuple[int, socket._RetAddress]: ...
287 def send(self, data: ReadableBuffer, flags: int = 0) -> int: ...
288 def sendall(self, data: ReadableBuffer, flags: int = 0) -> None: ...
289 @overload
290 def sendto(self, data: ReadableBuffer, flags_or_addr: socket._Address, addr: None = None) -> int: ...
291 @overload
292 def sendto(self, data: ReadableBuffer, flags_or_addr: int, addr: socket._Address) -> int: ...
293 def shutdown(self, how: int) -> None: ...
294 @deprecated("Deprecated since Python 3.6. Use `SSLSocket.recv` method instead.")
295 def read(self, len: int = 1024, buffer: bytearray | None = None) -> bytes: ...
296 @deprecated("Deprecated since Python 3.6. Use `SSLSocket.send` method instead.")
297 def write(self, data: ReadableBuffer) -> int: ...
298 def do_handshake(self, block: bool = False) -> None: ... # block is undocumented
299 @overload
300 def getpeercert(self, binary_form: Literal[False] = False) -> _PeerCertRetDictType | None: ...
301 @overload
302 def getpeercert(self, binary_form: Literal[True]) -> bytes | None: ...
303 @overload
304 def getpeercert(self, binary_form: bool) -> _PeerCertRetType: ...
305 def cipher(self) -> tuple[str, str, int] | None: ...
306 def shared_ciphers(self) -> list[tuple[str, str, int]] | None: ...
307 def compression(self) -> str | None: ...
308 def get_channel_binding(self, cb_type: str = "tls-unique") -> bytes | None: ...
309 def selected_alpn_protocol(self) -> str | None: ...
310 if sys.version_info >= (3, 10):
311 @deprecated("Deprecated since Python 3.10. Use ALPN instead.")
312 def selected_npn_protocol(self) -> str | None: ...
313 else:
314 def selected_npn_protocol(self) -> str | None: ...
315
316 def accept(self) -> tuple[SSLSocket, socket._RetAddress]: ...
317 def unwrap(self) -> socket.socket: ...
318 def version(self) -> str | None: ...
319 def pending(self) -> int: ...
320 def verify_client_post_handshake(self) -> None: ...
321 # These methods always raise `NotImplementedError`:
322 def recvmsg(self, *args: Never, **kwargs: Never) -> Never: ... # type: ignore[override]
323 def recvmsg_into(self, *args: Never, **kwargs: Never) -> Never: ... # type: ignore[override]
324 def sendmsg(self, *args: Never, **kwargs: Never) -> Never: ... # type: ignore[override]
325 if sys.version_info >= (3, 13):
326 def get_verified_chain(self) -> list[bytes]: ...
327 def get_unverified_chain(self) -> list[bytes]: ...
328
329 if sys.version_info < (3, 12):
330 @deprecated("Deprecated since Python 3.7; removed in Python 3.12. Use `SSLContext.wrap_socket()` instead.")
331 def wrap_socket(
332 sock: socket.socket,
333 keyfile: StrOrBytesPath | None = None,
334 certfile: StrOrBytesPath | None = None,
335 server_side: bool = False,
336 cert_reqs: int = VerifyMode.CERT_NONE,
337 ssl_version: int = _SSLMethod.PROTOCOL_TLS,
338 ca_certs: str | None = None,
339 do_handshake_on_connect: bool = True,
340 suppress_ragged_eofs: bool = True,
341 ciphers: str | None = None,
342 ) -> SSLSocket: ...
343 @deprecated("Deprecated since Python 3.7; removed in Python 3.12.")
344 def match_hostname(cert: _PeerCertRetDictType, hostname: str) -> None: ...
345
346 def cert_time_to_seconds(cert_time: str) -> int: ...
347 def DER_cert_to_PEM_cert(der_cert_bytes: ReadableBuffer) -> str: ...
348 def PEM_cert_to_DER_cert(pem_cert_string: str) -> bytes: ...
349
350 if sys.version_info >= (3, 10):
351 def get_server_certificate(
352 addr: tuple[str, int],
353 ssl_version: int = _SSLMethod.PROTOCOL_TLS_CLIENT,
354 ca_certs: str | None = None,
355 timeout: float = ...,
356 ) -> str: ...
357
358 else:
359 def get_server_certificate(
360 addr: tuple[str, int], ssl_version: int = _SSLMethod.PROTOCOL_TLS_CLIENT, ca_certs: str | None = None
361 ) -> str: ...
362
363 class TLSVersion(enum.IntEnum):
364 MINIMUM_SUPPORTED = -2
365 MAXIMUM_SUPPORTED = -1
366 SSLv3 = 768
367 TLSv1 = 769
368 TLSv1_1 = 770
369 TLSv1_2 = 771
370 TLSv1_3 = 772
371
372 class SSLContext(_SSLContext):
373 options: Options
374 verify_flags: VerifyFlags
375 verify_mode: VerifyMode
376 @property
377 def protocol(self) -> _SSLMethod: ... # type: ignore[override]
378 hostname_checks_common_name: bool
379 maximum_version: TLSVersion
380 minimum_version: TLSVersion
381 # The following two attributes have class-level defaults.
382 # However, the docs explicitly state that it's OK to override these attributes on instances,
383 # so making these ClassVars wouldn't be appropriate
384 sslobject_class: type[SSLObject]
385 sslsocket_class: type[SSLSocket]
386 keylog_filename: str
387 post_handshake_auth: bool
388 if sys.version_info >= (3, 10):
389 security_level: int
390 if sys.version_info >= (3, 10):
391 @overload
392 def __new__(cls, protocol: int, *args: Any, **kwargs: Any) -> Self: ...
393 @overload
394 @deprecated("Deprecated since Python 3.10. Use a specific version of the SSL protocol.")
395 def __new__(cls, protocol: None = None, *args: Any, **kwargs: Any) -> Self: ...
396 else:
397 def __new__(cls, protocol: int = ..., *args: Any, **kwargs: Any) -> Self: ...
398
399 def load_default_certs(self, purpose: Purpose = Purpose.SERVER_AUTH) -> None: ...
400 def load_verify_locations(
401 self,
402 cafile: StrOrBytesPath | None = None,
403 capath: StrOrBytesPath | None = None,
404 cadata: str | ReadableBuffer | None = None,
405 ) -> None: ...
406 @overload
407 def get_ca_certs(self, binary_form: Literal[False] = False) -> list[_PeerCertRetDictType]: ...
408 @overload
409 def get_ca_certs(self, binary_form: Literal[True]) -> list[bytes]: ...
410 @overload
411 def get_ca_certs(self, binary_form: bool = False) -> Any: ...
412 def get_ciphers(self) -> list[_Cipher]: ...
413 def set_default_verify_paths(self) -> None: ...
414 def set_ciphers(self, cipherlist: str, /) -> None: ...
415 def set_alpn_protocols(self, alpn_protocols: Iterable[str]) -> None: ...
416 if sys.version_info >= (3, 10):
417 @deprecated("Deprecated since Python 3.10. Use ALPN instead.")
418 def set_npn_protocols(self, npn_protocols: Iterable[str]) -> None: ...
419 else:
420 def set_npn_protocols(self, npn_protocols: Iterable[str]) -> None: ...
421
422 def set_servername_callback(self, server_name_callback: _SrvnmeCbType | None) -> None: ...
423 def load_dh_params(self, path: str, /) -> None: ...
424 def set_ecdh_curve(self, name: str, /) -> None: ...
425 def wrap_socket(
426 self,
427 sock: socket.socket,
428 server_side: bool = False,
429 do_handshake_on_connect: bool = True,
430 suppress_ragged_eofs: bool = True,
431 server_hostname: str | bytes | None = None,
432 session: SSLSession | None = None,
433 ) -> SSLSocket: ...
434 def wrap_bio(
435 self,
436 incoming: MemoryBIO,
437 outgoing: MemoryBIO,
438 server_side: bool = False,
439 server_hostname: str | bytes | None = None,
440 session: SSLSession | None = None,
441 ) -> SSLObject: ...
442
443 def create_default_context(
444 purpose: Purpose = Purpose.SERVER_AUTH,
445 *,
446 cafile: StrOrBytesPath | None = None,
447 capath: StrOrBytesPath | None = None,
448 cadata: str | ReadableBuffer | None = None,
449 ) -> SSLContext: ...
450
451 if sys.version_info >= (3, 10):
452 def _create_unverified_context(
453 protocol: int | None = None,
454 *,
455 cert_reqs: int = VerifyMode.CERT_NONE,
456 check_hostname: bool = False,
457 purpose: Purpose = Purpose.SERVER_AUTH,
458 certfile: StrOrBytesPath | None = None,
459 keyfile: StrOrBytesPath | None = None,
460 cafile: StrOrBytesPath | None = None,
461 capath: StrOrBytesPath | None = None,
462 cadata: str | ReadableBuffer | None = None,
463 ) -> SSLContext: ...
464
465 else:
466 def _create_unverified_context(
467 protocol: int = ...,
468 *,
469 cert_reqs: int = VerifyMode.CERT_NONE,
470 check_hostname: bool = False,
471 purpose: Purpose = Purpose.SERVER_AUTH,
472 certfile: StrOrBytesPath | None = None,
473 keyfile: StrOrBytesPath | None = None,
474 cafile: StrOrBytesPath | None = None,
475 capath: StrOrBytesPath | None = None,
476 cadata: str | ReadableBuffer | None = None,
477 ) -> SSLContext: ...
478
479 _create_default_https_context = create_default_context
480
481 class SSLObject:
482 context: SSLContext
483 @property
484 def server_side(self) -> bool: ...
485 @property
486 def server_hostname(self) -> str | None: ...
487 session: SSLSession | None
488 @property
489 def session_reused(self) -> bool: ...
490 def __init__(self, *args: Any, **kwargs: Any) -> None: ...
491 def read(self, len: int = 1024, buffer: bytearray | None = None) -> bytes: ...
492 def write(self, data: ReadableBuffer) -> int: ...
493 @overload
494 def getpeercert(self, binary_form: Literal[False] = False) -> _PeerCertRetDictType | None: ...
495 @overload
496 def getpeercert(self, binary_form: Literal[True]) -> bytes | None: ...
497 @overload
498 def getpeercert(self, binary_form: bool) -> _PeerCertRetType: ...
499 def selected_alpn_protocol(self) -> str | None: ...
500 if sys.version_info >= (3, 10):
501 @deprecated("Deprecated since Python 3.10. Use ALPN instead.")
502 def selected_npn_protocol(self) -> str | None: ...
503 else:
504 def selected_npn_protocol(self) -> str | None: ...
505
506 def cipher(self) -> tuple[str, str, int] | None: ...
507 def shared_ciphers(self) -> list[tuple[str, str, int]] | None: ...
508 def compression(self) -> str | None: ...
509 def pending(self) -> int: ...
510 def do_handshake(self) -> None: ...
511 def unwrap(self) -> None: ...
512 def version(self) -> str | None: ...
513 def get_channel_binding(self, cb_type: str = "tls-unique") -> bytes | None: ...
514 def verify_client_post_handshake(self) -> None: ...
515 if sys.version_info >= (3, 13):
516 def get_verified_chain(self) -> list[bytes]: ...
517 def get_unverified_chain(self) -> list[bytes]: ...
518
519 class SSLErrorNumber(enum.IntEnum):
520 SSL_ERROR_EOF = 8
521 SSL_ERROR_INVALID_ERROR_CODE = 10
522 SSL_ERROR_SSL = 1
523 SSL_ERROR_SYSCALL = 5
524 SSL_ERROR_WANT_CONNECT = 7
525 SSL_ERROR_WANT_READ = 2
526 SSL_ERROR_WANT_WRITE = 3
527 SSL_ERROR_WANT_X509_LOOKUP = 4
528 SSL_ERROR_ZERO_RETURN = 6
529
530 SSL_ERROR_EOF: Final = SSLErrorNumber.SSL_ERROR_EOF # undocumented
531 SSL_ERROR_INVALID_ERROR_CODE: Final = SSLErrorNumber.SSL_ERROR_INVALID_ERROR_CODE # undocumented
532 SSL_ERROR_SSL: Final = SSLErrorNumber.SSL_ERROR_SSL # undocumented
533 SSL_ERROR_SYSCALL: Final = SSLErrorNumber.SSL_ERROR_SYSCALL # undocumented
534 SSL_ERROR_WANT_CONNECT: Final = SSLErrorNumber.SSL_ERROR_WANT_CONNECT # undocumented
535 SSL_ERROR_WANT_READ: Final = SSLErrorNumber.SSL_ERROR_WANT_READ # undocumented
536 SSL_ERROR_WANT_WRITE: Final = SSLErrorNumber.SSL_ERROR_WANT_WRITE # undocumented
537 SSL_ERROR_WANT_X509_LOOKUP: Final = SSLErrorNumber.SSL_ERROR_WANT_X509_LOOKUP # undocumented
538 SSL_ERROR_ZERO_RETURN: Final = SSLErrorNumber.SSL_ERROR_ZERO_RETURN # undocumented
539
540 def get_protocol_name(protocol_code: int) -> str: ...
541
542 PEM_FOOTER: Final[str]
543 PEM_HEADER: Final[str]
544 SOCK_STREAM: Final = socket.SOCK_STREAM
545 SOL_SOCKET: Final = socket.SOL_SOCKET
546 SO_TYPE: Final = socket.SO_TYPE