Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding cipher tag to the serverFromString #12137

Open
wants to merge 25 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e9308d3
Adding cipher tag to the serverFromString
KaviHarjani Apr 24, 2024
6e30f9f
Adding cipher tag to the serverFromString
KaviHarjani Apr 24, 2024
692e540
isort changes
KaviHarjani Apr 25, 2024
7796194
Update src/twisted/internet/endpoints.py
KaviHarjani Apr 25, 2024
a9f55ad
Fixing the test error
KaviHarjani Apr 25, 2024
1ecf280
Merge branch 'kaviharjani_12134' of github.com:KaviHarjani/twisted in…
KaviHarjani Apr 25, 2024
9889492
Test fix
KaviHarjani Apr 25, 2024
7f069f9
Removed TLS version as that is not being passed in the string anymore…
KaviHarjani Apr 25, 2024
6e3ca2e
Undo NEWS.rst update
KaviHarjani Apr 25, 2024
a0ee495
Update cipher description
KaviHarjani Apr 25, 2024
fb447c1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 25, 2024
f991e5a
Update src/twisted/newsfragments/12134.feature
KaviHarjani Apr 27, 2024
fe8f46a
Cipher failing error message
KaviHarjani Apr 27, 2024
53b0d41
Limitations in test docstring
KaviHarjani Apr 27, 2024
acdf92c
Merge branch 'kaviharjani_12134' of github.com:KaviHarjani/twisted in…
KaviHarjani Apr 27, 2024
2f34e3f
Adding pyopenssl to GTK
KaviHarjani Apr 27, 2024
4255837
Adding pyopenssl in dependencies
KaviHarjani Apr 27, 2024
e458979
Using SSlError
KaviHarjani Apr 27, 2024
9a2a93b
Update test.yaml
KaviHarjani Apr 27, 2024
ce636b2
Test update
KaviHarjani Apr 27, 2024
746099b
Merge branch 'kaviharjani_12134' of github.com:KaviHarjani/twisted in…
KaviHarjani Apr 27, 2024
9fe9c61
Fixing the text in code
KaviHarjani Apr 28, 2024
d64992a
Raising SSL error except for generic one
KaviHarjani Apr 29, 2024
30078f9
Update src/twisted/internet/test/test_endpoints.py
KaviHarjani Apr 29, 2024
e94db6c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3873,7 +3873,7 @@ Twisted Core 15.4.0 (2015-09-04)
================================

This is the last Twisted release where Python 2.6 is supported, on any
platform.
platform.
KaviHarjani marked this conversation as resolved.
Show resolved Hide resolved

Features
--------
Expand Down Expand Up @@ -4417,6 +4417,7 @@ Twisted Core 15.0.0 (2015-01-24)

Features
--------
- twisted.internet.endpoints adding support for cipher in `serverFromString`(#12134)
KaviHarjani marked this conversation as resolved.
Show resolved Hide resolved
- twisted.internet.protocol.ClientFactory (and subclasses) may now
return None from buildProtocol to immediately close the connection.
(#710)
Expand Down
5 changes: 5 additions & 0 deletions src/twisted/internet/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,7 @@ def _parseSSL(
privateKey="server.pem",
certKey=None,
sslmethod=None,
cipher=None,
interface="",
backlog=50,
extraCertChain=None,
Expand Down Expand Up @@ -1466,6 +1467,10 @@ def _parseSSL(
dhParameters=dhParameters,
**kw,
)

if cipher:
if isinstance(cipher, str):
KaviHarjani marked this conversation as resolved.
Show resolved Hide resolved
cf.getContext().set_cipher_list(str.encode(cipher.replace(",", ":")))
KaviHarjani marked this conversation as resolved.
Show resolved Hide resolved
return ((int(port), factory, cf), {"interface": interface, "backlog": int(backlog)})


Expand Down
23 changes: 23 additions & 0 deletions src/twisted/internet/test/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3259,6 +3259,29 @@
ctx = server._sslContextFactory.getContext()
self.assertIsInstance(ctx, ContextType)

@skipIf(skipSSL, skipSSLReason)
def test_sslWithCustomCipher(self):
"""
Test adding custom cipher to the serverFromString function.
KaviHarjani marked this conversation as resolved.
Show resolved Hide resolved
"""
reactor = object()
server = (
endpoints.serverFromString(
reactor,
"ssl:1234:backlog=12:privateKey=%s:"
"certKey=%s:sslmethod=TLSv1_2_METHOD:interface=10.0.0.1:cipher=ECDHE-ECDSA-AES128-GCM-SHA256,ECDHE-ECDSA-CHACHA20-POLY1305,ECDHE-RSA-AES128-GCM-SHA256"
KaviHarjani marked this conversation as resolved.
Show resolved Hide resolved
% (escapedPEMPathName, escapedPEMPathName),
),
)
self.assertIsInstance(server, endpoints.SSL4ServerEndpoint)
self.assertIs(server._reactor, reactor)
self.assertEqual(server._port, 1234)
self.assertEqual(server._backlog, 12)
self.assertEqual(server._interface, "10.0.0.1")
self.assertEqual(server._sslContextFactory.method, TLSv1_2_METHOD)
KaviHarjani marked this conversation as resolved.
Show resolved Hide resolved
ctx = server._sslContextFactory.getContext()
self.assertIsInstance(ctx, ContextType)

Check warning on line 3283 in src/twisted/internet/test/test_endpoints.py

View check run for this annotation

Codecov / codecov/patch

src/twisted/internet/test/test_endpoints.py#L3277-L3283

Added lines #L3277 - L3283 were not covered by tests
KaviHarjani marked this conversation as resolved.
Show resolved Hide resolved

def test_unix(self):
"""
When passed a UNIX strports description, L{endpoint.serverFromString}
Expand Down