Bug 268043

Summary: devel/py-twisted: Consumer ports fail to run: module 'OpenSSL.SSL' has no attribute 'TLS_METHOD' after 22.10.0 update
Product: Ports & Packages Reporter: Dirk Meyer <dinoex>
Component: Individual Port(s)Assignee: Wen Heping <wen>
Status: Open ---    
Severity: Affects Many People CC: ashish, fcharlier, jocke, laszlo, peter, python, vishwin, wen
Priority: Normal Keywords: needs-qa, regression
Version: LatestFlags: bugzilla: maintainer-feedback? (python)
wen: maintainer-feedback+
Hardware: Any   
OS: Any   
See Also: https://github.com/twisted/twisted/issues/11778
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=266680
Bug Depends on:    
Bug Blocks: 268290    
Attachments:
Description Flags
Fix ashish: maintainer-approval?

Description Dirk Meyer freebsd_committer freebsd_triage 2022-11-28 16:49:26 UTC
Enviroment:

make.conf:
DEFAULT_VERSIONS+=      ssl=openssl

after upgrading matrix-synapse and its dependencies, server fails to start.

Logfile:
matrix pkg[26938]: py39-twisted upgraded: 22.4.0 -> 22.10.0
matrix root[37561]: /usr/local/etc/rc.d/synapse: WARNING: failed to start synapse

Backtrace ... ends with
AttributeError: module 'OpenSSL.SSL' has no attribute 'TLS_METHOD'


Crude workaround, I changed 2 files to make synapse starting again.
This maybe not well tested.

vim /usr/local/lib/python3.9/site-packages/twisted/internet/_sslverify.py

line 1492
-self.method = SSL.TLS_METHOD
+self.method = SSL.TLSv1_2_METHOD

line 1807
- SSL.TLS_METHOD,
+ SSL.TLSv1_2_METHOD,

vim /usr/local/lib/python3.9/site-packages/twisted/internet/ssl.py"

line 95
-sslmethod=SSL.TLS_METHOD,
+sslmethod=SSL.TLSv1_2_METHOD,

line 145
-method = SSL.TLS_METHOD
+method = SSL.TLSv1_2_METHOD

Aa alternate solution may be adding:

${REINPLACE_CMD} -e 's|TLS_METHOD|TLSv1_2_METHOD|' ....

If you pick one of the ways, I will generate a build tested patch.
Comment 1 Ashish SHUKLA freebsd_committer freebsd_triage 2022-12-01 05:28:54 UTC
Created attachment 238467 [details]
Fix

Attached patch based on dinoex@ 's suggestion fixes the issue for me, and gets my synapse instance up, and running again.

Thanks!
Comment 2 László Károlyi 2022-12-07 00:07:43 UTC
Related: https://github.com/twisted/twisted/issues/11778
Comment 3 Kubilay Kocak freebsd_committer freebsd_triage 2022-12-11 22:20:51 UTC
Affects many consumers.

@Wen If this cant be resolved quickly, please revert the recent twisted update. We'll use this issue to isolate the root cause(s) and propose the best path forward for the update.
Comment 4 Kubilay Kocak freebsd_committer freebsd_triage 2022-12-11 22:24:21 UTC
Noting from upstream issue: 

  "Use of TLS_METHOD forces requirement of pyOpenSSL >= 21.0"

Our port is currently at 20.*

It's unlikely we can update py-openssl across the board without extensive consumer port (including runtime) testing for version compatibility for that update first.
Comment 5 Kubilay Kocak freebsd_committer freebsd_triage 2022-12-11 22:26:28 UTC
Noting also, upstream did the correct thing and updated their minimum openssl package dependency version spec [1], which wasn't verified/updated in the port, which would have failed during QA if it were.

  tls =
    pyopenssl >= 21.0.0

[1] https://github.com/twisted/twisted/blob/twisted-22.10.0/setup.cfg#L75
Comment 6 Wen Heping freebsd_committer freebsd_triage 2022-12-11 23:32:52 UTC
Please go ahead !

wen
Comment 7 commit-hook freebsd_committer freebsd_triage 2022-12-12 15:00:32 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=e3f34f8a65e6aae0f177b5098b704ca1d0a62c4a

commit e3f34f8a65e6aae0f177b5098b704ca1d0a62c4a
Author:     Ashish SHUKLA <ashish@FreeBSD.org>
AuthorDate: 2022-12-12 14:58:20 +0000
Commit:     Ashish SHUKLA <ashish@FreeBSD.org>
CommitDate: 2022-12-12 14:58:20 +0000

    devel/py-twisted: Unbreak OpenSSL support

    Thanks to dinoex@ for suggessting the workaround.

    PR:             268043
    Reported by:    dinoex
    Approved by:    wen

 devel/py-twisted/Makefile | 5 +++++
 1 file changed, 5 insertions(+)
Comment 8 Charlie Li freebsd_committer freebsd_triage 2022-12-13 04:10:02 UTC
While this works as a quick-fix, this text replacement is ultimately incorrect. Hardcoding to TLSv1_2_method() locks the connection to TLSv1.2 mode only, which is problematic if higher protocol versions (ie TLSv1.3) are mutually available between client and server.

The correct solution is to update security/py-openssl to 21.0.0, as TLS_method() was exposed then, and the minimum security/py-cryptography version is 3.3. This commit should then be reverted.
Comment 9 Kubilay Kocak freebsd_committer freebsd_triage 2022-12-13 21:45:45 UTC
(In reply to Charlie Li from comment #8)

Are there any potential failure cases the recent commit didn't take into consideration?
Comment 10 Charlie Li freebsd_committer freebsd_triage 2022-12-14 01:54:37 UTC
When one of the client or server's minimum configured protocol version is TLSv1.3, the connection fails. Hardcoding TLSv1.2 does not even provide an opportunity for the connection to succeed.