atomicshop 2.11.47__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.
- atomicshop/__init__.py +1 -1
- atomicshop/{addons/mains → a_mains}/FACT/update_extract.py +3 -2
- atomicshop/a_mains/addons/process_list/compile.cmd +7 -0
- atomicshop/a_mains/addons/process_list/compiled/Win10x64/process_list.dll +0 -0
- atomicshop/a_mains/addons/process_list/compiled/Win10x64/process_list.exp +0 -0
- atomicshop/a_mains/addons/process_list/compiled/Win10x64/process_list.lib +0 -0
- atomicshop/{addons → a_mains/addons}/process_list/process_list.cpp +8 -1
- atomicshop/a_mains/dns_gateway_setting.py +11 -0
- atomicshop/a_mains/get_local_tcp_ports.py +85 -0
- atomicshop/a_mains/github_wrapper.py +11 -0
- atomicshop/a_mains/install_ca_certificate.py +172 -0
- atomicshop/{addons/mains → a_mains}/msi_unpacker.py +3 -1
- atomicshop/a_mains/process_from_port.py +119 -0
- atomicshop/a_mains/set_default_dns_gateway.py +90 -0
- atomicshop/a_mains/update_config_toml.py +38 -0
- atomicshop/appointment_management.py +5 -3
- atomicshop/basics/ansi_escape_codes.py +3 -1
- atomicshop/basics/argparse_template.py +2 -0
- atomicshop/basics/booleans.py +27 -30
- atomicshop/basics/bytes_arrays.py +43 -0
- atomicshop/basics/classes.py +149 -1
- atomicshop/basics/dicts.py +12 -0
- atomicshop/basics/enums.py +2 -2
- atomicshop/basics/exceptions.py +5 -1
- atomicshop/basics/list_of_classes.py +29 -0
- atomicshop/basics/list_of_dicts.py +69 -5
- atomicshop/basics/lists.py +14 -0
- atomicshop/basics/multiprocesses.py +374 -50
- atomicshop/basics/package_module.py +10 -0
- atomicshop/basics/strings.py +160 -7
- atomicshop/basics/threads.py +14 -0
- atomicshop/basics/tracebacks.py +13 -4
- atomicshop/certificates.py +153 -52
- atomicshop/config_init.py +12 -7
- atomicshop/console_user_response.py +7 -14
- atomicshop/consoles.py +9 -0
- atomicshop/datetimes.py +98 -0
- atomicshop/diff_check.py +340 -40
- atomicshop/dns.py +128 -12
- atomicshop/etws/_pywintrace_fix.py +17 -0
- atomicshop/etws/const.py +38 -0
- atomicshop/etws/providers.py +21 -0
- atomicshop/etws/sessions.py +43 -0
- atomicshop/etws/trace.py +168 -0
- atomicshop/etws/traces/trace_dns.py +162 -0
- atomicshop/etws/traces/trace_sysmon_process_creation.py +126 -0
- atomicshop/etws/traces/trace_tcp.py +130 -0
- atomicshop/file_io/csvs.py +222 -24
- atomicshop/file_io/docxs.py +35 -18
- atomicshop/file_io/file_io.py +35 -19
- atomicshop/file_io/jsons.py +49 -0
- atomicshop/file_io/tomls.py +139 -0
- atomicshop/filesystem.py +864 -293
- atomicshop/get_process_list.py +133 -0
- atomicshop/{process_name_cmd.py → get_process_name_cmd_dll.py} +52 -19
- atomicshop/http_parse.py +149 -93
- atomicshop/ip_addresses.py +6 -1
- atomicshop/mitm/centered_settings.py +132 -0
- atomicshop/mitm/config_static.py +207 -0
- atomicshop/mitm/config_toml_editor.py +55 -0
- atomicshop/mitm/connection_thread_worker.py +875 -357
- atomicshop/mitm/engines/__parent/parser___parent.py +4 -17
- atomicshop/mitm/engines/__parent/recorder___parent.py +108 -51
- atomicshop/mitm/engines/__parent/requester___parent.py +116 -0
- atomicshop/mitm/engines/__parent/responder___parent.py +75 -114
- atomicshop/mitm/engines/__reference_general/parser___reference_general.py +10 -7
- atomicshop/mitm/engines/__reference_general/recorder___reference_general.py +5 -5
- atomicshop/mitm/engines/__reference_general/requester___reference_general.py +47 -0
- atomicshop/mitm/engines/__reference_general/responder___reference_general.py +95 -13
- atomicshop/mitm/engines/create_module_template.py +58 -14
- atomicshop/mitm/import_config.py +359 -139
- atomicshop/mitm/initialize_engines.py +160 -74
- atomicshop/mitm/message.py +64 -23
- atomicshop/mitm/mitm_main.py +892 -0
- atomicshop/mitm/recs_files.py +183 -0
- atomicshop/mitm/shared_functions.py +4 -10
- atomicshop/mitm/ssh_tester.py +82 -0
- atomicshop/mitm/statistic_analyzer.py +257 -166
- atomicshop/mitm/statistic_analyzer_helper/analyzer_helper.py +136 -0
- atomicshop/mitm/statistic_analyzer_helper/moving_average_helper.py +525 -0
- atomicshop/monitor/change_monitor.py +96 -120
- atomicshop/monitor/checks/dns.py +139 -70
- atomicshop/monitor/checks/file.py +77 -0
- atomicshop/monitor/checks/network.py +81 -77
- atomicshop/monitor/checks/process_running.py +33 -34
- atomicshop/monitor/checks/url.py +94 -0
- atomicshop/networks.py +671 -0
- atomicshop/on_exit.py +205 -0
- atomicshop/package_mains_processor.py +84 -0
- atomicshop/permissions/permissions.py +22 -0
- atomicshop/permissions/ubuntu_permissions.py +239 -0
- atomicshop/permissions/win_permissions.py +33 -0
- atomicshop/print_api.py +24 -41
- atomicshop/process.py +63 -17
- atomicshop/process_poller/__init__.py +0 -0
- atomicshop/process_poller/pollers/__init__.py +0 -0
- atomicshop/process_poller/pollers/psutil_pywin32wmi_dll.py +95 -0
- atomicshop/process_poller/process_pool.py +207 -0
- atomicshop/process_poller/simple_process_pool.py +311 -0
- atomicshop/process_poller/tracer_base.py +45 -0
- atomicshop/process_poller/tracers/__init__.py +0 -0
- atomicshop/process_poller/tracers/event_log.py +46 -0
- atomicshop/process_poller/tracers/sysmon_etw.py +68 -0
- atomicshop/python_file_patcher.py +1 -1
- atomicshop/python_functions.py +27 -75
- atomicshop/question_answer_engine.py +2 -2
- atomicshop/scheduling.py +24 -5
- atomicshop/sound.py +4 -2
- atomicshop/speech_recognize.py +8 -0
- atomicshop/ssh_remote.py +158 -172
- atomicshop/startup/__init__.py +0 -0
- atomicshop/startup/win/__init__.py +0 -0
- atomicshop/startup/win/startup_folder.py +53 -0
- atomicshop/startup/win/task_scheduler.py +119 -0
- atomicshop/system_resource_monitor.py +61 -46
- atomicshop/system_resources.py +8 -8
- atomicshop/tempfiles.py +1 -2
- atomicshop/timer.py +30 -11
- atomicshop/urls.py +41 -0
- atomicshop/venvs.py +28 -0
- atomicshop/versioning.py +27 -0
- atomicshop/web.py +110 -25
- atomicshop/web_apis/__init__.py +0 -0
- atomicshop/web_apis/google_custom_search.py +44 -0
- atomicshop/web_apis/google_llm.py +188 -0
- atomicshop/websocket_parse.py +450 -0
- atomicshop/wrappers/certauthw/certauth.py +1 -0
- atomicshop/wrappers/cryptographyw.py +29 -8
- atomicshop/wrappers/ctyping/etw_winapi/__init__.py +0 -0
- atomicshop/wrappers/ctyping/etw_winapi/const.py +335 -0
- atomicshop/wrappers/ctyping/etw_winapi/etw_functions.py +393 -0
- atomicshop/wrappers/ctyping/file_details_winapi.py +67 -0
- atomicshop/wrappers/ctyping/msi_windows_installer/cabs.py +2 -1
- atomicshop/wrappers/ctyping/msi_windows_installer/extract_msi_main.py +13 -9
- atomicshop/wrappers/ctyping/msi_windows_installer/tables.py +35 -0
- atomicshop/wrappers/ctyping/setup_device.py +466 -0
- atomicshop/wrappers/ctyping/win_console.py +39 -0
- atomicshop/wrappers/dockerw/dockerw.py +113 -2
- atomicshop/wrappers/elasticsearchw/config_basic.py +0 -12
- atomicshop/wrappers/elasticsearchw/elastic_infra.py +75 -0
- atomicshop/wrappers/elasticsearchw/elasticsearchw.py +2 -20
- atomicshop/wrappers/factw/get_file_data.py +12 -5
- atomicshop/wrappers/factw/install/install_after_restart.py +89 -5
- atomicshop/wrappers/factw/install/pre_install_and_install_before_restart.py +20 -14
- atomicshop/wrappers/factw/postgresql/firmware.py +4 -6
- atomicshop/wrappers/githubw.py +583 -51
- atomicshop/wrappers/loggingw/consts.py +49 -0
- atomicshop/wrappers/loggingw/filters.py +102 -0
- atomicshop/wrappers/loggingw/formatters.py +58 -71
- atomicshop/wrappers/loggingw/handlers.py +459 -40
- atomicshop/wrappers/loggingw/loggers.py +19 -0
- atomicshop/wrappers/loggingw/loggingw.py +1010 -178
- atomicshop/wrappers/loggingw/reading.py +344 -19
- atomicshop/wrappers/mongodbw/__init__.py +0 -0
- atomicshop/wrappers/mongodbw/mongo_infra.py +31 -0
- atomicshop/wrappers/mongodbw/mongodbw.py +1432 -0
- atomicshop/wrappers/netshw.py +271 -0
- atomicshop/wrappers/playwrightw/engine.py +34 -19
- atomicshop/wrappers/playwrightw/infra.py +5 -0
- atomicshop/wrappers/playwrightw/javascript.py +7 -3
- atomicshop/wrappers/playwrightw/keyboard.py +14 -0
- atomicshop/wrappers/playwrightw/scenarios.py +172 -5
- atomicshop/wrappers/playwrightw/waits.py +9 -7
- atomicshop/wrappers/powershell_networking.py +80 -0
- atomicshop/wrappers/psutilw/processes.py +81 -0
- atomicshop/wrappers/psutilw/psutil_networks.py +85 -0
- atomicshop/wrappers/psutilw/psutilw.py +9 -0
- atomicshop/wrappers/pyopensslw.py +9 -2
- atomicshop/wrappers/pywin32w/__init__.py +0 -0
- atomicshop/wrappers/pywin32w/cert_store.py +116 -0
- atomicshop/wrappers/pywin32w/console.py +34 -0
- atomicshop/wrappers/pywin32w/win_event_log/__init__.py +0 -0
- atomicshop/wrappers/pywin32w/win_event_log/fetch.py +174 -0
- atomicshop/wrappers/pywin32w/win_event_log/subscribe.py +212 -0
- atomicshop/wrappers/pywin32w/win_event_log/subscribes/__init__.py +0 -0
- atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_create.py +57 -0
- atomicshop/wrappers/pywin32w/win_event_log/subscribes/process_terminate.py +49 -0
- atomicshop/wrappers/pywin32w/win_event_log/subscribes/schannel_logging.py +97 -0
- atomicshop/wrappers/pywin32w/winshell.py +19 -0
- atomicshop/wrappers/pywin32w/wmis/__init__.py +0 -0
- atomicshop/wrappers/pywin32w/wmis/msft_netipaddress.py +113 -0
- atomicshop/wrappers/pywin32w/wmis/win32_networkadapterconfiguration.py +259 -0
- atomicshop/wrappers/pywin32w/wmis/win32networkadapter.py +112 -0
- atomicshop/wrappers/pywin32w/wmis/wmi_helpers.py +236 -0
- atomicshop/wrappers/socketw/accepter.py +21 -7
- atomicshop/wrappers/socketw/certificator.py +216 -150
- atomicshop/wrappers/socketw/creator.py +190 -50
- atomicshop/wrappers/socketw/dns_server.py +500 -173
- atomicshop/wrappers/socketw/exception_wrapper.py +45 -52
- atomicshop/wrappers/socketw/process_getter.py +86 -0
- atomicshop/wrappers/socketw/receiver.py +144 -102
- atomicshop/wrappers/socketw/sender.py +65 -35
- atomicshop/wrappers/socketw/sni.py +334 -165
- atomicshop/wrappers/socketw/socket_base.py +134 -0
- atomicshop/wrappers/socketw/socket_client.py +137 -95
- atomicshop/wrappers/socketw/socket_server_tester.py +14 -9
- atomicshop/wrappers/socketw/socket_wrapper.py +717 -116
- atomicshop/wrappers/socketw/ssl_base.py +15 -14
- atomicshop/wrappers/socketw/statistics_csv.py +148 -17
- atomicshop/wrappers/sysmonw.py +157 -0
- atomicshop/wrappers/ubuntu_terminal.py +65 -26
- atomicshop/wrappers/win_auditw.py +189 -0
- atomicshop/wrappers/winregw/__init__.py +0 -0
- atomicshop/wrappers/winregw/winreg_installed_software.py +58 -0
- atomicshop/wrappers/winregw/winreg_network.py +232 -0
- {atomicshop-2.11.47.dist-info → atomicshop-3.10.5.dist-info}/METADATA +31 -49
- atomicshop-3.10.5.dist-info/RECORD +306 -0
- {atomicshop-2.11.47.dist-info → atomicshop-3.10.5.dist-info}/WHEEL +1 -1
- atomicshop/_basics_temp.py +0 -101
- atomicshop/addons/a_setup_scripts/install_psycopg2_ubuntu.sh +0 -3
- atomicshop/addons/a_setup_scripts/install_pywintrace_0.3.cmd +0 -2
- atomicshop/addons/mains/install_docker_rootless_ubuntu.py +0 -11
- atomicshop/addons/mains/install_docker_ubuntu_main_sudo.py +0 -11
- atomicshop/addons/mains/install_elastic_search_and_kibana_ubuntu.py +0 -10
- atomicshop/addons/mains/install_wsl_ubuntu_lts_admin.py +0 -9
- atomicshop/addons/package_setup/CreateWheel.cmd +0 -7
- atomicshop/addons/package_setup/Setup in Edit mode.cmd +0 -6
- atomicshop/addons/package_setup/Setup.cmd +0 -7
- atomicshop/addons/process_list/compile.cmd +0 -2
- atomicshop/addons/process_list/compiled/Win10x64/process_list.dll +0 -0
- atomicshop/addons/process_list/compiled/Win10x64/process_list.exp +0 -0
- atomicshop/addons/process_list/compiled/Win10x64/process_list.lib +0 -0
- atomicshop/archiver/_search_in_zip.py +0 -189
- atomicshop/archiver/archiver.py +0 -34
- atomicshop/archiver/search_in_archive.py +0 -250
- atomicshop/archiver/sevenz_app_w.py +0 -86
- atomicshop/archiver/sevenzs.py +0 -44
- atomicshop/archiver/zips.py +0 -293
- atomicshop/etw/dns_trace.py +0 -118
- atomicshop/etw/etw.py +0 -61
- atomicshop/file_types.py +0 -24
- atomicshop/mitm/engines/create_module_template_example.py +0 -13
- atomicshop/mitm/initialize_mitm_server.py +0 -240
- atomicshop/monitor/checks/hash.py +0 -44
- atomicshop/monitor/checks/hash_checks/file.py +0 -55
- atomicshop/monitor/checks/hash_checks/url.py +0 -62
- atomicshop/pbtkmultifile_argparse.py +0 -88
- atomicshop/permissions.py +0 -110
- atomicshop/process_poller.py +0 -237
- atomicshop/script_as_string_processor.py +0 -38
- atomicshop/ssh_scripts/process_from_ipv4.py +0 -37
- atomicshop/ssh_scripts/process_from_port.py +0 -27
- atomicshop/wrappers/_process_wrapper_curl.py +0 -27
- atomicshop/wrappers/_process_wrapper_tar.py +0 -21
- atomicshop/wrappers/dockerw/install_docker.py +0 -209
- atomicshop/wrappers/elasticsearchw/infrastructure.py +0 -265
- atomicshop/wrappers/elasticsearchw/install_elastic.py +0 -232
- atomicshop/wrappers/ffmpegw.py +0 -125
- atomicshop/wrappers/loggingw/checks.py +0 -20
- atomicshop/wrappers/nodejsw/install_nodejs.py +0 -139
- atomicshop/wrappers/process_wrapper_pbtk.py +0 -16
- atomicshop/wrappers/socketw/base.py +0 -59
- atomicshop/wrappers/socketw/get_process.py +0 -107
- atomicshop/wrappers/wslw.py +0 -191
- atomicshop-2.11.47.dist-info/RECORD +0 -251
- /atomicshop/{addons/mains → a_mains}/FACT/factw_fact_extractor_docker_image_main_sudo.py +0 -0
- /atomicshop/{addons → a_mains/addons}/PlayWrightCodegen.cmd +0 -0
- /atomicshop/{addons → a_mains/addons}/ScriptExecution.cmd +0 -0
- /atomicshop/{addons/mains → a_mains/addons}/inits/init_to_import_all_modules.py +0 -0
- /atomicshop/{addons → a_mains/addons}/process_list/ReadMe.txt +0 -0
- /atomicshop/{addons/mains → a_mains}/search_for_hyperlinks_in_docx.py +0 -0
- /atomicshop/{archiver → etws}/__init__.py +0 -0
- /atomicshop/{etw → etws/traces}/__init__.py +0 -0
- /atomicshop/{monitor/checks/hash_checks → mitm/statistic_analyzer_helper}/__init__.py +0 -0
- /atomicshop/{wrappers/nodejsw → permissions}/__init__.py +0 -0
- /atomicshop/wrappers/pywin32w/{wmi_win32process.py → wmis/win32process.py} +0 -0
- {atomicshop-2.11.47.dist-info → atomicshop-3.10.5.dist-info/licenses}/LICENSE.txt +0 -0
- {atomicshop-2.11.47.dist-info → atomicshop-3.10.5.dist-info}/top_level.txt +0 -0
|
@@ -1,169 +1,235 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import sys
|
|
3
3
|
|
|
4
|
-
from
|
|
4
|
+
from cryptography import x509
|
|
5
|
+
|
|
6
|
+
from . import creator, socket_base, socket_client
|
|
5
7
|
from .. import pyopensslw, cryptographyw
|
|
6
8
|
from ..certauthw.certauthw import CertAuthWrapper
|
|
7
9
|
from ...print_api import print_api
|
|
10
|
+
from ... import filesystem
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Certificator:
|
|
14
|
+
"""
|
|
15
|
+
Certificator class is used to create and manage certificates, wrapping ssl contexts and sockets.
|
|
16
|
+
"""
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
ca_certificate_name: str,
|
|
20
|
+
ca_certificate_filepath: str,
|
|
21
|
+
default_server_certificate_usage: bool,
|
|
22
|
+
default_server_certificate_name: str,
|
|
23
|
+
default_server_certificate_directory: str,
|
|
24
|
+
default_certificate_domain_list: list,
|
|
25
|
+
sni_server_certificates_cache_directory: str,
|
|
26
|
+
sni_get_server_certificate_from_server_socket: bool,
|
|
27
|
+
sni_server_certificate_from_server_socket_download_directory: str,
|
|
28
|
+
custom_server_certificate_usage: bool,
|
|
29
|
+
custom_server_certificate_path: str,
|
|
30
|
+
custom_private_key_path: str,
|
|
31
|
+
forwarding_dns_service_ipv4_list___only_for_localhost: list,
|
|
32
|
+
skip_extension_id_list: list,
|
|
33
|
+
tls: bool,
|
|
34
|
+
enable_sslkeylogfile_env_to_client_ssl_context: bool,
|
|
35
|
+
sslkeylog_file_path: str
|
|
36
|
+
):
|
|
37
|
+
self.ca_certificate_name = ca_certificate_name
|
|
38
|
+
self.ca_certificate_filepath = ca_certificate_filepath
|
|
39
|
+
self.default_server_certificate_usage = default_server_certificate_usage
|
|
40
|
+
self.default_server_certificate_name = default_server_certificate_name
|
|
41
|
+
self.default_server_certificate_directory = default_server_certificate_directory
|
|
42
|
+
self.default_certificate_domain_list = default_certificate_domain_list
|
|
43
|
+
self.sni_server_certificates_cache_directory = sni_server_certificates_cache_directory
|
|
44
|
+
self.sni_get_server_certificate_from_server_socket = sni_get_server_certificate_from_server_socket
|
|
45
|
+
self.sni_server_certificate_from_server_socket_download_directory = (
|
|
46
|
+
sni_server_certificate_from_server_socket_download_directory)
|
|
47
|
+
self.custom_server_certificate_usage = custom_server_certificate_usage
|
|
48
|
+
self.custom_server_certificate_path = custom_server_certificate_path
|
|
49
|
+
self.custom_private_key_path = custom_private_key_path
|
|
50
|
+
self.forwarding_dns_service_ipv4_list___only_for_localhost = (
|
|
51
|
+
forwarding_dns_service_ipv4_list___only_for_localhost)
|
|
52
|
+
self.skip_extension_id_list = skip_extension_id_list
|
|
53
|
+
self.tls = tls
|
|
54
|
+
self.enable_sslkeylogfile_env_to_client_ssl_context: bool = (
|
|
55
|
+
enable_sslkeylogfile_env_to_client_ssl_context)
|
|
56
|
+
self.sslkeylog_file_path: str = sslkeylog_file_path
|
|
57
|
+
|
|
58
|
+
# noinspection PyTypeChecker
|
|
59
|
+
self.certauth_wrapper: CertAuthWrapper = None
|
|
60
|
+
|
|
61
|
+
def initialize_certauth_create_use_ca_certificate(self, server_certificate_directory: str):
|
|
62
|
+
"""
|
|
63
|
+
Initialize CertAuthWrapper and create CA certificate if it doesn't exist.
|
|
64
|
+
:return:
|
|
65
|
+
"""
|
|
66
|
+
# Initialize CertAuthWrapper.
|
|
67
|
+
certauth_wrapper = CertAuthWrapper(
|
|
68
|
+
ca_certificate_name=self.ca_certificate_name,
|
|
69
|
+
ca_certificate_filepath=self.ca_certificate_filepath,
|
|
70
|
+
server_certificate_directory=server_certificate_directory
|
|
71
|
+
)
|
|
8
72
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
#
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
# Check if default certificate was created.
|
|
46
|
-
if server_certificate_file_path:
|
|
47
|
-
message = f"Default Server Certificate was created / overwritten: {server_certificate_file_path}"
|
|
48
|
-
print_api(message, **print_kwargs)
|
|
49
|
-
|
|
50
|
-
message = \
|
|
51
|
-
f"Default Server Certificate current 'Subject Alternative Names': {default_server_certificate_san}"
|
|
52
|
-
print_api(message, **print_kwargs)
|
|
53
|
-
else:
|
|
54
|
-
message = f"Couldn't create / overwrite Default Server Certificate: {server_certificate_file_path}"
|
|
55
|
-
print_api(message, error_type=True, logger_method='critical', **print_kwargs)
|
|
56
|
-
sys.exit()
|
|
73
|
+
# Create CA certificate if it doesn't exist.
|
|
74
|
+
certauth_wrapper.create_use_ca_certificate()
|
|
75
|
+
|
|
76
|
+
return certauth_wrapper
|
|
77
|
+
|
|
78
|
+
# noinspection PyTypeChecker
|
|
79
|
+
def select_server_ssl_context_certificate(
|
|
80
|
+
self,
|
|
81
|
+
print_kwargs: dict = None
|
|
82
|
+
):
|
|
83
|
+
"""
|
|
84
|
+
This function selects between the default certificate and custom certificate for the sll context.
|
|
85
|
+
Returns the selected certificate file path and the private key file path.
|
|
86
|
+
"""
|
|
87
|
+
# We need to nullify the variable, since we have several checks if the variable was set or not.
|
|
88
|
+
server_certificate_file_path: str = None
|
|
89
|
+
server_private_key_file_path: str = None
|
|
90
|
+
|
|
91
|
+
# Creating if non-existent/overwriting default server certificate.
|
|
92
|
+
if self.default_server_certificate_usage:
|
|
93
|
+
# Creating if non-existent/overwriting default server certificate.
|
|
94
|
+
server_certificate_file_path, default_server_certificate_san = \
|
|
95
|
+
self.create_overwrite_default_server_certificate_ca_signed()
|
|
96
|
+
|
|
97
|
+
# Check if default certificate was created.
|
|
98
|
+
if server_certificate_file_path:
|
|
99
|
+
message = f"Default Server Certificate was created / overwritten: {server_certificate_file_path}"
|
|
100
|
+
print_api(message, **(print_kwargs or {}))
|
|
101
|
+
|
|
102
|
+
message = \
|
|
103
|
+
f"Default Server Certificate current 'Subject Alternative Names': {default_server_certificate_san}"
|
|
104
|
+
print_api(message, **(print_kwargs or {}))
|
|
105
|
+
else:
|
|
106
|
+
message = f"Couldn't create / overwrite Default Server Certificate: {server_certificate_file_path}"
|
|
107
|
+
print_api(message, error_type=True, logger_method='critical', **(print_kwargs or {}))
|
|
108
|
+
sys.exit()
|
|
57
109
|
|
|
58
110
|
# Assigning 'certificate_path' to 'custom_certificate_path' if usage was set.
|
|
59
|
-
if
|
|
60
|
-
server_certificate_file_path =
|
|
111
|
+
if self.custom_server_certificate_usage:
|
|
112
|
+
server_certificate_file_path = self.custom_server_certificate_path
|
|
61
113
|
# Since 'ssl_context.load_cert_chain' uses 'keypath' as 'None' if certificate contains private key.
|
|
62
114
|
# We'd like to leave it that way and don't fetch empty string from 'config'.
|
|
63
|
-
if
|
|
64
|
-
server_private_key_file_path =
|
|
65
|
-
|
|
66
|
-
return server_certificate_file_path, server_private_key_file_path
|
|
67
|
-
|
|
115
|
+
if self.custom_private_key_path:
|
|
116
|
+
server_private_key_file_path = self.custom_private_key_path
|
|
68
117
|
|
|
69
|
-
|
|
70
|
-
global CERTAUTH_WRAPPER
|
|
71
|
-
CERTAUTH_WRAPPER = initialize_certauth_create_use_ca_certificate(config=config)
|
|
118
|
+
return server_certificate_file_path, server_private_key_file_path
|
|
72
119
|
|
|
73
|
-
|
|
74
|
-
|
|
120
|
+
def create_overwrite_default_server_certificate_ca_signed(self):
|
|
121
|
+
"""
|
|
122
|
+
Create or overwrite default server certificate.
|
|
123
|
+
:return:
|
|
124
|
+
"""
|
|
75
125
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
domain_list=domain_list,
|
|
79
|
-
server_certificate_file_name_no_extension=server_certificate_file_name_no_extension
|
|
126
|
+
self.certauth_wrapper = self.initialize_certauth_create_use_ca_certificate(
|
|
127
|
+
server_certificate_directory=self.default_server_certificate_directory
|
|
80
128
|
)
|
|
81
129
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def create_use_sni_server_certificate_ca_signed(sni_received_dict: dict, config: dict, print_kwargs: dict = None):
|
|
86
|
-
global CERTAUTH_WRAPPER
|
|
87
|
-
|
|
88
|
-
# === Connect to the domain and get the certificate. ===========================================================
|
|
89
|
-
certificate_from_socket_x509 = None
|
|
90
|
-
if config['certificates']['sni_get_server_certificate_from_server_socket']:
|
|
91
|
-
# Generate PEM certificate file path string for downloaded certificates. Signed certificates will go to the
|
|
92
|
-
# 'certs' folder.
|
|
93
|
-
certificate_from_socket_file_path: str = \
|
|
94
|
-
config['certificates']['sni_server_certificate_from_server_socket_download_directory'] + \
|
|
95
|
-
os.sep + sni_received_dict['destination_name'] + ".pem"
|
|
96
|
-
# Get client ip.
|
|
97
|
-
client_ip = base.get_source_address_from_socket(sni_received_dict['ssl_socket'])[0]
|
|
98
|
-
|
|
99
|
-
# If we're on localhost, then use external services list in order to resolve the domain:
|
|
100
|
-
if client_ip == "127.0.0.1":
|
|
101
|
-
service_client = socket_client.SocketClient(
|
|
102
|
-
service_name=sni_received_dict['destination_name'],
|
|
103
|
-
service_port=base.get_destination_address_from_socket(sni_received_dict['ssl_socket'])[1],
|
|
104
|
-
dns_servers_list=config['tcp']['forwarding_dns_service_ipv4_list___only_for_localhost'])
|
|
105
|
-
# If we're not on localhost, then connect to domain directly.
|
|
106
|
-
else:
|
|
107
|
-
service_client = socket_client.SocketClient(
|
|
108
|
-
service_name=sni_received_dict['destination_name'],
|
|
109
|
-
service_port=base.get_destination_address_from_socket(sni_received_dict['ssl_socket'])[1])
|
|
110
|
-
|
|
111
|
-
# Get certificate from socket and convert to X509 cryptography module object.
|
|
112
|
-
certificate_from_socket_x509_cryptography_object = service_client.get_certificate_from_server(
|
|
113
|
-
save_as_file=True, cert_file_path=certificate_from_socket_file_path, cert_output_type='cryptography'
|
|
114
|
-
)
|
|
130
|
+
server_certificate_file_name_no_extension = self.default_server_certificate_name
|
|
115
131
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
132
|
+
server_certificate_file_path, default_server_certificate_san = \
|
|
133
|
+
self.certauth_wrapper.create_overwrite_server_certificate_ca_signed_return_path_and_san(
|
|
134
|
+
domain_list=self.default_certificate_domain_list,
|
|
135
|
+
server_certificate_file_name_no_extension=server_certificate_file_name_no_extension
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
return server_certificate_file_path, default_server_certificate_san
|
|
139
|
+
|
|
140
|
+
def create_use_sni_server_certificate_ca_signed(
|
|
141
|
+
self,
|
|
142
|
+
sni_received_parameters,
|
|
143
|
+
print_kwargs: dict = None
|
|
144
|
+
):
|
|
145
|
+
# === Connect to the domain and get the certificate. ===========================================================
|
|
146
|
+
certificate_from_socket_x509 = None
|
|
147
|
+
if self.sni_get_server_certificate_from_server_socket:
|
|
148
|
+
# Generate PEM certificate file path string for downloaded certificates. Signed certificates will go to the
|
|
149
|
+
# 'certs' folder.
|
|
150
|
+
certificate_from_socket_file_path: str = \
|
|
151
|
+
self.sni_server_certificate_from_server_socket_download_directory + \
|
|
152
|
+
os.sep + sni_received_parameters.destination_name + ".pem"
|
|
153
|
+
# Get client ip.
|
|
154
|
+
client_ip = socket_base.get_source_address_from_socket(sni_received_parameters.ssl_socket)[0]
|
|
155
|
+
|
|
156
|
+
# If we're on localhost, then use external services list in order to resolve the domain:
|
|
157
|
+
if client_ip in socket_base.THIS_DEVICE_IP_LIST:
|
|
158
|
+
service_client = socket_client.SocketClient(
|
|
159
|
+
service_name=sni_received_parameters.destination_name,
|
|
160
|
+
service_port=socket_base.get_destination_address_from_socket(sni_received_parameters.ssl_socket)[1],
|
|
161
|
+
tls=self.tls,
|
|
162
|
+
dns_servers_list=self.forwarding_dns_service_ipv4_list___only_for_localhost,
|
|
163
|
+
logger=print_kwargs.get('logger') if print_kwargs else None
|
|
164
|
+
)
|
|
165
|
+
# If we're not on localhost, then connect to domain directly.
|
|
166
|
+
else:
|
|
167
|
+
service_client = socket_client.SocketClient(
|
|
168
|
+
service_name=sni_received_parameters.destination_name,
|
|
169
|
+
service_port=socket_base.get_destination_address_from_socket(sni_received_parameters.ssl_socket)[1],
|
|
170
|
+
tls=self.tls,
|
|
171
|
+
logger=print_kwargs.get('logger') if print_kwargs else None
|
|
127
172
|
)
|
|
128
173
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
#
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
174
|
+
# If certificate from socket exists, then we don't need to get it from the socket and write to file.
|
|
175
|
+
# and we will return None, since no certificate was fetched.
|
|
176
|
+
# noinspection PyTypeChecker
|
|
177
|
+
certificate_from_socket_x509_cryptography_object: x509.Certificate = None
|
|
178
|
+
if not filesystem.is_file_exists(certificate_from_socket_file_path):
|
|
179
|
+
print_api("Certificate from socket doesn't exist, fetching.", **(print_kwargs or {}))
|
|
180
|
+
# Get certificate from socket and convert to X509 cryptography module object.
|
|
181
|
+
certificate_from_socket_x509_cryptography_object: x509.Certificate = (
|
|
182
|
+
service_client.get_certificate_from_server(
|
|
183
|
+
save_as_file=True, cert_file_path=certificate_from_socket_file_path,
|
|
184
|
+
cert_output_type='cryptography')
|
|
185
|
+
)
|
|
186
|
+
else:
|
|
187
|
+
print_api("The Certificate from socket already exists, not fetching", **(print_kwargs or {}))
|
|
188
|
+
certificate_from_socket_x509_cryptography_object: x509.Certificate = (
|
|
189
|
+
cryptographyw.convert_object_to_x509(certificate_from_socket_file_path))
|
|
190
|
+
|
|
191
|
+
# skip_extensions = ['1.3.6.1.5.5.7.3.2', '2.5.29.31', '1.3.6.1.5.5.7.1.1']
|
|
192
|
+
|
|
193
|
+
# If certificate was downloaded successfully, then remove extensions if they were provided.
|
|
194
|
+
# If certificate was downloaded successfully and no extensions to skip were provided, then use it as is.
|
|
195
|
+
if certificate_from_socket_x509_cryptography_object and self.skip_extension_id_list:
|
|
196
|
+
# Copy extensions from old certificate to new certificate, without specified extensions.
|
|
197
|
+
certificate_from_socket_x509_cryptography_object, _ = \
|
|
198
|
+
cryptographyw.copy_extensions_from_old_cert_to_new_cert(
|
|
199
|
+
certificate_from_socket_x509_cryptography_object,
|
|
200
|
+
skip_extensions=self.skip_extension_id_list,
|
|
201
|
+
print_kwargs=print_kwargs
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
# If certificate was downloaded successfully, then convert it to pyopenssl object.
|
|
205
|
+
if certificate_from_socket_x509_cryptography_object:
|
|
206
|
+
# Convert X509 cryptography module object to pyopenssl, since certauth uses pyopenssl.
|
|
207
|
+
certificate_from_socket_x509 = \
|
|
208
|
+
pyopensslw.convert_cryptography_object_to_pyopenssl(
|
|
209
|
+
certificate_from_socket_x509_cryptography_object)
|
|
210
|
+
|
|
211
|
+
# === EOF Get certificate from the domain. =====================================================================
|
|
212
|
+
|
|
213
|
+
# If CertAuthWrapper wasn't initialized yet, it means that CA wasn't created/loaded yet.
|
|
214
|
+
if not self.certauth_wrapper:
|
|
215
|
+
self.certauth_wrapper = self.initialize_certauth_create_use_ca_certificate(
|
|
216
|
+
server_certificate_directory=self.sni_server_certificates_cache_directory)
|
|
217
|
+
# try:
|
|
218
|
+
# Create if non-existent / read existing server certificate.
|
|
219
|
+
sni_server_certificate_file_path = self.certauth_wrapper.create_read_server_certificate_ca_signed(
|
|
220
|
+
sni_received_parameters.destination_name, certificate_from_socket_x509)
|
|
221
|
+
|
|
222
|
+
message = f"SNI Handler: port " \
|
|
223
|
+
f"{socket_base.get_destination_address_from_socket(sni_received_parameters.ssl_socket)[1]}: " \
|
|
224
|
+
f"Using certificate: {sni_server_certificate_file_path}"
|
|
225
|
+
print_api(message, **print_kwargs)
|
|
226
|
+
|
|
227
|
+
# You need to build new context and exchange the context that being inherited from the main socket,
|
|
228
|
+
# or else the context will receive previous certificate each time.
|
|
229
|
+
sni_received_parameters.ssl_socket.context = (
|
|
230
|
+
creator.create_server_ssl_context___load_certificate_and_key(
|
|
231
|
+
certificate_file_path=sni_server_certificate_file_path, key_file_path=None,
|
|
232
|
+
enable_sslkeylogfile_env_to_client_ssl_context=self.enable_sslkeylogfile_env_to_client_ssl_context,
|
|
233
|
+
sslkeylog_file_path=self.sslkeylog_file_path
|
|
234
|
+
)
|
|
235
|
+
)
|