massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / ssl.pyi
1 import enum
2 import socket
3 import sys
4 from _typeshed import ReadableBuffer, Self, StrOrBytesPath, WriteableBuffer
5 from typing import Any, Callable, ClassVar, Dict, Iterable, List, NamedTuple, Optional, Set, Tuple, Type, Union, overload
6 from typing_extensions import Literal, TypedDict
7
8 _PCTRTT = Tuple[Tuple[str, str], ...]
9 _PCTRTTT = Tuple[_PCTRTT, ...]
10 _PeerCertRetDictType = Dict[str, Union[str, _PCTRTTT, _PCTRTT]]
11 _PeerCertRetType = Union[_PeerCertRetDictType, bytes, None]
12 _EnumRetType = List[Tuple[bytes, str, Union[Set[str], bool]]]
13 _PasswordType = Union[Callable[[], Union[str, bytes]], str, bytes]
14
15 _SrvnmeCbType = Callable[[Union[SSLSocket, SSLObject], Optional[str], SSLSocket], Optional[int]]
16
17 class _Cipher(TypedDict):
18     aead: bool
19     alg_bits: int
20     auth: str
21     description: str
22     digest: str | None
23     id: int
24     kea: str
25     name: str
26     protocol: str
27     strength_bits: int
28     symmetric: str
29
30 class SSLError(OSError):
31     library: str
32     reason: str
33
34 class SSLZeroReturnError(SSLError): ...
35 class SSLWantReadError(SSLError): ...
36 class SSLWantWriteError(SSLError): ...
37 class SSLSyscallError(SSLError): ...
38 class SSLEOFError(SSLError): ...
39
40 if sys.version_info >= (3, 7):
41     class SSLCertVerificationError(SSLError, ValueError):
42         verify_code: int
43         verify_message: str
44     CertificateError = SSLCertVerificationError
45 else:
46     class CertificateError(ValueError): ...
47
48 def wrap_socket(
49     sock: socket.socket,
50     keyfile: StrOrBytesPath | None = ...,
51     certfile: StrOrBytesPath | None = ...,
52     server_side: bool = ...,
53     cert_reqs: int = ...,
54     ssl_version: int = ...,
55     ca_certs: str | None = ...,
56     do_handshake_on_connect: bool = ...,
57     suppress_ragged_eofs: bool = ...,
58     ciphers: str | None = ...,
59 ) -> SSLSocket: ...
60 def create_default_context(
61     purpose: Purpose = ...,
62     *,
63     cafile: StrOrBytesPath | None = ...,
64     capath: StrOrBytesPath | None = ...,
65     cadata: str | bytes | None = ...,
66 ) -> SSLContext: ...
67
68 if sys.version_info >= (3, 7):
69     def _create_unverified_context(
70         protocol: int = ...,
71         *,
72         cert_reqs: int = ...,
73         check_hostname: bool = ...,
74         purpose: Purpose = ...,
75         certfile: StrOrBytesPath | None = ...,
76         keyfile: StrOrBytesPath | None = ...,
77         cafile: StrOrBytesPath | None = ...,
78         capath: StrOrBytesPath | None = ...,
79         cadata: str | bytes | None = ...,
80     ) -> SSLContext: ...
81
82 else:
83     def _create_unverified_context(
84         protocol: int = ...,
85         *,
86         cert_reqs: int | None = ...,
87         check_hostname: bool = ...,
88         purpose: Purpose = ...,
89         certfile: StrOrBytesPath | None = ...,
90         keyfile: StrOrBytesPath | None = ...,
91         cafile: StrOrBytesPath | None = ...,
92         capath: StrOrBytesPath | None = ...,
93         cadata: str | bytes | None = ...,
94     ) -> SSLContext: ...
95
96 _create_default_https_context: Callable[..., SSLContext]
97
98 def RAND_bytes(__num: int) -> bytes: ...
99 def RAND_pseudo_bytes(__num: int) -> tuple[bytes, bool]: ...
100 def RAND_status() -> bool: ...
101 def RAND_egd(path: str) -> None: ...
102 def RAND_add(__s: bytes, __entropy: float) -> None: ...
103 def match_hostname(cert: _PeerCertRetType, hostname: str) -> None: ...
104 def cert_time_to_seconds(cert_time: str) -> int: ...
105 def get_server_certificate(addr: tuple[str, int], ssl_version: int = ..., ca_certs: str | None = ...) -> str: ...
106 def DER_cert_to_PEM_cert(der_cert_bytes: bytes) -> str: ...
107 def PEM_cert_to_DER_cert(pem_cert_string: str) -> bytes: ...
108
109 class DefaultVerifyPaths(NamedTuple):
110     cafile: str
111     capath: str
112     openssl_cafile_env: str
113     openssl_cafile: str
114     openssl_capath_env: str
115     openssl_capath: str
116
117 def get_default_verify_paths() -> DefaultVerifyPaths: ...
118
119 if sys.platform == "win32":
120     def enum_certificates(store_name: str) -> _EnumRetType: ...
121     def enum_crls(store_name: str) -> _EnumRetType: ...
122
123 class VerifyMode(enum.IntEnum):
124     CERT_NONE: int
125     CERT_OPTIONAL: int
126     CERT_REQUIRED: int
127
128 CERT_NONE: VerifyMode
129 CERT_OPTIONAL: VerifyMode
130 CERT_REQUIRED: VerifyMode
131
132 class VerifyFlags(enum.IntFlag):
133     VERIFY_DEFAULT: int
134     VERIFY_CRL_CHECK_LEAF: int
135     VERIFY_CRL_CHECK_CHAIN: int
136     VERIFY_X509_STRICT: int
137     VERIFY_X509_TRUSTED_FIRST: int
138
139 VERIFY_DEFAULT: VerifyFlags
140 VERIFY_CRL_CHECK_LEAF: VerifyFlags
141 VERIFY_CRL_CHECK_CHAIN: VerifyFlags
142 VERIFY_X509_STRICT: VerifyFlags
143 VERIFY_X509_TRUSTED_FIRST: VerifyFlags
144
145 class _SSLMethod(enum.IntEnum):
146     PROTOCOL_SSLv23: int
147     PROTOCOL_SSLv2: int
148     PROTOCOL_SSLv3: int
149     PROTOCOL_TLSv1: int
150     PROTOCOL_TLSv1_1: int
151     PROTOCOL_TLSv1_2: int
152     PROTOCOL_TLS: int
153     PROTOCOL_TLS_CLIENT: int
154     PROTOCOL_TLS_SERVER: int
155
156 PROTOCOL_SSLv23: _SSLMethod
157 PROTOCOL_SSLv2: _SSLMethod
158 PROTOCOL_SSLv3: _SSLMethod
159 PROTOCOL_TLSv1: _SSLMethod
160 PROTOCOL_TLSv1_1: _SSLMethod
161 PROTOCOL_TLSv1_2: _SSLMethod
162 PROTOCOL_TLS: _SSLMethod
163 PROTOCOL_TLS_CLIENT: _SSLMethod
164 PROTOCOL_TLS_SERVER: _SSLMethod
165
166 class Options(enum.IntFlag):
167     OP_ALL: int
168     OP_NO_SSLv2: int
169     OP_NO_SSLv3: int
170     OP_NO_TLSv1: int
171     OP_NO_TLSv1_1: int
172     OP_NO_TLSv1_2: int
173     OP_NO_TLSv1_3: int
174     OP_CIPHER_SERVER_PREFERENCE: int
175     OP_SINGLE_DH_USE: int
176     OP_SINGLE_ECDH_USE: int
177     OP_NO_COMPRESSION: int
178     OP_NO_TICKET: int
179     if sys.version_info >= (3, 7):
180         OP_NO_RENEGOTIATION: int
181     if sys.version_info >= (3, 8):
182         OP_ENABLE_MIDDLEBOX_COMPAT: int
183
184 OP_ALL: Options
185 OP_NO_SSLv2: Options
186 OP_NO_SSLv3: Options
187 OP_NO_TLSv1: Options
188 OP_NO_TLSv1_1: Options
189 OP_NO_TLSv1_2: Options
190 OP_NO_TLSv1_3: Options
191 OP_CIPHER_SERVER_PREFERENCE: Options
192 OP_SINGLE_DH_USE: Options
193 OP_SINGLE_ECDH_USE: Options
194 OP_NO_COMPRESSION: Options
195 OP_NO_TICKET: Options
196 if sys.version_info >= (3, 7):
197     OP_NO_RENEGOTIATION: Options
198 if sys.version_info >= (3, 8):
199     OP_ENABLE_MIDDLEBOX_COMPAT: Options
200
201 if sys.version_info >= (3, 7):
202     HAS_NEVER_CHECK_COMMON_NAME: bool
203     HAS_SSLv2: bool
204     HAS_SSLv3: bool
205     HAS_TLSv1: bool
206     HAS_TLSv1_1: bool
207     HAS_TLSv1_2: bool
208     HAS_TLSv1_3: bool
209 HAS_ALPN: bool
210 HAS_ECDH: bool
211 HAS_SNI: bool
212 HAS_NPN: bool
213 CHANNEL_BINDING_TYPES: list[str]
214
215 OPENSSL_VERSION: str
216 OPENSSL_VERSION_INFO: tuple[int, int, int, int, int]
217 OPENSSL_VERSION_NUMBER: int
218
219 class AlertDescription(enum.IntEnum):
220     ALERT_DESCRIPTION_ACCESS_DENIED: int
221     ALERT_DESCRIPTION_BAD_CERTIFICATE: int
222     ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE: int
223     ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE: int
224     ALERT_DESCRIPTION_BAD_RECORD_MAC: int
225     ALERT_DESCRIPTION_CERTIFICATE_EXPIRED: int
226     ALERT_DESCRIPTION_CERTIFICATE_REVOKED: int
227     ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN: int
228     ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE: int
229     ALERT_DESCRIPTION_CLOSE_NOTIFY: int
230     ALERT_DESCRIPTION_DECODE_ERROR: int
231     ALERT_DESCRIPTION_DECOMPRESSION_FAILURE: int
232     ALERT_DESCRIPTION_DECRYPT_ERROR: int
233     ALERT_DESCRIPTION_HANDSHAKE_FAILURE: int
234     ALERT_DESCRIPTION_ILLEGAL_PARAMETER: int
235     ALERT_DESCRIPTION_INSUFFICIENT_SECURITY: int
236     ALERT_DESCRIPTION_INTERNAL_ERROR: int
237     ALERT_DESCRIPTION_NO_RENEGOTIATION: int
238     ALERT_DESCRIPTION_PROTOCOL_VERSION: int
239     ALERT_DESCRIPTION_RECORD_OVERFLOW: int
240     ALERT_DESCRIPTION_UNEXPECTED_MESSAGE: int
241     ALERT_DESCRIPTION_UNKNOWN_CA: int
242     ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY: int
243     ALERT_DESCRIPTION_UNRECOGNIZED_NAME: int
244     ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: int
245     ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: int
246     ALERT_DESCRIPTION_USER_CANCELLED: int
247
248 ALERT_DESCRIPTION_HANDSHAKE_FAILURE: AlertDescription
249 ALERT_DESCRIPTION_INTERNAL_ERROR: AlertDescription
250 ALERT_DESCRIPTION_ACCESS_DENIED: AlertDescription
251 ALERT_DESCRIPTION_BAD_CERTIFICATE: AlertDescription
252 ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE: AlertDescription
253 ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE: AlertDescription
254 ALERT_DESCRIPTION_BAD_RECORD_MAC: AlertDescription
255 ALERT_DESCRIPTION_CERTIFICATE_EXPIRED: AlertDescription
256 ALERT_DESCRIPTION_CERTIFICATE_REVOKED: AlertDescription
257 ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN: AlertDescription
258 ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE: AlertDescription
259 ALERT_DESCRIPTION_CLOSE_NOTIFY: AlertDescription
260 ALERT_DESCRIPTION_DECODE_ERROR: AlertDescription
261 ALERT_DESCRIPTION_DECOMPRESSION_FAILURE: AlertDescription
262 ALERT_DESCRIPTION_DECRYPT_ERROR: AlertDescription
263 ALERT_DESCRIPTION_ILLEGAL_PARAMETER: AlertDescription
264 ALERT_DESCRIPTION_INSUFFICIENT_SECURITY: AlertDescription
265 ALERT_DESCRIPTION_NO_RENEGOTIATION: AlertDescription
266 ALERT_DESCRIPTION_PROTOCOL_VERSION: AlertDescription
267 ALERT_DESCRIPTION_RECORD_OVERFLOW: AlertDescription
268 ALERT_DESCRIPTION_UNEXPECTED_MESSAGE: AlertDescription
269 ALERT_DESCRIPTION_UNKNOWN_CA: AlertDescription
270 ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY: AlertDescription
271 ALERT_DESCRIPTION_UNRECOGNIZED_NAME: AlertDescription
272 ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: AlertDescription
273 ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: AlertDescription
274 ALERT_DESCRIPTION_USER_CANCELLED: AlertDescription
275
276 class _ASN1Object(NamedTuple):
277     nid: int
278     shortname: str
279     longname: str
280     oid: str
281     @classmethod
282     def fromnid(cls: Type[Self], nid: int) -> Self: ...
283     @classmethod
284     def fromname(cls: Type[Self], name: str) -> Self: ...
285
286 class Purpose(_ASN1Object, enum.Enum):
287     SERVER_AUTH: _ASN1Object
288     CLIENT_AUTH: _ASN1Object
289
290 class SSLSocket(socket.socket):
291     context: SSLContext
292     server_side: bool
293     server_hostname: str | None
294     session: SSLSession | None
295     session_reused: bool | None
296     if sys.version_info < (3, 7):
297         def __init__(
298             self,
299             sock: socket.socket | None = ...,
300             keyfile: str | None = ...,
301             certfile: str | None = ...,
302             server_side: bool = ...,
303             cert_reqs: int = ...,
304             ssl_version: int = ...,
305             ca_certs: str | None = ...,
306             do_handshake_on_connect: bool = ...,
307             family: int = ...,
308             type: int = ...,
309             proto: int = ...,
310             fileno: int | None = ...,
311             suppress_ragged_eofs: bool = ...,
312             npn_protocols: Iterable[str] | None = ...,
313             ciphers: str | None = ...,
314             server_hostname: str | None = ...,
315             _context: SSLContext | None = ...,
316             _session: Any | None = ...,
317         ) -> None: ...
318     else:
319         def __init__(self, *args: Any, **kwargs: Any) -> None: ...
320     def connect(self, addr: socket._Address | bytes) -> None: ...
321     def connect_ex(self, addr: socket._Address | bytes) -> int: ...
322     def recv(self, buflen: int = ..., flags: int = ...) -> bytes: ...
323     def recv_into(self, buffer: WriteableBuffer, nbytes: int | None = ..., flags: int = ...) -> int: ...
324     def recvfrom(self, buflen: int = ..., flags: int = ...) -> tuple[bytes, socket._RetAddress]: ...
325     def recvfrom_into(
326         self, buffer: WriteableBuffer, nbytes: int | None = ..., flags: int = ...
327     ) -> tuple[int, socket._RetAddress]: ...
328     def send(self, data: ReadableBuffer, flags: int = ...) -> int: ...
329     def sendall(self, data: ReadableBuffer, flags: int = ...) -> None: ...
330     @overload
331     def sendto(self, data: ReadableBuffer, flags_or_addr: socket._Address) -> int: ...
332     @overload
333     def sendto(self, data: ReadableBuffer, flags_or_addr: int | socket._Address, addr: socket._Address | None = ...) -> int: ...
334     def shutdown(self, how: int) -> None: ...
335     def read(self, len: int = ..., buffer: bytearray | None = ...) -> bytes: ...
336     def write(self, data: bytes) -> int: ...
337     def do_handshake(self, block: bool = ...) -> None: ...  # block is undocumented
338     @overload
339     def getpeercert(self, binary_form: Literal[False] = ...) -> _PeerCertRetDictType | None: ...
340     @overload
341     def getpeercert(self, binary_form: Literal[True]) -> bytes | None: ...
342     @overload
343     def getpeercert(self, binary_form: bool) -> _PeerCertRetType: ...
344     def cipher(self) -> tuple[str, str, int] | None: ...
345     def shared_ciphers(self) -> list[tuple[str, str, int]] | None: ...
346     def compression(self) -> str | None: ...
347     def get_channel_binding(self, cb_type: str = ...) -> bytes | None: ...
348     def selected_alpn_protocol(self) -> str | None: ...
349     def selected_npn_protocol(self) -> str | None: ...
350     def accept(self) -> tuple[SSLSocket, socket._RetAddress]: ...
351     def unwrap(self) -> socket.socket: ...
352     def version(self) -> str | None: ...
353     def pending(self) -> int: ...
354     if sys.version_info >= (3, 8):
355         def verify_client_post_handshake(self) -> None: ...
356
357 if sys.version_info >= (3, 7):
358     class TLSVersion(enum.IntEnum):
359         MINIMUM_SUPPORTED: int
360         MAXIMUM_SUPPORTED: int
361         SSLv3: int
362         TLSv1: int
363         TLSv1_1: int
364         TLSv1_2: int
365         TLSv1_3: int
366
367 class SSLContext:
368     check_hostname: bool
369     options: Options
370     verify_flags: VerifyFlags
371     verify_mode: VerifyMode
372     @property
373     def protocol(self) -> _SSLMethod: ...
374     if sys.version_info >= (3, 7):
375         hostname_checks_common_name: bool
376         maximum_version: TLSVersion
377         minimum_version: TLSVersion
378         sni_callback: Callable[[SSLObject, str, SSLContext], None | int] | None
379         sslobject_class: ClassVar[Type[SSLObject]]
380         sslsocket_class: ClassVar[Type[SSLSocket]]
381     if sys.version_info >= (3, 8):
382         keylog_filename: str
383         post_handshake_auth: bool
384     def __new__(cls, protocol: int = ..., *args: Any, **kwargs: Any) -> SSLContext: ...
385     def __init__(self, protocol: int = ...) -> None: ...
386     def cert_store_stats(self) -> dict[str, int]: ...
387     def load_cert_chain(
388         self, certfile: StrOrBytesPath, keyfile: StrOrBytesPath | None = ..., password: _PasswordType | None = ...
389     ) -> None: ...
390     def load_default_certs(self, purpose: Purpose = ...) -> None: ...
391     def load_verify_locations(
392         self, cafile: StrOrBytesPath | None = ..., capath: StrOrBytesPath | None = ..., cadata: str | bytes | None = ...
393     ) -> None: ...
394     def get_ca_certs(self, binary_form: bool = ...) -> list[_PeerCertRetDictType] | list[bytes]: ...
395     def get_ciphers(self) -> list[_Cipher]: ...
396     def set_default_verify_paths(self) -> None: ...
397     def set_ciphers(self, __cipherlist: str) -> None: ...
398     def set_alpn_protocols(self, alpn_protocols: Iterable[str]) -> None: ...
399     def set_npn_protocols(self, npn_protocols: Iterable[str]) -> None: ...
400     if sys.version_info >= (3, 7):
401         def set_servername_callback(self, server_name_callback: _SrvnmeCbType | None) -> None: ...
402     else:
403         def set_servername_callback(self, __method: _SrvnmeCbType | None) -> None: ...
404     def load_dh_params(self, __path: str) -> None: ...
405     def set_ecdh_curve(self, __name: str) -> None: ...
406     def wrap_socket(
407         self,
408         sock: socket.socket,
409         server_side: bool = ...,
410         do_handshake_on_connect: bool = ...,
411         suppress_ragged_eofs: bool = ...,
412         server_hostname: str | None = ...,
413         session: SSLSession | None = ...,
414     ) -> SSLSocket: ...
415     def wrap_bio(
416         self,
417         incoming: MemoryBIO,
418         outgoing: MemoryBIO,
419         server_side: bool = ...,
420         server_hostname: str | None = ...,
421         session: SSLSession | None = ...,
422     ) -> SSLObject: ...
423     def session_stats(self) -> dict[str, int]: ...
424
425 class SSLObject:
426     context: SSLContext
427     server_side: bool
428     server_hostname: str | None
429     session: SSLSession | None
430     session_reused: bool
431     if sys.version_info >= (3, 7):
432         def __init__(self, *args: Any, **kwargs: Any) -> None: ...
433     else:
434         def __init__(self, sslobj: Any, owner: SSLSocket | SSLObject | None = ..., session: Any | None = ...) -> None: ...
435     def read(self, len: int = ..., buffer: bytearray | None = ...) -> bytes: ...
436     def write(self, data: bytes) -> int: ...
437     @overload
438     def getpeercert(self, binary_form: Literal[False] = ...) -> _PeerCertRetDictType | None: ...
439     @overload
440     def getpeercert(self, binary_form: Literal[True]) -> bytes | None: ...
441     @overload
442     def getpeercert(self, binary_form: bool) -> _PeerCertRetType: ...
443     def selected_alpn_protocol(self) -> str | None: ...
444     def selected_npn_protocol(self) -> str | None: ...
445     def cipher(self) -> tuple[str, str, int] | None: ...
446     def shared_ciphers(self) -> list[tuple[str, str, int]] | None: ...
447     def compression(self) -> str | None: ...
448     def pending(self) -> int: ...
449     def do_handshake(self) -> None: ...
450     def unwrap(self) -> None: ...
451     def version(self) -> str | None: ...
452     def get_channel_binding(self, cb_type: str = ...) -> bytes | None: ...
453     if sys.version_info >= (3, 8):
454         def verify_client_post_handshake(self) -> None: ...
455
456 class MemoryBIO:
457     pending: int
458     eof: bool
459     def read(self, __size: int = ...) -> bytes: ...
460     def write(self, __buf: bytes) -> int: ...
461     def write_eof(self) -> None: ...
462
463 class SSLSession:
464     id: bytes
465     time: int
466     timeout: int
467     ticket_lifetime_hint: int
468     has_ticket: bool
469
470 class SSLErrorNumber(enum.IntEnum):
471     SSL_ERROR_EOF: int
472     SSL_ERROR_INVALID_ERROR_CODE: int
473     SSL_ERROR_SSL: int
474     SSL_ERROR_SYSCALL: int
475     SSL_ERROR_WANT_CONNECT: int
476     SSL_ERROR_WANT_READ: int
477     SSL_ERROR_WANT_WRITE: int
478     SSL_ERROR_WANT_X509_LOOKUP: int
479     SSL_ERROR_ZERO_RETURN: int
480
481 SSL_ERROR_EOF: SSLErrorNumber  # undocumented
482 SSL_ERROR_INVALID_ERROR_CODE: SSLErrorNumber  # undocumented
483 SSL_ERROR_SSL: SSLErrorNumber  # undocumented
484 SSL_ERROR_SYSCALL: SSLErrorNumber  # undocumented
485 SSL_ERROR_WANT_CONNECT: SSLErrorNumber  # undocumented
486 SSL_ERROR_WANT_READ: SSLErrorNumber  # undocumented
487 SSL_ERROR_WANT_WRITE: SSLErrorNumber  # undocumented
488 SSL_ERROR_WANT_X509_LOOKUP: SSLErrorNumber  # undocumented
489 SSL_ERROR_ZERO_RETURN: SSLErrorNumber  # undocumented
490
491 def get_protocol_name(protocol_code: int) -> str: ...
492
493 if sys.version_info < (3, 9):
494     AF_INET: int
495 PEM_FOOTER: str
496 PEM_HEADER: str
497 SOCK_STREAM: int
498 SOL_SOCKET: int
499 SO_TYPE: int