(except for iceshrimp, but who cares) (well, I do. Would not be nice to not be compatible with a not-so-rarely used software)
This commit is contained in:
parent
59dd8d82cf
commit
5e13817563
7 changed files with 167 additions and 93 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.mstar.dev/mstar/goutils/other"
|
||||
|
@ -12,6 +13,7 @@ import (
|
|||
|
||||
"git.mstar.dev/mstar/linstrom/config"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||
webshared "git.mstar.dev/mstar/linstrom/web/shared"
|
||||
)
|
||||
|
||||
|
@ -54,35 +56,35 @@ func ImportRemoteAccount(targetName string) (string, error) {
|
|||
return t.Relation == "self"
|
||||
})
|
||||
if len(selfLinks) == 0 {
|
||||
return "", errors.New("No self link")
|
||||
return "", errors.New("no self link")
|
||||
}
|
||||
APLink := selfLinks[0]
|
||||
req, err := webshared.NewRequest("GET", *APLink.Href, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
req.Header.Add("Accept", "application/activity+json")
|
||||
|
||||
// Server actor key for signing
|
||||
linstromActor, err := dbgen.User.Where(dbgen.User.Username.Eq("linstrom")).First()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var keyBytes []byte
|
||||
if config.GlobalConfig.Experimental.UseEd25519Keys {
|
||||
keyBytes = linstromActor.PrivateKeyEd
|
||||
} else {
|
||||
keyBytes = linstromActor.PrivateKeyRsa
|
||||
}
|
||||
|
||||
// Sign and send
|
||||
err = webshared.SignRequest(req, linstromActor.ID+"#main-key", keyBytes, nil)
|
||||
// err = webshared.SignRequestWithHttpsig(req, linstromActor.ID+"#main-key", keyBytes, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
log.Debug().Str("Signature", req.Header.Get("Signature")).Msg("Post sign signature")
|
||||
response, err := webshared.RequestClient.Do(req)
|
||||
var response *http.Response
|
||||
// if config.GlobalConfig.Experimental.UseEd25519Keys {
|
||||
// response, err = webshared.RequestSignedCavage(
|
||||
// "GET",
|
||||
// *APLink.Href,
|
||||
// nil,
|
||||
// config.GlobalConfig.General.GetFullPublicUrl()+"/api/activitypub/user/"+linstromActor.ID+"#main-key",
|
||||
// linstromActor.PrivateKeyEd,
|
||||
// true,
|
||||
// )
|
||||
// } else {
|
||||
// response, err = webshared.RequestSignedCavage(
|
||||
// "GET",
|
||||
// *APLink.Href,
|
||||
// nil,
|
||||
// config.GlobalConfig.General.GetFullPublicUrl()+"/api/activitypub/user/"+linstromActor.ID+"#main-key",
|
||||
// linstromActor.PrivateKeyRsa,
|
||||
// false,
|
||||
// )
|
||||
// }
|
||||
response, err = customReq(*APLink.Href, linstromActor)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -94,7 +96,7 @@ func ImportRemoteAccount(targetName string) (string, error) {
|
|||
Any("headers", response.Header).
|
||||
Msg("Response information")
|
||||
if response.StatusCode != 200 {
|
||||
return "", errors.New("Bad status")
|
||||
return "", errors.New("bad status")
|
||||
}
|
||||
var data InboundUser
|
||||
err = json.Unmarshal(body, &data)
|
||||
|
@ -104,3 +106,26 @@ func ImportRemoteAccount(targetName string) (string, error) {
|
|||
log.Info().Any("received-data", data).Msg("Response data")
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func customReq(target string, linstromActor *models.User) (*http.Response, error) {
|
||||
req, err := webshared.NewRequest("GET", target, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Add("Accept", "application/activity+json")
|
||||
|
||||
var keyBytes []byte
|
||||
if config.GlobalConfig.Experimental.UseEd25519Keys {
|
||||
keyBytes = linstromActor.PrivateKeyEd
|
||||
} else {
|
||||
keyBytes = linstromActor.PrivateKeyRsa
|
||||
}
|
||||
|
||||
// Sign and send
|
||||
err = webshared.SignRequest(req, linstromActor.ID+"#main-key", keyBytes, nil)
|
||||
// err = webshared.SignRequestWithHttpsig(req, linstromActor.ID+"#main-key", keyBytes, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return webshared.RequestClient.Do(req)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue