Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Cross-signing device signatures incorrectly assumed to be unique per device #6447

Closed
jryans opened this issue Dec 2, 2019 · 3 comments
Closed
Labels
z-cross-signing (Deprecated Label) z-cross-signing-sprint (Deprecated Label)

Comments

@jryans
Copy link
Contributor

jryans commented Dec 2, 2019

As shown in the full log below, cross-signing device signature handling appears to assume there will only ever be one signature for a user's device:

sqlite3.IntegrityError: UNIQUE constraint failed: e2e_cross_signing_signatures.user_id, e2e_cross_signing_signatures.target_user_id, e2e_cross_signing_signatures.target_device_id

A user's cross-signing keys can be reset if they are lost for some reason. In such a case, new device signatures will be created for each of the users devices, so we either need to remove the old signatures or allow multiple signatures per device.

Full log
2019-12-02 11:27:35,669 - synapse.access.https.8448 - 233 - INFO - POST-375 - ::ffff:127.0.0.1 - 8448 - Received request: POST /_matrix/client/unstable/keys/signatures/upload
2019-12-02 11:27:35,674 - synapse.http.server - 109 - ERROR - POST-375 - Failed handle request via 'SignaturesUploadServlet': 
Traceback (most recent call last):
  File "/Users/jryans/Projects/Matrix/synapse/synapse/http/server.py", line 77, in wrapped_request_handler
    await h(self, request)
  File "/Users/jryans/Projects/Matrix/synapse/synapse/http/server.py", line 326, in _async_render
    callback_return = await callback_return
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/internet/defer.py", line 14
16, in _inlineCallbacks
    result = result.throwExceptionIntoGenerator(g)
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/python/failure.py", line 51
2, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "/Users/jryans/Projects/Matrix/synapse/synapse/rest/client/v2_alpha/keys.py", line 325, in on_POST
    user_id, body
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/internet/defer.py", line 14
16, in _inlineCallbacks
    result = result.throwExceptionIntoGenerator(g)
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/python/failure.py", line 51
2, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "/Users/jryans/Projects/Matrix/synapse/synapse/handlers/e2e_keys.py", line 671, in upload_signatures_for_device_keys
    yield self.store.store_e2e_cross_signing_signatures(user_id, signature_list)
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
    result = result.throwExceptionIntoGenerator(g)
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/python/failure.py", line 512, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "/Users/jryans/Projects/Matrix/synapse/synapse/storage/_base.py", line 504, in runInteraction
    **kwargs
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
    result = result.throwExceptionIntoGenerator(g)
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/python/failure.py", line 512, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "/Users/jryans/Projects/Matrix/synapse/synapse/storage/_base.py", line 552, in runWithConnection
    self._db_pool.runWithConnection(inner_func, *args, **kwargs)
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/python/threadpool.py", line 250, in inContext
    result = inContext.theWork()
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/python/threadpool.py", line 266, in 
    inContext.theWork = lambda: context.call(ctx, func, *args, **kw)
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/enterprise/adbapi.py", line 306, in _runWithConnection
    compat.reraise(excValue, excTraceback)
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/python/compat.py", line 464, in reraise
    raise exception.with_traceback(traceback)
  File "/Users/jryans/Projects/Matrix/synapse/venv-py3/lib/python3.7/site-packages/twisted/enterprise/adbapi.py", line 297, in _runWithConnection
    result = func(conn, *args, **kw)
  File "/Users/jryans/Projects/Matrix/synapse/synapse/storage/_base.py", line 549, in inner_func
    return func(conn, *args, **kwargs)
  File "/Users/jryans/Projects/Matrix/synapse/synapse/storage/_base.py", line 421, in _new_transaction
    r = func(txn, *args, **kwargs)
  File "/Users/jryans/Projects/Matrix/synapse/synapse/storage/_base.py", line 662, in _simple_insert_many_txn
    txn.executemany(sql, vals)
  File "/Users/jryans/Projects/Matrix/synapse/synapse/storage/_base.py", line 155, in executemany
    self._do_execute(self.txn.executemany, sql, *args)
  File "/Users/jryans/Projects/Matrix/synapse/synapse/storage/_base.py", line 178, in _do_execute
    return func(sql, *args)
sqlite3.IntegrityError: UNIQUE constraint failed: e2e_cross_signing_signatures.user_id, e2e_cross_signing_signatures.target_user_id, e2e_cross_signing_signatures.target_device_id
2019-12-02 11:27:35,685 - synapse.access.https.8448 - 302 - INFO - POST-375 - ::ffff:127.0.0.1 - 8448 - {@bob1:test.convolv.es} Processed request: 0.016sec/0.000sec (0.000sec, 0.000sec) (0.001sec/0.001sec/4) 67B 500 "POST /_matrix/client/unstable/keys/signatures/upload HTTP/1.1" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:72.0) Gecko/20100101 Firefox/72.0" [0 dbevts]
@jryans
Copy link
Contributor Author

jryans commented Dec 2, 2019

@uhoreg Maybe you have some idea how this should be resolved?

@cyphar
Copy link

cyphar commented Jan 1, 2020

This probably should've been closed by #6451, right?

@uhoreg
Copy link
Member

uhoreg commented Jan 2, 2020

Yes. I don't know why it wasn't automatically closed. :-/

@uhoreg uhoreg closed this as completed Jan 2, 2020
@jryans jryans added the phase:1 label Feb 10, 2020
@MadLittleMods MadLittleMods added the z-cross-signing (Deprecated Label) label Jun 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
z-cross-signing (Deprecated Label) z-cross-signing-sprint (Deprecated Label)
Projects
None yet
Development

No branches or pull requests

4 participants