mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 23:48: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)
|
||||
}
|
||||
|
||||
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
|
||||
type KeyError struct {
|
||||
|
|
|
@ -437,32 +437,29 @@ func (a *KeyInternalAPI) crossSigningKeys(
|
|||
return fmt.Errorf("a.DB.CrossSigningKeysForUser (%q): %w", userID, err)
|
||||
}
|
||||
|
||||
for keyType, keysByType := range keys {
|
||||
for keyID, keyData := range keysByType {
|
||||
key := gomatrixserverlib.CrossSigningKey{
|
||||
UserID: userID,
|
||||
Usage: []gomatrixserverlib.CrossSigningKeyPurpose{
|
||||
keyType,
|
||||
},
|
||||
Keys: map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes{
|
||||
keyID: keyData,
|
||||
},
|
||||
}
|
||||
for keyType, keyData := range keys {
|
||||
b64 := keyData.Encode()
|
||||
key := gomatrixserverlib.CrossSigningKey{
|
||||
UserID: userID,
|
||||
Usage: []gomatrixserverlib.CrossSigningKeyPurpose{
|
||||
keyType,
|
||||
},
|
||||
Keys: map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes{
|
||||
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.CrossSigningKeyPurposeMaster:
|
||||
res.MasterKeys[userID] = key
|
||||
case gomatrixserverlib.CrossSigningKeyPurposeSelfSigning:
|
||||
res.SelfSigningKeys[userID] = key
|
||||
|
||||
case gomatrixserverlib.CrossSigningKeyPurposeSelfSigning:
|
||||
res.SelfSigningKeys[userID] = key
|
||||
|
||||
case gomatrixserverlib.CrossSigningKeyPurposeUserSigning:
|
||||
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 (
|
||||
user_id TEXT NOT NULL,
|
||||
key_type TEXT NOT NULL,
|
||||
key_id TEXT NOT NULL,
|
||||
key_data TEXT 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 = "" +
|
||||
"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" +
|
||||
" ORDER BY user_id, key_type, stream_id DESC"
|
||||
|
||||
|
@ -71,15 +70,11 @@ func (s *crossSigningKeysStatements) SelectCrossSigningKeysForUser(
|
|||
r = api.CrossSigningKeyMap{}
|
||||
for rows.Next() {
|
||||
var keyType gomatrixserverlib.CrossSigningKeyPurpose
|
||||
var keyID gomatrixserverlib.KeyID
|
||||
var keyData gomatrixserverlib.Base64Bytes
|
||||
if err := rows.Scan(&keyType, &keyID, &keyData); err != nil {
|
||||
if err := rows.Scan(&keyType, &keyData); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, ok := r[keyType]; !ok {
|
||||
r[keyType] = map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes{}
|
||||
}
|
||||
r[keyType][keyID] = keyData
|
||||
r[keyType] = keyData
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ var crossSigningKeysSchema = `
|
|||
CREATE TABLE IF NOT EXISTS keyserver_cross_signing_keys (
|
||||
user_id TEXT NOT NULL,
|
||||
key_type TEXT NOT NULL,
|
||||
key_id TEXT NOT NULL,
|
||||
key_data TEXT 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 = "" +
|
||||
"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)" +
|
||||
" GROUP BY user_id, key_type"
|
||||
|
||||
|
@ -71,15 +70,11 @@ func (s *crossSigningKeysStatements) SelectCrossSigningKeysForUser(
|
|||
r = api.CrossSigningKeyMap{}
|
||||
for rows.Next() {
|
||||
var keyType gomatrixserverlib.CrossSigningKeyPurpose
|
||||
var keyID gomatrixserverlib.KeyID
|
||||
var keyData gomatrixserverlib.Base64Bytes
|
||||
if err := rows.Scan(&keyType, &keyID, &keyData); err != nil {
|
||||
if err := rows.Scan(&keyType, &keyData); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, ok := r[keyType]; !ok {
|
||||
r[keyType] = map[gomatrixserverlib.KeyID]gomatrixserverlib.Base64Bytes{}
|
||||
}
|
||||
r[keyType][keyID] = keyData
|
||||
r[keyType] = keyData
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue