mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-29 08:18:27 +00:00
Generate key IDs automatically
This commit is contained in:
parent
b638b06ec1
commit
701ffdeb36
4 changed files with 26 additions and 39 deletions
|
@ -40,7 +40,7 @@ type KeyInternalAPI interface {
|
||||||
QueryDeviceMessages(ctx context.Context, req *QueryDeviceMessagesRequest, res *QueryDeviceMessagesResponse)
|
QueryDeviceMessages(ctx context.Context, req *QueryDeviceMessagesRequest, res *QueryDeviceMessagesResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CrossSigningKeyMap map[gomatrixserverlib.CrossSigningKeyPurpose]map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes
|
type CrossSigningKeyMap map[gomatrixserverlib.CrossSigningKeyPurpose]gomatrixserverlib.Base64Bytes
|
||||||
|
|
||||||
// KeyError is returned if there was a problem performing/querying the server
|
// KeyError is returned if there was a problem performing/querying the server
|
||||||
type KeyError struct {
|
type KeyError struct {
|
||||||
|
|
|
@ -437,32 +437,29 @@ func (a *KeyInternalAPI) crossSigningKeys(
|
||||||
return fmt.Errorf("a.DB.CrossSigningKeysForUser (%q): %w", userID, err)
|
return fmt.Errorf("a.DB.CrossSigningKeysForUser (%q): %w", userID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for keyType, keysByType := range keys {
|
for keyType, keyData := range keys {
|
||||||
for keyID, keyData := range keysByType {
|
b64 := keyData.Encode()
|
||||||
key := gomatrixserverlib.CrossSigningKey{
|
key := gomatrixserverlib.CrossSigningKey{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
Usage: []gomatrixserverlib.CrossSigningKeyPurpose{
|
Usage: []gomatrixserverlib.CrossSigningKeyPurpose{
|
||||||
keyType,
|
keyType,
|
||||||
},
|
},
|
||||||
Keys: map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes{
|
Keys: map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes{
|
||||||
keyID: keyData,
|
gomatrixserverlib.KeyID("ed25519:" + b64): keyData,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.WithField("key", key).Info("Cross-signing key")
|
// TODO: populate signatures
|
||||||
|
|
||||||
// TODO: populate signatures
|
switch keyType {
|
||||||
|
case gomatrixserverlib.CrossSigningKeyPurposeMaster:
|
||||||
|
res.MasterKeys[userID] = key
|
||||||
|
|
||||||
switch keyType {
|
case gomatrixserverlib.CrossSigningKeyPurposeSelfSigning:
|
||||||
case gomatrixserverlib.CrossSigningKeyPurposeMaster:
|
res.SelfSigningKeys[userID] = key
|
||||||
res.MasterKeys[userID] = key
|
|
||||||
|
|
||||||
case gomatrixserverlib.CrossSigningKeyPurposeSelfSigning:
|
case gomatrixserverlib.CrossSigningKeyPurposeUserSigning:
|
||||||
res.SelfSigningKeys[userID] = key
|
res.UserSigningKeys[userID] = key
|
||||||
|
|
||||||
case gomatrixserverlib.CrossSigningKeyPurposeUserSigning:
|
|
||||||
res.UserSigningKeys[userID] = key
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ var crossSigningKeysSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS keyserver_cross_signing_keys (
|
CREATE TABLE IF NOT EXISTS keyserver_cross_signing_keys (
|
||||||
user_id TEXT NOT NULL,
|
user_id TEXT NOT NULL,
|
||||||
key_type TEXT NOT NULL,
|
key_type TEXT NOT NULL,
|
||||||
key_id TEXT NOT NULL,
|
|
||||||
key_data TEXT NOT NULL,
|
key_data TEXT NOT NULL,
|
||||||
stream_id BIGINT NOT NULL
|
stream_id BIGINT NOT NULL
|
||||||
);
|
);
|
||||||
|
@ -37,7 +36,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS keyserver_cross_signing_keys_idx ON keyserver_
|
||||||
`
|
`
|
||||||
|
|
||||||
const selectCrossSigningKeysForUserSQL = "" +
|
const selectCrossSigningKeysForUserSQL = "" +
|
||||||
"SELECT DISTINCT ON (user_id, key_type) key_type, key_id, key_data FROM keyserver_cross_signing_keys" +
|
"SELECT DISTINCT ON (user_id, key_type) key_type, key_data FROM keyserver_cross_signing_keys" +
|
||||||
" WHERE user_id = $1" +
|
" WHERE user_id = $1" +
|
||||||
" ORDER BY user_id, key_type, stream_id DESC"
|
" ORDER BY user_id, key_type, stream_id DESC"
|
||||||
|
|
||||||
|
@ -71,15 +70,11 @@ func (s *crossSigningKeysStatements) SelectCrossSigningKeysForUser(
|
||||||
r = api.CrossSigningKeyMap{}
|
r = api.CrossSigningKeyMap{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var keyType gomatrixserverlib.CrossSigningKeyPurpose
|
var keyType gomatrixserverlib.CrossSigningKeyPurpose
|
||||||
var keyID gomatrixserverlib.KeyID
|
|
||||||
var keyData gomatrixserverlib.Base64Bytes
|
var keyData gomatrixserverlib.Base64Bytes
|
||||||
if err := rows.Scan(&keyType, &keyID, &keyData); err != nil {
|
if err := rows.Scan(&keyType, &keyData); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, ok := r[keyType]; !ok {
|
r[keyType] = keyData
|
||||||
r[keyType] = map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes{}
|
|
||||||
}
|
|
||||||
r[keyType][keyID] = keyData
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ var crossSigningKeysSchema = `
|
||||||
CREATE TABLE IF NOT EXISTS keyserver_cross_signing_keys (
|
CREATE TABLE IF NOT EXISTS keyserver_cross_signing_keys (
|
||||||
user_id TEXT NOT NULL,
|
user_id TEXT NOT NULL,
|
||||||
key_type TEXT NOT NULL,
|
key_type TEXT NOT NULL,
|
||||||
key_id TEXT NOT NULL,
|
|
||||||
key_data TEXT NOT NULL,
|
key_data TEXT NOT NULL,
|
||||||
stream_id BIGINT NOT NULL
|
stream_id BIGINT NOT NULL
|
||||||
);
|
);
|
||||||
|
@ -37,7 +36,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS keyserver_cross_signing_keys_idx ON keyserver_
|
||||||
`
|
`
|
||||||
|
|
||||||
const selectCrossSigningKeysForUserSQL = "" +
|
const selectCrossSigningKeysForUserSQL = "" +
|
||||||
"SELECT key_type, key_id, key_data FROM " +
|
"SELECT key_type, key_data FROM " +
|
||||||
" (SELECT * FROM keyserver_cross_signing_keys WHERE user_id = $1 ORDER BY stream_id DESC)" +
|
" (SELECT * FROM keyserver_cross_signing_keys WHERE user_id = $1 ORDER BY stream_id DESC)" +
|
||||||
" GROUP BY user_id, key_type"
|
" GROUP BY user_id, key_type"
|
||||||
|
|
||||||
|
@ -71,15 +70,11 @@ func (s *crossSigningKeysStatements) SelectCrossSigningKeysForUser(
|
||||||
r = api.CrossSigningKeyMap{}
|
r = api.CrossSigningKeyMap{}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var keyType gomatrixserverlib.CrossSigningKeyPurpose
|
var keyType gomatrixserverlib.CrossSigningKeyPurpose
|
||||||
var keyID gomatrixserverlib.KeyID
|
|
||||||
var keyData gomatrixserverlib.Base64Bytes
|
var keyData gomatrixserverlib.Base64Bytes
|
||||||
if err := rows.Scan(&keyType, &keyID, &keyData); err != nil {
|
if err := rows.Scan(&keyType, &keyData); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if _, ok := r[keyType]; !ok {
|
r[keyType] = keyData
|
||||||
r[keyType] = map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes{}
|
|
||||||
}
|
|
||||||
r[keyType][keyID] = keyData
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue