mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-01 22:02:46 +00:00
Enforce valid key IDs (#1437)
* Enforce valid key IDs * Don't use key_id from dendrite.yaml as it is in matrix_key.pem
This commit is contained in:
parent
f908f8baab
commit
de8b39065e
4 changed files with 13 additions and 5 deletions
|
@ -25,6 +25,7 @@ import (
|
|||
"math/big"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/config"
|
||||
|
@ -146,10 +147,14 @@ func NewMatrixKey(matrixKeyPath string) (err error) {
|
|||
err = keyOut.Close()
|
||||
})()
|
||||
|
||||
keyID := base64.RawURLEncoding.EncodeToString(data[:])
|
||||
keyID = strings.ReplaceAll(keyID, "-", "")
|
||||
keyID = strings.ReplaceAll(keyID, "_", "")
|
||||
|
||||
err = pem.Encode(keyOut, &pem.Block{
|
||||
Type: "MATRIX PRIVATE KEY",
|
||||
Headers: map[string]string{
|
||||
"Key-ID": "ed25519:" + base64.RawStdEncoding.EncodeToString(data[:3]),
|
||||
"Key-ID": fmt.Sprintf("ed25519:%s", keyID[:6]),
|
||||
},
|
||||
Bytes: data[3:],
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue