74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
package storage
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"database/sql"
|
|
|
|
"git.mstar.dev/mstar/goutils/other"
|
|
"gorm.io/gorm"
|
|
|
|
"git.mstar.dev/mstar/linstrom/shared"
|
|
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
|
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
|
)
|
|
|
|
var UnknownActorId string
|
|
|
|
func InsertUnknownActorPlaceholder() error {
|
|
dbUser, err := dbgen.User.GetByUsername(shared.UnknownActorName)
|
|
if err == nil {
|
|
UnknownActorId = dbUser.ID
|
|
return nil
|
|
}
|
|
if err != gorm.ErrRecordNotFound {
|
|
return err
|
|
}
|
|
server, err := dbgen.RemoteServer.Where(dbgen.RemoteServer.IsSelf.Is(true)).First()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
publicEdKeyBytes, privateEdKeyBytes, err := shared.GenerateKeypair(true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
publicRsaKeyBytes, privateRsaKeyBytes, err := shared.GenerateKeypair(false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pkeyId := make([]byte, 64)
|
|
_, err = rand.Read(pkeyId)
|
|
if err != nil {
|
|
return other.Error(
|
|
"storage",
|
|
"failed to generate passkey ID for linstrom account",
|
|
err,
|
|
)
|
|
}
|
|
user := models.User{
|
|
ID: shared.NewId(),
|
|
Username: shared.UnknownActorName,
|
|
Server: *server,
|
|
ServerId: server.ID,
|
|
DisplayName: "Placeholder user",
|
|
Description: "Placeholder user for when the actual users are unknown, like with Mastodon likes and boosts",
|
|
IsBot: true,
|
|
IconId: sql.NullString{Valid: false},
|
|
Background: nil,
|
|
BackgroundId: sql.NullString{Valid: false},
|
|
Banner: nil,
|
|
BannerId: sql.NullString{Valid: false},
|
|
Indexable: false,
|
|
PublicKeyEd: publicEdKeyBytes,
|
|
PrivateKeyEd: privateEdKeyBytes,
|
|
PublicKeyRsa: publicRsaKeyBytes,
|
|
PrivateKeyRsa: privateRsaKeyBytes,
|
|
Verified: true,
|
|
FinishedRegistration: true,
|
|
PasskeyId: pkeyId,
|
|
}
|
|
err = dbgen.User.Save(&user)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|