Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
8da0d83a
Commit
8da0d83a
authored
5 years ago
by
Erik Johnston
Browse files
Options
Downloads
Plain Diff
Merge branch 'erikj/fix_null_valid_until_ms' of github.com:matrix-org/synapse into release-v1.0.0
parents
88d7182a
9bc7768a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/5415.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/5415.bugfix
synapse/storage/keys.py
+8
-0
8 additions, 0 deletions
synapse/storage/keys.py
tests/crypto/test_keyring.py
+49
-1
49 additions, 1 deletion
tests/crypto/test_keyring.py
with
58 additions
and
1 deletion
changelog.d/5415.bugfix
0 → 100644
+
1
−
0
View file @
8da0d83a
Fix bug where old keys stored in the database with a null valid until timestamp caused all verification requests for that key to fail.
This diff is collapsed.
Click to expand it.
synapse/storage/keys.py
+
8
−
0
View file @
8da0d83a
...
...
@@ -80,6 +80,14 @@ class KeyStore(SQLBaseStore):
for
row
in
txn
:
server_name
,
key_id
,
key_bytes
,
ts_valid_until_ms
=
row
if
ts_valid_until_ms
is
None
:
# Old keys may be stored with a ts_valid_until_ms of null,
# in which case we treat this as if it was set to `0`, i.e.
# it won't match key requests that define a minimum
# `ts_valid_until_ms`.
ts_valid_until_ms
=
0
res
=
FetchKeyResult
(
verify_key
=
decode_verify_key_bytes
(
key_id
,
bytes
(
key_bytes
)),
valid_until_ts
=
ts_valid_until_ms
,
...
...
This diff is collapsed.
Click to expand it.
tests/crypto/test_keyring.py
+
49
−
1
View file @
8da0d83a
...
...
@@ -25,7 +25,11 @@ from twisted.internet import defer
from
synapse.api.errors
import
SynapseError
from
synapse.crypto
import
keyring
from
synapse.crypto.keyring
import
PerspectivesKeyFetcher
,
ServerKeyFetcher
from
synapse.crypto.keyring
import
(
PerspectivesKeyFetcher
,
ServerKeyFetcher
,
StoreKeyFetcher
,
)
from
synapse.storage.keys
import
FetchKeyResult
from
synapse.util
import
logcontext
from
synapse.util.logcontext
import
LoggingContext
...
...
@@ -219,6 +223,50 @@ class KeyringTestCase(unittest.HomeserverTestCase):
# self.assertFalse(d.called)
self
.
get_success
(
d
)
def
test_verify_json_for_server_with_null_valid_until_ms
(
self
):
"""
Tests that we correctly handle key requests for keys we
'
ve stored
with a null `ts_valid_until_ms`
"""
mock_fetcher
=
keyring
.
KeyFetcher
()
mock_fetcher
.
get_keys
=
Mock
(
return_value
=
defer
.
succeed
({}))
kr
=
keyring
.
Keyring
(
self
.
hs
,
key_fetchers
=
(
StoreKeyFetcher
(
self
.
hs
),
mock_fetcher
)
)
key1
=
signedjson
.
key
.
generate_signing_key
(
1
)
r
=
self
.
hs
.
datastore
.
store_server_verify_keys
(
"
server9
"
,
time
.
time
()
*
1000
,
[(
"
server9
"
,
get_key_id
(
key1
),
FetchKeyResult
(
get_verify_key
(
key1
),
None
))],
)
self
.
get_success
(
r
)
json1
=
{}
signedjson
.
sign
.
sign_json
(
json1
,
"
server9
"
,
key1
)
# should fail immediately on an unsigned object
d
=
_verify_json_for_server
(
kr
,
"
server9
"
,
{},
0
,
"
test unsigned
"
)
self
.
failureResultOf
(
d
,
SynapseError
)
# should fail on a signed object with a non-zero minimum_valid_until_ms,
# as it tries to refetch the keys and fails.
d
=
_verify_json_for_server
(
kr
,
"
server9
"
,
json1
,
500
,
"
test signed non-zero min
"
)
self
.
get_failure
(
d
,
SynapseError
)
# We expect the keyring tried to refetch the key once.
mock_fetcher
.
get_keys
.
assert_called_once_with
(
{
"
server9
"
:
{
get_key_id
(
key1
):
500
}}
)
# should succeed on a signed object with a 0 minimum_valid_until_ms
d
=
_verify_json_for_server
(
kr
,
"
server9
"
,
json1
,
0
,
"
test signed with zero min
"
)
self
.
get_success
(
d
)
def
test_verify_json_dedupes_key_requests
(
self
):
"""
Two requests for the same key should be deduped.
"""
key1
=
signedjson
.
key
.
generate_signing_key
(
1
)
...
...
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