legacy-ssh-proxy 0.1.1__py3-none-win_amd64.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.
@@ -0,0 +1,87 @@
1
+ """Run the Go compatibility proxy as a context manager."""
2
+ from __future__ import annotations
3
+
4
+ import os
5
+ import socket
6
+ import subprocess
7
+ import sys
8
+ import time
9
+ from contextlib import contextmanager
10
+ from pathlib import Path
11
+ from typing import Iterator
12
+
13
+ __all__ = ["legacy_ssh_proxy", "find_free_tcp_port", "get_binary_path"]
14
+
15
+
16
+ def get_binary_path() -> Path:
17
+ """Locate the bundled Go executable inside the installed package."""
18
+ bin_dir = Path(__file__).parent / "bin"
19
+ exe_name = "legacy-ssh-proxy.exe" if sys.platform == "win32" else "legacy-ssh-proxy"
20
+ binary_path = bin_dir / exe_name
21
+
22
+ if not binary_path.exists():
23
+ raise FileNotFoundError(f"Bundled binary not found at {binary_path}")
24
+
25
+ if sys.platform != "win32":
26
+ os.chmod(binary_path, 0o755)
27
+
28
+ return binary_path
29
+
30
+
31
+ def find_free_tcp_port() -> int:
32
+ # There is a small bind-close-rebind race. For production orchestration,
33
+ # prefer starting the Go library with ListenAddress="127.0.0.1:0".
34
+ with socket.socket() as sock:
35
+ sock.bind(("127.0.0.1", 0))
36
+ return int(sock.getsockname()[1])
37
+
38
+
39
+ @contextmanager
40
+ def legacy_ssh_proxy(
41
+ target: str,
42
+ *,
43
+ listen_host: str = "127.0.0.1",
44
+ executable: str | None = None,
45
+ host_key_file: str | None = None,
46
+ known_hosts: str | None = None,
47
+ insecure_ignore_host_key: bool = False,
48
+ startup_timeout: float = 10.0,
49
+ ) -> Iterator[tuple[str, int]]:
50
+ binary = (
51
+ executable
52
+ or os.environ.get("LEGACY_SSH_PROXY_BIN")
53
+ or str(get_binary_path())
54
+ )
55
+ port = find_free_tcp_port()
56
+ command = [binary, "-listen", f"{listen_host}:{port}", "-target", target]
57
+ if host_key_file:
58
+ command += ["-host-key", host_key_file]
59
+ if known_hosts:
60
+ command += ["-known-hosts", known_hosts]
61
+ if insecure_ignore_host_key:
62
+ command += ["-insecure-ignore-host-key"]
63
+
64
+ process = subprocess.Popen(
65
+ command, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, text=True
66
+ )
67
+ try:
68
+ deadline = time.monotonic() + startup_timeout
69
+ while time.monotonic() < deadline:
70
+ if process.poll() is not None:
71
+ error = process.stderr.read() if process.stderr else ""
72
+ raise RuntimeError(f"SSH proxy exited during startup: {error}")
73
+ try:
74
+ with socket.create_connection((listen_host, port), timeout=0.2):
75
+ break
76
+ except OSError:
77
+ time.sleep(0.05)
78
+ else:
79
+ raise TimeoutError("SSH proxy did not become ready")
80
+ yield listen_host, port
81
+ finally:
82
+ process.terminate()
83
+ try:
84
+ process.wait(timeout=5)
85
+ except subprocess.TimeoutExpired:
86
+ process.kill()
87
+ process.wait(timeout=5)
@@ -0,0 +1,8 @@
1
+ import subprocess
2
+ import sys
3
+ from . import get_binary_path
4
+
5
+ def main():
6
+ binary = get_binary_path()
7
+ result = subprocess.run([str(binary), *sys.argv[1:]])
8
+ sys.exit(result.returncode)
@@ -0,0 +1,48 @@
1
+ import paramiko
2
+ from legacy_ssh_proxy import legacy_ssh_proxy
3
+
4
+
5
+ real_host = "aggrouter.cissta.local.net"
6
+ port = "22"
7
+ username = "user"
8
+ password = "secret"
9
+
10
+ def paramiko_router_test():
11
+ client = paramiko.SSHClient()
12
+ client.load_system_host_keys()
13
+ client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
14
+ try:
15
+ client.connect(
16
+ hostname=real_host, port=port, username=username, password=password,
17
+ look_for_keys=False, allow_agent=False,
18
+ )
19
+ _, stdout, _ = client.exec_command("show platform")
20
+ print(stdout.read().decode())
21
+ finally:
22
+ client.close()
23
+
24
+
25
+ def proxy_test():
26
+ with legacy_ssh_proxy(f"{real_host}:22", insecure_ignore_host_key=True) as (host, port):
27
+ client = paramiko.SSHClient()
28
+ client.load_system_host_keys()
29
+ client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
30
+ print(f"we will connect paramiko to {real_host} via {host}:{port}")
31
+ try:
32
+ client.connect(
33
+ hostname=host, port=port, username=username, password=password,
34
+ look_for_keys=False, allow_agent=False,
35
+ )
36
+ _, stdout, _ = client.exec_command("show platform")
37
+ print(stdout.read().decode())
38
+ finally:
39
+ client.close()
40
+
41
+
42
+ def main():
43
+ # paramiko_router_test()
44
+ # proxy_test()
45
+ pass
46
+
47
+
48
+ main()
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.4
2
+ Name: legacy-ssh-proxy
3
+ Version: 0.1.1
4
+ Summary: Python wrapper and context manager for Legacy SSH Proxy
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+
9
+
10
+ # Legacy SSH Proxy for Python
11
+
12
+ A lightweight, cross-platform SSH compatibility proxy and Python wrapper. It terminates incoming SSH connections from modern Python clients (such as Paramiko) using modern cryptographic defaults and establishes a separate outbound connection to legacy SSH servers using selectively enabled legacy algorithms.
13
+ The precompiled Go binary for your operating system and CPU architecture is bundled inside the wheel—no Go toolchain or manual binary download is required.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pip install legacy-ssh-proxy
19
+ ```
20
+
21
+ If you plan to connect through the proxy using Paramiko, install paramiko alongside it:
22
+
23
+ ```bash
24
+ pip install legacy-ssh-proxy paramiko
25
+ ```
26
+
27
+ ## Quick Start: Context Manager
28
+
29
+ Use the built-in legacy_ssh_proxy context manager to automatically start the bundled proxy on a free local TCP port, yield the (host, port) pair to Paramiko, and terminate the background process when the block exits.
30
+ ```python
31
+ import paramiko
32
+ from legacy_ssh_proxy import legacy_ssh_proxy
33
+
34
+ with legacy_ssh_proxy("192.0.2.50:22", insecure_ignore_host_key=True, known_hosts="/home/me/.ssh/known_hosts") as (host, port):
35
+ client = paramiko.SSHClient()
36
+ client.load_system_host_keys()
37
+ client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
38
+ try:
39
+ client.connect(
40
+ hostname=host, port=port, username="your-user",
41
+ password="your-password", look_for_keys=False, allow_agent=False,
42
+ )
43
+ _, stdout, _ = client.exec_command("uname -a")
44
+ print(stdout.read().decode())
45
+ finally:
46
+ client.close()
47
+ ```
48
+
49
+ ### Context Manager Parameters
50
+
51
+ * target (str): Destination legacy SSH server address (host:port).
52
+ * listen_host (str): Local bind address (defaults to "127.0.0.1").
53
+ * host_key_file (str | None): Path to a persistent SSH host key for the local proxy listener.
54
+ * known_hosts (str | None): Path to the known_hosts file used to verify the destination server.
55
+ * insecure_ignore_host_key (bool): Skip destination host-key verification. Use only in disposable lab environments.
56
+ * executable (str | None): Optional path to a custom legacy-ssh-proxy binary (overrides LEGACY_SSH_PROXY_BIN and the bundled executable).
57
+ * startup_timeout (float): Maximum seconds to wait for the local listener to accept connections (defaults to 10.0).
58
+
59
+ ## CLI Usage
60
+
61
+ Installing the package also adds the legacy-ssh-proxy command to your environment:
62
+ ```bash
63
+ legacy-ssh-proxy \
64
+ -listen 127.0.0.1:2222 \
65
+ -target 192.0.2.50:22 \
66
+ -insecure-ignore-host-key \
67
+ -known-hosts ~/.ssh/known_hosts
68
+ ```
69
+ You can then point any standard SSH, SFTP, or Python Paramiko client at 127.0.0.1:2222.
70
+
71
+ ## Security & Host Keys
72
+
73
+ * Destination verification: The proxy verifies the target server against the known_hosts file passed via known_hosts or -known-hosts. Avoid setting insecure_ignore_host_key=True in production, as it exposes the connection to man-in-the-middle attacks.
74
+ * Local proxy verification: Paramiko separately verifies the proxy's local-facing host key. Because the proxy generates an ephemeral host key on each start by default, pass host_key_file (or -host-key) and pin its public key in your Paramiko known_hosts database when using RejectPolicy().
75
+ * Avoid AutoAddPolicy(): Do not use paramiko.AutoAddPolicy() in production environment
76
+
@@ -0,0 +1,9 @@
1
+ legacy_ssh_proxy/__init__.py,sha256=P-gutKbliJAW_QB3HnhUlBDXV3eLgXu7D4L2vUn0bKk,2785
2
+ legacy_ssh_proxy/cli.py,sha256=Rn8oHVM4iN-1Q9W0y4Ab_cHXxsmLIi7JdTPm1SRX0Bc,193
3
+ legacy_ssh_proxy/demo.py,sha256=lmWgPWC59yy7u8M3BvNvm-wKJvBnvyFriUjO06p9yj0,1384
4
+ legacy_ssh_proxy/bin/legacy-ssh-proxy.exe,sha256=wJKPmarubfN_WnFXkd4n7OnesmE0mgvsicfYMypzdns,4706304
5
+ legacy_ssh_proxy-0.1.1.dist-info/METADATA,sha256=sLE1PDMQlWliV4NIrPFPfrDnOsR-LHqJWQ7SyQaKujw,3527
6
+ legacy_ssh_proxy-0.1.1.dist-info/WHEEL,sha256=bhMFZwp6VMtrbl2Ck6PlXryKaCggO1NzYn_HcFbBF1I,97
7
+ legacy_ssh_proxy-0.1.1.dist-info/entry_points.txt,sha256=KKJpBBrgYv16s-6D6Q3W7-5Kh07Chu28g9JYacNYoek,63
8
+ legacy_ssh_proxy-0.1.1.dist-info/top_level.txt,sha256=jMKBFP29rAwatC4YWWSjtkm2mMvNCuvdNeGa8PYaxIE,17
9
+ legacy_ssh_proxy-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-win_amd64
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ legacy-ssh-proxy = legacy_ssh_proxy.cli:main
@@ -0,0 +1 @@
1
+ legacy_ssh_proxy