Signing works
This commit is contained in:
parent
d272fa90b4
commit
da2a89010c
19 changed files with 348 additions and 100 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
func BuildActivitypubRouter() http.Handler {
|
||||
router := http.NewServeMux()
|
||||
router.HandleFunc("/user/{id}", users)
|
||||
router.HandleFunc("/user/{id}/inbox", userInbox)
|
||||
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "in ap")
|
||||
})
|
||||
|
|
|
@ -3,13 +3,17 @@ package activitypub
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
webutils "git.mstar.dev/mstar/goutils/http"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/rs/zerolog/hlog"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/config"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
||||
webshared "git.mstar.dev/mstar/linstrom/web/shared"
|
||||
)
|
||||
|
||||
var baseLdContext = []any{
|
||||
|
@ -23,17 +27,30 @@ func users(w http.ResponseWriter, r *http.Request) {
|
|||
Owner string `json:"owner"`
|
||||
Pem string `json:"publicKeyPem"`
|
||||
}
|
||||
type Outbound struct {
|
||||
Context []any `json:"@context"`
|
||||
Id string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
PreferredUsername string `json:"preferredUsername"`
|
||||
Inbox string `json:"inbox"`
|
||||
// FIXME: Public key stuff is borken. Focus on fixing
|
||||
// PublicKey OutboundKey `json:"publicKey"`
|
||||
type OutboundMedia struct {
|
||||
Type string `json:"type"`
|
||||
Url string `json:"url"`
|
||||
MediaType string `json:"mediaType"`
|
||||
}
|
||||
type Outbound struct {
|
||||
Context []any `json:"@context"`
|
||||
Id string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
PreferredUsername string `json:"preferredUsername"`
|
||||
Inbox string `json:"inbox"`
|
||||
PublicKey OutboundKey `json:"publicKey"`
|
||||
Published time.Time `json:"published"`
|
||||
DisplayName string `json:"name"`
|
||||
Description *string `json:"summary,omitempty"`
|
||||
PublicUrl string `json:"url"`
|
||||
Icon *OutboundMedia `json:"icon,omitempty"`
|
||||
Banner *OutboundMedia `json:"image,omitempty"`
|
||||
}
|
||||
log := hlog.FromRequest(r)
|
||||
userId := r.PathValue("id")
|
||||
user, err := dbgen.User.Where(dbgen.User.ID.Eq(userId)).First()
|
||||
user, err := dbgen.User.Where(dbgen.User.ID.Eq(userId)).
|
||||
Preload(dbgen.User.Icon).Preload(dbgen.User.Banner).
|
||||
First()
|
||||
if err != nil {
|
||||
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil)
|
||||
if storage.HandleReconnectError(err) {
|
||||
|
@ -43,20 +60,47 @@ func users(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
return
|
||||
}
|
||||
// fmt.Println(x509.ParsePKCS1PublicKey(user.PublicKey))
|
||||
|
||||
apUrl := userIdToApUrl(user.ID)
|
||||
var keyBytes string
|
||||
if config.GlobalConfig.Experimental.UseEd25519Keys {
|
||||
keyBytes = keyBytesToPem(user.PublicKeyEd)
|
||||
} else {
|
||||
keyBytes = keyBytesToPem(user.PublicKeyRsa)
|
||||
}
|
||||
data := Outbound{
|
||||
Context: baseLdContext,
|
||||
Id: apUrl,
|
||||
Type: "Person",
|
||||
PreferredUsername: user.DisplayName,
|
||||
PreferredUsername: user.Username,
|
||||
Inbox: apUrl + "/inbox",
|
||||
// PublicKey: OutboundKey{
|
||||
// Id: apUrl + "#main-key",
|
||||
// Owner: apUrl,
|
||||
// Pem: keyBytesToPem(user.PublicKey),
|
||||
// },
|
||||
PublicKey: OutboundKey{
|
||||
Id: apUrl + "#main-key",
|
||||
Owner: apUrl,
|
||||
Pem: keyBytes,
|
||||
},
|
||||
Published: user.CreatedAt,
|
||||
DisplayName: user.DisplayName,
|
||||
PublicUrl: config.GlobalConfig.General.GetFullPublicUrl() + "/user/" + user.Username,
|
||||
}
|
||||
if user.Description != "" {
|
||||
data.Description = &user.Description
|
||||
}
|
||||
if user.Icon != nil {
|
||||
log.Debug().Msg("icon found")
|
||||
data.Icon = &OutboundMedia{
|
||||
Type: "Image",
|
||||
Url: webshared.EnsurePublicUrl(user.Icon.Location),
|
||||
MediaType: user.Icon.Type,
|
||||
}
|
||||
}
|
||||
if user.Banner != nil {
|
||||
log.Debug().Msg("icon banner")
|
||||
data.Banner = &OutboundMedia{
|
||||
Type: "Image",
|
||||
Url: webshared.EnsurePublicUrl(user.Banner.Location),
|
||||
MediaType: user.Banner.Type,
|
||||
}
|
||||
}
|
||||
|
||||
encoded, err := json.Marshal(data)
|
||||
|
@ -64,6 +108,13 @@ func users(w http.ResponseWriter, r *http.Request) {
|
|||
fmt.Fprint(w, string(encoded))
|
||||
}
|
||||
|
||||
func userInbox(w http.ResponseWriter, r *http.Request) {
|
||||
log := hlog.FromRequest(r)
|
||||
userId := r.PathValue("id")
|
||||
data, err := io.ReadAll(r.Body)
|
||||
log.Info().Err(err).Str("userId", userId).Bytes("body", data).Msg("Inbox message")
|
||||
}
|
||||
|
||||
/*
|
||||
Fine. You win JsonLD. I can't get you to work properly. I'll just treat you like normal json then
|
||||
Fuck you.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue