mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-03-02 06:44:28 -06:00
Add key validity checks
This commit is contained in:
parent
f7025d3499
commit
5408af1baf
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/caching"
|
"github.com/matrix-org/dendrite/internal/caching"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
@ -94,8 +95,12 @@ func (s *httpServerKeyInternalAPI) FetchKeys(
|
||||||
response := QueryPublicKeysResponse{
|
response := QueryPublicKeysResponse{
|
||||||
Results: make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult),
|
Results: make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult),
|
||||||
}
|
}
|
||||||
|
now := gomatrixserverlib.AsTimestamp(time.Now())
|
||||||
for req, ts := range requests {
|
for req, ts := range requests {
|
||||||
if res, ok := s.immutableCache.GetServerKey(req); ok {
|
if res, ok := s.immutableCache.GetServerKey(req); ok {
|
||||||
|
if now > res.ValidUntilTS && res.ExpiredTS == gomatrixserverlib.PublicKeyNotExpired {
|
||||||
|
continue
|
||||||
|
}
|
||||||
result[req] = res
|
result[req] = res
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package internal
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/caching"
|
"github.com/matrix-org/dendrite/internal/caching"
|
||||||
"github.com/matrix-org/dendrite/serverkeyapi/api"
|
"github.com/matrix-org/dendrite/serverkeyapi/api"
|
||||||
|
@ -39,10 +40,14 @@ func (s *ServerKeyAPI) FetchKeys(
|
||||||
// First consult our local database and see if we have the requested
|
// First consult our local database and see if we have the requested
|
||||||
// keys. These might come from a cache, depending on the database
|
// keys. These might come from a cache, depending on the database
|
||||||
// implementation used.
|
// implementation used.
|
||||||
|
now := gomatrixserverlib.AsTimestamp(time.Now())
|
||||||
if dbResults, err := s.OurKeyRing.KeyDatabase.FetchKeys(ctx, requests); err == nil {
|
if dbResults, err := s.OurKeyRing.KeyDatabase.FetchKeys(ctx, requests); err == nil {
|
||||||
// We successfully got some keys. Add them to the results and
|
// We successfully got some keys. Add them to the results and
|
||||||
// remove them from the request list.
|
// remove them from the request list.
|
||||||
for req, res := range dbResults {
|
for req, res := range dbResults {
|
||||||
|
if now > res.ValidUntilTS && res.ExpiredTS == gomatrixserverlib.PublicKeyNotExpired {
|
||||||
|
continue
|
||||||
|
}
|
||||||
results[req] = res
|
results[req] = res
|
||||||
delete(requests, req)
|
delete(requests, req)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue