python-aiosmtpd/284.patch
2022-06-14 14:33:53 +08:00

47 lines
2.1 KiB
Diff

From e302182240ea59f4cf65c7d4b128be29417f33a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Thu, 23 Sep 2021 15:55:02 +0200
Subject: [PATCH] Avoid SSLError: Cannot create a client socket with a
PROTOCOL_TLS_SERVER context
When we build mailman3 in Fedora with Python 3.10.0rc2,
we see the following problem:
Traceback (most recent call last):
File "/builddir/build/BUILD/mailman-3.3.4/src/mailman/testing/layers.py", line 297, in setUp
cls.smtpd.start()
File "/builddir/build/BUILD/mailman-3.3.4/src/mailman/testing/mta.py", line 177, in start
super().start()
File "/usr/lib/python3.10/site-packages/aiosmtpd/controller.py", line 288, in start
self._trigger_server()
File "/usr/lib/python3.10/site-packages/aiosmtpd/controller.py", line 481, in _trigger_server
InetMixin._trigger_server(self)
File "/usr/lib/python3.10/site-packages/aiosmtpd/controller.py", line 428, in _trigger_server
s = stk.enter_context(self.ssl_context.wrap_socket(s))
File "/usr/lib64/python3.10/ssl.py", line 512, in wrap_socket
return self.sslsocket_class._create(
File "/usr/lib64/python3.10/ssl.py", line 1061, in _create
self._sslobj = self._context._wrap_socket(
ssl.SSLError: Cannot create a client socket with a PROTOCOL_TLS_SERVER context (_ssl.c:801)
This makes the problem go away.
Disclaimer: I have no idea what I'm doing here.
---
aiosmtpd/controller.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/aiosmtpd/controller.py b/aiosmtpd/controller.py
index 79bdbd04..30fd4a11 100644
--- a/aiosmtpd/controller.py
+++ b/aiosmtpd/controller.py
@@ -424,7 +424,7 @@ def _trigger_server(self):
hostname = self.hostname or self._localhost
with ExitStack() as stk:
s = stk.enter_context(create_connection((hostname, self.port), 1.0))
- if self.ssl_context:
+ if self.ssl_context and self.ssl_context.protocol != ssl.PROTOCOL_TLS_SERVER:
s = stk.enter_context(self.ssl_context.wrap_socket(s))
s.recv(1024)