From bfb954519bdf172451d999ac4c654b3d15eff124 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 15 May 2020 17:39:20 +0100 Subject: [PATCH] Only keep keys valid for 100 years rather than the heat death of the universe WASM builds really dislike thinking that far into the future, causing WASM to trap with "float unrepresentable in integer range", which corrupts the Go stack in wasm_exec which then leads to a segfault and the program exiting. --- common/keydb/postgres/keydb.go | 4 ++-- common/keydb/sqlite3/keydb.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/common/keydb/postgres/keydb.go b/common/keydb/postgres/keydb.go index 706ca005..a8a30437 100644 --- a/common/keydb/postgres/keydb.go +++ b/common/keydb/postgres/keydb.go @@ -17,7 +17,7 @@ package postgres import ( "context" - "math" + "time" "golang.org/x/crypto/ed25519" @@ -62,7 +62,7 @@ func NewDatabase( VerifyKey: gomatrixserverlib.VerifyKey{ Key: gomatrixserverlib.Base64String(serverKey), }, - ValidUntilTS: math.MaxUint64 >> 1, + ValidUntilTS: gomatrixserverlib.AsTimestamp(time.Now().Add(100 * 365 * 24 * time.Hour)), ExpiredTS: gomatrixserverlib.PublicKeyNotExpired, } err = d.StoreKeys( diff --git a/common/keydb/sqlite3/keydb.go b/common/keydb/sqlite3/keydb.go index 94a32e29..1ff315d7 100644 --- a/common/keydb/sqlite3/keydb.go +++ b/common/keydb/sqlite3/keydb.go @@ -17,7 +17,7 @@ package sqlite3 import ( "context" - "math" + "time" "golang.org/x/crypto/ed25519" @@ -63,7 +63,7 @@ func NewDatabase( VerifyKey: gomatrixserverlib.VerifyKey{ Key: gomatrixserverlib.Base64String(serverKey), }, - ValidUntilTS: math.MaxUint64 >> 1, + ValidUntilTS: gomatrixserverlib.AsTimestamp(time.Now().Add(100 * 365 * 24 * time.Hour)), ExpiredTS: gomatrixserverlib.PublicKeyNotExpired, } err = d.StoreKeys(