Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
d11c634c
Commit
d11c634c
authored
5 years ago
by
Richard van der Hoff
Browse files
Options
Downloads
Patches
Plain Diff
clean up impl, and import idna directly
parent
c2b6e945
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/crypto/context_factory.py
+11
-15
11 additions, 15 deletions
synapse/crypto/context_factory.py
synapse/python_dependencies.py
+1
-0
1 addition, 0 deletions
synapse/python_dependencies.py
with
12 additions
and
15 deletions
synapse/crypto/context_factory.py
+
11
−
15
View file @
d11c634c
...
...
@@ -15,6 +15,7 @@
import
logging
import
idna
from
service_identity
import
VerificationError
from
service_identity.pyopenssl
import
verify_hostname
from
zope.interface
import
implementer
...
...
@@ -58,20 +59,6 @@ class ServerContextFactory(ContextFactory):
return
self
.
_context
def
_idnaBytes
(
text
):
"""
Convert some text typed by a human into some ASCII bytes. This is a
copy of twisted.internet._idna._idnaBytes. For documentation, see the
twisted documentation.
"""
try
:
import
idna
except
ImportError
:
return
text
.
encode
(
"
idna
"
)
else
:
return
idna
.
encode
(
text
)
class
ClientTLSOptionsFactory
(
object
):
"""
Factory for Twisted SSLClientConnectionCreators that are used to make connections
to remote servers for federation.
...
...
@@ -162,13 +149,21 @@ class ConnectionVerifier(object):
This is a thing which is attached to the TLSMemoryBIOProtocol, and is called by
the ssl context
'
s info callback.
"""
# This code is based on twisted.internet.ssl.ClientTLSOptions.
def
__init__
(
self
,
hostname
,
verify_certs
):
self
.
_verify_certs
=
verify_certs
if
isIPAddress
(
hostname
)
or
isIPv6Address
(
hostname
):
self
.
_hostnameBytes
=
hostname
.
encode
(
'
ascii
'
)
self
.
_sendSNI
=
False
else
:
self
.
_hostnameBytes
=
_idnaBytes
(
hostname
)
# twisted's ClientTLSOptions falls back to the stdlib impl here if
# idna is not installed, but points out that lacks support for
# IDNA2008 (http://bugs.python.org/issue17305).
#
# We can rely on having idna.
self
.
_hostnameBytes
=
idna
.
encode
(
hostname
)
self
.
_sendSNI
=
True
self
.
_hostnameASCII
=
self
.
_hostnameBytes
.
decode
(
"
ascii
"
)
...
...
@@ -176,6 +171,7 @@ class ConnectionVerifier(object):
def
verify_context_info_cb
(
self
,
ssl_connection
,
where
):
if
where
&
SSL
.
SSL_CB_HANDSHAKE_START
and
self
.
_sendSNI
:
ssl_connection
.
set_tlsext_host_name
(
self
.
_hostnameBytes
)
if
where
&
SSL
.
SSL_CB_HANDSHAKE_DONE
and
self
.
_verify_certs
:
try
:
verify_hostname
(
ssl_connection
,
self
.
_hostnameASCII
)
...
...
This diff is collapsed.
Click to expand it.
synapse/python_dependencies.py
+
1
−
0
View file @
d11c634c
...
...
@@ -44,6 +44,7 @@ REQUIREMENTS = [
"
canonicaljson>=1.1.3
"
,
"
signedjson>=1.0.0
"
,
"
pynacl>=1.2.1
"
,
"
idna>=2
"
,
"
service_identity>=16.0.0
"
,
# our logcontext handling relies on the ability to cancel inlineCallbacks
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment