aboutsummaryrefslogtreecommitdiff
path: root/internal/caching/cache_serverkeys.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/caching/cache_serverkeys.go')
-rw-r--r--internal/caching/cache_serverkeys.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/internal/caching/cache_serverkeys.go b/internal/caching/cache_serverkeys.go
index b5e31575..4697fb4d 100644
--- a/internal/caching/cache_serverkeys.go
+++ b/internal/caching/cache_serverkeys.go
@@ -2,7 +2,6 @@ package caching
import (
"fmt"
- "time"
"github.com/matrix-org/gomatrixserverlib"
)
@@ -16,22 +15,29 @@ const (
// ServerKeyCache contains the subset of functions needed for
// a server key cache.
type ServerKeyCache interface {
- GetServerKey(request gomatrixserverlib.PublicKeyLookupRequest) (response gomatrixserverlib.PublicKeyLookupResult, ok bool)
+ // request -> timestamp is emulating gomatrixserverlib.FetchKeys:
+ // https://github.com/matrix-org/gomatrixserverlib/blob/f69539c86ea55d1e2cc76fd8e944e2d82d30397c/keyring.go#L95
+ // The timestamp should be the timestamp of the event that is being
+ // verified. We will not return keys from the cache that are not valid
+ // at this timestamp.
+ GetServerKey(request gomatrixserverlib.PublicKeyLookupRequest, timestamp gomatrixserverlib.Timestamp) (response gomatrixserverlib.PublicKeyLookupResult, ok bool)
+
+ // request -> result is emulating gomatrixserverlib.StoreKeys:
+ // https://github.com/matrix-org/gomatrixserverlib/blob/f69539c86ea55d1e2cc76fd8e944e2d82d30397c/keyring.go#L112
StoreServerKey(request gomatrixserverlib.PublicKeyLookupRequest, response gomatrixserverlib.PublicKeyLookupResult)
}
func (c Caches) GetServerKey(
request gomatrixserverlib.PublicKeyLookupRequest,
+ timestamp gomatrixserverlib.Timestamp,
) (gomatrixserverlib.PublicKeyLookupResult, bool) {
key := fmt.Sprintf("%s/%s", request.ServerName, request.KeyID)
- now := gomatrixserverlib.AsTimestamp(time.Now())
val, found := c.ServerKeys.Get(key)
if found && val != nil {
if keyLookupResult, ok := val.(gomatrixserverlib.PublicKeyLookupResult); ok {
- if !keyLookupResult.WasValidAt(now, true) {
- // We appear to be past the key validity so don't return this
- // with the results. This ensures that the cache doesn't return
- // values that are not useful to us.
+ if !keyLookupResult.WasValidAt(timestamp, true) {
+ // The key wasn't valid at the requested timestamp so don't
+ // return it. The caller will have to work out what to do.
c.ServerKeys.Unset(key)
return gomatrixserverlib.PublicKeyLookupResult{}, false
}