| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import os |
| 16 |
import subprocess |
| 17 |
|
| 18 |
from rsyncfns import SCRATCHDIR, SRCDIR, rmtree, test_fail |
| 19 |
|
| 20 |
base = SCRATCHDIR / 'rsync-ssl-stunnel' |
| 21 |
rmtree(base) |
| 22 |
base.mkdir(parents=True) |
| 23 |
|
| 24 |
config_capture = base / 'stunnel_config' |
| 25 |
fake_stunnel = base / 'fake_stunnel' |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
fake_stunnel.write_text(f"#!/usr/bin/env bash\ncat <&10 > {config_capture} 2>/dev/null\nexit 0\n") |
| 30 |
fake_stunnel.chmod(0o755) |
| 31 |
|
| 32 |
helper = ['--HELPER', 'localhost', 'rsync', '--server', '--daemon', '.'] |
| 33 |
env = {**os.environ, 'RSYNC_SSL_TYPE': 'stunnel', 'RSYNC_SSL_STUNNEL': str(fake_stunnel)} |
| 34 |
env.pop('RSYNC_SSL_CA_CERT', None) |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
env1 = {**env, 'RSYNC_SSL_ALLOW_INSECURE_STUNNEL': '1'} |
| 39 |
subprocess.run(['bash', str(SRCDIR / 'rsync-ssl')] + helper, env=env1, |
| 40 |
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 41 |
cfg = config_capture.read_text() if config_capture.exists() else '' |
| 42 |
if 'connect = localhost' not in cfg: |
| 43 |
test_fail(f"premise: fake stunnel did not capture a config:\n{cfg!r}") |
| 44 |
if 'verifyChain' in cfg or 'CAfile' in cfg: |
| 45 |
test_fail("premise: expected NO certificate-verification directives in the " |
| 46 |
f"no-CA stunnel config:\n{cfg}") |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
proc = subprocess.run(['bash', str(SRCDIR / 'rsync-ssl')] + helper, env=env, |
| 51 |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) |
| 52 |
if proc.returncode == 0 or 'stunnel requires RSYNC_SSL_CA_CERT' not in proc.stdout: |
| 53 |
test_fail("rsync-ssl did NOT refuse insecure stunnel mode without a CA:\n" + proc.stdout) |
| 54 |
|
| 55 |
print("rsync-ssl-stunnel-ca-required: stunnel without a CA yields an unverified " |
| 56 |
"(MITM-able) config; rsync-ssl refuses it unless explicitly opted out") |