@rowstile/cli-linux-x64 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (565) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +5 -0
  3. package/package.json +26 -0
  4. package/python/bin/python3.13 +0 -0
  5. package/python/bin/python3.13-config +122 -0
  6. package/python/lib/libpython3.13.so.1.0 +0 -0
  7. package/python/lib/libpython3.so +0 -0
  8. package/python/lib/python3.13/LICENSE.txt +277 -0
  9. package/python/lib/python3.13/__future__.py +147 -0
  10. package/python/lib/python3.13/__hello__.py +16 -0
  11. package/python/lib/python3.13/_aix_support.py +108 -0
  12. package/python/lib/python3.13/_android_support.py +192 -0
  13. package/python/lib/python3.13/_apple_support.py +66 -0
  14. package/python/lib/python3.13/_collections_abc.py +1187 -0
  15. package/python/lib/python3.13/_colorize.py +119 -0
  16. package/python/lib/python3.13/_compat_pickle.py +251 -0
  17. package/python/lib/python3.13/_compression.py +162 -0
  18. package/python/lib/python3.13/_ios_support.py +71 -0
  19. package/python/lib/python3.13/_markupbase.py +396 -0
  20. package/python/lib/python3.13/_opcode_metadata.py +343 -0
  21. package/python/lib/python3.13/_osx_support.py +579 -0
  22. package/python/lib/python3.13/_py_abc.py +147 -0
  23. package/python/lib/python3.13/_pydatetime.py +2640 -0
  24. package/python/lib/python3.13/_pydecimal.py +6356 -0
  25. package/python/lib/python3.13/_pyio.py +2714 -0
  26. package/python/lib/python3.13/_pylong.py +363 -0
  27. package/python/lib/python3.13/_pyrepl/__init__.py +19 -0
  28. package/python/lib/python3.13/_pyrepl/__main__.py +10 -0
  29. package/python/lib/python3.13/_pyrepl/_minimal_curses.py +68 -0
  30. package/python/lib/python3.13/_pyrepl/_threading_handler.py +74 -0
  31. package/python/lib/python3.13/_pyrepl/base_eventqueue.py +110 -0
  32. package/python/lib/python3.13/_pyrepl/commands.py +492 -0
  33. package/python/lib/python3.13/_pyrepl/completing_reader.py +295 -0
  34. package/python/lib/python3.13/_pyrepl/console.py +229 -0
  35. package/python/lib/python3.13/_pyrepl/curses.py +33 -0
  36. package/python/lib/python3.13/_pyrepl/fancy_termios.py +82 -0
  37. package/python/lib/python3.13/_pyrepl/historical_reader.py +419 -0
  38. package/python/lib/python3.13/_pyrepl/input.py +114 -0
  39. package/python/lib/python3.13/_pyrepl/keymap.py +213 -0
  40. package/python/lib/python3.13/_pyrepl/main.py +59 -0
  41. package/python/lib/python3.13/_pyrepl/mypy.ini +29 -0
  42. package/python/lib/python3.13/_pyrepl/pager.py +175 -0
  43. package/python/lib/python3.13/_pyrepl/reader.py +764 -0
  44. package/python/lib/python3.13/_pyrepl/readline.py +599 -0
  45. package/python/lib/python3.13/_pyrepl/simple_interact.py +180 -0
  46. package/python/lib/python3.13/_pyrepl/trace.py +21 -0
  47. package/python/lib/python3.13/_pyrepl/types.py +10 -0
  48. package/python/lib/python3.13/_pyrepl/unix_console.py +852 -0
  49. package/python/lib/python3.13/_pyrepl/unix_eventqueue.py +76 -0
  50. package/python/lib/python3.13/_pyrepl/utils.py +83 -0
  51. package/python/lib/python3.13/_pyrepl/windows_console.py +687 -0
  52. package/python/lib/python3.13/_pyrepl/windows_eventqueue.py +42 -0
  53. package/python/lib/python3.13/_sitebuiltins.py +91 -0
  54. package/python/lib/python3.13/_strptime.py +800 -0
  55. package/python/lib/python3.13/_sysconfigdata__linux_x86_64-linux-gnu.py +1079 -0
  56. package/python/lib/python3.13/_threading_local.py +120 -0
  57. package/python/lib/python3.13/_weakrefset.py +205 -0
  58. package/python/lib/python3.13/abc.py +188 -0
  59. package/python/lib/python3.13/antigravity.py +17 -0
  60. package/python/lib/python3.13/argparse.py +2690 -0
  61. package/python/lib/python3.13/ast.py +1865 -0
  62. package/python/lib/python3.13/asyncio/__init__.py +47 -0
  63. package/python/lib/python3.13/asyncio/__main__.py +211 -0
  64. package/python/lib/python3.13/asyncio/base_events.py +2086 -0
  65. package/python/lib/python3.13/asyncio/base_futures.py +67 -0
  66. package/python/lib/python3.13/asyncio/base_subprocess.py +312 -0
  67. package/python/lib/python3.13/asyncio/base_tasks.py +94 -0
  68. package/python/lib/python3.13/asyncio/constants.py +41 -0
  69. package/python/lib/python3.13/asyncio/coroutines.py +109 -0
  70. package/python/lib/python3.13/asyncio/events.py +885 -0
  71. package/python/lib/python3.13/asyncio/exceptions.py +62 -0
  72. package/python/lib/python3.13/asyncio/format_helpers.py +84 -0
  73. package/python/lib/python3.13/asyncio/futures.py +425 -0
  74. package/python/lib/python3.13/asyncio/locks.py +617 -0
  75. package/python/lib/python3.13/asyncio/log.py +7 -0
  76. package/python/lib/python3.13/asyncio/mixins.py +21 -0
  77. package/python/lib/python3.13/asyncio/proactor_events.py +891 -0
  78. package/python/lib/python3.13/asyncio/protocols.py +216 -0
  79. package/python/lib/python3.13/asyncio/queues.py +309 -0
  80. package/python/lib/python3.13/asyncio/runners.py +217 -0
  81. package/python/lib/python3.13/asyncio/selector_events.py +1328 -0
  82. package/python/lib/python3.13/asyncio/sslproto.py +929 -0
  83. package/python/lib/python3.13/asyncio/staggered.py +174 -0
  84. package/python/lib/python3.13/asyncio/streams.py +787 -0
  85. package/python/lib/python3.13/asyncio/subprocess.py +229 -0
  86. package/python/lib/python3.13/asyncio/taskgroups.py +278 -0
  87. package/python/lib/python3.13/asyncio/tasks.py +1121 -0
  88. package/python/lib/python3.13/asyncio/threads.py +26 -0
  89. package/python/lib/python3.13/asyncio/timeouts.py +185 -0
  90. package/python/lib/python3.13/asyncio/transports.py +337 -0
  91. package/python/lib/python3.13/asyncio/trsock.py +98 -0
  92. package/python/lib/python3.13/asyncio/unix_events.py +1550 -0
  93. package/python/lib/python3.13/asyncio/windows_events.py +906 -0
  94. package/python/lib/python3.13/asyncio/windows_utils.py +181 -0
  95. package/python/lib/python3.13/base64.py +628 -0
  96. package/python/lib/python3.13/bdb.py +973 -0
  97. package/python/lib/python3.13/bisect.py +118 -0
  98. package/python/lib/python3.13/bz2.py +352 -0
  99. package/python/lib/python3.13/cProfile.py +197 -0
  100. package/python/lib/python3.13/calendar.py +813 -0
  101. package/python/lib/python3.13/cmd.py +409 -0
  102. package/python/lib/python3.13/code.py +386 -0
  103. package/python/lib/python3.13/codecs.py +1132 -0
  104. package/python/lib/python3.13/codeop.py +155 -0
  105. package/python/lib/python3.13/collections/__init__.py +1603 -0
  106. package/python/lib/python3.13/colorsys.py +166 -0
  107. package/python/lib/python3.13/compileall.py +470 -0
  108. package/python/lib/python3.13/concurrent/__init__.py +1 -0
  109. package/python/lib/python3.13/concurrent/futures/__init__.py +54 -0
  110. package/python/lib/python3.13/concurrent/futures/_base.py +660 -0
  111. package/python/lib/python3.13/concurrent/futures/process.py +892 -0
  112. package/python/lib/python3.13/concurrent/futures/thread.py +240 -0
  113. package/python/lib/python3.13/configparser.py +1396 -0
  114. package/python/lib/python3.13/contextlib.py +814 -0
  115. package/python/lib/python3.13/contextvars.py +4 -0
  116. package/python/lib/python3.13/copy.py +306 -0
  117. package/python/lib/python3.13/copyreg.py +217 -0
  118. package/python/lib/python3.13/csv.py +527 -0
  119. package/python/lib/python3.13/ctypes/__init__.py +605 -0
  120. package/python/lib/python3.13/ctypes/_aix.py +327 -0
  121. package/python/lib/python3.13/ctypes/_endian.py +78 -0
  122. package/python/lib/python3.13/ctypes/macholib/README.ctypes +7 -0
  123. package/python/lib/python3.13/ctypes/macholib/__init__.py +9 -0
  124. package/python/lib/python3.13/ctypes/macholib/dyld.py +165 -0
  125. package/python/lib/python3.13/ctypes/macholib/dylib.py +42 -0
  126. package/python/lib/python3.13/ctypes/macholib/fetch_macholib +2 -0
  127. package/python/lib/python3.13/ctypes/macholib/fetch_macholib.bat +1 -0
  128. package/python/lib/python3.13/ctypes/macholib/framework.py +42 -0
  129. package/python/lib/python3.13/ctypes/util.py +387 -0
  130. package/python/lib/python3.13/ctypes/wintypes.py +202 -0
  131. package/python/lib/python3.13/curses/__init__.py +101 -0
  132. package/python/lib/python3.13/curses/ascii.py +99 -0
  133. package/python/lib/python3.13/curses/has_key.py +192 -0
  134. package/python/lib/python3.13/curses/panel.py +6 -0
  135. package/python/lib/python3.13/curses/textpad.py +236 -0
  136. package/python/lib/python3.13/dataclasses.py +1679 -0
  137. package/python/lib/python3.13/datetime.py +9 -0
  138. package/python/lib/python3.13/dbm/__init__.py +194 -0
  139. package/python/lib/python3.13/dbm/dumb.py +319 -0
  140. package/python/lib/python3.13/dbm/gnu.py +3 -0
  141. package/python/lib/python3.13/dbm/ndbm.py +3 -0
  142. package/python/lib/python3.13/dbm/sqlite3.py +144 -0
  143. package/python/lib/python3.13/decimal.py +109 -0
  144. package/python/lib/python3.13/difflib.py +2058 -0
  145. package/python/lib/python3.13/dis.py +1075 -0
  146. package/python/lib/python3.13/doctest.py +2919 -0
  147. package/python/lib/python3.13/email/__init__.py +61 -0
  148. package/python/lib/python3.13/email/_encoded_words.py +233 -0
  149. package/python/lib/python3.13/email/_header_value_parser.py +3153 -0
  150. package/python/lib/python3.13/email/_parseaddr.py +563 -0
  151. package/python/lib/python3.13/email/_policybase.py +382 -0
  152. package/python/lib/python3.13/email/architecture.rst +216 -0
  153. package/python/lib/python3.13/email/base64mime.py +115 -0
  154. package/python/lib/python3.13/email/charset.py +396 -0
  155. package/python/lib/python3.13/email/contentmanager.py +254 -0
  156. package/python/lib/python3.13/email/encoders.py +65 -0
  157. package/python/lib/python3.13/email/errors.py +117 -0
  158. package/python/lib/python3.13/email/feedparser.py +536 -0
  159. package/python/lib/python3.13/email/generator.py +530 -0
  160. package/python/lib/python3.13/email/header.py +582 -0
  161. package/python/lib/python3.13/email/headerregistry.py +618 -0
  162. package/python/lib/python3.13/email/iterators.py +68 -0
  163. package/python/lib/python3.13/email/message.py +1217 -0
  164. package/python/lib/python3.13/email/mime/__init__.py +0 -0
  165. package/python/lib/python3.13/email/mime/application.py +37 -0
  166. package/python/lib/python3.13/email/mime/audio.py +97 -0
  167. package/python/lib/python3.13/email/mime/base.py +29 -0
  168. package/python/lib/python3.13/email/mime/image.py +152 -0
  169. package/python/lib/python3.13/email/mime/message.py +33 -0
  170. package/python/lib/python3.13/email/mime/multipart.py +47 -0
  171. package/python/lib/python3.13/email/mime/nonmultipart.py +21 -0
  172. package/python/lib/python3.13/email/mime/text.py +40 -0
  173. package/python/lib/python3.13/email/parser.py +127 -0
  174. package/python/lib/python3.13/email/policy.py +232 -0
  175. package/python/lib/python3.13/email/quoprimime.py +300 -0
  176. package/python/lib/python3.13/email/utils.py +497 -0
  177. package/python/lib/python3.13/encodings/__init__.py +179 -0
  178. package/python/lib/python3.13/encodings/__pycache__/__init__.cpython-313.pyc +0 -0
  179. package/python/lib/python3.13/encodings/__pycache__/aliases.cpython-313.pyc +0 -0
  180. package/python/lib/python3.13/encodings/__pycache__/utf_8.cpython-313.pyc +0 -0
  181. package/python/lib/python3.13/encodings/aliases.py +560 -0
  182. package/python/lib/python3.13/encodings/ascii.py +50 -0
  183. package/python/lib/python3.13/encodings/base64_codec.py +55 -0
  184. package/python/lib/python3.13/encodings/big5.py +39 -0
  185. package/python/lib/python3.13/encodings/big5hkscs.py +39 -0
  186. package/python/lib/python3.13/encodings/bz2_codec.py +78 -0
  187. package/python/lib/python3.13/encodings/charmap.py +69 -0
  188. package/python/lib/python3.13/encodings/cp037.py +307 -0
  189. package/python/lib/python3.13/encodings/cp1006.py +307 -0
  190. package/python/lib/python3.13/encodings/cp1026.py +307 -0
  191. package/python/lib/python3.13/encodings/cp1125.py +698 -0
  192. package/python/lib/python3.13/encodings/cp1140.py +307 -0
  193. package/python/lib/python3.13/encodings/cp1250.py +307 -0
  194. package/python/lib/python3.13/encodings/cp1251.py +307 -0
  195. package/python/lib/python3.13/encodings/cp1252.py +307 -0
  196. package/python/lib/python3.13/encodings/cp1253.py +307 -0
  197. package/python/lib/python3.13/encodings/cp1254.py +307 -0
  198. package/python/lib/python3.13/encodings/cp1255.py +307 -0
  199. package/python/lib/python3.13/encodings/cp1256.py +307 -0
  200. package/python/lib/python3.13/encodings/cp1257.py +307 -0
  201. package/python/lib/python3.13/encodings/cp1258.py +307 -0
  202. package/python/lib/python3.13/encodings/cp273.py +307 -0
  203. package/python/lib/python3.13/encodings/cp424.py +307 -0
  204. package/python/lib/python3.13/encodings/cp437.py +698 -0
  205. package/python/lib/python3.13/encodings/cp500.py +307 -0
  206. package/python/lib/python3.13/encodings/cp720.py +309 -0
  207. package/python/lib/python3.13/encodings/cp737.py +698 -0
  208. package/python/lib/python3.13/encodings/cp775.py +697 -0
  209. package/python/lib/python3.13/encodings/cp850.py +698 -0
  210. package/python/lib/python3.13/encodings/cp852.py +698 -0
  211. package/python/lib/python3.13/encodings/cp855.py +698 -0
  212. package/python/lib/python3.13/encodings/cp856.py +307 -0
  213. package/python/lib/python3.13/encodings/cp857.py +694 -0
  214. package/python/lib/python3.13/encodings/cp858.py +698 -0
  215. package/python/lib/python3.13/encodings/cp860.py +698 -0
  216. package/python/lib/python3.13/encodings/cp861.py +698 -0
  217. package/python/lib/python3.13/encodings/cp862.py +698 -0
  218. package/python/lib/python3.13/encodings/cp863.py +698 -0
  219. package/python/lib/python3.13/encodings/cp864.py +690 -0
  220. package/python/lib/python3.13/encodings/cp865.py +698 -0
  221. package/python/lib/python3.13/encodings/cp866.py +698 -0
  222. package/python/lib/python3.13/encodings/cp869.py +689 -0
  223. package/python/lib/python3.13/encodings/cp874.py +307 -0
  224. package/python/lib/python3.13/encodings/cp875.py +307 -0
  225. package/python/lib/python3.13/encodings/cp932.py +39 -0
  226. package/python/lib/python3.13/encodings/cp949.py +39 -0
  227. package/python/lib/python3.13/encodings/cp950.py +39 -0
  228. package/python/lib/python3.13/encodings/euc_jis_2004.py +39 -0
  229. package/python/lib/python3.13/encodings/euc_jisx0213.py +39 -0
  230. package/python/lib/python3.13/encodings/euc_jp.py +39 -0
  231. package/python/lib/python3.13/encodings/euc_kr.py +39 -0
  232. package/python/lib/python3.13/encodings/gb18030.py +39 -0
  233. package/python/lib/python3.13/encodings/gb2312.py +39 -0
  234. package/python/lib/python3.13/encodings/gbk.py +39 -0
  235. package/python/lib/python3.13/encodings/hex_codec.py +55 -0
  236. package/python/lib/python3.13/encodings/hp_roman8.py +314 -0
  237. package/python/lib/python3.13/encodings/hz.py +39 -0
  238. package/python/lib/python3.13/encodings/idna.py +387 -0
  239. package/python/lib/python3.13/encodings/iso2022_jp.py +39 -0
  240. package/python/lib/python3.13/encodings/iso2022_jp_1.py +39 -0
  241. package/python/lib/python3.13/encodings/iso2022_jp_2.py +39 -0
  242. package/python/lib/python3.13/encodings/iso2022_jp_2004.py +39 -0
  243. package/python/lib/python3.13/encodings/iso2022_jp_3.py +39 -0
  244. package/python/lib/python3.13/encodings/iso2022_jp_ext.py +39 -0
  245. package/python/lib/python3.13/encodings/iso2022_kr.py +39 -0
  246. package/python/lib/python3.13/encodings/iso8859_1.py +307 -0
  247. package/python/lib/python3.13/encodings/iso8859_10.py +307 -0
  248. package/python/lib/python3.13/encodings/iso8859_11.py +307 -0
  249. package/python/lib/python3.13/encodings/iso8859_13.py +307 -0
  250. package/python/lib/python3.13/encodings/iso8859_14.py +307 -0
  251. package/python/lib/python3.13/encodings/iso8859_15.py +307 -0
  252. package/python/lib/python3.13/encodings/iso8859_16.py +307 -0
  253. package/python/lib/python3.13/encodings/iso8859_2.py +307 -0
  254. package/python/lib/python3.13/encodings/iso8859_3.py +307 -0
  255. package/python/lib/python3.13/encodings/iso8859_4.py +307 -0
  256. package/python/lib/python3.13/encodings/iso8859_5.py +307 -0
  257. package/python/lib/python3.13/encodings/iso8859_6.py +307 -0
  258. package/python/lib/python3.13/encodings/iso8859_7.py +307 -0
  259. package/python/lib/python3.13/encodings/iso8859_8.py +307 -0
  260. package/python/lib/python3.13/encodings/iso8859_9.py +307 -0
  261. package/python/lib/python3.13/encodings/johab.py +39 -0
  262. package/python/lib/python3.13/encodings/koi8_r.py +307 -0
  263. package/python/lib/python3.13/encodings/koi8_t.py +308 -0
  264. package/python/lib/python3.13/encodings/koi8_u.py +307 -0
  265. package/python/lib/python3.13/encodings/kz1048.py +307 -0
  266. package/python/lib/python3.13/encodings/latin_1.py +50 -0
  267. package/python/lib/python3.13/encodings/mac_arabic.py +698 -0
  268. package/python/lib/python3.13/encodings/mac_croatian.py +307 -0
  269. package/python/lib/python3.13/encodings/mac_cyrillic.py +307 -0
  270. package/python/lib/python3.13/encodings/mac_farsi.py +307 -0
  271. package/python/lib/python3.13/encodings/mac_greek.py +307 -0
  272. package/python/lib/python3.13/encodings/mac_iceland.py +307 -0
  273. package/python/lib/python3.13/encodings/mac_latin2.py +312 -0
  274. package/python/lib/python3.13/encodings/mac_roman.py +307 -0
  275. package/python/lib/python3.13/encodings/mac_romanian.py +307 -0
  276. package/python/lib/python3.13/encodings/mac_turkish.py +307 -0
  277. package/python/lib/python3.13/encodings/mbcs.py +47 -0
  278. package/python/lib/python3.13/encodings/oem.py +41 -0
  279. package/python/lib/python3.13/encodings/palmos.py +308 -0
  280. package/python/lib/python3.13/encodings/ptcp154.py +312 -0
  281. package/python/lib/python3.13/encodings/punycode.py +253 -0
  282. package/python/lib/python3.13/encodings/quopri_codec.py +56 -0
  283. package/python/lib/python3.13/encodings/raw_unicode_escape.py +46 -0
  284. package/python/lib/python3.13/encodings/rot_13.py +113 -0
  285. package/python/lib/python3.13/encodings/shift_jis.py +39 -0
  286. package/python/lib/python3.13/encodings/shift_jis_2004.py +39 -0
  287. package/python/lib/python3.13/encodings/shift_jisx0213.py +39 -0
  288. package/python/lib/python3.13/encodings/tis_620.py +307 -0
  289. package/python/lib/python3.13/encodings/undefined.py +49 -0
  290. package/python/lib/python3.13/encodings/unicode_escape.py +46 -0
  291. package/python/lib/python3.13/encodings/utf_16.py +155 -0
  292. package/python/lib/python3.13/encodings/utf_16_be.py +42 -0
  293. package/python/lib/python3.13/encodings/utf_16_le.py +42 -0
  294. package/python/lib/python3.13/encodings/utf_32.py +150 -0
  295. package/python/lib/python3.13/encodings/utf_32_be.py +37 -0
  296. package/python/lib/python3.13/encodings/utf_32_le.py +37 -0
  297. package/python/lib/python3.13/encodings/utf_7.py +38 -0
  298. package/python/lib/python3.13/encodings/utf_8.py +42 -0
  299. package/python/lib/python3.13/encodings/utf_8_sig.py +130 -0
  300. package/python/lib/python3.13/encodings/uu_codec.py +103 -0
  301. package/python/lib/python3.13/encodings/zlib_codec.py +77 -0
  302. package/python/lib/python3.13/enum.py +2183 -0
  303. package/python/lib/python3.13/filecmp.py +320 -0
  304. package/python/lib/python3.13/fileinput.py +442 -0
  305. package/python/lib/python3.13/fnmatch.py +192 -0
  306. package/python/lib/python3.13/fractions.py +1043 -0
  307. package/python/lib/python3.13/ftplib.py +975 -0
  308. package/python/lib/python3.13/functools.py +1036 -0
  309. package/python/lib/python3.13/genericpath.py +200 -0
  310. package/python/lib/python3.13/getopt.py +215 -0
  311. package/python/lib/python3.13/getpass.py +192 -0
  312. package/python/lib/python3.13/gettext.py +657 -0
  313. package/python/lib/python3.13/glob.py +572 -0
  314. package/python/lib/python3.13/graphlib.py +250 -0
  315. package/python/lib/python3.13/gzip.py +693 -0
  316. package/python/lib/python3.13/hashlib.py +255 -0
  317. package/python/lib/python3.13/heapq.py +603 -0
  318. package/python/lib/python3.13/hmac.py +220 -0
  319. package/python/lib/python3.13/html/__init__.py +132 -0
  320. package/python/lib/python3.13/html/entities.py +2513 -0
  321. package/python/lib/python3.13/html/parser.py +583 -0
  322. package/python/lib/python3.13/http/__init__.py +202 -0
  323. package/python/lib/python3.13/http/client.py +1598 -0
  324. package/python/lib/python3.13/http/cookiejar.py +2122 -0
  325. package/python/lib/python3.13/http/cookies.py +635 -0
  326. package/python/lib/python3.13/http/server.py +1355 -0
  327. package/python/lib/python3.13/imaplib.py +1769 -0
  328. package/python/lib/python3.13/importlib/__init__.py +136 -0
  329. package/python/lib/python3.13/importlib/_abc.py +39 -0
  330. package/python/lib/python3.13/importlib/_bootstrap.py +1559 -0
  331. package/python/lib/python3.13/importlib/_bootstrap_external.py +1826 -0
  332. package/python/lib/python3.13/importlib/abc.py +243 -0
  333. package/python/lib/python3.13/importlib/machinery.py +21 -0
  334. package/python/lib/python3.13/importlib/metadata/__init__.py +1093 -0
  335. package/python/lib/python3.13/importlib/metadata/_adapters.py +89 -0
  336. package/python/lib/python3.13/importlib/metadata/_collections.py +30 -0
  337. package/python/lib/python3.13/importlib/metadata/_functools.py +104 -0
  338. package/python/lib/python3.13/importlib/metadata/_itertools.py +73 -0
  339. package/python/lib/python3.13/importlib/metadata/_meta.py +67 -0
  340. package/python/lib/python3.13/importlib/metadata/_text.py +99 -0
  341. package/python/lib/python3.13/importlib/metadata/diagnose.py +21 -0
  342. package/python/lib/python3.13/importlib/readers.py +12 -0
  343. package/python/lib/python3.13/importlib/resources/__init__.py +43 -0
  344. package/python/lib/python3.13/importlib/resources/_adapters.py +168 -0
  345. package/python/lib/python3.13/importlib/resources/_common.py +211 -0
  346. package/python/lib/python3.13/importlib/resources/_functional.py +81 -0
  347. package/python/lib/python3.13/importlib/resources/_itertools.py +38 -0
  348. package/python/lib/python3.13/importlib/resources/abc.py +173 -0
  349. package/python/lib/python3.13/importlib/resources/readers.py +203 -0
  350. package/python/lib/python3.13/importlib/resources/simple.py +106 -0
  351. package/python/lib/python3.13/importlib/simple.py +14 -0
  352. package/python/lib/python3.13/importlib/util.py +274 -0
  353. package/python/lib/python3.13/inspect.py +3479 -0
  354. package/python/lib/python3.13/io.py +99 -0
  355. package/python/lib/python3.13/ipaddress.py +2440 -0
  356. package/python/lib/python3.13/json/__init__.py +365 -0
  357. package/python/lib/python3.13/json/decoder.py +364 -0
  358. package/python/lib/python3.13/json/encoder.py +446 -0
  359. package/python/lib/python3.13/json/scanner.py +73 -0
  360. package/python/lib/python3.13/json/tool.py +90 -0
  361. package/python/lib/python3.13/keyword.py +64 -0
  362. package/python/lib/python3.13/lib-dynload/.empty +0 -0
  363. package/python/lib/python3.13/lib-dynload/_dbm.cpython-313-x86_64-linux-gnu.so +0 -0
  364. package/python/lib/python3.13/linecache.py +236 -0
  365. package/python/lib/python3.13/locale.py +1987 -0
  366. package/python/lib/python3.13/logging/__init__.py +2330 -0
  367. package/python/lib/python3.13/logging/config.py +1080 -0
  368. package/python/lib/python3.13/logging/handlers.py +1629 -0
  369. package/python/lib/python3.13/lzma.py +364 -0
  370. package/python/lib/python3.13/mailbox.py +2219 -0
  371. package/python/lib/python3.13/mimetypes.py +679 -0
  372. package/python/lib/python3.13/modulefinder.py +671 -0
  373. package/python/lib/python3.13/multiprocessing/__init__.py +37 -0
  374. package/python/lib/python3.13/multiprocessing/connection.py +1216 -0
  375. package/python/lib/python3.13/multiprocessing/context.py +383 -0
  376. package/python/lib/python3.13/multiprocessing/dummy/__init__.py +126 -0
  377. package/python/lib/python3.13/multiprocessing/dummy/connection.py +75 -0
  378. package/python/lib/python3.13/multiprocessing/forkserver.py +373 -0
  379. package/python/lib/python3.13/multiprocessing/heap.py +337 -0
  380. package/python/lib/python3.13/multiprocessing/managers.py +1397 -0
  381. package/python/lib/python3.13/multiprocessing/pool.py +957 -0
  382. package/python/lib/python3.13/multiprocessing/popen_fork.py +97 -0
  383. package/python/lib/python3.13/multiprocessing/popen_forkserver.py +74 -0
  384. package/python/lib/python3.13/multiprocessing/popen_spawn_posix.py +76 -0
  385. package/python/lib/python3.13/multiprocessing/popen_spawn_win32.py +147 -0
  386. package/python/lib/python3.13/multiprocessing/process.py +436 -0
  387. package/python/lib/python3.13/multiprocessing/queues.py +399 -0
  388. package/python/lib/python3.13/multiprocessing/reduction.py +281 -0
  389. package/python/lib/python3.13/multiprocessing/resource_sharer.py +154 -0
  390. package/python/lib/python3.13/multiprocessing/resource_tracker.py +499 -0
  391. package/python/lib/python3.13/multiprocessing/shared_memory.py +544 -0
  392. package/python/lib/python3.13/multiprocessing/sharedctypes.py +240 -0
  393. package/python/lib/python3.13/multiprocessing/spawn.py +307 -0
  394. package/python/lib/python3.13/multiprocessing/synchronize.py +404 -0
  395. package/python/lib/python3.13/multiprocessing/util.py +562 -0
  396. package/python/lib/python3.13/netrc.py +199 -0
  397. package/python/lib/python3.13/ntpath.py +872 -0
  398. package/python/lib/python3.13/nturl2path.py +69 -0
  399. package/python/lib/python3.13/numbers.py +427 -0
  400. package/python/lib/python3.13/opcode.py +115 -0
  401. package/python/lib/python3.13/operator.py +467 -0
  402. package/python/lib/python3.13/optparse.py +1681 -0
  403. package/python/lib/python3.13/os.py +1184 -0
  404. package/python/lib/python3.13/pathlib/__init__.py +12 -0
  405. package/python/lib/python3.13/pathlib/_abc.py +930 -0
  406. package/python/lib/python3.13/pathlib/_local.py +861 -0
  407. package/python/lib/python3.13/pdb.py +2550 -0
  408. package/python/lib/python3.13/pickle.py +1860 -0
  409. package/python/lib/python3.13/pickletools.py +2904 -0
  410. package/python/lib/python3.13/pkgutil.py +529 -0
  411. package/python/lib/python3.13/platform.py +1454 -0
  412. package/python/lib/python3.13/plistlib.py +948 -0
  413. package/python/lib/python3.13/poplib.py +477 -0
  414. package/python/lib/python3.13/posixpath.py +578 -0
  415. package/python/lib/python3.13/pprint.py +658 -0
  416. package/python/lib/python3.13/profile.py +616 -0
  417. package/python/lib/python3.13/pstats.py +778 -0
  418. package/python/lib/python3.13/pty.py +211 -0
  419. package/python/lib/python3.13/py_compile.py +212 -0
  420. package/python/lib/python3.13/pyclbr.py +314 -0
  421. package/python/lib/python3.13/pydoc.py +2861 -0
  422. package/python/lib/python3.13/queue.py +383 -0
  423. package/python/lib/python3.13/quopri.py +237 -0
  424. package/python/lib/python3.13/random.py +1078 -0
  425. package/python/lib/python3.13/re/__init__.py +428 -0
  426. package/python/lib/python3.13/re/_casefix.py +106 -0
  427. package/python/lib/python3.13/re/_compiler.py +768 -0
  428. package/python/lib/python3.13/re/_constants.py +222 -0
  429. package/python/lib/python3.13/re/_parser.py +1081 -0
  430. package/python/lib/python3.13/reprlib.py +230 -0
  431. package/python/lib/python3.13/rlcompleter.py +222 -0
  432. package/python/lib/python3.13/runpy.py +326 -0
  433. package/python/lib/python3.13/sched.py +167 -0
  434. package/python/lib/python3.13/secrets.py +71 -0
  435. package/python/lib/python3.13/selectors.py +603 -0
  436. package/python/lib/python3.13/shelve.py +250 -0
  437. package/python/lib/python3.13/shlex.py +345 -0
  438. package/python/lib/python3.13/shutil.py +1569 -0
  439. package/python/lib/python3.13/signal.py +94 -0
  440. package/python/lib/python3.13/site.py +773 -0
  441. package/python/lib/python3.13/smtplib.py +1123 -0
  442. package/python/lib/python3.13/socket.py +988 -0
  443. package/python/lib/python3.13/socketserver.py +863 -0
  444. package/python/lib/python3.13/sqlite3/__init__.py +70 -0
  445. package/python/lib/python3.13/sqlite3/__main__.py +139 -0
  446. package/python/lib/python3.13/sqlite3/dbapi2.py +108 -0
  447. package/python/lib/python3.13/sqlite3/dump.py +118 -0
  448. package/python/lib/python3.13/sre_compile.py +7 -0
  449. package/python/lib/python3.13/sre_constants.py +7 -0
  450. package/python/lib/python3.13/sre_parse.py +7 -0
  451. package/python/lib/python3.13/ssl.py +1541 -0
  452. package/python/lib/python3.13/stat.py +212 -0
  453. package/python/lib/python3.13/statistics.py +1817 -0
  454. package/python/lib/python3.13/string.py +314 -0
  455. package/python/lib/python3.13/stringprep.py +272 -0
  456. package/python/lib/python3.13/struct.py +15 -0
  457. package/python/lib/python3.13/subprocess.py +2258 -0
  458. package/python/lib/python3.13/symtable.py +414 -0
  459. package/python/lib/python3.13/sysconfig/__init__.py +734 -0
  460. package/python/lib/python3.13/sysconfig/__main__.py +248 -0
  461. package/python/lib/python3.13/tabnanny.py +340 -0
  462. package/python/lib/python3.13/tarfile.py +3136 -0
  463. package/python/lib/python3.13/tempfile.py +958 -0
  464. package/python/lib/python3.13/textwrap.py +497 -0
  465. package/python/lib/python3.13/this.py +28 -0
  466. package/python/lib/python3.13/threading.py +1602 -0
  467. package/python/lib/python3.13/timeit.py +381 -0
  468. package/python/lib/python3.13/token.py +141 -0
  469. package/python/lib/python3.13/tokenize.py +592 -0
  470. package/python/lib/python3.13/tomllib/__init__.py +10 -0
  471. package/python/lib/python3.13/tomllib/_parser.py +703 -0
  472. package/python/lib/python3.13/tomllib/_re.py +107 -0
  473. package/python/lib/python3.13/tomllib/_types.py +10 -0
  474. package/python/lib/python3.13/tomllib/mypy.ini +15 -0
  475. package/python/lib/python3.13/trace.py +754 -0
  476. package/python/lib/python3.13/traceback.py +1639 -0
  477. package/python/lib/python3.13/tracemalloc.py +560 -0
  478. package/python/lib/python3.13/tty.py +73 -0
  479. package/python/lib/python3.13/types.py +346 -0
  480. package/python/lib/python3.13/typing.py +3846 -0
  481. package/python/lib/python3.13/unittest/__init__.py +80 -0
  482. package/python/lib/python3.13/unittest/__main__.py +18 -0
  483. package/python/lib/python3.13/unittest/_log.py +86 -0
  484. package/python/lib/python3.13/unittest/async_case.py +146 -0
  485. package/python/lib/python3.13/unittest/case.py +1478 -0
  486. package/python/lib/python3.13/unittest/loader.py +460 -0
  487. package/python/lib/python3.13/unittest/main.py +280 -0
  488. package/python/lib/python3.13/unittest/mock.py +3189 -0
  489. package/python/lib/python3.13/unittest/result.py +256 -0
  490. package/python/lib/python3.13/unittest/runner.py +292 -0
  491. package/python/lib/python3.13/unittest/signals.py +71 -0
  492. package/python/lib/python3.13/unittest/suite.py +379 -0
  493. package/python/lib/python3.13/unittest/util.py +170 -0
  494. package/python/lib/python3.13/urllib/__init__.py +0 -0
  495. package/python/lib/python3.13/urllib/error.py +74 -0
  496. package/python/lib/python3.13/urllib/parse.py +1264 -0
  497. package/python/lib/python3.13/urllib/request.py +2796 -0
  498. package/python/lib/python3.13/urllib/response.py +84 -0
  499. package/python/lib/python3.13/urllib/robotparser.py +363 -0
  500. package/python/lib/python3.13/uuid.py +784 -0
  501. package/python/lib/python3.13/warnings.py +735 -0
  502. package/python/lib/python3.13/wave.py +665 -0
  503. package/python/lib/python3.13/weakref.py +674 -0
  504. package/python/lib/python3.13/webbrowser.py +724 -0
  505. package/python/lib/python3.13/wsgiref/__init__.py +25 -0
  506. package/python/lib/python3.13/wsgiref/handlers.py +575 -0
  507. package/python/lib/python3.13/wsgiref/headers.py +192 -0
  508. package/python/lib/python3.13/wsgiref/simple_server.py +161 -0
  509. package/python/lib/python3.13/wsgiref/types.py +54 -0
  510. package/python/lib/python3.13/wsgiref/util.py +159 -0
  511. package/python/lib/python3.13/wsgiref/validate.py +438 -0
  512. package/python/lib/python3.13/xml/__init__.py +20 -0
  513. package/python/lib/python3.13/xml/dom/NodeFilter.py +27 -0
  514. package/python/lib/python3.13/xml/dom/__init__.py +140 -0
  515. package/python/lib/python3.13/xml/dom/domreg.py +99 -0
  516. package/python/lib/python3.13/xml/dom/expatbuilder.py +962 -0
  517. package/python/lib/python3.13/xml/dom/minicompat.py +109 -0
  518. package/python/lib/python3.13/xml/dom/minidom.py +2024 -0
  519. package/python/lib/python3.13/xml/dom/pulldom.py +336 -0
  520. package/python/lib/python3.13/xml/dom/xmlbuilder.py +389 -0
  521. package/python/lib/python3.13/xml/etree/ElementInclude.py +186 -0
  522. package/python/lib/python3.13/xml/etree/ElementPath.py +430 -0
  523. package/python/lib/python3.13/xml/etree/ElementTree.py +2116 -0
  524. package/python/lib/python3.13/xml/etree/__init__.py +33 -0
  525. package/python/lib/python3.13/xml/etree/cElementTree.py +3 -0
  526. package/python/lib/python3.13/xml/parsers/__init__.py +8 -0
  527. package/python/lib/python3.13/xml/parsers/expat.py +8 -0
  528. package/python/lib/python3.13/xml/sax/__init__.py +94 -0
  529. package/python/lib/python3.13/xml/sax/_exceptions.py +127 -0
  530. package/python/lib/python3.13/xml/sax/expatreader.py +454 -0
  531. package/python/lib/python3.13/xml/sax/handler.py +387 -0
  532. package/python/lib/python3.13/xml/sax/saxutils.py +369 -0
  533. package/python/lib/python3.13/xml/sax/xmlreader.py +378 -0
  534. package/python/lib/python3.13/xmlrpc/__init__.py +1 -0
  535. package/python/lib/python3.13/xmlrpc/client.py +1503 -0
  536. package/python/lib/python3.13/xmlrpc/server.py +1002 -0
  537. package/python/lib/python3.13/zipapp.py +229 -0
  538. package/python/lib/python3.13/zipfile/__init__.py +2391 -0
  539. package/python/lib/python3.13/zipfile/__main__.py +4 -0
  540. package/python/lib/python3.13/zipfile/_path/__init__.py +452 -0
  541. package/python/lib/python3.13/zipfile/_path/glob.py +113 -0
  542. package/python/lib/python3.13/zipimport.py +803 -0
  543. package/python/lib/python3.13/zoneinfo/__init__.py +34 -0
  544. package/python/lib/python3.13/zoneinfo/_common.py +172 -0
  545. package/python/lib/python3.13/zoneinfo/_tzpath.py +189 -0
  546. package/python/lib/python3.13/zoneinfo/_zoneinfo.py +779 -0
  547. package/python/licenses/LICENSE.bdb.txt +126 -0
  548. package/python/licenses/LICENSE.bzip2.txt +37 -0
  549. package/python/licenses/LICENSE.cpython.txt +771 -0
  550. package/python/licenses/LICENSE.expat.txt +21 -0
  551. package/python/licenses/LICENSE.libX11.txt +942 -0
  552. package/python/licenses/LICENSE.libXau.txt +21 -0
  553. package/python/licenses/LICENSE.libedit.txt +29 -0
  554. package/python/licenses/LICENSE.libffi.txt +21 -0
  555. package/python/licenses/LICENSE.liblzma.txt +13 -0
  556. package/python/licenses/LICENSE.libuuid.txt +27 -0
  557. package/python/licenses/LICENSE.libxcb.txt +30 -0
  558. package/python/licenses/LICENSE.mpdecimal.txt +24 -0
  559. package/python/licenses/LICENSE.ncurses.txt +29 -0
  560. package/python/licenses/LICENSE.openssl-1.1.txt +124 -0
  561. package/python/licenses/LICENSE.openssl-3.txt +177 -0
  562. package/python/licenses/LICENSE.sqlite.txt +23 -0
  563. package/python/licenses/LICENSE.tcl.txt +40 -0
  564. package/python/licenses/LICENSE.tix.txt +54 -0
  565. package/python/licenses/LICENSE.zlib.txt +21 -0
@@ -0,0 +1,1541 @@
1
+ # Wrapper module for _ssl, providing some additional facilities
2
+ # implemented in Python. Written by Bill Janssen.
3
+
4
+ """This module provides some more Pythonic support for SSL.
5
+
6
+ Object types:
7
+
8
+ SSLSocket -- subtype of socket.socket which does SSL over the socket
9
+
10
+ Exceptions:
11
+
12
+ SSLError -- exception raised for I/O errors
13
+
14
+ Functions:
15
+
16
+ cert_time_to_seconds -- convert time string used for certificate
17
+ notBefore and notAfter functions to integer
18
+ seconds past the Epoch (the time values
19
+ returned from time.time())
20
+
21
+ get_server_certificate (addr, ssl_version, ca_certs, timeout) -- Retrieve the
22
+ certificate from the server at the specified
23
+ address and return it as a PEM-encoded string
24
+
25
+
26
+ Integer constants:
27
+
28
+ SSL_ERROR_ZERO_RETURN
29
+ SSL_ERROR_WANT_READ
30
+ SSL_ERROR_WANT_WRITE
31
+ SSL_ERROR_WANT_X509_LOOKUP
32
+ SSL_ERROR_SYSCALL
33
+ SSL_ERROR_SSL
34
+ SSL_ERROR_WANT_CONNECT
35
+
36
+ SSL_ERROR_EOF
37
+ SSL_ERROR_INVALID_ERROR_CODE
38
+
39
+ The following group define certificate requirements that one side is
40
+ allowing/requiring from the other side:
41
+
42
+ CERT_NONE - no certificates from the other side are required (or will
43
+ be looked at if provided)
44
+ CERT_OPTIONAL - certificates are not required, but if provided will be
45
+ validated, and if validation fails, the connection will
46
+ also fail
47
+ CERT_REQUIRED - certificates are required, and will be validated, and
48
+ if validation fails, the connection will also fail
49
+
50
+ The following constants identify various SSL protocol variants:
51
+
52
+ PROTOCOL_SSLv2
53
+ PROTOCOL_SSLv3
54
+ PROTOCOL_SSLv23
55
+ PROTOCOL_TLS
56
+ PROTOCOL_TLS_CLIENT
57
+ PROTOCOL_TLS_SERVER
58
+ PROTOCOL_TLSv1
59
+ PROTOCOL_TLSv1_1
60
+ PROTOCOL_TLSv1_2
61
+
62
+ The following constants identify various SSL alert message descriptions as per
63
+ http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-6
64
+
65
+ ALERT_DESCRIPTION_CLOSE_NOTIFY
66
+ ALERT_DESCRIPTION_UNEXPECTED_MESSAGE
67
+ ALERT_DESCRIPTION_BAD_RECORD_MAC
68
+ ALERT_DESCRIPTION_RECORD_OVERFLOW
69
+ ALERT_DESCRIPTION_DECOMPRESSION_FAILURE
70
+ ALERT_DESCRIPTION_HANDSHAKE_FAILURE
71
+ ALERT_DESCRIPTION_BAD_CERTIFICATE
72
+ ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE
73
+ ALERT_DESCRIPTION_CERTIFICATE_REVOKED
74
+ ALERT_DESCRIPTION_CERTIFICATE_EXPIRED
75
+ ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN
76
+ ALERT_DESCRIPTION_ILLEGAL_PARAMETER
77
+ ALERT_DESCRIPTION_UNKNOWN_CA
78
+ ALERT_DESCRIPTION_ACCESS_DENIED
79
+ ALERT_DESCRIPTION_DECODE_ERROR
80
+ ALERT_DESCRIPTION_DECRYPT_ERROR
81
+ ALERT_DESCRIPTION_PROTOCOL_VERSION
82
+ ALERT_DESCRIPTION_INSUFFICIENT_SECURITY
83
+ ALERT_DESCRIPTION_INTERNAL_ERROR
84
+ ALERT_DESCRIPTION_USER_CANCELLED
85
+ ALERT_DESCRIPTION_NO_RENEGOTIATION
86
+ ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION
87
+ ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE
88
+ ALERT_DESCRIPTION_UNRECOGNIZED_NAME
89
+ ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE
90
+ ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE
91
+ ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY
92
+ """
93
+
94
+ import sys
95
+ import os
96
+ from collections import namedtuple
97
+ from enum import Enum as _Enum, IntEnum as _IntEnum, IntFlag as _IntFlag
98
+ from enum import _simple_enum
99
+
100
+ import _ssl # if we can't import it, let the error propagate
101
+
102
+ from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION
103
+ from _ssl import _SSLContext, MemoryBIO, SSLSession
104
+ from _ssl import (
105
+ SSLError, SSLZeroReturnError, SSLWantReadError, SSLWantWriteError,
106
+ SSLSyscallError, SSLEOFError, SSLCertVerificationError
107
+ )
108
+ from _ssl import txt2obj as _txt2obj, nid2obj as _nid2obj
109
+ from _ssl import RAND_status, RAND_add, RAND_bytes
110
+ try:
111
+ from _ssl import RAND_egd
112
+ except ImportError:
113
+ # RAND_egd is not supported on some platforms
114
+ pass
115
+
116
+
117
+ from _ssl import (
118
+ HAS_SNI, HAS_ECDH, HAS_NPN, HAS_ALPN, HAS_SSLv2, HAS_SSLv3, HAS_TLSv1,
119
+ HAS_TLSv1_1, HAS_TLSv1_2, HAS_TLSv1_3, HAS_PSK
120
+ )
121
+ from _ssl import _DEFAULT_CIPHERS, _OPENSSL_API_VERSION
122
+
123
+ _IntEnum._convert_(
124
+ '_SSLMethod', __name__,
125
+ lambda name: name.startswith('PROTOCOL_') and name != 'PROTOCOL_SSLv23',
126
+ source=_ssl)
127
+
128
+ _IntFlag._convert_(
129
+ 'Options', __name__,
130
+ lambda name: name.startswith('OP_'),
131
+ source=_ssl)
132
+
133
+ _IntEnum._convert_(
134
+ 'AlertDescription', __name__,
135
+ lambda name: name.startswith('ALERT_DESCRIPTION_'),
136
+ source=_ssl)
137
+
138
+ _IntEnum._convert_(
139
+ 'SSLErrorNumber', __name__,
140
+ lambda name: name.startswith('SSL_ERROR_'),
141
+ source=_ssl)
142
+
143
+ _IntFlag._convert_(
144
+ 'VerifyFlags', __name__,
145
+ lambda name: name.startswith('VERIFY_'),
146
+ source=_ssl)
147
+
148
+ _IntEnum._convert_(
149
+ 'VerifyMode', __name__,
150
+ lambda name: name.startswith('CERT_'),
151
+ source=_ssl)
152
+
153
+ PROTOCOL_SSLv23 = _SSLMethod.PROTOCOL_SSLv23 = _SSLMethod.PROTOCOL_TLS
154
+ _PROTOCOL_NAMES = {value: name for name, value in _SSLMethod.__members__.items()}
155
+
156
+ _SSLv2_IF_EXISTS = getattr(_SSLMethod, 'PROTOCOL_SSLv2', None)
157
+
158
+
159
+ @_simple_enum(_IntEnum)
160
+ class TLSVersion:
161
+ MINIMUM_SUPPORTED = _ssl.PROTO_MINIMUM_SUPPORTED
162
+ SSLv3 = _ssl.PROTO_SSLv3
163
+ TLSv1 = _ssl.PROTO_TLSv1
164
+ TLSv1_1 = _ssl.PROTO_TLSv1_1
165
+ TLSv1_2 = _ssl.PROTO_TLSv1_2
166
+ TLSv1_3 = _ssl.PROTO_TLSv1_3
167
+ MAXIMUM_SUPPORTED = _ssl.PROTO_MAXIMUM_SUPPORTED
168
+
169
+
170
+ @_simple_enum(_IntEnum)
171
+ class _TLSContentType:
172
+ """Content types (record layer)
173
+
174
+ See RFC 8446, section B.1
175
+ """
176
+ CHANGE_CIPHER_SPEC = 20
177
+ ALERT = 21
178
+ HANDSHAKE = 22
179
+ APPLICATION_DATA = 23
180
+ # pseudo content types
181
+ HEADER = 0x100
182
+ INNER_CONTENT_TYPE = 0x101
183
+
184
+
185
+ @_simple_enum(_IntEnum)
186
+ class _TLSAlertType:
187
+ """Alert types for TLSContentType.ALERT messages
188
+
189
+ See RFC 8446, section B.2
190
+ """
191
+ CLOSE_NOTIFY = 0
192
+ UNEXPECTED_MESSAGE = 10
193
+ BAD_RECORD_MAC = 20
194
+ DECRYPTION_FAILED = 21
195
+ RECORD_OVERFLOW = 22
196
+ DECOMPRESSION_FAILURE = 30
197
+ HANDSHAKE_FAILURE = 40
198
+ NO_CERTIFICATE = 41
199
+ BAD_CERTIFICATE = 42
200
+ UNSUPPORTED_CERTIFICATE = 43
201
+ CERTIFICATE_REVOKED = 44
202
+ CERTIFICATE_EXPIRED = 45
203
+ CERTIFICATE_UNKNOWN = 46
204
+ ILLEGAL_PARAMETER = 47
205
+ UNKNOWN_CA = 48
206
+ ACCESS_DENIED = 49
207
+ DECODE_ERROR = 50
208
+ DECRYPT_ERROR = 51
209
+ EXPORT_RESTRICTION = 60
210
+ PROTOCOL_VERSION = 70
211
+ INSUFFICIENT_SECURITY = 71
212
+ INTERNAL_ERROR = 80
213
+ INAPPROPRIATE_FALLBACK = 86
214
+ USER_CANCELED = 90
215
+ NO_RENEGOTIATION = 100
216
+ MISSING_EXTENSION = 109
217
+ UNSUPPORTED_EXTENSION = 110
218
+ CERTIFICATE_UNOBTAINABLE = 111
219
+ UNRECOGNIZED_NAME = 112
220
+ BAD_CERTIFICATE_STATUS_RESPONSE = 113
221
+ BAD_CERTIFICATE_HASH_VALUE = 114
222
+ UNKNOWN_PSK_IDENTITY = 115
223
+ CERTIFICATE_REQUIRED = 116
224
+ NO_APPLICATION_PROTOCOL = 120
225
+
226
+
227
+ @_simple_enum(_IntEnum)
228
+ class _TLSMessageType:
229
+ """Message types (handshake protocol)
230
+
231
+ See RFC 8446, section B.3
232
+ """
233
+ HELLO_REQUEST = 0
234
+ CLIENT_HELLO = 1
235
+ SERVER_HELLO = 2
236
+ HELLO_VERIFY_REQUEST = 3
237
+ NEWSESSION_TICKET = 4
238
+ END_OF_EARLY_DATA = 5
239
+ HELLO_RETRY_REQUEST = 6
240
+ ENCRYPTED_EXTENSIONS = 8
241
+ CERTIFICATE = 11
242
+ SERVER_KEY_EXCHANGE = 12
243
+ CERTIFICATE_REQUEST = 13
244
+ SERVER_DONE = 14
245
+ CERTIFICATE_VERIFY = 15
246
+ CLIENT_KEY_EXCHANGE = 16
247
+ FINISHED = 20
248
+ CERTIFICATE_URL = 21
249
+ CERTIFICATE_STATUS = 22
250
+ SUPPLEMENTAL_DATA = 23
251
+ KEY_UPDATE = 24
252
+ NEXT_PROTO = 67
253
+ MESSAGE_HASH = 254
254
+ CHANGE_CIPHER_SPEC = 0x0101
255
+
256
+
257
+ if sys.platform == "win32":
258
+ from _ssl import enum_certificates, enum_crls
259
+
260
+ from socket import socket, SOCK_STREAM, create_connection
261
+ from socket import SOL_SOCKET, SO_TYPE, _GLOBAL_DEFAULT_TIMEOUT
262
+ import socket as _socket
263
+ import base64 # for DER-to-PEM translation
264
+ import errno
265
+ import warnings
266
+
267
+
268
+ socket_error = OSError # keep that public name in module namespace
269
+
270
+ CHANNEL_BINDING_TYPES = ['tls-unique']
271
+
272
+ HAS_NEVER_CHECK_COMMON_NAME = hasattr(_ssl, 'HOSTFLAG_NEVER_CHECK_SUBJECT')
273
+
274
+
275
+ _RESTRICTED_SERVER_CIPHERS = _DEFAULT_CIPHERS
276
+
277
+ CertificateError = SSLCertVerificationError
278
+
279
+
280
+ def _dnsname_match(dn, hostname):
281
+ """Matching according to RFC 6125, section 6.4.3
282
+
283
+ - Hostnames are compared lower-case.
284
+ - For IDNA, both dn and hostname must be encoded as IDN A-label (ACE).
285
+ - Partial wildcards like 'www*.example.org', multiple wildcards, sole
286
+ wildcard or wildcards in labels other then the left-most label are not
287
+ supported and a CertificateError is raised.
288
+ - A wildcard must match at least one character.
289
+ """
290
+ if not dn:
291
+ return False
292
+
293
+ wildcards = dn.count('*')
294
+ # speed up common case w/o wildcards
295
+ if not wildcards:
296
+ return dn.lower() == hostname.lower()
297
+
298
+ if wildcards > 1:
299
+ raise CertificateError(
300
+ "too many wildcards in certificate DNS name: {!r}.".format(dn))
301
+
302
+ dn_leftmost, sep, dn_remainder = dn.partition('.')
303
+
304
+ if '*' in dn_remainder:
305
+ # Only match wildcard in leftmost segment.
306
+ raise CertificateError(
307
+ "wildcard can only be present in the leftmost label: "
308
+ "{!r}.".format(dn))
309
+
310
+ if not sep:
311
+ # no right side
312
+ raise CertificateError(
313
+ "sole wildcard without additional labels are not support: "
314
+ "{!r}.".format(dn))
315
+
316
+ if dn_leftmost != '*':
317
+ # no partial wildcard matching
318
+ raise CertificateError(
319
+ "partial wildcards in leftmost label are not supported: "
320
+ "{!r}.".format(dn))
321
+
322
+ hostname_leftmost, sep, hostname_remainder = hostname.partition('.')
323
+ if not hostname_leftmost or not sep:
324
+ # wildcard must match at least one char
325
+ return False
326
+ return dn_remainder.lower() == hostname_remainder.lower()
327
+
328
+
329
+ def _inet_paton(ipname):
330
+ """Try to convert an IP address to packed binary form
331
+
332
+ Supports IPv4 addresses on all platforms and IPv6 on platforms with IPv6
333
+ support.
334
+ """
335
+ # inet_aton() also accepts strings like '1', '127.1', some also trailing
336
+ # data like '127.0.0.1 whatever'.
337
+ try:
338
+ addr = _socket.inet_aton(ipname)
339
+ except OSError:
340
+ # not an IPv4 address
341
+ pass
342
+ else:
343
+ if _socket.inet_ntoa(addr) == ipname:
344
+ # only accept injective ipnames
345
+ return addr
346
+ else:
347
+ # refuse for short IPv4 notation and additional trailing data
348
+ raise ValueError(
349
+ "{!r} is not a quad-dotted IPv4 address.".format(ipname)
350
+ )
351
+
352
+ try:
353
+ return _socket.inet_pton(_socket.AF_INET6, ipname)
354
+ except OSError:
355
+ raise ValueError("{!r} is neither an IPv4 nor an IP6 "
356
+ "address.".format(ipname))
357
+ except AttributeError:
358
+ # AF_INET6 not available
359
+ pass
360
+
361
+ raise ValueError("{!r} is not an IPv4 address.".format(ipname))
362
+
363
+
364
+ def _ipaddress_match(cert_ipaddress, host_ip):
365
+ """Exact matching of IP addresses.
366
+
367
+ RFC 6125 explicitly doesn't define an algorithm for this
368
+ (section 1.7.2 - "Out of Scope").
369
+ """
370
+ # OpenSSL may add a trailing newline to a subjectAltName's IP address,
371
+ # commonly with IPv6 addresses. Strip off trailing \n.
372
+ ip = _inet_paton(cert_ipaddress.rstrip())
373
+ return ip == host_ip
374
+
375
+
376
+ DefaultVerifyPaths = namedtuple("DefaultVerifyPaths",
377
+ "cafile capath openssl_cafile_env openssl_cafile openssl_capath_env "
378
+ "openssl_capath")
379
+
380
+ def get_default_verify_paths():
381
+ """Return paths to default cafile and capath.
382
+ """
383
+ parts = _ssl.get_default_verify_paths()
384
+
385
+ # environment vars shadow paths
386
+ cafile = os.environ.get(parts[0], parts[1])
387
+ capath = os.environ.get(parts[2], parts[3])
388
+
389
+ return DefaultVerifyPaths(cafile if os.path.isfile(cafile) else None,
390
+ capath if os.path.isdir(capath) else None,
391
+ *parts)
392
+
393
+
394
+ class _ASN1Object(namedtuple("_ASN1Object", "nid shortname longname oid")):
395
+ """ASN.1 object identifier lookup
396
+ """
397
+ __slots__ = ()
398
+
399
+ def __new__(cls, oid):
400
+ return super().__new__(cls, *_txt2obj(oid, name=False))
401
+
402
+ @classmethod
403
+ def fromnid(cls, nid):
404
+ """Create _ASN1Object from OpenSSL numeric ID
405
+ """
406
+ return super().__new__(cls, *_nid2obj(nid))
407
+
408
+ @classmethod
409
+ def fromname(cls, name):
410
+ """Create _ASN1Object from short name, long name or OID
411
+ """
412
+ return super().__new__(cls, *_txt2obj(name, name=True))
413
+
414
+
415
+ class Purpose(_ASN1Object, _Enum):
416
+ """SSLContext purpose flags with X509v3 Extended Key Usage objects
417
+ """
418
+ SERVER_AUTH = '1.3.6.1.5.5.7.3.1'
419
+ CLIENT_AUTH = '1.3.6.1.5.5.7.3.2'
420
+
421
+
422
+ class SSLContext(_SSLContext):
423
+ """An SSLContext holds various SSL-related configuration options and
424
+ data, such as certificates and possibly a private key."""
425
+ _windows_cert_stores = ("CA", "ROOT")
426
+ _FALLBACK_CERT_FILE = "/etc/pki/tls/cert.pem" # RHEL 8 and below, Fedora 33 and below
427
+ _FALLBACK_CERT_DIR = "/etc/pki/tls/certs" # RHEL 8 and below, Fedora 33 and below
428
+
429
+ sslsocket_class = None # SSLSocket is assigned later.
430
+ sslobject_class = None # SSLObject is assigned later.
431
+
432
+ def __new__(cls, protocol=None, *args, **kwargs):
433
+ if protocol is None:
434
+ warnings.warn(
435
+ "ssl.SSLContext() without protocol argument is deprecated.",
436
+ category=DeprecationWarning,
437
+ stacklevel=2
438
+ )
439
+ protocol = PROTOCOL_TLS
440
+ self = _SSLContext.__new__(cls, protocol)
441
+ return self
442
+
443
+ def _encode_hostname(self, hostname):
444
+ if hostname is None:
445
+ return None
446
+ elif isinstance(hostname, str):
447
+ return hostname.encode('idna').decode('ascii')
448
+ else:
449
+ return hostname.decode('ascii')
450
+
451
+ def wrap_socket(self, sock, server_side=False,
452
+ do_handshake_on_connect=True,
453
+ suppress_ragged_eofs=True,
454
+ server_hostname=None, session=None):
455
+ # SSLSocket class handles server_hostname encoding before it calls
456
+ # ctx._wrap_socket()
457
+ return self.sslsocket_class._create(
458
+ sock=sock,
459
+ server_side=server_side,
460
+ do_handshake_on_connect=do_handshake_on_connect,
461
+ suppress_ragged_eofs=suppress_ragged_eofs,
462
+ server_hostname=server_hostname,
463
+ context=self,
464
+ session=session
465
+ )
466
+
467
+ def wrap_bio(self, incoming, outgoing, server_side=False,
468
+ server_hostname=None, session=None):
469
+ # Need to encode server_hostname here because _wrap_bio() can only
470
+ # handle ASCII str.
471
+ return self.sslobject_class._create(
472
+ incoming, outgoing, server_side=server_side,
473
+ server_hostname=self._encode_hostname(server_hostname),
474
+ session=session, context=self,
475
+ )
476
+
477
+ def set_npn_protocols(self, npn_protocols):
478
+ warnings.warn(
479
+ "ssl NPN is deprecated, use ALPN instead",
480
+ DeprecationWarning,
481
+ stacklevel=2
482
+ )
483
+ protos = bytearray()
484
+ for protocol in npn_protocols:
485
+ b = bytes(protocol, 'ascii')
486
+ if len(b) == 0 or len(b) > 255:
487
+ raise SSLError('NPN protocols must be 1 to 255 in length')
488
+ protos.append(len(b))
489
+ protos.extend(b)
490
+
491
+ self._set_npn_protocols(protos)
492
+
493
+ def set_servername_callback(self, server_name_callback):
494
+ if server_name_callback is None:
495
+ self.sni_callback = None
496
+ else:
497
+ if not callable(server_name_callback):
498
+ raise TypeError("not a callable object")
499
+
500
+ def shim_cb(sslobj, servername, sslctx):
501
+ servername = self._encode_hostname(servername)
502
+ return server_name_callback(sslobj, servername, sslctx)
503
+
504
+ self.sni_callback = shim_cb
505
+
506
+ def set_alpn_protocols(self, alpn_protocols):
507
+ protos = bytearray()
508
+ for protocol in alpn_protocols:
509
+ b = bytes(protocol, 'ascii')
510
+ if len(b) == 0 or len(b) > 255:
511
+ raise SSLError('ALPN protocols must be 1 to 255 in length')
512
+ protos.append(len(b))
513
+ protos.extend(b)
514
+
515
+ self._set_alpn_protocols(protos)
516
+
517
+ def _load_windows_store_certs(self, storename, purpose):
518
+ try:
519
+ for cert, encoding, trust in enum_certificates(storename):
520
+ # CA certs are never PKCS#7 encoded
521
+ if encoding == "x509_asn":
522
+ if trust is True or purpose.oid in trust:
523
+ try:
524
+ self.load_verify_locations(cadata=cert)
525
+ except SSLError as exc:
526
+ warnings.warn(f"Bad certificate in Windows certificate store: {exc!s}")
527
+ except PermissionError:
528
+ warnings.warn("unable to enumerate Windows certificate store")
529
+
530
+ def load_default_certs(self, purpose=Purpose.SERVER_AUTH):
531
+ if not isinstance(purpose, _ASN1Object):
532
+ raise TypeError(purpose)
533
+ if sys.platform == "win32":
534
+ for storename in self._windows_cert_stores:
535
+ self._load_windows_store_certs(storename, purpose)
536
+ elif sys.platform == "linux":
537
+ _def_paths = _ssl.get_default_verify_paths()
538
+ if (_def_paths[0] not in os.environ and
539
+ not os.path.isfile(_def_paths[1]) and
540
+ os.path.isfile(self._FALLBACK_CERT_FILE)):
541
+ self.load_verify_locations(cafile=self._FALLBACK_CERT_FILE)
542
+ if (_def_paths[2] not in os.environ and
543
+ not os.path.isdir(_def_paths[3]) and
544
+ os.path.isdir(self._FALLBACK_CERT_DIR)):
545
+ self.load_verify_locations(capath=self._FALLBACK_CERT_DIR)
546
+ self.set_default_verify_paths()
547
+
548
+ if hasattr(_SSLContext, 'minimum_version'):
549
+ @property
550
+ def minimum_version(self):
551
+ return TLSVersion(super().minimum_version)
552
+
553
+ @minimum_version.setter
554
+ def minimum_version(self, value):
555
+ if value == TLSVersion.SSLv3:
556
+ self.options &= ~Options.OP_NO_SSLv3
557
+ super(SSLContext, SSLContext).minimum_version.__set__(self, value)
558
+
559
+ @property
560
+ def maximum_version(self):
561
+ return TLSVersion(super().maximum_version)
562
+
563
+ @maximum_version.setter
564
+ def maximum_version(self, value):
565
+ super(SSLContext, SSLContext).maximum_version.__set__(self, value)
566
+
567
+ @property
568
+ def options(self):
569
+ return Options(super().options)
570
+
571
+ @options.setter
572
+ def options(self, value):
573
+ super(SSLContext, SSLContext).options.__set__(self, value)
574
+
575
+ if hasattr(_ssl, 'HOSTFLAG_NEVER_CHECK_SUBJECT'):
576
+ @property
577
+ def hostname_checks_common_name(self):
578
+ ncs = self._host_flags & _ssl.HOSTFLAG_NEVER_CHECK_SUBJECT
579
+ return ncs != _ssl.HOSTFLAG_NEVER_CHECK_SUBJECT
580
+
581
+ @hostname_checks_common_name.setter
582
+ def hostname_checks_common_name(self, value):
583
+ if value:
584
+ self._host_flags &= ~_ssl.HOSTFLAG_NEVER_CHECK_SUBJECT
585
+ else:
586
+ self._host_flags |= _ssl.HOSTFLAG_NEVER_CHECK_SUBJECT
587
+ else:
588
+ @property
589
+ def hostname_checks_common_name(self):
590
+ return True
591
+
592
+ @property
593
+ def _msg_callback(self):
594
+ """TLS message callback
595
+
596
+ The message callback provides a debugging hook to analyze TLS
597
+ connections. The callback is called for any TLS protocol message
598
+ (header, handshake, alert, and more), but not for application data.
599
+ Due to technical limitations, the callback can't be used to filter
600
+ traffic or to abort a connection. Any exception raised in the
601
+ callback is delayed until the handshake, read, or write operation
602
+ has been performed.
603
+
604
+ def msg_cb(conn, direction, version, content_type, msg_type, data):
605
+ pass
606
+
607
+ conn
608
+ :class:`SSLSocket` or :class:`SSLObject` instance
609
+ direction
610
+ ``read`` or ``write``
611
+ version
612
+ :class:`TLSVersion` enum member or int for unknown version. For a
613
+ frame header, it's the header version.
614
+ content_type
615
+ :class:`_TLSContentType` enum member or int for unsupported
616
+ content type.
617
+ msg_type
618
+ Either a :class:`_TLSContentType` enum number for a header
619
+ message, a :class:`_TLSAlertType` enum member for an alert
620
+ message, a :class:`_TLSMessageType` enum member for other
621
+ messages, or int for unsupported message types.
622
+ data
623
+ Raw, decrypted message content as bytes
624
+ """
625
+ inner = super()._msg_callback
626
+ if inner is not None:
627
+ return inner.user_function
628
+ else:
629
+ return None
630
+
631
+ @_msg_callback.setter
632
+ def _msg_callback(self, callback):
633
+ if callback is None:
634
+ super(SSLContext, SSLContext)._msg_callback.__set__(self, None)
635
+ return
636
+
637
+ if not hasattr(callback, '__call__'):
638
+ raise TypeError(f"{callback} is not callable.")
639
+
640
+ def inner(conn, direction, version, content_type, msg_type, data):
641
+ try:
642
+ version = TLSVersion(version)
643
+ except ValueError:
644
+ pass
645
+
646
+ try:
647
+ content_type = _TLSContentType(content_type)
648
+ except ValueError:
649
+ pass
650
+
651
+ if content_type == _TLSContentType.HEADER:
652
+ msg_enum = _TLSContentType
653
+ elif content_type == _TLSContentType.ALERT:
654
+ msg_enum = _TLSAlertType
655
+ else:
656
+ msg_enum = _TLSMessageType
657
+ try:
658
+ msg_type = msg_enum(msg_type)
659
+ except ValueError:
660
+ pass
661
+
662
+ return callback(conn, direction, version,
663
+ content_type, msg_type, data)
664
+
665
+ inner.user_function = callback
666
+
667
+ super(SSLContext, SSLContext)._msg_callback.__set__(self, inner)
668
+
669
+ @property
670
+ def protocol(self):
671
+ return _SSLMethod(super().protocol)
672
+
673
+ @property
674
+ def verify_flags(self):
675
+ return VerifyFlags(super().verify_flags)
676
+
677
+ @verify_flags.setter
678
+ def verify_flags(self, value):
679
+ super(SSLContext, SSLContext).verify_flags.__set__(self, value)
680
+
681
+ @property
682
+ def verify_mode(self):
683
+ value = super().verify_mode
684
+ try:
685
+ return VerifyMode(value)
686
+ except ValueError:
687
+ return value
688
+
689
+ @verify_mode.setter
690
+ def verify_mode(self, value):
691
+ super(SSLContext, SSLContext).verify_mode.__set__(self, value)
692
+
693
+
694
+ def create_default_context(purpose=Purpose.SERVER_AUTH, *, cafile=None,
695
+ capath=None, cadata=None):
696
+ """Create a SSLContext object with default settings.
697
+
698
+ NOTE: The protocol and settings may change anytime without prior
699
+ deprecation. The values represent a fair balance between maximum
700
+ compatibility and security.
701
+ """
702
+ if not isinstance(purpose, _ASN1Object):
703
+ raise TypeError(purpose)
704
+
705
+ # SSLContext sets OP_NO_SSLv2, OP_NO_SSLv3, OP_NO_COMPRESSION,
706
+ # OP_CIPHER_SERVER_PREFERENCE, OP_SINGLE_DH_USE and OP_SINGLE_ECDH_USE
707
+ # by default.
708
+ if purpose == Purpose.SERVER_AUTH:
709
+ # verify certs and host name in client mode
710
+ context = SSLContext(PROTOCOL_TLS_CLIENT)
711
+ context.verify_mode = CERT_REQUIRED
712
+ context.check_hostname = True
713
+ elif purpose == Purpose.CLIENT_AUTH:
714
+ context = SSLContext(PROTOCOL_TLS_SERVER)
715
+ else:
716
+ raise ValueError(purpose)
717
+
718
+ # `VERIFY_X509_PARTIAL_CHAIN` makes OpenSSL's chain building behave more
719
+ # like RFC 3280 and 5280, which specify that chain building stops with the
720
+ # first trust anchor, even if that anchor is not self-signed.
721
+ #
722
+ # `VERIFY_X509_STRICT` makes OpenSSL more conservative about the
723
+ # certificates it accepts, including "disabling workarounds for
724
+ # some broken certificates."
725
+ context.verify_flags |= (_ssl.VERIFY_X509_PARTIAL_CHAIN |
726
+ _ssl.VERIFY_X509_STRICT)
727
+
728
+ if cafile or capath or cadata:
729
+ context.load_verify_locations(cafile, capath, cadata)
730
+ elif context.verify_mode != CERT_NONE:
731
+ # no explicit cafile, capath or cadata but the verify mode is
732
+ # CERT_OPTIONAL or CERT_REQUIRED. Let's try to load default system
733
+ # root CA certificates for the given purpose. This may fail silently.
734
+ context.load_default_certs(purpose)
735
+ # OpenSSL 1.1.1 keylog file
736
+ if hasattr(context, 'keylog_filename'):
737
+ keylogfile = os.environ.get('SSLKEYLOGFILE')
738
+ if keylogfile and not sys.flags.ignore_environment:
739
+ context.keylog_filename = keylogfile
740
+ return context
741
+
742
+ def _create_unverified_context(protocol=None, *, cert_reqs=CERT_NONE,
743
+ check_hostname=False, purpose=Purpose.SERVER_AUTH,
744
+ certfile=None, keyfile=None,
745
+ cafile=None, capath=None, cadata=None):
746
+ """Create a SSLContext object for Python stdlib modules
747
+
748
+ All Python stdlib modules shall use this function to create SSLContext
749
+ objects in order to keep common settings in one place. The configuration
750
+ is less restrict than create_default_context()'s to increase backward
751
+ compatibility.
752
+ """
753
+ if not isinstance(purpose, _ASN1Object):
754
+ raise TypeError(purpose)
755
+
756
+ # SSLContext sets OP_NO_SSLv2, OP_NO_SSLv3, OP_NO_COMPRESSION,
757
+ # OP_CIPHER_SERVER_PREFERENCE, OP_SINGLE_DH_USE and OP_SINGLE_ECDH_USE
758
+ # by default.
759
+ if purpose == Purpose.SERVER_AUTH:
760
+ # verify certs and host name in client mode
761
+ if protocol is None:
762
+ protocol = PROTOCOL_TLS_CLIENT
763
+ elif purpose == Purpose.CLIENT_AUTH:
764
+ if protocol is None:
765
+ protocol = PROTOCOL_TLS_SERVER
766
+ else:
767
+ raise ValueError(purpose)
768
+
769
+ context = SSLContext(protocol)
770
+ context.check_hostname = check_hostname
771
+ if cert_reqs is not None:
772
+ context.verify_mode = cert_reqs
773
+ if check_hostname:
774
+ context.check_hostname = True
775
+
776
+ if keyfile and not certfile:
777
+ raise ValueError("certfile must be specified")
778
+ if certfile or keyfile:
779
+ context.load_cert_chain(certfile, keyfile)
780
+
781
+ # load CA root certs
782
+ if cafile or capath or cadata:
783
+ context.load_verify_locations(cafile, capath, cadata)
784
+ elif context.verify_mode != CERT_NONE:
785
+ # no explicit cafile, capath or cadata but the verify mode is
786
+ # CERT_OPTIONAL or CERT_REQUIRED. Let's try to load default system
787
+ # root CA certificates for the given purpose. This may fail silently.
788
+ context.load_default_certs(purpose)
789
+ # OpenSSL 1.1.1 keylog file
790
+ if hasattr(context, 'keylog_filename'):
791
+ keylogfile = os.environ.get('SSLKEYLOGFILE')
792
+ if keylogfile and not sys.flags.ignore_environment:
793
+ context.keylog_filename = keylogfile
794
+ return context
795
+
796
+ # Used by http.client if no context is explicitly passed.
797
+ _create_default_https_context = create_default_context
798
+
799
+
800
+ # Backwards compatibility alias, even though it's not a public name.
801
+ _create_stdlib_context = _create_unverified_context
802
+
803
+
804
+ class SSLObject:
805
+ """This class implements an interface on top of a low-level SSL object as
806
+ implemented by OpenSSL. This object captures the state of an SSL connection
807
+ but does not provide any network IO itself. IO needs to be performed
808
+ through separate "BIO" objects which are OpenSSL's IO abstraction layer.
809
+
810
+ This class does not have a public constructor. Instances are returned by
811
+ ``SSLContext.wrap_bio``. This class is typically used by framework authors
812
+ that want to implement asynchronous IO for SSL through memory buffers.
813
+
814
+ When compared to ``SSLSocket``, this object lacks the following features:
815
+
816
+ * Any form of network IO, including methods such as ``recv`` and ``send``.
817
+ * The ``do_handshake_on_connect`` and ``suppress_ragged_eofs`` machinery.
818
+ """
819
+ def __init__(self, *args, **kwargs):
820
+ raise TypeError(
821
+ f"{self.__class__.__name__} does not have a public "
822
+ f"constructor. Instances are returned by SSLContext.wrap_bio()."
823
+ )
824
+
825
+ @classmethod
826
+ def _create(cls, incoming, outgoing, server_side=False,
827
+ server_hostname=None, session=None, context=None):
828
+ self = cls.__new__(cls)
829
+ sslobj = context._wrap_bio(
830
+ incoming, outgoing, server_side=server_side,
831
+ server_hostname=server_hostname,
832
+ owner=self, session=session
833
+ )
834
+ self._sslobj = sslobj
835
+ return self
836
+
837
+ @property
838
+ def context(self):
839
+ """The SSLContext that is currently in use."""
840
+ return self._sslobj.context
841
+
842
+ @context.setter
843
+ def context(self, ctx):
844
+ self._sslobj.context = ctx
845
+
846
+ @property
847
+ def session(self):
848
+ """The SSLSession for client socket."""
849
+ return self._sslobj.session
850
+
851
+ @session.setter
852
+ def session(self, session):
853
+ self._sslobj.session = session
854
+
855
+ @property
856
+ def session_reused(self):
857
+ """Was the client session reused during handshake"""
858
+ return self._sslobj.session_reused
859
+
860
+ @property
861
+ def server_side(self):
862
+ """Whether this is a server-side socket."""
863
+ return self._sslobj.server_side
864
+
865
+ @property
866
+ def server_hostname(self):
867
+ """The currently set server hostname (for SNI), or ``None`` if no
868
+ server hostname is set."""
869
+ return self._sslobj.server_hostname
870
+
871
+ def read(self, len=1024, buffer=None):
872
+ """Read up to 'len' bytes from the SSL object and return them.
873
+
874
+ If 'buffer' is provided, read into this buffer and return the number of
875
+ bytes read.
876
+ """
877
+ if buffer is not None:
878
+ v = self._sslobj.read(len, buffer)
879
+ else:
880
+ v = self._sslobj.read(len)
881
+ return v
882
+
883
+ def write(self, data):
884
+ """Write 'data' to the SSL object and return the number of bytes
885
+ written.
886
+
887
+ The 'data' argument must support the buffer interface.
888
+ """
889
+ return self._sslobj.write(data)
890
+
891
+ def getpeercert(self, binary_form=False):
892
+ """Returns a formatted version of the data in the certificate provided
893
+ by the other end of the SSL channel.
894
+
895
+ Return None if no certificate was provided, {} if a certificate was
896
+ provided, but not validated.
897
+ """
898
+ return self._sslobj.getpeercert(binary_form)
899
+
900
+ def get_verified_chain(self):
901
+ """Returns verified certificate chain provided by the other
902
+ end of the SSL channel as a list of DER-encoded bytes.
903
+
904
+ If certificate verification was disabled method acts the same as
905
+ ``SSLSocket.get_unverified_chain``.
906
+ """
907
+ chain = self._sslobj.get_verified_chain()
908
+
909
+ if chain is None:
910
+ return []
911
+
912
+ return [cert.public_bytes(_ssl.ENCODING_DER) for cert in chain]
913
+
914
+ def get_unverified_chain(self):
915
+ """Returns raw certificate chain provided by the other
916
+ end of the SSL channel as a list of DER-encoded bytes.
917
+ """
918
+ chain = self._sslobj.get_unverified_chain()
919
+
920
+ if chain is None:
921
+ return []
922
+
923
+ return [cert.public_bytes(_ssl.ENCODING_DER) for cert in chain]
924
+
925
+ def selected_npn_protocol(self):
926
+ """Return the currently selected NPN protocol as a string, or ``None``
927
+ if a next protocol was not negotiated or if NPN is not supported by one
928
+ of the peers."""
929
+ warnings.warn(
930
+ "ssl NPN is deprecated, use ALPN instead",
931
+ DeprecationWarning,
932
+ stacklevel=2
933
+ )
934
+
935
+ def selected_alpn_protocol(self):
936
+ """Return the currently selected ALPN protocol as a string, or ``None``
937
+ if a next protocol was not negotiated or if ALPN is not supported by one
938
+ of the peers."""
939
+ return self._sslobj.selected_alpn_protocol()
940
+
941
+ def cipher(self):
942
+ """Return the currently selected cipher as a 3-tuple ``(name,
943
+ ssl_version, secret_bits)``."""
944
+ return self._sslobj.cipher()
945
+
946
+ def shared_ciphers(self):
947
+ """Return a list of ciphers shared by the client during the handshake or
948
+ None if this is not a valid server connection.
949
+ """
950
+ return self._sslobj.shared_ciphers()
951
+
952
+ def compression(self):
953
+ """Return the current compression algorithm in use, or ``None`` if
954
+ compression was not negotiated or not supported by one of the peers."""
955
+ return self._sslobj.compression()
956
+
957
+ def pending(self):
958
+ """Return the number of bytes that can be read immediately."""
959
+ return self._sslobj.pending()
960
+
961
+ def do_handshake(self):
962
+ """Start the SSL/TLS handshake."""
963
+ self._sslobj.do_handshake()
964
+
965
+ def unwrap(self):
966
+ """Start the SSL shutdown handshake."""
967
+ return self._sslobj.shutdown()
968
+
969
+ def get_channel_binding(self, cb_type="tls-unique"):
970
+ """Get channel binding data for current connection. Raise ValueError
971
+ if the requested `cb_type` is not supported. Return bytes of the data
972
+ or None if the data is not available (e.g. before the handshake)."""
973
+ return self._sslobj.get_channel_binding(cb_type)
974
+
975
+ def version(self):
976
+ """Return a string identifying the protocol version used by the
977
+ current SSL channel. """
978
+ return self._sslobj.version()
979
+
980
+ def verify_client_post_handshake(self):
981
+ return self._sslobj.verify_client_post_handshake()
982
+
983
+
984
+ def _sslcopydoc(func):
985
+ """Copy docstring from SSLObject to SSLSocket"""
986
+ func.__doc__ = getattr(SSLObject, func.__name__).__doc__
987
+ return func
988
+
989
+
990
+ class SSLSocket(socket):
991
+ """This class implements a subtype of socket.socket that wraps
992
+ the underlying OS socket in an SSL context when necessary, and
993
+ provides read and write methods over that channel. """
994
+
995
+ def __init__(self, *args, **kwargs):
996
+ raise TypeError(
997
+ f"{self.__class__.__name__} does not have a public "
998
+ f"constructor. Instances are returned by "
999
+ f"SSLContext.wrap_socket()."
1000
+ )
1001
+
1002
+ @classmethod
1003
+ def _create(cls, sock, server_side=False, do_handshake_on_connect=True,
1004
+ suppress_ragged_eofs=True, server_hostname=None,
1005
+ context=None, session=None):
1006
+ if sock.getsockopt(SOL_SOCKET, SO_TYPE) != SOCK_STREAM:
1007
+ raise NotImplementedError("only stream sockets are supported")
1008
+ if server_side:
1009
+ if server_hostname:
1010
+ raise ValueError("server_hostname can only be specified "
1011
+ "in client mode")
1012
+ if session is not None:
1013
+ raise ValueError("session can only be specified in "
1014
+ "client mode")
1015
+ if context.check_hostname and not server_hostname:
1016
+ raise ValueError("check_hostname requires server_hostname")
1017
+
1018
+ sock_timeout = sock.gettimeout()
1019
+ kwargs = dict(
1020
+ family=sock.family, type=sock.type, proto=sock.proto,
1021
+ fileno=sock.fileno()
1022
+ )
1023
+ self = cls.__new__(cls, **kwargs)
1024
+ super(SSLSocket, self).__init__(**kwargs)
1025
+ sock.detach()
1026
+ # Now SSLSocket is responsible for closing the file descriptor.
1027
+ try:
1028
+ self._context = context
1029
+ self._session = session
1030
+ self._closed = False
1031
+ self._sslobj = None
1032
+ self.server_side = server_side
1033
+ self.server_hostname = context._encode_hostname(server_hostname)
1034
+ self.do_handshake_on_connect = do_handshake_on_connect
1035
+ self.suppress_ragged_eofs = suppress_ragged_eofs
1036
+
1037
+ # See if we are connected
1038
+ try:
1039
+ self.getpeername()
1040
+ except OSError as e:
1041
+ if e.errno != errno.ENOTCONN:
1042
+ raise
1043
+ connected = False
1044
+ blocking = self.getblocking()
1045
+ self.setblocking(False)
1046
+ try:
1047
+ # We are not connected so this is not supposed to block, but
1048
+ # testing revealed otherwise on macOS and Windows so we do
1049
+ # the non-blocking dance regardless. Our raise when any data
1050
+ # is found means consuming the data is harmless.
1051
+ notconn_pre_handshake_data = self.recv(1)
1052
+ except OSError as e:
1053
+ # EINVAL occurs for recv(1) on non-connected on unix sockets.
1054
+ if e.errno not in (errno.ENOTCONN, errno.EINVAL):
1055
+ raise
1056
+ notconn_pre_handshake_data = b''
1057
+ self.setblocking(blocking)
1058
+ if notconn_pre_handshake_data:
1059
+ # This prevents pending data sent to the socket before it was
1060
+ # closed from escaping to the caller who could otherwise
1061
+ # presume it came through a successful TLS connection.
1062
+ reason = "Closed before TLS handshake with data in recv buffer."
1063
+ notconn_pre_handshake_data_error = SSLError(e.errno, reason)
1064
+ # Add the SSLError attributes that _ssl.c always adds.
1065
+ notconn_pre_handshake_data_error.reason = reason
1066
+ notconn_pre_handshake_data_error.library = None
1067
+ try:
1068
+ raise notconn_pre_handshake_data_error
1069
+ finally:
1070
+ # Explicitly break the reference cycle.
1071
+ notconn_pre_handshake_data_error = None
1072
+ else:
1073
+ connected = True
1074
+
1075
+ self.settimeout(sock_timeout) # Must come after setblocking() calls.
1076
+ self._connected = connected
1077
+ if connected:
1078
+ # create the SSL object
1079
+ self._sslobj = self._context._wrap_socket(
1080
+ self, server_side, self.server_hostname,
1081
+ owner=self, session=self._session,
1082
+ )
1083
+ if do_handshake_on_connect:
1084
+ timeout = self.gettimeout()
1085
+ if timeout == 0.0:
1086
+ # non-blocking
1087
+ raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
1088
+ self.do_handshake()
1089
+ except:
1090
+ try:
1091
+ self.close()
1092
+ except OSError:
1093
+ pass
1094
+ raise
1095
+ return self
1096
+
1097
+ @property
1098
+ @_sslcopydoc
1099
+ def context(self):
1100
+ return self._context
1101
+
1102
+ @context.setter
1103
+ def context(self, ctx):
1104
+ self._context = ctx
1105
+ self._sslobj.context = ctx
1106
+
1107
+ @property
1108
+ @_sslcopydoc
1109
+ def session(self):
1110
+ if self._sslobj is not None:
1111
+ return self._sslobj.session
1112
+
1113
+ @session.setter
1114
+ def session(self, session):
1115
+ self._session = session
1116
+ if self._sslobj is not None:
1117
+ self._sslobj.session = session
1118
+
1119
+ @property
1120
+ @_sslcopydoc
1121
+ def session_reused(self):
1122
+ if self._sslobj is not None:
1123
+ return self._sslobj.session_reused
1124
+
1125
+ def dup(self):
1126
+ raise NotImplementedError("Can't dup() %s instances" %
1127
+ self.__class__.__name__)
1128
+
1129
+ def _checkClosed(self, msg=None):
1130
+ # raise an exception here if you wish to check for spurious closes
1131
+ pass
1132
+
1133
+ def _check_connected(self):
1134
+ if not self._connected:
1135
+ # getpeername() will raise ENOTCONN if the socket is really
1136
+ # not connected; note that we can be connected even without
1137
+ # _connected being set, e.g. if connect() first returned
1138
+ # EAGAIN.
1139
+ self.getpeername()
1140
+
1141
+ def read(self, len=1024, buffer=None):
1142
+ """Read up to LEN bytes and return them.
1143
+ Return zero-length string on EOF."""
1144
+
1145
+ self._checkClosed()
1146
+ if self._sslobj is None:
1147
+ raise ValueError("Read on closed or unwrapped SSL socket.")
1148
+ try:
1149
+ if buffer is not None:
1150
+ return self._sslobj.read(len, buffer)
1151
+ else:
1152
+ return self._sslobj.read(len)
1153
+ except SSLError as x:
1154
+ if x.args[0] == SSL_ERROR_EOF and self.suppress_ragged_eofs:
1155
+ if buffer is not None:
1156
+ return 0
1157
+ else:
1158
+ return b''
1159
+ else:
1160
+ raise
1161
+
1162
+ def write(self, data):
1163
+ """Write DATA to the underlying SSL channel. Returns
1164
+ number of bytes of DATA actually transmitted."""
1165
+
1166
+ self._checkClosed()
1167
+ if self._sslobj is None:
1168
+ raise ValueError("Write on closed or unwrapped SSL socket.")
1169
+ return self._sslobj.write(data)
1170
+
1171
+ @_sslcopydoc
1172
+ def getpeercert(self, binary_form=False):
1173
+ self._checkClosed()
1174
+ self._check_connected()
1175
+ return self._sslobj.getpeercert(binary_form)
1176
+
1177
+ @_sslcopydoc
1178
+ def get_verified_chain(self):
1179
+ chain = self._sslobj.get_verified_chain()
1180
+
1181
+ if chain is None:
1182
+ return []
1183
+
1184
+ return [cert.public_bytes(_ssl.ENCODING_DER) for cert in chain]
1185
+
1186
+ @_sslcopydoc
1187
+ def get_unverified_chain(self):
1188
+ chain = self._sslobj.get_unverified_chain()
1189
+
1190
+ if chain is None:
1191
+ return []
1192
+
1193
+ return [cert.public_bytes(_ssl.ENCODING_DER) for cert in chain]
1194
+
1195
+ @_sslcopydoc
1196
+ def selected_npn_protocol(self):
1197
+ self._checkClosed()
1198
+ warnings.warn(
1199
+ "ssl NPN is deprecated, use ALPN instead",
1200
+ DeprecationWarning,
1201
+ stacklevel=2
1202
+ )
1203
+ return None
1204
+
1205
+ @_sslcopydoc
1206
+ def selected_alpn_protocol(self):
1207
+ self._checkClosed()
1208
+ if self._sslobj is None or not _ssl.HAS_ALPN:
1209
+ return None
1210
+ else:
1211
+ return self._sslobj.selected_alpn_protocol()
1212
+
1213
+ @_sslcopydoc
1214
+ def cipher(self):
1215
+ self._checkClosed()
1216
+ if self._sslobj is None:
1217
+ return None
1218
+ else:
1219
+ return self._sslobj.cipher()
1220
+
1221
+ @_sslcopydoc
1222
+ def shared_ciphers(self):
1223
+ self._checkClosed()
1224
+ if self._sslobj is None:
1225
+ return None
1226
+ else:
1227
+ return self._sslobj.shared_ciphers()
1228
+
1229
+ @_sslcopydoc
1230
+ def compression(self):
1231
+ self._checkClosed()
1232
+ if self._sslobj is None:
1233
+ return None
1234
+ else:
1235
+ return self._sslobj.compression()
1236
+
1237
+ def send(self, data, flags=0):
1238
+ self._checkClosed()
1239
+ if self._sslobj is not None:
1240
+ if flags != 0:
1241
+ raise ValueError(
1242
+ "non-zero flags not allowed in calls to send() on %s" %
1243
+ self.__class__)
1244
+ return self._sslobj.write(data)
1245
+ else:
1246
+ return super().send(data, flags)
1247
+
1248
+ def sendto(self, data, flags_or_addr, addr=None):
1249
+ self._checkClosed()
1250
+ if self._sslobj is not None:
1251
+ raise ValueError("sendto not allowed on instances of %s" %
1252
+ self.__class__)
1253
+ elif addr is None:
1254
+ return super().sendto(data, flags_or_addr)
1255
+ else:
1256
+ return super().sendto(data, flags_or_addr, addr)
1257
+
1258
+ def sendmsg(self, *args, **kwargs):
1259
+ # Ensure programs don't send data unencrypted if they try to
1260
+ # use this method.
1261
+ raise NotImplementedError("sendmsg not allowed on instances of %s" %
1262
+ self.__class__)
1263
+
1264
+ def sendall(self, data, flags=0):
1265
+ self._checkClosed()
1266
+ if self._sslobj is not None:
1267
+ if flags != 0:
1268
+ raise ValueError(
1269
+ "non-zero flags not allowed in calls to sendall() on %s" %
1270
+ self.__class__)
1271
+ count = 0
1272
+ with memoryview(data) as view, view.cast("B") as byte_view:
1273
+ amount = len(byte_view)
1274
+ while count < amount:
1275
+ v = self.send(byte_view[count:])
1276
+ count += v
1277
+ else:
1278
+ return super().sendall(data, flags)
1279
+
1280
+ def sendfile(self, file, offset=0, count=None):
1281
+ """Send a file, possibly by using os.sendfile() if this is a
1282
+ clear-text socket. Return the total number of bytes sent.
1283
+ """
1284
+ if self._sslobj is not None:
1285
+ return self._sendfile_use_send(file, offset, count)
1286
+ else:
1287
+ # os.sendfile() works with plain sockets only
1288
+ return super().sendfile(file, offset, count)
1289
+
1290
+ def recv(self, buflen=1024, flags=0):
1291
+ self._checkClosed()
1292
+ if self._sslobj is not None:
1293
+ if flags != 0:
1294
+ raise ValueError(
1295
+ "non-zero flags not allowed in calls to recv() on %s" %
1296
+ self.__class__)
1297
+ return self.read(buflen)
1298
+ else:
1299
+ return super().recv(buflen, flags)
1300
+
1301
+ def recv_into(self, buffer, nbytes=None, flags=0):
1302
+ self._checkClosed()
1303
+ if nbytes is None:
1304
+ if buffer is not None:
1305
+ with memoryview(buffer) as view:
1306
+ nbytes = view.nbytes
1307
+ if not nbytes:
1308
+ nbytes = 1024
1309
+ else:
1310
+ nbytes = 1024
1311
+ if self._sslobj is not None:
1312
+ if flags != 0:
1313
+ raise ValueError(
1314
+ "non-zero flags not allowed in calls to recv_into() on %s" %
1315
+ self.__class__)
1316
+ return self.read(nbytes, buffer)
1317
+ else:
1318
+ return super().recv_into(buffer, nbytes, flags)
1319
+
1320
+ def recvfrom(self, buflen=1024, flags=0):
1321
+ self._checkClosed()
1322
+ if self._sslobj is not None:
1323
+ raise ValueError("recvfrom not allowed on instances of %s" %
1324
+ self.__class__)
1325
+ else:
1326
+ return super().recvfrom(buflen, flags)
1327
+
1328
+ def recvfrom_into(self, buffer, nbytes=None, flags=0):
1329
+ self._checkClosed()
1330
+ if self._sslobj is not None:
1331
+ raise ValueError("recvfrom_into not allowed on instances of %s" %
1332
+ self.__class__)
1333
+ else:
1334
+ return super().recvfrom_into(buffer, nbytes, flags)
1335
+
1336
+ def recvmsg(self, *args, **kwargs):
1337
+ raise NotImplementedError("recvmsg not allowed on instances of %s" %
1338
+ self.__class__)
1339
+
1340
+ def recvmsg_into(self, *args, **kwargs):
1341
+ raise NotImplementedError("recvmsg_into not allowed on instances of "
1342
+ "%s" % self.__class__)
1343
+
1344
+ @_sslcopydoc
1345
+ def pending(self):
1346
+ self._checkClosed()
1347
+ if self._sslobj is not None:
1348
+ return self._sslobj.pending()
1349
+ else:
1350
+ return 0
1351
+
1352
+ def shutdown(self, how):
1353
+ self._checkClosed()
1354
+ self._sslobj = None
1355
+ super().shutdown(how)
1356
+
1357
+ @_sslcopydoc
1358
+ def unwrap(self):
1359
+ if self._sslobj:
1360
+ s = self._sslobj.shutdown()
1361
+ self._sslobj = None
1362
+ return s
1363
+ else:
1364
+ raise ValueError("No SSL wrapper around " + str(self))
1365
+
1366
+ @_sslcopydoc
1367
+ def verify_client_post_handshake(self):
1368
+ if self._sslobj:
1369
+ return self._sslobj.verify_client_post_handshake()
1370
+ else:
1371
+ raise ValueError("No SSL wrapper around " + str(self))
1372
+
1373
+ def _real_close(self):
1374
+ self._sslobj = None
1375
+ super()._real_close()
1376
+
1377
+ @_sslcopydoc
1378
+ def do_handshake(self, block=False):
1379
+ self._check_connected()
1380
+ timeout = self.gettimeout()
1381
+ try:
1382
+ if timeout == 0.0 and block:
1383
+ self.settimeout(None)
1384
+ self._sslobj.do_handshake()
1385
+ finally:
1386
+ self.settimeout(timeout)
1387
+
1388
+ def _real_connect(self, addr, connect_ex):
1389
+ if self.server_side:
1390
+ raise ValueError("can't connect in server-side mode")
1391
+ # Here we assume that the socket is client-side, and not
1392
+ # connected at the time of the call. We connect it, then wrap it.
1393
+ if self._connected or self._sslobj is not None:
1394
+ raise ValueError("attempt to connect already-connected SSLSocket!")
1395
+ self._sslobj = self.context._wrap_socket(
1396
+ self, False, self.server_hostname,
1397
+ owner=self, session=self._session
1398
+ )
1399
+ try:
1400
+ if connect_ex:
1401
+ rc = super().connect_ex(addr)
1402
+ else:
1403
+ rc = None
1404
+ super().connect(addr)
1405
+ if not rc:
1406
+ self._connected = True
1407
+ if self.do_handshake_on_connect:
1408
+ self.do_handshake()
1409
+ return rc
1410
+ except (OSError, ValueError):
1411
+ self._sslobj = None
1412
+ raise
1413
+
1414
+ def connect(self, addr):
1415
+ """Connects to remote ADDR, and then wraps the connection in
1416
+ an SSL channel."""
1417
+ self._real_connect(addr, False)
1418
+
1419
+ def connect_ex(self, addr):
1420
+ """Connects to remote ADDR, and then wraps the connection in
1421
+ an SSL channel."""
1422
+ return self._real_connect(addr, True)
1423
+
1424
+ def accept(self):
1425
+ """Accepts a new connection from a remote client, and returns
1426
+ a tuple containing that new connection wrapped with a server-side
1427
+ SSL channel, and the address of the remote client."""
1428
+
1429
+ newsock, addr = super().accept()
1430
+ newsock = self.context.wrap_socket(newsock,
1431
+ do_handshake_on_connect=self.do_handshake_on_connect,
1432
+ suppress_ragged_eofs=self.suppress_ragged_eofs,
1433
+ server_side=True)
1434
+ return newsock, addr
1435
+
1436
+ @_sslcopydoc
1437
+ def get_channel_binding(self, cb_type="tls-unique"):
1438
+ if self._sslobj is not None:
1439
+ return self._sslobj.get_channel_binding(cb_type)
1440
+ else:
1441
+ if cb_type not in CHANNEL_BINDING_TYPES:
1442
+ raise ValueError(
1443
+ "{0} channel binding type not implemented".format(cb_type)
1444
+ )
1445
+ return None
1446
+
1447
+ @_sslcopydoc
1448
+ def version(self):
1449
+ if self._sslobj is not None:
1450
+ return self._sslobj.version()
1451
+ else:
1452
+ return None
1453
+
1454
+
1455
+ # Python does not support forward declaration of types.
1456
+ SSLContext.sslsocket_class = SSLSocket
1457
+ SSLContext.sslobject_class = SSLObject
1458
+
1459
+
1460
+ # some utility functions
1461
+
1462
+ def cert_time_to_seconds(cert_time):
1463
+ """Return the time in seconds since the Epoch, given the timestring
1464
+ representing the "notBefore" or "notAfter" date from a certificate
1465
+ in ``"%b %d %H:%M:%S %Y %Z"`` strptime format (C locale).
1466
+
1467
+ "notBefore" or "notAfter" dates must use UTC (RFC 5280).
1468
+
1469
+ Month is one of: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1470
+ UTC should be specified as GMT (see ASN1_TIME_print())
1471
+ """
1472
+ from time import strptime
1473
+ from calendar import timegm
1474
+
1475
+ months = (
1476
+ "Jan","Feb","Mar","Apr","May","Jun",
1477
+ "Jul","Aug","Sep","Oct","Nov","Dec"
1478
+ )
1479
+ time_format = ' %d %H:%M:%S %Y GMT' # NOTE: no month, fixed GMT
1480
+ try:
1481
+ month_number = months.index(cert_time[:3].title()) + 1
1482
+ except ValueError:
1483
+ raise ValueError('time data %r does not match '
1484
+ 'format "%%b%s"' % (cert_time, time_format))
1485
+ else:
1486
+ # found valid month
1487
+ tt = strptime(cert_time[3:], time_format)
1488
+ # return an integer, the previous mktime()-based implementation
1489
+ # returned a float (fractional seconds are always zero here).
1490
+ return timegm((tt[0], month_number) + tt[2:6])
1491
+
1492
+ PEM_HEADER = "-----BEGIN CERTIFICATE-----"
1493
+ PEM_FOOTER = "-----END CERTIFICATE-----"
1494
+
1495
+ def DER_cert_to_PEM_cert(der_cert_bytes):
1496
+ """Takes a certificate in binary DER format and returns the
1497
+ PEM version of it as a string."""
1498
+
1499
+ f = str(base64.standard_b64encode(der_cert_bytes), 'ASCII', 'strict')
1500
+ ss = [PEM_HEADER]
1501
+ ss += [f[i:i+64] for i in range(0, len(f), 64)]
1502
+ ss.append(PEM_FOOTER + '\n')
1503
+ return '\n'.join(ss)
1504
+
1505
+ def PEM_cert_to_DER_cert(pem_cert_string):
1506
+ """Takes a certificate in ASCII PEM format and returns the
1507
+ DER-encoded version of it as a byte sequence"""
1508
+
1509
+ if not pem_cert_string.startswith(PEM_HEADER):
1510
+ raise ValueError("Invalid PEM encoding; must start with %s"
1511
+ % PEM_HEADER)
1512
+ if not pem_cert_string.strip().endswith(PEM_FOOTER):
1513
+ raise ValueError("Invalid PEM encoding; must end with %s"
1514
+ % PEM_FOOTER)
1515
+ d = pem_cert_string.strip()[len(PEM_HEADER):-len(PEM_FOOTER)]
1516
+ return base64.decodebytes(d.encode('ASCII', 'strict'))
1517
+
1518
+ def get_server_certificate(addr, ssl_version=PROTOCOL_TLS_CLIENT,
1519
+ ca_certs=None, timeout=_GLOBAL_DEFAULT_TIMEOUT):
1520
+ """Retrieve the certificate from the server at the specified address,
1521
+ and return it as a PEM-encoded string.
1522
+ If 'ca_certs' is specified, validate the server cert against it.
1523
+ If 'ssl_version' is specified, use it in the connection attempt.
1524
+ If 'timeout' is specified, use it in the connection attempt.
1525
+ """
1526
+
1527
+ host, port = addr
1528
+ if ca_certs is not None:
1529
+ cert_reqs = CERT_REQUIRED
1530
+ else:
1531
+ cert_reqs = CERT_NONE
1532
+ context = _create_stdlib_context(ssl_version,
1533
+ cert_reqs=cert_reqs,
1534
+ cafile=ca_certs)
1535
+ with create_connection(addr, timeout=timeout) as sock:
1536
+ with context.wrap_socket(sock, server_hostname=host) as sslsock:
1537
+ dercert = sslsock.getpeercert(True)
1538
+ return DER_cert_to_PEM_cert(dercert)
1539
+
1540
+ def get_protocol_name(protocol_code):
1541
+ return _PROTOCOL_NAMES.get(protocol_code, '<unknown>')