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
dc2cd6f7
Commit
dc2cd6f7
authored
5 years ago
by
Hubert Chathi
Browse files
Options
Downloads
Patches
Plain Diff
move get_e2e_cross_signing_key to EndToEndKeyWorkerStore so it works with workers
parent
480eac30
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/end_to_end_keys.py
+67
-67
67 additions, 67 deletions
synapse/storage/end_to_end_keys.py
with
67 additions
and
67 deletions
synapse/storage/end_to_end_keys.py
+
67
−
67
View file @
dc2cd6f7
...
@@ -249,6 +249,73 @@ class EndToEndKeyWorkerStore(SQLBaseStore):
...
@@ -249,6 +249,73 @@ class EndToEndKeyWorkerStore(SQLBaseStore):
return
self
.
runInteraction
(
"
count_e2e_one_time_keys
"
,
_count_e2e_one_time_keys
)
return
self
.
runInteraction
(
"
count_e2e_one_time_keys
"
,
_count_e2e_one_time_keys
)
def
_get_e2e_cross_signing_key_txn
(
self
,
txn
,
user_id
,
key_type
,
from_user_id
=
None
):
"""
Returns a user
'
s cross-signing key.
Args:
txn (twisted.enterprise.adbapi.Connection): db connection
user_id (str): the user whose key is being requested
key_type (str): the type of key that is being set: either
'
master
'
for a master key,
'
self_signing
'
for a self-signing key, or
'
user_signing
'
for a user-signing key
from_user_id (str): if specified, signatures made by this user on
the key will be included in the result
Returns:
dict of the key data or None if not found
"""
sql
=
(
"
SELECT keydata
"
"
FROM e2e_cross_signing_keys
"
"
WHERE user_id = ? AND keytype = ? ORDER BY stream_id DESC LIMIT 1
"
)
txn
.
execute
(
sql
,
(
user_id
,
key_type
))
row
=
txn
.
fetchone
()
if
not
row
:
return
None
key
=
json
.
loads
(
row
[
0
])
device_id
=
None
for
k
in
key
[
"
keys
"
].
values
():
device_id
=
k
if
from_user_id
is
not
None
:
sql
=
(
"
SELECT key_id, signature
"
"
FROM e2e_cross_signing_signatures
"
"
WHERE user_id = ?
"
"
AND target_user_id = ?
"
"
AND target_device_id = ?
"
)
txn
.
execute
(
sql
,
(
from_user_id
,
user_id
,
device_id
))
row
=
txn
.
fetchone
()
if
row
:
key
.
setdefault
(
"
signatures
"
,
{}).
setdefault
(
from_user_id
,
{})[
row
[
0
]
]
=
row
[
1
]
return
key
def
get_e2e_cross_signing_key
(
self
,
user_id
,
key_type
,
from_user_id
=
None
):
"""
Returns a user
'
s cross-signing key.
Args:
user_id (str): the user whose self-signing key is being requested
key_type (str): the type of cross-signing key to get
from_user_id (str): if specified, signatures made by this user on
the self-signing key will be included in the result
Returns:
dict of the key data or None if not found
"""
return
self
.
runInteraction
(
"
get_e2e_cross_signing_key
"
,
self
.
_get_e2e_cross_signing_key_txn
,
user_id
,
key_type
,
from_user_id
,
)
class
EndToEndKeyStore
(
EndToEndKeyWorkerStore
,
SQLBaseStore
):
class
EndToEndKeyStore
(
EndToEndKeyWorkerStore
,
SQLBaseStore
):
def
set_e2e_device_keys
(
self
,
user_id
,
device_id
,
time_now
,
device_keys
):
def
set_e2e_device_keys
(
self
,
user_id
,
device_id
,
time_now
,
device_keys
):
...
@@ -427,73 +494,6 @@ class EndToEndKeyStore(EndToEndKeyWorkerStore, SQLBaseStore):
...
@@ -427,73 +494,6 @@ class EndToEndKeyStore(EndToEndKeyWorkerStore, SQLBaseStore):
key
,
key
,
)
)
def
_get_e2e_cross_signing_key_txn
(
self
,
txn
,
user_id
,
key_type
,
from_user_id
=
None
):
"""
Returns a user
'
s cross-signing key.
Args:
txn (twisted.enterprise.adbapi.Connection): db connection
user_id (str): the user whose key is being requested
key_type (str): the type of key that is being set: either
'
master
'
for a master key,
'
self_signing
'
for a self-signing key, or
'
user_signing
'
for a user-signing key
from_user_id (str): if specified, signatures made by this user on
the key will be included in the result
Returns:
dict of the key data or None if not found
"""
sql
=
(
"
SELECT keydata
"
"
FROM e2e_cross_signing_keys
"
"
WHERE user_id = ? AND keytype = ? ORDER BY stream_id DESC LIMIT 1
"
)
txn
.
execute
(
sql
,
(
user_id
,
key_type
))
row
=
txn
.
fetchone
()
if
not
row
:
return
None
key
=
json
.
loads
(
row
[
0
])
device_id
=
None
for
k
in
key
[
"
keys
"
].
values
():
device_id
=
k
if
from_user_id
is
not
None
:
sql
=
(
"
SELECT key_id, signature
"
"
FROM e2e_cross_signing_signatures
"
"
WHERE user_id = ?
"
"
AND target_user_id = ?
"
"
AND target_device_id = ?
"
)
txn
.
execute
(
sql
,
(
from_user_id
,
user_id
,
device_id
))
row
=
txn
.
fetchone
()
if
row
:
key
.
setdefault
(
"
signatures
"
,
{}).
setdefault
(
from_user_id
,
{})[
row
[
0
]
]
=
row
[
1
]
return
key
def
get_e2e_cross_signing_key
(
self
,
user_id
,
key_type
,
from_user_id
=
None
):
"""
Returns a user
'
s cross-signing key.
Args:
user_id (str): the user whose self-signing key is being requested
key_type (str): the type of cross-signing key to get
from_user_id (str): if specified, signatures made by this user on
the self-signing key will be included in the result
Returns:
dict of the key data or None if not found
"""
return
self
.
runInteraction
(
"
get_e2e_cross_signing_key
"
,
self
.
_get_e2e_cross_signing_key_txn
,
user_id
,
key_type
,
from_user_id
,
)
def
store_e2e_cross_signing_signatures
(
self
,
user_id
,
signatures
):
def
store_e2e_cross_signing_signatures
(
self
,
user_id
,
signatures
):
"""
Stores cross-signing signatures.
"""
Stores cross-signing signatures.
...
...
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