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 3 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 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
15 changes: 15 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 @@ -1414,6 +1415,9 @@ def _parseSSL(
constant in C{OpenSSL.SSL}.
@type sslmethod: C{str}

@param cipher: A string containing a list of cipher values, formatted as comma-separated values.
KaviHarjani marked this conversation as resolved.
Show resolved Hide resolved
@type cipher: C{str}

@param extraCertChain: The path of a file containing one or more
certificates in PEM format that establish the chain from a root CA to
the CA that signed your C{certKey}.
Expand Down Expand Up @@ -1466,6 +1470,10 @@ def _parseSSL(
dhParameters=dhParameters,
**kw,
)

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


Expand Down Expand Up @@ -1768,6 +1776,13 @@ def serverFromString(reactor, description):
file name (C{certKey}) isn't provided, the private key file is assumed to
contain the certificate as well.

For custom cipher list, you can make use of the 'cipher' keyword and a comma seperated
string as below::

serverFromString(
reactor, "ssl:443:privateKey=key.pem:certKey=crt.pem:cipher=ECDHE-ECDSA-AES128-GCM-SHA256,ECDHE-RSA-AES128-GCM-SHA256"
)

You may escape colons in arguments with a backslash, which you will need to
use if you want to specify a full pathname argument on Windows::

Expand Down
21 changes: 21 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,27 @@
ctx = server._sslContextFactory.getContext()
self.assertIsInstance(ctx, ContextType)

@skipIf(skipSSL, skipSSLReason)
def test_sslWithCustomCipher(self):
"""
A cipher list is supported, using the OpenSSL format.
The colon (:) from the OpenSSL format is replaced with a comma (,).
"""
reactor = object()
server = (
endpoints.serverFromString(
reactor,
"ssl:1234:backlog=12:privateKey=%s:"
"certKey=%s:cipher=ECDHE-ECDSA-AES128-GCM-SHA256,ECDHE-RSA-AES128-GCM-SHA256,ALL,!ADH,"
"@STRENGTH,+RSA,-DSA,SHA1+DES"
% (escapedPEMPathName, escapedPEMPathName),
),
)
self.assertIsInstance(server, endpoints.SSL4ServerEndpoint)
self.assertEqual(server._sslContextFactory.method, TLSv1_2_METHOD)
ctx = server._sslContextFactory.getContext()
self.assertIsInstance(ctx, ContextType)

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

View check run for this annotation

Codecov / codecov/patch

src/twisted/internet/test/test_endpoints.py#L3279-L3281

Added lines #L3279 - L3281 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
1 change: 1 addition & 0 deletions src/twisted/newsfragments/12134.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for `cipher` in `serverFromString` function
KaviHarjani marked this conversation as resolved.
Show resolved Hide resolved
Loading