mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Handle errors when fetching remote server keys
This commit is contained in:
parent
d14e94bae4
commit
41285ffe5b
@ -17,6 +17,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
from six import raise_from
|
||||||
from six.moves import urllib
|
from six.moves import urllib
|
||||||
|
|
||||||
from signedjson.key import (
|
from signedjson.key import (
|
||||||
@ -35,7 +36,12 @@ from unpaddedbase64 import decode_base64
|
|||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
from synapse.api.errors import Codes, RequestSendFailed, SynapseError
|
from synapse.api.errors import (
|
||||||
|
Codes,
|
||||||
|
HttpResponseException,
|
||||||
|
RequestSendFailed,
|
||||||
|
SynapseError,
|
||||||
|
)
|
||||||
from synapse.util import logcontext, unwrapFirstError
|
from synapse.util import logcontext, unwrapFirstError
|
||||||
from synapse.util.logcontext import (
|
from synapse.util.logcontext import (
|
||||||
LoggingContext,
|
LoggingContext,
|
||||||
@ -44,6 +50,7 @@ from synapse.util.logcontext import (
|
|||||||
run_in_background,
|
run_in_background,
|
||||||
)
|
)
|
||||||
from synapse.util.metrics import Measure
|
from synapse.util.metrics import Measure
|
||||||
|
from synapse.util.retryutils import NotRetryingDestination
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -367,12 +374,17 @@ class Keyring(object):
|
|||||||
server_name_and_key_ids, perspective_name, perspective_keys
|
server_name_and_key_ids, perspective_name, perspective_keys
|
||||||
)
|
)
|
||||||
defer.returnValue(result)
|
defer.returnValue(result)
|
||||||
|
except KeyLookupError as e:
|
||||||
|
logger.warning(
|
||||||
|
"Key lookup failed from %r: %s", perspective_name, e,
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
"Unable to get key from %r: %s %s",
|
"Unable to get key from %r: %s %s",
|
||||||
perspective_name,
|
perspective_name,
|
||||||
type(e).__name__, str(e),
|
type(e).__name__, str(e),
|
||||||
)
|
)
|
||||||
|
|
||||||
defer.returnValue({})
|
defer.returnValue({})
|
||||||
|
|
||||||
results = yield logcontext.make_deferred_yieldable(defer.gatherResults(
|
results = yield logcontext.make_deferred_yieldable(defer.gatherResults(
|
||||||
@ -421,6 +433,7 @@ class Keyring(object):
|
|||||||
# TODO(mark): Set the minimum_valid_until_ts to that needed by
|
# TODO(mark): Set the minimum_valid_until_ts to that needed by
|
||||||
# the events being validated or the current time if validating
|
# the events being validated or the current time if validating
|
||||||
# an incoming request.
|
# an incoming request.
|
||||||
|
try:
|
||||||
query_response = yield self.client.post_json(
|
query_response = yield self.client.post_json(
|
||||||
destination=perspective_name,
|
destination=perspective_name,
|
||||||
path="/_matrix/key/v2/query",
|
path="/_matrix/key/v2/query",
|
||||||
@ -436,6 +449,14 @@ class Keyring(object):
|
|||||||
},
|
},
|
||||||
long_retries=True,
|
long_retries=True,
|
||||||
)
|
)
|
||||||
|
except (NotRetryingDestination, RequestSendFailed) as e:
|
||||||
|
raise raise_from(
|
||||||
|
KeyLookupError("Failed to connect to remote server"), e,
|
||||||
|
)
|
||||||
|
except HttpResponseException as e:
|
||||||
|
raise raise_from(
|
||||||
|
KeyLookupError("Remote server returned an error"), e,
|
||||||
|
)
|
||||||
|
|
||||||
keys = {}
|
keys = {}
|
||||||
|
|
||||||
@ -502,11 +523,20 @@ class Keyring(object):
|
|||||||
if requested_key_id in keys:
|
if requested_key_id in keys:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
response = yield self.client.get_json(
|
response = yield self.client.get_json(
|
||||||
destination=server_name,
|
destination=server_name,
|
||||||
path="/_matrix/key/v2/server/" + urllib.parse.quote(requested_key_id),
|
path="/_matrix/key/v2/server/" + urllib.parse.quote(requested_key_id),
|
||||||
ignore_backoff=True,
|
ignore_backoff=True,
|
||||||
)
|
)
|
||||||
|
except (NotRetryingDestination, RequestSendFailed) as e:
|
||||||
|
raise raise_from(
|
||||||
|
KeyLookupError("Failed to connect to remote server"), e,
|
||||||
|
)
|
||||||
|
except HttpResponseException as e:
|
||||||
|
raise raise_from(
|
||||||
|
KeyLookupError("Remote server returned an error"), e,
|
||||||
|
)
|
||||||
|
|
||||||
if (u"signatures" not in response
|
if (u"signatures" not in response
|
||||||
or server_name not in response[u"signatures"]):
|
or server_name not in response[u"signatures"]):
|
||||||
|
Loading…
Reference in New Issue
Block a user