2024-04-10 12:58:02 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
from mosq_test_helper import *
|
2026-05-13 00:17:57 +02:00
|
|
|
|
|
|
|
|
from broker_config import BrokerConfig, ListenerConfig
|
|
|
|
|
from matchers import Contains
|
|
|
|
|
from mosquitto_broker import MosquittoBroker
|
2024-08-17 10:08:11 +02:00
|
|
|
from proxy_helper import *
|
2024-04-10 12:58:02 +02:00
|
|
|
import json
|
|
|
|
|
import shutil
|
|
|
|
|
import socket
|
|
|
|
|
|
2026-03-10 13:21:00 +01:00
|
|
|
mosq_test.require_features(["WITH_TLS", "WITH_WEBSOCKETS", "WITH_WEBSOCKETS_BUILTIN"])
|
|
|
|
|
|
2024-04-10 12:58:02 +02:00
|
|
|
def do_test(data):
|
|
|
|
|
port = mosq_test.get_port()
|
2026-05-13 00:17:57 +02:00
|
|
|
broker_config = BrokerConfig(
|
|
|
|
|
listeners=[
|
|
|
|
|
ListenerConfig(
|
|
|
|
|
port=port,
|
|
|
|
|
enable_proxy_protocol=2,
|
|
|
|
|
proxy_protocol_v2_require_tls=True,
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
allow_anonymous=True,
|
|
|
|
|
log_type="all",
|
|
|
|
|
)
|
|
|
|
|
broker = MosquittoBroker(config=broker_config)
|
|
|
|
|
with broker:
|
2024-08-17 10:08:11 +02:00
|
|
|
sock = do_proxy_v2_connect(port, PROXY_VER, PROXY_CMD_PROXY, PROXY_FAM_IPV4 | PROXY_PROTO_TCP, data)
|
2024-04-10 12:58:02 +02:00
|
|
|
try:
|
|
|
|
|
data = sock.recv(10)
|
2026-05-13 00:17:57 +02:00
|
|
|
if len(data) > 0:
|
|
|
|
|
raise ValueError(data)
|
2024-04-10 12:58:02 +02:00
|
|
|
except ConnectionResetError:
|
2026-05-13 00:17:57 +02:00
|
|
|
pass
|
2024-04-10 12:58:02 +02:00
|
|
|
sock.close()
|
2026-05-13 00:17:57 +02:00
|
|
|
broker.check_log(Contains("Connection from 192.0.2.5:6275 rejected, client did not connect using TLS."))
|
2024-04-10 12:58:02 +02:00
|
|
|
|
|
|
|
|
# No SSL at all
|
|
|
|
|
data = b"\xC0\x00\x02\x05" + b"\x00\x00\x00\x00" + b"\x18\x83" + b"\x00\x00"
|
|
|
|
|
do_test(data)
|