Port crypto/ to Python 3 (#3822)
This commit is contained in:
parent
4073f73edc
commit
8fd93b5eea
|
@ -0,0 +1 @@
|
||||||
|
crypto/ is now ported to Python 3.
|
|
@ -123,6 +123,6 @@ class ClientTLSOptionsFactory(object):
|
||||||
|
|
||||||
def get_options(self, host):
|
def get_options(self, host):
|
||||||
return ClientTLSOptions(
|
return ClientTLSOptions(
|
||||||
host.decode('utf-8'),
|
host,
|
||||||
CertificateOptions(verify=False).getContext()
|
CertificateOptions(verify=False).getContext()
|
||||||
)
|
)
|
||||||
|
|
|
@ -50,7 +50,7 @@ def fetch_server_key(server_name, tls_client_options_factory, path=KEY_API_V1):
|
||||||
defer.returnValue((server_response, server_certificate))
|
defer.returnValue((server_response, server_certificate))
|
||||||
except SynapseKeyClientError as e:
|
except SynapseKeyClientError as e:
|
||||||
logger.warn("Error getting key for %r: %s", server_name, e)
|
logger.warn("Error getting key for %r: %s", server_name, e)
|
||||||
if e.status.startswith("4"):
|
if e.status.startswith(b"4"):
|
||||||
# Don't retry for 4xx responses.
|
# Don't retry for 4xx responses.
|
||||||
raise IOError("Cannot get key for %r" % server_name)
|
raise IOError("Cannot get key for %r" % server_name)
|
||||||
except (ConnectError, DomainError) as e:
|
except (ConnectError, DomainError) as e:
|
||||||
|
@ -82,6 +82,12 @@ class SynapseKeyClientProtocol(HTTPClient):
|
||||||
self._peer = self.transport.getPeer()
|
self._peer = self.transport.getPeer()
|
||||||
logger.debug("Connected to %s", self._peer)
|
logger.debug("Connected to %s", self._peer)
|
||||||
|
|
||||||
|
if not isinstance(self.path, bytes):
|
||||||
|
self.path = self.path.encode('ascii')
|
||||||
|
|
||||||
|
if not isinstance(self.host, bytes):
|
||||||
|
self.host = self.host.encode('ascii')
|
||||||
|
|
||||||
self.sendCommand(b"GET", self.path)
|
self.sendCommand(b"GET", self.path)
|
||||||
if self.host:
|
if self.host:
|
||||||
self.sendHeader(b"Host", self.host)
|
self.sendHeader(b"Host", self.host)
|
||||||
|
|
|
@ -16,9 +16,10 @@
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
import urllib
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
from six.moves import urllib
|
||||||
|
|
||||||
from signedjson.key import (
|
from signedjson.key import (
|
||||||
decode_verify_key_bytes,
|
decode_verify_key_bytes,
|
||||||
encode_verify_key_base64,
|
encode_verify_key_base64,
|
||||||
|
@ -432,7 +433,7 @@ class Keyring(object):
|
||||||
# an incoming request.
|
# an incoming request.
|
||||||
query_response = yield self.client.post_json(
|
query_response = yield self.client.post_json(
|
||||||
destination=perspective_name,
|
destination=perspective_name,
|
||||||
path=b"/_matrix/key/v2/query",
|
path="/_matrix/key/v2/query",
|
||||||
data={
|
data={
|
||||||
u"server_keys": {
|
u"server_keys": {
|
||||||
server_name: {
|
server_name: {
|
||||||
|
@ -513,8 +514,8 @@ class Keyring(object):
|
||||||
|
|
||||||
(response, tls_certificate) = yield fetch_server_key(
|
(response, tls_certificate) = yield fetch_server_key(
|
||||||
server_name, self.hs.tls_client_options_factory,
|
server_name, self.hs.tls_client_options_factory,
|
||||||
path=(b"/_matrix/key/v2/server/%s" % (
|
path=("/_matrix/key/v2/server/%s" % (
|
||||||
urllib.quote(requested_key_id),
|
urllib.parse.quote(requested_key_id),
|
||||||
)).encode("ascii"),
|
)).encode("ascii"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue