test_keyring.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. # Copyright 2017 New Vector Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import time
  15. from unittest.mock import Mock
  16. import attr
  17. import canonicaljson
  18. import signedjson.key
  19. import signedjson.sign
  20. from nacl.signing import SigningKey
  21. from signedjson.key import encode_verify_key_base64, get_verify_key
  22. from twisted.internet import defer
  23. from twisted.internet.defer import Deferred, ensureDeferred
  24. from synapse.api.errors import SynapseError
  25. from synapse.crypto import keyring
  26. from synapse.crypto.keyring import (
  27. PerspectivesKeyFetcher,
  28. ServerKeyFetcher,
  29. StoreKeyFetcher,
  30. )
  31. from synapse.logging.context import (
  32. LoggingContext,
  33. current_context,
  34. make_deferred_yieldable,
  35. )
  36. from synapse.storage.keys import FetchKeyResult
  37. from tests import unittest
  38. from tests.test_utils import make_awaitable
  39. from tests.unittest import logcontext_clean
  40. class MockPerspectiveServer:
  41. def __init__(self):
  42. self.server_name = "mock_server"
  43. self.key = signedjson.key.generate_signing_key(0)
  44. def get_verify_keys(self):
  45. vk = signedjson.key.get_verify_key(self.key)
  46. return {"%s:%s" % (vk.alg, vk.version): encode_verify_key_base64(vk)}
  47. def get_signed_key(self, server_name, verify_key):
  48. key_id = "%s:%s" % (verify_key.alg, verify_key.version)
  49. res = {
  50. "server_name": server_name,
  51. "old_verify_keys": {},
  52. "valid_until_ts": time.time() * 1000 + 3600,
  53. "verify_keys": {key_id: {"key": encode_verify_key_base64(verify_key)}},
  54. }
  55. self.sign_response(res)
  56. return res
  57. def sign_response(self, res):
  58. signedjson.sign.sign_json(res, self.server_name, self.key)
  59. @attr.s(slots=True)
  60. class FakeRequest:
  61. id = attr.ib()
  62. @logcontext_clean
  63. class KeyringTestCase(unittest.HomeserverTestCase):
  64. def check_context(self, val, expected):
  65. self.assertEquals(getattr(current_context(), "request", None), expected)
  66. return val
  67. def test_verify_json_objects_for_server_awaits_previous_requests(self):
  68. mock_fetcher = Mock()
  69. mock_fetcher.get_keys = Mock()
  70. kr = keyring.Keyring(self.hs, key_fetchers=(mock_fetcher,))
  71. # a signed object that we are going to try to validate
  72. key1 = signedjson.key.generate_signing_key(1)
  73. json1 = {}
  74. signedjson.sign.sign_json(json1, "server10", key1)
  75. # start off a first set of lookups. We make the mock fetcher block until this
  76. # deferred completes.
  77. first_lookup_deferred = Deferred()
  78. async def first_lookup_fetch(keys_to_fetch):
  79. self.assertEquals(current_context().request.id, "context_11")
  80. self.assertEqual(keys_to_fetch, {"server10": {get_key_id(key1): 0}})
  81. await make_deferred_yieldable(first_lookup_deferred)
  82. return {
  83. "server10": {
  84. get_key_id(key1): FetchKeyResult(get_verify_key(key1), 100)
  85. }
  86. }
  87. mock_fetcher.get_keys.side_effect = first_lookup_fetch
  88. async def first_lookup():
  89. with LoggingContext("context_11", request=FakeRequest("context_11")):
  90. res_deferreds = kr.verify_json_objects_for_server(
  91. [("server10", json1, 0, "test10"), ("server11", {}, 0, "test11")]
  92. )
  93. # the unsigned json should be rejected pretty quickly
  94. self.assertTrue(res_deferreds[1].called)
  95. try:
  96. await res_deferreds[1]
  97. self.assertFalse("unsigned json didn't cause a failure")
  98. except SynapseError:
  99. pass
  100. self.assertFalse(res_deferreds[0].called)
  101. res_deferreds[0].addBoth(self.check_context, None)
  102. await make_deferred_yieldable(res_deferreds[0])
  103. d0 = ensureDeferred(first_lookup())
  104. mock_fetcher.get_keys.assert_called_once()
  105. # a second request for a server with outstanding requests
  106. # should block rather than start a second call
  107. async def second_lookup_fetch(keys_to_fetch):
  108. self.assertEquals(current_context().request.id, "context_12")
  109. return {
  110. "server10": {
  111. get_key_id(key1): FetchKeyResult(get_verify_key(key1), 100)
  112. }
  113. }
  114. mock_fetcher.get_keys.reset_mock()
  115. mock_fetcher.get_keys.side_effect = second_lookup_fetch
  116. second_lookup_state = [0]
  117. async def second_lookup():
  118. with LoggingContext("context_12", request=FakeRequest("context_12")):
  119. res_deferreds_2 = kr.verify_json_objects_for_server(
  120. [("server10", json1, 0, "test")]
  121. )
  122. res_deferreds_2[0].addBoth(self.check_context, None)
  123. second_lookup_state[0] = 1
  124. await make_deferred_yieldable(res_deferreds_2[0])
  125. second_lookup_state[0] = 2
  126. d2 = ensureDeferred(second_lookup())
  127. self.pump()
  128. # the second request should be pending, but the fetcher should not yet have been
  129. # called
  130. self.assertEqual(second_lookup_state[0], 1)
  131. mock_fetcher.get_keys.assert_not_called()
  132. # complete the first request
  133. first_lookup_deferred.callback(None)
  134. # and now both verifications should succeed.
  135. self.get_success(d0)
  136. self.get_success(d2)
  137. def test_verify_json_for_server(self):
  138. kr = keyring.Keyring(self.hs)
  139. key1 = signedjson.key.generate_signing_key(1)
  140. r = self.hs.get_datastore().store_server_verify_keys(
  141. "server9",
  142. time.time() * 1000,
  143. [("server9", get_key_id(key1), FetchKeyResult(get_verify_key(key1), 1000))],
  144. )
  145. self.get_success(r)
  146. json1 = {}
  147. signedjson.sign.sign_json(json1, "server9", key1)
  148. # should fail immediately on an unsigned object
  149. d = _verify_json_for_server(kr, "server9", {}, 0, "test unsigned")
  150. self.get_failure(d, SynapseError)
  151. # should succeed on a signed object
  152. d = _verify_json_for_server(kr, "server9", json1, 500, "test signed")
  153. # self.assertFalse(d.called)
  154. self.get_success(d)
  155. def test_verify_json_for_server_with_null_valid_until_ms(self):
  156. """Tests that we correctly handle key requests for keys we've stored
  157. with a null `ts_valid_until_ms`
  158. """
  159. mock_fetcher = Mock()
  160. mock_fetcher.get_keys = Mock(return_value=make_awaitable({}))
  161. kr = keyring.Keyring(
  162. self.hs, key_fetchers=(StoreKeyFetcher(self.hs), mock_fetcher)
  163. )
  164. key1 = signedjson.key.generate_signing_key(1)
  165. r = self.hs.get_datastore().store_server_verify_keys(
  166. "server9",
  167. time.time() * 1000,
  168. [("server9", get_key_id(key1), FetchKeyResult(get_verify_key(key1), None))],
  169. )
  170. self.get_success(r)
  171. json1 = {}
  172. signedjson.sign.sign_json(json1, "server9", key1)
  173. # should fail immediately on an unsigned object
  174. d = _verify_json_for_server(kr, "server9", {}, 0, "test unsigned")
  175. self.get_failure(d, SynapseError)
  176. # should fail on a signed object with a non-zero minimum_valid_until_ms,
  177. # as it tries to refetch the keys and fails.
  178. d = _verify_json_for_server(
  179. kr, "server9", json1, 500, "test signed non-zero min"
  180. )
  181. self.get_failure(d, SynapseError)
  182. # We expect the keyring tried to refetch the key once.
  183. mock_fetcher.get_keys.assert_called_once_with(
  184. {"server9": {get_key_id(key1): 500}}
  185. )
  186. # should succeed on a signed object with a 0 minimum_valid_until_ms
  187. d = _verify_json_for_server(
  188. kr, "server9", json1, 0, "test signed with zero min"
  189. )
  190. self.get_success(d)
  191. def test_verify_json_dedupes_key_requests(self):
  192. """Two requests for the same key should be deduped."""
  193. key1 = signedjson.key.generate_signing_key(1)
  194. async def get_keys(keys_to_fetch):
  195. # there should only be one request object (with the max validity)
  196. self.assertEqual(keys_to_fetch, {"server1": {get_key_id(key1): 1500}})
  197. return {
  198. "server1": {
  199. get_key_id(key1): FetchKeyResult(get_verify_key(key1), 1200)
  200. }
  201. }
  202. mock_fetcher = Mock()
  203. mock_fetcher.get_keys = Mock(side_effect=get_keys)
  204. kr = keyring.Keyring(self.hs, key_fetchers=(mock_fetcher,))
  205. json1 = {}
  206. signedjson.sign.sign_json(json1, "server1", key1)
  207. # the first request should succeed; the second should fail because the key
  208. # has expired
  209. results = kr.verify_json_objects_for_server(
  210. [("server1", json1, 500, "test1"), ("server1", json1, 1500, "test2")]
  211. )
  212. self.assertEqual(len(results), 2)
  213. self.get_success(results[0])
  214. e = self.get_failure(results[1], SynapseError).value
  215. self.assertEqual(e.errcode, "M_UNAUTHORIZED")
  216. self.assertEqual(e.code, 401)
  217. # there should have been a single call to the fetcher
  218. mock_fetcher.get_keys.assert_called_once()
  219. def test_verify_json_falls_back_to_other_fetchers(self):
  220. """If the first fetcher cannot provide a recent enough key, we fall back"""
  221. key1 = signedjson.key.generate_signing_key(1)
  222. async def get_keys1(keys_to_fetch):
  223. self.assertEqual(keys_to_fetch, {"server1": {get_key_id(key1): 1500}})
  224. return {
  225. "server1": {get_key_id(key1): FetchKeyResult(get_verify_key(key1), 800)}
  226. }
  227. async def get_keys2(keys_to_fetch):
  228. self.assertEqual(keys_to_fetch, {"server1": {get_key_id(key1): 1500}})
  229. return {
  230. "server1": {
  231. get_key_id(key1): FetchKeyResult(get_verify_key(key1), 1200)
  232. }
  233. }
  234. mock_fetcher1 = Mock()
  235. mock_fetcher1.get_keys = Mock(side_effect=get_keys1)
  236. mock_fetcher2 = Mock()
  237. mock_fetcher2.get_keys = Mock(side_effect=get_keys2)
  238. kr = keyring.Keyring(self.hs, key_fetchers=(mock_fetcher1, mock_fetcher2))
  239. json1 = {}
  240. signedjson.sign.sign_json(json1, "server1", key1)
  241. results = kr.verify_json_objects_for_server(
  242. [("server1", json1, 1200, "test1"), ("server1", json1, 1500, "test2")]
  243. )
  244. self.assertEqual(len(results), 2)
  245. self.get_success(results[0])
  246. e = self.get_failure(results[1], SynapseError).value
  247. self.assertEqual(e.errcode, "M_UNAUTHORIZED")
  248. self.assertEqual(e.code, 401)
  249. # there should have been a single call to each fetcher
  250. mock_fetcher1.get_keys.assert_called_once()
  251. mock_fetcher2.get_keys.assert_called_once()
  252. @logcontext_clean
  253. class ServerKeyFetcherTestCase(unittest.HomeserverTestCase):
  254. def make_homeserver(self, reactor, clock):
  255. self.http_client = Mock()
  256. hs = self.setup_test_homeserver(federation_http_client=self.http_client)
  257. return hs
  258. def test_get_keys_from_server(self):
  259. # arbitrarily advance the clock a bit
  260. self.reactor.advance(100)
  261. SERVER_NAME = "server2"
  262. fetcher = ServerKeyFetcher(self.hs)
  263. testkey = signedjson.key.generate_signing_key("ver1")
  264. testverifykey = signedjson.key.get_verify_key(testkey)
  265. testverifykey_id = "ed25519:ver1"
  266. VALID_UNTIL_TS = 200 * 1000
  267. # valid response
  268. response = {
  269. "server_name": SERVER_NAME,
  270. "old_verify_keys": {},
  271. "valid_until_ts": VALID_UNTIL_TS,
  272. "verify_keys": {
  273. testverifykey_id: {
  274. "key": signedjson.key.encode_verify_key_base64(testverifykey)
  275. }
  276. },
  277. }
  278. signedjson.sign.sign_json(response, SERVER_NAME, testkey)
  279. async def get_json(destination, path, **kwargs):
  280. self.assertEqual(destination, SERVER_NAME)
  281. self.assertEqual(path, "/_matrix/key/v2/server/key1")
  282. return response
  283. self.http_client.get_json.side_effect = get_json
  284. keys_to_fetch = {SERVER_NAME: {"key1": 0}}
  285. keys = self.get_success(fetcher.get_keys(keys_to_fetch))
  286. k = keys[SERVER_NAME][testverifykey_id]
  287. self.assertEqual(k.valid_until_ts, VALID_UNTIL_TS)
  288. self.assertEqual(k.verify_key, testverifykey)
  289. self.assertEqual(k.verify_key.alg, "ed25519")
  290. self.assertEqual(k.verify_key.version, "ver1")
  291. # check that the perspectives store is correctly updated
  292. lookup_triplet = (SERVER_NAME, testverifykey_id, None)
  293. key_json = self.get_success(
  294. self.hs.get_datastore().get_server_keys_json([lookup_triplet])
  295. )
  296. res = key_json[lookup_triplet]
  297. self.assertEqual(len(res), 1)
  298. res = res[0]
  299. self.assertEqual(res["key_id"], testverifykey_id)
  300. self.assertEqual(res["from_server"], SERVER_NAME)
  301. self.assertEqual(res["ts_added_ms"], self.reactor.seconds() * 1000)
  302. self.assertEqual(res["ts_valid_until_ms"], VALID_UNTIL_TS)
  303. # we expect it to be encoded as canonical json *before* it hits the db
  304. self.assertEqual(
  305. bytes(res["key_json"]), canonicaljson.encode_canonical_json(response)
  306. )
  307. # change the server name: the result should be ignored
  308. response["server_name"] = "OTHER_SERVER"
  309. keys = self.get_success(fetcher.get_keys(keys_to_fetch))
  310. self.assertEqual(keys, {})
  311. class PerspectivesKeyFetcherTestCase(unittest.HomeserverTestCase):
  312. def make_homeserver(self, reactor, clock):
  313. self.mock_perspective_server = MockPerspectiveServer()
  314. self.http_client = Mock()
  315. config = self.default_config()
  316. config["trusted_key_servers"] = [
  317. {
  318. "server_name": self.mock_perspective_server.server_name,
  319. "verify_keys": self.mock_perspective_server.get_verify_keys(),
  320. }
  321. ]
  322. return self.setup_test_homeserver(
  323. federation_http_client=self.http_client, config=config
  324. )
  325. def build_perspectives_response(
  326. self,
  327. server_name: str,
  328. signing_key: SigningKey,
  329. valid_until_ts: int,
  330. ) -> dict:
  331. """
  332. Build a valid perspectives server response to a request for the given key
  333. """
  334. verify_key = signedjson.key.get_verify_key(signing_key)
  335. verifykey_id = "%s:%s" % (verify_key.alg, verify_key.version)
  336. response = {
  337. "server_name": server_name,
  338. "old_verify_keys": {},
  339. "valid_until_ts": valid_until_ts,
  340. "verify_keys": {
  341. verifykey_id: {
  342. "key": signedjson.key.encode_verify_key_base64(verify_key)
  343. }
  344. },
  345. }
  346. # the response must be signed by both the origin server and the perspectives
  347. # server.
  348. signedjson.sign.sign_json(response, server_name, signing_key)
  349. self.mock_perspective_server.sign_response(response)
  350. return response
  351. def expect_outgoing_key_query(
  352. self, expected_server_name: str, expected_key_id: str, response: dict
  353. ) -> None:
  354. """
  355. Tell the mock http client to expect a perspectives-server key query
  356. """
  357. async def post_json(destination, path, data, **kwargs):
  358. self.assertEqual(destination, self.mock_perspective_server.server_name)
  359. self.assertEqual(path, "/_matrix/key/v2/query")
  360. # check that the request is for the expected key
  361. q = data["server_keys"]
  362. self.assertEqual(list(q[expected_server_name].keys()), [expected_key_id])
  363. return {"server_keys": [response]}
  364. self.http_client.post_json.side_effect = post_json
  365. def test_get_keys_from_perspectives(self):
  366. # arbitrarily advance the clock a bit
  367. self.reactor.advance(100)
  368. fetcher = PerspectivesKeyFetcher(self.hs)
  369. SERVER_NAME = "server2"
  370. testkey = signedjson.key.generate_signing_key("ver1")
  371. testverifykey = signedjson.key.get_verify_key(testkey)
  372. testverifykey_id = "ed25519:ver1"
  373. VALID_UNTIL_TS = 200 * 1000
  374. response = self.build_perspectives_response(
  375. SERVER_NAME,
  376. testkey,
  377. VALID_UNTIL_TS,
  378. )
  379. self.expect_outgoing_key_query(SERVER_NAME, "key1", response)
  380. keys_to_fetch = {SERVER_NAME: {"key1": 0}}
  381. keys = self.get_success(fetcher.get_keys(keys_to_fetch))
  382. self.assertIn(SERVER_NAME, keys)
  383. k = keys[SERVER_NAME][testverifykey_id]
  384. self.assertEqual(k.valid_until_ts, VALID_UNTIL_TS)
  385. self.assertEqual(k.verify_key, testverifykey)
  386. self.assertEqual(k.verify_key.alg, "ed25519")
  387. self.assertEqual(k.verify_key.version, "ver1")
  388. # check that the perspectives store is correctly updated
  389. lookup_triplet = (SERVER_NAME, testverifykey_id, None)
  390. key_json = self.get_success(
  391. self.hs.get_datastore().get_server_keys_json([lookup_triplet])
  392. )
  393. res = key_json[lookup_triplet]
  394. self.assertEqual(len(res), 1)
  395. res = res[0]
  396. self.assertEqual(res["key_id"], testverifykey_id)
  397. self.assertEqual(res["from_server"], self.mock_perspective_server.server_name)
  398. self.assertEqual(res["ts_added_ms"], self.reactor.seconds() * 1000)
  399. self.assertEqual(res["ts_valid_until_ms"], VALID_UNTIL_TS)
  400. self.assertEqual(
  401. bytes(res["key_json"]), canonicaljson.encode_canonical_json(response)
  402. )
  403. def test_get_perspectives_own_key(self):
  404. """Check that we can get the perspectives server's own keys
  405. This is slightly complicated by the fact that the perspectives server may
  406. use different keys for signing notary responses.
  407. """
  408. # arbitrarily advance the clock a bit
  409. self.reactor.advance(100)
  410. fetcher = PerspectivesKeyFetcher(self.hs)
  411. SERVER_NAME = self.mock_perspective_server.server_name
  412. testkey = signedjson.key.generate_signing_key("ver1")
  413. testverifykey = signedjson.key.get_verify_key(testkey)
  414. testverifykey_id = "ed25519:ver1"
  415. VALID_UNTIL_TS = 200 * 1000
  416. response = self.build_perspectives_response(
  417. SERVER_NAME, testkey, VALID_UNTIL_TS
  418. )
  419. self.expect_outgoing_key_query(SERVER_NAME, "key1", response)
  420. keys_to_fetch = {SERVER_NAME: {"key1": 0}}
  421. keys = self.get_success(fetcher.get_keys(keys_to_fetch))
  422. self.assertIn(SERVER_NAME, keys)
  423. k = keys[SERVER_NAME][testverifykey_id]
  424. self.assertEqual(k.valid_until_ts, VALID_UNTIL_TS)
  425. self.assertEqual(k.verify_key, testverifykey)
  426. self.assertEqual(k.verify_key.alg, "ed25519")
  427. self.assertEqual(k.verify_key.version, "ver1")
  428. # check that the perspectives store is correctly updated
  429. lookup_triplet = (SERVER_NAME, testverifykey_id, None)
  430. key_json = self.get_success(
  431. self.hs.get_datastore().get_server_keys_json([lookup_triplet])
  432. )
  433. res = key_json[lookup_triplet]
  434. self.assertEqual(len(res), 1)
  435. res = res[0]
  436. self.assertEqual(res["key_id"], testverifykey_id)
  437. self.assertEqual(res["from_server"], self.mock_perspective_server.server_name)
  438. self.assertEqual(res["ts_added_ms"], self.reactor.seconds() * 1000)
  439. self.assertEqual(res["ts_valid_until_ms"], VALID_UNTIL_TS)
  440. self.assertEqual(
  441. bytes(res["key_json"]), canonicaljson.encode_canonical_json(response)
  442. )
  443. def test_invalid_perspectives_responses(self):
  444. """Check that invalid responses from the perspectives server are rejected"""
  445. # arbitrarily advance the clock a bit
  446. self.reactor.advance(100)
  447. SERVER_NAME = "server2"
  448. testkey = signedjson.key.generate_signing_key("ver1")
  449. testverifykey = signedjson.key.get_verify_key(testkey)
  450. testverifykey_id = "ed25519:ver1"
  451. VALID_UNTIL_TS = 200 * 1000
  452. def build_response():
  453. return self.build_perspectives_response(
  454. SERVER_NAME, testkey, VALID_UNTIL_TS
  455. )
  456. def get_key_from_perspectives(response):
  457. fetcher = PerspectivesKeyFetcher(self.hs)
  458. keys_to_fetch = {SERVER_NAME: {"key1": 0}}
  459. self.expect_outgoing_key_query(SERVER_NAME, "key1", response)
  460. return self.get_success(fetcher.get_keys(keys_to_fetch))
  461. # start with a valid response so we can check we are testing the right thing
  462. response = build_response()
  463. keys = get_key_from_perspectives(response)
  464. k = keys[SERVER_NAME][testverifykey_id]
  465. self.assertEqual(k.verify_key, testverifykey)
  466. # remove the perspectives server's signature
  467. response = build_response()
  468. del response["signatures"][self.mock_perspective_server.server_name]
  469. keys = get_key_from_perspectives(response)
  470. self.assertEqual(keys, {}, "Expected empty dict with missing persp server sig")
  471. # remove the origin server's signature
  472. response = build_response()
  473. del response["signatures"][SERVER_NAME]
  474. keys = get_key_from_perspectives(response)
  475. self.assertEqual(keys, {}, "Expected empty dict with missing origin server sig")
  476. def get_key_id(key):
  477. """Get the matrix ID tag for a given SigningKey or VerifyKey"""
  478. return "%s:%s" % (key.alg, key.version)
  479. @defer.inlineCallbacks
  480. def run_in_context(f, *args, **kwargs):
  481. with LoggingContext("testctx"):
  482. rv = yield f(*args, **kwargs)
  483. return rv
  484. def _verify_json_for_server(kr, *args):
  485. """thin wrapper around verify_json_for_server which makes sure it is wrapped
  486. with the patched defer.inlineCallbacks.
  487. """
  488. @defer.inlineCallbacks
  489. def v():
  490. rv1 = yield kr.verify_json_for_server(*args)
  491. return rv1
  492. return run_in_context(v)