Signing works
This commit is contained in:
parent
d272fa90b4
commit
da2a89010c
19 changed files with 348 additions and 100 deletions
|
@ -2,8 +2,6 @@ package storage
|
|||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"database/sql"
|
||||
|
||||
"git.mstar.dev/mstar/goutils/other"
|
||||
|
@ -11,6 +9,7 @@ import (
|
|||
"gorm.io/gorm"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/config"
|
||||
"git.mstar.dev/mstar/linstrom/shared"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||
)
|
||||
|
@ -27,7 +26,7 @@ func InsertSelf() error {
|
|||
if err != nil {
|
||||
return other.Error("storage", "failed to save/update self server", err)
|
||||
}
|
||||
user, err := insertUser(server)
|
||||
user, err := insertUser(server, duck)
|
||||
if err != nil {
|
||||
return other.Error("storage", "failed to save/update self user", err)
|
||||
}
|
||||
|
@ -95,7 +94,10 @@ func insertServer(duck *models.MediaMetadata) (*models.RemoteServer, error) {
|
|||
return &server, nil
|
||||
}
|
||||
|
||||
func insertUser(server *models.RemoteServer) (*models.User, error) {
|
||||
func insertUser(
|
||||
server *models.RemoteServer,
|
||||
duckMedia *models.MediaMetadata,
|
||||
) (*models.User, error) {
|
||||
dbUser, err := dbgen.User.GetByUsername("linstrom")
|
||||
if err == nil {
|
||||
return dbUser, nil
|
||||
|
@ -103,16 +105,14 @@ func insertUser(server *models.RemoteServer) (*models.User, error) {
|
|||
if err != gorm.ErrRecordNotFound {
|
||||
return nil, err
|
||||
}
|
||||
// publicKey, privateKey, err := ed25519.GenerateKey(nil)
|
||||
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||
publicEdKeyBytes, privateEdKeyBytes, err := shared.GenerateKeypair(true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = privateKey.Validate(); err != nil {
|
||||
publicRsaKeyBytes, privateRsaKeyBytes, err := shared.GenerateKeypair(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
privateKeyBytes := x509.MarshalPKCS1PrivateKey(privateKey)
|
||||
publicKeyBytes := x509.MarshalPKCS1PublicKey(&privateKey.PublicKey)
|
||||
pkeyId := make([]byte, 64)
|
||||
_, err = rand.Read(pkeyId)
|
||||
if err != nil {
|
||||
|
@ -129,15 +129,17 @@ func insertUser(server *models.RemoteServer) (*models.User, error) {
|
|||
DisplayName: config.GlobalConfig.Self.ServerActorDisplayName,
|
||||
Description: "The default linstrom server user",
|
||||
IsBot: true,
|
||||
Icon: nil,
|
||||
IconId: sql.NullString{Valid: false},
|
||||
Icon: duckMedia,
|
||||
IconId: sql.NullString{Valid: true, String: duckMedia.ID},
|
||||
Background: nil,
|
||||
BackgroundId: sql.NullString{Valid: false},
|
||||
Banner: nil,
|
||||
BannerId: sql.NullString{Valid: false},
|
||||
Indexable: false,
|
||||
PublicKey: publicKeyBytes,
|
||||
PrivateKey: privateKeyBytes,
|
||||
PublicKeyEd: publicEdKeyBytes,
|
||||
PrivateKeyEd: privateEdKeyBytes,
|
||||
PublicKeyRsa: publicRsaKeyBytes,
|
||||
PrivateKeyRsa: privateRsaKeyBytes,
|
||||
Verified: true,
|
||||
FinishedRegistration: true,
|
||||
PasskeyId: pkeyId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue