atomicshop 2.15.11__py3-none-any.whl → 3.10.5__py3-none-any.whl

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 (221) hide show
  1. atomicshop/__init__.py +1 -1
  2. atomicshop/{addons/mains → a_mains}/FACT/update_extract.py +3 -2
  3. atomicshop/a_mains/dns_gateway_setting.py +11 -0
  4. atomicshop/a_mains/get_local_tcp_ports.py +85 -0
  5. atomicshop/a_mains/github_wrapper.py +11 -0
  6. atomicshop/a_mains/install_ca_certificate.py +172 -0
  7. atomicshop/a_mains/process_from_port.py +119 -0
  8. atomicshop/a_mains/set_default_dns_gateway.py +90 -0
  9. atomicshop/a_mains/update_config_toml.py +38 -0
  10. atomicshop/basics/ansi_escape_codes.py +3 -1
  11. atomicshop/basics/argparse_template.py +2 -0
  12. atomicshop/basics/booleans.py +27 -30
  13. atomicshop/basics/bytes_arrays.py +43 -0
  14. atomicshop/basics/classes.py +149 -1
  15. atomicshop/basics/enums.py +2 -2
  16. atomicshop/basics/exceptions.py +5 -1
  17. atomicshop/basics/list_of_classes.py +29 -0
  18. atomicshop/basics/multiprocesses.py +374 -50
  19. atomicshop/basics/strings.py +72 -3
  20. atomicshop/basics/threads.py +14 -0
  21. atomicshop/basics/tracebacks.py +13 -3
  22. atomicshop/certificates.py +153 -52
  23. atomicshop/config_init.py +11 -6
  24. atomicshop/console_user_response.py +7 -14
  25. atomicshop/consoles.py +9 -0
  26. atomicshop/datetimes.py +1 -1
  27. atomicshop/diff_check.py +3 -3
  28. atomicshop/dns.py +128 -3
  29. atomicshop/etws/_pywintrace_fix.py +17 -0
  30. atomicshop/etws/trace.py +40 -42
  31. atomicshop/etws/traces/trace_dns.py +56 -44
  32. atomicshop/etws/traces/trace_tcp.py +130 -0
  33. atomicshop/file_io/csvs.py +27 -5
  34. atomicshop/file_io/docxs.py +34 -17
  35. atomicshop/file_io/file_io.py +31 -17
  36. atomicshop/file_io/jsons.py +49 -0
  37. atomicshop/file_io/tomls.py +139 -0
  38. atomicshop/filesystem.py +616 -291
  39. atomicshop/get_process_list.py +3 -3
  40. atomicshop/http_parse.py +149 -93
  41. atomicshop/ip_addresses.py +6 -1
  42. atomicshop/mitm/centered_settings.py +132 -0
  43. atomicshop/mitm/config_static.py +207 -0
  44. atomicshop/mitm/config_toml_editor.py +55 -0
  45. atomicshop/mitm/connection_thread_worker.py +875 -357
  46. atomicshop/mitm/engines/__parent/parser___parent.py +4 -17
  47. atomicshop/mitm/engines/__parent/recorder___parent.py +108 -51
  48. atomicshop/mitm/engines/__parent/requester___parent.py +116 -0
  49. atomicshop/mitm/engines/__parent/responder___parent.py +75 -114
  50. atomicshop/mitm/engines/__reference_general/parser___reference_general.py +10 -7
  51. atomicshop/mitm/engines/__reference_general/recorder___reference_general.py +5 -5
  52. atomicshop/mitm/engines/__reference_general/requester___reference_general.py +47 -0
  53. atomicshop/mitm/engines/__reference_general/responder___reference_general.py +95 -13
  54. atomicshop/mitm/engines/create_module_template.py +58 -14
  55. atomicshop/mitm/import_config.py +359 -139
  56. atomicshop/mitm/initialize_engines.py +160 -80
  57. atomicshop/mitm/message.py +64 -23
  58. atomicshop/mitm/mitm_main.py +892 -0
  59. atomicshop/mitm/recs_files.py +183 -0
  60. atomicshop/mitm/shared_functions.py +4 -10
  61. atomicshop/mitm/ssh_tester.py +82 -0
  62. atomicshop/mitm/statistic_analyzer.py +136 -40
  63. atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py +265 -83
  64. atomicshop/monitor/checks/dns.py +1 -1
  65. atomicshop/networks.py +671 -0
  66. atomicshop/on_exit.py +39 -9
  67. atomicshop/package_mains_processor.py +84 -0
  68. atomicshop/permissions/permissions.py +22 -0
  69. atomicshop/permissions/ubuntu_permissions.py +239 -0
  70. atomicshop/permissions/win_permissions.py +33 -0
  71. atomicshop/print_api.py +24 -42
  72. atomicshop/process.py +24 -6
  73. atomicshop/process_poller/process_pool.py +0 -1
  74. atomicshop/process_poller/simple_process_pool.py +204 -5
  75. atomicshop/python_file_patcher.py +1 -1
  76. atomicshop/python_functions.py +27 -75
  77. atomicshop/speech_recognize.py +8 -0
  78. atomicshop/ssh_remote.py +158 -172
  79. atomicshop/system_resource_monitor.py +61 -47
  80. atomicshop/system_resources.py +8 -8
  81. atomicshop/tempfiles.py +1 -2
  82. atomicshop/urls.py +6 -0
  83. atomicshop/venvs.py +28 -0
  84. atomicshop/versioning.py +27 -0
  85. atomicshop/web.py +98 -27
  86. atomicshop/web_apis/google_custom_search.py +44 -0
  87. atomicshop/web_apis/google_llm.py +188 -0
  88. atomicshop/websocket_parse.py +450 -0
  89. atomicshop/wrappers/certauthw/certauth.py +1 -0
  90. atomicshop/wrappers/cryptographyw.py +29 -8
  91. atomicshop/wrappers/ctyping/etw_winapi/const.py +97 -47
  92. atomicshop/wrappers/ctyping/etw_winapi/etw_functions.py +178 -49
  93. atomicshop/wrappers/ctyping/file_details_winapi.py +67 -0
  94. atomicshop/wrappers/ctyping/msi_windows_installer/cabs.py +2 -1
  95. atomicshop/wrappers/ctyping/msi_windows_installer/extract_msi_main.py +2 -2
  96. atomicshop/wrappers/ctyping/setup_device.py +466 -0
  97. atomicshop/wrappers/ctyping/win_console.py +39 -0
  98. atomicshop/wrappers/dockerw/dockerw.py +113 -2
  99. atomicshop/wrappers/elasticsearchw/config_basic.py +0 -12
  100. atomicshop/wrappers/elasticsearchw/elastic_infra.py +75 -0
  101. atomicshop/wrappers/elasticsearchw/elasticsearchw.py +2 -20
  102. atomicshop/wrappers/factw/get_file_data.py +12 -5
  103. atomicshop/wrappers/factw/install/install_after_restart.py +89 -5
  104. atomicshop/wrappers/factw/install/pre_install_and_install_before_restart.py +20 -14
  105. atomicshop/wrappers/githubw.py +537 -54
  106. atomicshop/wrappers/loggingw/consts.py +1 -1
  107. atomicshop/wrappers/loggingw/filters.py +23 -0
  108. atomicshop/wrappers/loggingw/formatters.py +12 -0
  109. atomicshop/wrappers/loggingw/handlers.py +214 -107
  110. atomicshop/wrappers/loggingw/loggers.py +19 -0
  111. atomicshop/wrappers/loggingw/loggingw.py +860 -22
  112. atomicshop/wrappers/loggingw/reading.py +134 -112
  113. atomicshop/wrappers/mongodbw/mongo_infra.py +31 -0
  114. atomicshop/wrappers/mongodbw/mongodbw.py +1324 -36
  115. atomicshop/wrappers/netshw.py +271 -0
  116. atomicshop/wrappers/playwrightw/engine.py +34 -19
  117. atomicshop/wrappers/playwrightw/infra.py +5 -0
  118. atomicshop/wrappers/playwrightw/javascript.py +7 -3
  119. atomicshop/wrappers/playwrightw/keyboard.py +14 -0
  120. atomicshop/wrappers/playwrightw/scenarios.py +172 -5
  121. atomicshop/wrappers/playwrightw/waits.py +9 -7
  122. atomicshop/wrappers/powershell_networking.py +80 -0
  123. atomicshop/wrappers/psutilw/processes.py +37 -1
  124. atomicshop/wrappers/psutilw/psutil_networks.py +85 -0
  125. atomicshop/wrappers/pyopensslw.py +9 -2
  126. atomicshop/wrappers/pywin32w/cert_store.py +116 -0
  127. atomicshop/wrappers/pywin32w/win_event_log/fetch.py +174 -0
  128. atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_create.py +3 -105
  129. atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_terminate.py +3 -57
  130. atomicshop/wrappers/pywin32w/wmis/msft_netipaddress.py +113 -0
  131. atomicshop/wrappers/pywin32w/wmis/win32_networkadapterconfiguration.py +259 -0
  132. atomicshop/wrappers/pywin32w/wmis/win32networkadapter.py +112 -0
  133. atomicshop/wrappers/pywin32w/wmis/wmi_helpers.py +236 -0
  134. atomicshop/wrappers/socketw/accepter.py +21 -7
  135. atomicshop/wrappers/socketw/certificator.py +216 -150
  136. atomicshop/wrappers/socketw/creator.py +190 -50
  137. atomicshop/wrappers/socketw/dns_server.py +491 -182
  138. atomicshop/wrappers/socketw/exception_wrapper.py +45 -52
  139. atomicshop/wrappers/socketw/process_getter.py +86 -0
  140. atomicshop/wrappers/socketw/receiver.py +144 -102
  141. atomicshop/wrappers/socketw/sender.py +65 -35
  142. atomicshop/wrappers/socketw/sni.py +334 -165
  143. atomicshop/wrappers/socketw/socket_base.py +134 -0
  144. atomicshop/wrappers/socketw/socket_client.py +137 -95
  145. atomicshop/wrappers/socketw/socket_server_tester.py +11 -7
  146. atomicshop/wrappers/socketw/socket_wrapper.py +717 -116
  147. atomicshop/wrappers/socketw/ssl_base.py +15 -14
  148. atomicshop/wrappers/socketw/statistics_csv.py +148 -17
  149. atomicshop/wrappers/sysmonw.py +1 -1
  150. atomicshop/wrappers/ubuntu_terminal.py +65 -26
  151. atomicshop/wrappers/win_auditw.py +189 -0
  152. atomicshop/wrappers/winregw/__init__.py +0 -0
  153. atomicshop/wrappers/winregw/winreg_installed_software.py +58 -0
  154. atomicshop/wrappers/winregw/winreg_network.py +232 -0
  155. {atomicshop-2.15.11.dist-info → atomicshop-3.10.5.dist-info}/METADATA +31 -51
  156. atomicshop-3.10.5.dist-info/RECORD +306 -0
  157. {atomicshop-2.15.11.dist-info → atomicshop-3.10.5.dist-info}/WHEEL +1 -1
  158. atomicshop/_basics_temp.py +0 -101
  159. atomicshop/a_installs/win/fibratus.py +0 -9
  160. atomicshop/a_installs/win/mongodb.py +0 -9
  161. atomicshop/a_installs/win/pycharm.py +0 -9
  162. atomicshop/addons/a_setup_scripts/install_psycopg2_ubuntu.sh +0 -3
  163. atomicshop/addons/a_setup_scripts/install_pywintrace_0.3.cmd +0 -2
  164. atomicshop/addons/mains/__pycache__/install_fibratus_windows.cpython-312.pyc +0 -0
  165. atomicshop/addons/mains/__pycache__/msi_unpacker.cpython-312.pyc +0 -0
  166. atomicshop/addons/mains/install_docker_rootless_ubuntu.py +0 -11
  167. atomicshop/addons/mains/install_docker_ubuntu_main_sudo.py +0 -11
  168. atomicshop/addons/mains/install_elastic_search_and_kibana_ubuntu.py +0 -10
  169. atomicshop/addons/mains/install_wsl_ubuntu_lts_admin.py +0 -9
  170. atomicshop/addons/package_setup/CreateWheel.cmd +0 -7
  171. atomicshop/addons/package_setup/Setup in Edit mode.cmd +0 -6
  172. atomicshop/addons/package_setup/Setup.cmd +0 -7
  173. atomicshop/archiver/_search_in_zip.py +0 -189
  174. atomicshop/archiver/archiver.py +0 -34
  175. atomicshop/archiver/search_in_archive.py +0 -250
  176. atomicshop/archiver/sevenz_app_w.py +0 -86
  177. atomicshop/archiver/sevenzs.py +0 -44
  178. atomicshop/archiver/zips.py +0 -293
  179. atomicshop/file_types.py +0 -24
  180. atomicshop/mitm/config_editor.py +0 -37
  181. atomicshop/mitm/engines/create_module_template_example.py +0 -13
  182. atomicshop/mitm/initialize_mitm_server.py +0 -268
  183. atomicshop/pbtkmultifile_argparse.py +0 -88
  184. atomicshop/permissions.py +0 -151
  185. atomicshop/script_as_string_processor.py +0 -38
  186. atomicshop/ssh_scripts/process_from_ipv4.py +0 -37
  187. atomicshop/ssh_scripts/process_from_port.py +0 -27
  188. atomicshop/wrappers/_process_wrapper_curl.py +0 -27
  189. atomicshop/wrappers/_process_wrapper_tar.py +0 -21
  190. atomicshop/wrappers/dockerw/install_docker.py +0 -209
  191. atomicshop/wrappers/elasticsearchw/infrastructure.py +0 -265
  192. atomicshop/wrappers/elasticsearchw/install_elastic.py +0 -232
  193. atomicshop/wrappers/ffmpegw.py +0 -125
  194. atomicshop/wrappers/fibratusw/install.py +0 -81
  195. atomicshop/wrappers/mongodbw/infrastructure.py +0 -53
  196. atomicshop/wrappers/mongodbw/install_mongodb.py +0 -190
  197. atomicshop/wrappers/msiw.py +0 -149
  198. atomicshop/wrappers/nodejsw/install_nodejs.py +0 -139
  199. atomicshop/wrappers/process_wrapper_pbtk.py +0 -16
  200. atomicshop/wrappers/psutilw/networks.py +0 -45
  201. atomicshop/wrappers/pycharmw.py +0 -81
  202. atomicshop/wrappers/socketw/base.py +0 -59
  203. atomicshop/wrappers/socketw/get_process.py +0 -107
  204. atomicshop/wrappers/wslw.py +0 -191
  205. atomicshop-2.15.11.dist-info/RECORD +0 -302
  206. /atomicshop/{addons/mains → a_mains}/FACT/factw_fact_extractor_docker_image_main_sudo.py +0 -0
  207. /atomicshop/{addons → a_mains/addons}/PlayWrightCodegen.cmd +0 -0
  208. /atomicshop/{addons → a_mains/addons}/ScriptExecution.cmd +0 -0
  209. /atomicshop/{addons → a_mains/addons}/inits/init_to_import_all_modules.py +0 -0
  210. /atomicshop/{addons → a_mains/addons}/process_list/ReadMe.txt +0 -0
  211. /atomicshop/{addons → a_mains/addons}/process_list/compile.cmd +0 -0
  212. /atomicshop/{addons → a_mains/addons}/process_list/compiled/Win10x64/process_list.dll +0 -0
  213. /atomicshop/{addons → a_mains/addons}/process_list/compiled/Win10x64/process_list.exp +0 -0
  214. /atomicshop/{addons → a_mains/addons}/process_list/compiled/Win10x64/process_list.lib +0 -0
  215. /atomicshop/{addons → a_mains/addons}/process_list/process_list.cpp +0 -0
  216. /atomicshop/{archiver → permissions}/__init__.py +0 -0
  217. /atomicshop/{wrappers/fibratusw → web_apis}/__init__.py +0 -0
  218. /atomicshop/wrappers/{nodejsw → pywin32w/wmis}/__init__.py +0 -0
  219. /atomicshop/wrappers/pywin32w/{wmi_win32process.py → wmis/win32process.py} +0 -0
  220. {atomicshop-2.15.11.dist-info → atomicshop-3.10.5.dist-info/licenses}/LICENSE.txt +0 -0
  221. {atomicshop-2.15.11.dist-info → atomicshop-3.10.5.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,8 @@
1
+ import os
1
2
  import socket
2
3
  import ssl
3
4
 
4
- from . import base, sni, certificator, exception_wrapper
5
+ from . import socket_base, exception_wrapper
5
6
  from ...print_api import print_api
6
7
 
7
8
 
@@ -24,24 +25,113 @@ def add_reusable_address_option(socket_instance):
24
25
  socket_instance.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
25
26
 
26
27
 
27
- def create_ssl_context_for_server():
28
+ def create_ssl_context_for_server(
29
+ enable_sslkeylogfile_env_to_client_ssl_context: bool = False,
30
+ sslkeylog_file_path: str = None,
31
+ allow_legacy: bool = False
32
+ ) -> ssl.SSLContext:
33
+ """
34
+ This function creates the SSL context for the server.
35
+ Meaning that your script will act like a server, and the client will connect to it.
36
+ """
28
37
  # Creating context with SSL certificate and the private key before the socket
29
38
  # https://docs.python.org/3/library/ssl.html
30
39
  # Creating context for SSL wrapper, specifying "PROTOCOL_TLS_SERVER" will pick the best TLS version protocol for
31
40
  # the server.
32
- return ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
33
- # return ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
34
41
 
42
+ # ssl_context: ssl.SSLContext = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
43
+
44
+ # # Enforce the use of TLS 1.2 only (disable TLS 1.0, TLS 1.1, and TLS 1.3)
45
+ # ssl_context.options |= ssl.OP_NO_TLSv1 # Disable TLS 1.0
46
+ # ssl_context.options |= ssl.OP_NO_TLSv1_1 # Disable TLS 1.1
47
+ # ssl_context.options |= ssl.OP_NO_TLSv1_3 # Disable TLS 1.3
48
+
49
+ # Correct factory for servers
50
+ ssl_context: ssl.SSLContext = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
51
+
52
+ # Modern default; relax only if you must
53
+ ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2
54
+
55
+ # Don't verify client certificates.
56
+ ssl_context.verify_mode = ssl.CERT_NONE
57
+ ssl_context.check_hostname = False
58
+
59
+ if enable_sslkeylogfile_env_to_client_ssl_context:
60
+ if sslkeylog_file_path is None:
61
+ sslkeylog_file_path = os.environ.get('SSLKEYLOGFILE')
62
+
63
+ if not os.path.exists(sslkeylog_file_path):
64
+ open(sslkeylog_file_path, "a").close()
65
+
66
+ ssl_context.keylog_filename = sslkeylog_file_path
67
+
68
+ # If you must support old clients that only offer TLS_RSA_* suites under OpenSSL 3:
69
+ if allow_legacy:
70
+ # This enables RSA key exchange and other legacy bits at security level 1
71
+ ssl_context.set_ciphers('DEFAULT:@SECLEVEL=1')
72
+ # If you truly have TLS 1.0/1.1 clients, uncomment the next line (not recommended):
73
+ ssl_context.minimum_version = ssl.TLSVersion.TLSv1
74
+
75
+ return ssl_context
76
+
77
+
78
+ def create_ssl_context_for_client(
79
+ enable_sslkeylogfile_env_to_client_ssl_context: bool = False,
80
+ sslkeylog_file_path: str = None
81
+ ) -> ssl.SSLContext:
82
+ """
83
+ This function creates the SSL context for the client.
84
+ This means that your script will act like a client, and will connect to a server.
85
+ The SSL context is created with the "PROTOCOL_TLS_CLIENT" protocol.
86
+
87
+ :param enable_sslkeylogfile_env_to_client_ssl_context: boolean, enables the SSLKEYLOGFILE environment variable
88
+ to the SSL context. Default is False.
89
+ if True, SSLKEYLOGFILE will be added to SSL context with:
90
+ ssl_context.keylog_filename = os.environ.get('SSLKEYLOGFILE')
91
+ This is useful for debugging SSL/TLS connections with WireShark.
92
+ Since WireShark also uses this environment variable to read the key log file and apply to the SSL/TLS
93
+ connections, so you can see the decrypted traffic.
94
+ :param sslkeylog_file_path: string, full file path for the SSL key log file. Default is None.
95
+
96
+ :return: ssl.SSLContext
97
+ """
98
+ ssl_context: ssl.SSLContext = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
99
+
100
+ if enable_sslkeylogfile_env_to_client_ssl_context:
101
+ if sslkeylog_file_path is None:
102
+ sslkeylog_file_path = os.environ.get('SSLKEYLOGFILE')
103
+
104
+ if not os.path.exists(sslkeylog_file_path):
105
+ open(sslkeylog_file_path, "a").close()
106
+
107
+ ssl_context.keylog_filename = sslkeylog_file_path
35
108
 
36
- def create_ssl_context_for_client():
37
- return ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
109
+ current_ciphers = 'AES256-GCM-SHA384:' + ssl._DEFAULT_CIPHERS
110
+ ssl_context.set_ciphers(current_ciphers)
111
+
112
+ return ssl_context
38
113
 
39
114
 
40
- def set_client_ssl_context_default_certs(ssl_context):
41
- # "load_default_certs" method is telling the client to check the local certificate storage on the system for the
42
- # needed certificate of the server. Without this line you will get an error from the server that the client
43
- # is using self-signed certificate. Which is partly true, since you used the SLL wrapper,
44
- # but didn't specify the certificate at all.
115
+ def set_client_ssl_context_ca_default_certs(ssl_context):
116
+ """
117
+ "load_default_certs" method is telling the client to check the local certificate storage on the system for the
118
+ needed certificate of the server. Without this line you will get an error from the server that the client
119
+ is using self-signed certificate. Which is partly true, since you used the SLL wrapper,
120
+ but didn't specify the certificate at all.
121
+ -----------------------------------------
122
+ https://docs.python.org/3/library/ssl.html#ssl.SSLContext.load_default_certs
123
+ Load a set of default “certification authority” (CA) certificates from default locations.
124
+ On Windows it loads CA certs from the CA and ROOT system stores.
125
+ On all systems it calls SSLContext.set_default_verify_paths().
126
+ In the future the method may load CA certificates from other locations, too.
127
+
128
+ The purpose flag specifies what kind of CA certificates are loaded.
129
+ The default settings Purpose.SERVER_AUTH loads certificates, that are flagged and trusted for
130
+ TLS web server authentication (client side sockets). Purpose.CLIENT_AUTH loads CA certificates for
131
+ client certificate verification on the server side.
132
+ -----------------------------------------
133
+ """
134
+
45
135
  # The purpose of the certificate is to authenticate on the server
46
136
  # context.load_default_certs(Purpose.SERVER_AUTH)
47
137
  # You don't have to specify the purpose to connect, but if you get a purpose error, you know where to find it
@@ -91,9 +181,48 @@ def load_certificate_and_key_into_server_ssl_context(
91
181
  print_api(message, error_type=True, logger_method="critical", **print_kwargs)
92
182
 
93
183
 
94
- def create_server_ssl_context___load_certificate_and_key(certificate_file_path: str, key_file_path):
184
+ def copy_server_ctx_settings(src: ssl.SSLContext, dst: ssl.SSLContext) -> None:
185
+ # Versions & options
186
+ try: dst.minimum_version = src.minimum_version
187
+ except Exception: pass
188
+ try: dst.maximum_version = src.maximum_version
189
+ except Exception: pass
190
+ try: dst.options = src.options
191
+ except Exception: pass
192
+
193
+ # Verification knobs (server usually CERT_NONE unless you do mTLS)
194
+ try: dst.verify_mode = src.verify_mode
195
+ except Exception: pass
196
+ try: dst.check_hostname = src.check_hostname
197
+ except Exception: pass
198
+
199
+ # Cipher policy – replicate current enabled list
200
+ try:
201
+ cipher_names = ':'.join(c['name'] for c in src.get_ciphers())
202
+ if cipher_names:
203
+ dst.set_ciphers(cipher_names)
204
+ except Exception:
205
+ pass
206
+
207
+ # (ALPN/curves/etc. don’t have public getters; set them the same way you set them on src, if applicable)
208
+
209
+
210
+ def create_server_ssl_context___load_certificate_and_key(
211
+ certificate_file_path: str,
212
+ key_file_path: str | None,
213
+ inherit_from: ssl.SSLContext | None = None,
214
+ enable_sslkeylogfile_env_to_client_ssl_context: bool = False,
215
+ sslkeylog_file_path: str = None,
216
+ ) -> ssl.SSLContext:
95
217
  # Create and set ssl context for server.
96
- ssl_context = create_ssl_context_for_server()
218
+ ssl_context: ssl.SSLContext = create_ssl_context_for_server(
219
+ allow_legacy=True, enable_sslkeylogfile_env_to_client_ssl_context=enable_sslkeylogfile_env_to_client_ssl_context,
220
+ sslkeylog_file_path=sslkeylog_file_path)
221
+
222
+ # If you replaced contexts during SNI, copy policy from the old one
223
+ if inherit_from is not None:
224
+ copy_server_ctx_settings(inherit_from, ssl_context)
225
+
97
226
  # Load certificate into context.
98
227
  load_certificate_and_key_into_server_ssl_context(ssl_context, certificate_file_path, key_file_path)
99
228
  # Return ssl context only.
@@ -101,17 +230,22 @@ def create_server_ssl_context___load_certificate_and_key(certificate_file_path:
101
230
 
102
231
 
103
232
  @exception_wrapper.connection_exception_decorator
104
- def wrap_socket_with_ssl_context_server(socket_object, ssl_context, dns_domain: str = None, print_kwargs: dict = None):
233
+ def wrap_socket_with_ssl_context_server(
234
+ socket_object,
235
+ ssl_context,
236
+ domain_from_dns_server: str = None,
237
+ print_kwargs: dict = None
238
+ ):
105
239
  """
106
240
  This function is wrapped with exception wrapper.
107
241
  After you execute the function, you can get the error message if there was any with:
108
242
  error_message = wrap_socket_with_ssl_context_server.message
109
243
 
110
- :param socket_object:
111
- :param ssl_context:
112
- :param dns_domain:
113
- :param print_kwargs:
114
- :return:
244
+ :param socket_object: The socket object to accept the connection on.
245
+ :param ssl_context: The SSL context to wrap the socket with.
246
+ :param domain_from_dns_server: The domain that will be printed to console on logger, needed for the decorator.
247
+ If not provided, the TCP data will be used.
248
+ :param print_kwargs: Additional arguments for the print_api function, needed for the decorator.
115
249
  """
116
250
 
117
251
  # Wrapping the server socket with SSL context. This should happen right after setting up the raw socket.
@@ -122,10 +256,16 @@ def wrap_socket_with_ssl_context_server(socket_object, ssl_context, dns_domain:
122
256
 
123
257
 
124
258
  def wrap_socket_with_ssl_context_server_with_error_message(
125
- socket_object, ssl_context, dns_domain: str = None, print_kwargs: dict = None):
259
+ socket_object,
260
+ ssl_context,
261
+ domain_from_dns_server,
262
+ print_kwargs: dict = None
263
+ ):
126
264
 
127
265
  ssl_socket = wrap_socket_with_ssl_context_server(
128
- socket_object, ssl_context, dns_domain=dns_domain, print_kwargs=print_kwargs)
266
+ socket_object=socket_object, ssl_context=ssl_context, domain_from_dns_server=domain_from_dns_server,
267
+ print_kwargs=print_kwargs)
268
+
129
269
  error_message = wrap_socket_with_ssl_context_server.message
130
270
 
131
271
  return ssl_socket, error_message
@@ -173,7 +313,7 @@ def set_listen_on_socket(socket_object, **kwargs):
173
313
  # To determine the maximum listening sockets, you may use the 'socket' library and 'SOMAXCONN' parameter
174
314
  # from it.
175
315
  socket_object.listen(socket.SOMAXCONN)
176
- ip_address, port = base.get_destination_address_from_socket(socket_object)
316
+ ip_address, port = socket_base.get_destination_address_from_socket(socket_object)
177
317
 
178
318
  print_api(f"Listening for new connections on: {ip_address}:{port}", **kwargs)
179
319
 
@@ -182,36 +322,36 @@ def set_listen_on_socket(socket_object, **kwargs):
182
322
  # Socket Creator Presets
183
323
 
184
324
  def wrap_socket_with_ssl_context_client___default_certs___ignore_verification(
185
- socket_object, server_hostname: str = None):
186
- ssl_context: ssl.SSLContext = create_ssl_context_for_client()
187
- set_client_ssl_context_default_certs(ssl_context)
325
+ socket_object,
326
+ server_hostname: str = None,
327
+ custom_pem_client_certificate_file_path: str = None,
328
+ enable_sslkeylogfile_env_to_client_ssl_context: bool = False,
329
+ sslkeylog_file_path: str = None
330
+ ) -> ssl.SSLSocket:
331
+ """
332
+ This function is a preset for wrapping the socket with SSL context for the client.
333
+ It sets the CA default certificates, and ignores the server's certificate verification.
334
+
335
+ :param socket_object: socket.socket object
336
+ :param server_hostname: string, hostname of the server. Default is None.
337
+ :param custom_pem_client_certificate_file_path: string, full file path for the client certificate PEM file.
338
+ Default is None.
339
+ :param enable_sslkeylogfile_env_to_client_ssl_context: boolean, enables the SSLKEYLOGFILE environment variable
340
+ to the SSL context. Default is False.
341
+ :param sslkeylog_file_path: string, full file path for the SSL key log file. Default is None.
342
+
343
+ :return: ssl.SSLSocket object
344
+ """
345
+ ssl_context: ssl.SSLContext = create_ssl_context_for_client(
346
+ enable_sslkeylogfile_env_to_client_ssl_context=enable_sslkeylogfile_env_to_client_ssl_context
347
+ ,sslkeylog_file_path=sslkeylog_file_path)
348
+ set_client_ssl_context_ca_default_certs(ssl_context)
188
349
  set_client_ssl_context_certificate_verification_ignore(ssl_context)
350
+
351
+ if custom_pem_client_certificate_file_path:
352
+ ssl_context.load_cert_chain(certfile=custom_pem_client_certificate_file_path, keyfile=None)
353
+
189
354
  ssl_socket: ssl.SSLSocket = wrap_socket_with_ssl_context_client(
190
355
  socket_object, ssl_context, server_hostname=server_hostname)
191
356
 
192
357
  return ssl_socket
193
-
194
-
195
- def wrap_socket_with_ssl_context_server_sni_extended(
196
- socket_object, config: dict, dns_domain: str = None, print_kwargs: dict = None):
197
-
198
- ssl_context = create_ssl_context_for_server()
199
-
200
- sni.add_sni_callback_function_reference_to_ssl_context(
201
- ssl_context=ssl_context, config=config, dns_domain=dns_domain, use_default_sni_function=True,
202
- use_sni_extended=True, print_kwargs=print_kwargs)
203
-
204
- server_certificate_file_path, server_private_key_file_path = \
205
- certificator.select_server_ssl_context_certificate(config=config, print_kwargs=print_kwargs)
206
-
207
- # If the user chose 'sni_create_server_certificate_for_each_domain = 1' in the configuration file,
208
- # it means that 'self.server_certificate_file_path' will be empty, which is OK, since we'll inject
209
- # dynamically created certificate from certs folder through SNI.
210
- if server_certificate_file_path:
211
- load_certificate_and_key_into_server_ssl_context(
212
- ssl_context, server_certificate_file_path, server_private_key_file_path,
213
- print_kwargs=print_kwargs)
214
-
215
- ssl_socket, error_message = wrap_socket_with_ssl_context_server_with_error_message(
216
- socket_object, ssl_context, dns_domain=dns_domain, print_kwargs=print_kwargs)
217
- return ssl_socket, error_message