aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--registry/registry.go23
-rw-r--r--urls/urls.go8
-rw-r--r--views/actor.go25
3 files changed, 54 insertions, 2 deletions
diff --git a/registry/registry.go b/registry/registry.go
index e7f66fc..dc83328 100644
--- a/registry/registry.go
+++ b/registry/registry.go
@@ -2,7 +2,9 @@ package registry
import (
"bytes"
+ "crypto/x509"
"encoding/gob"
+ "encoding/pem"
"net/http"
"net/url"
"strings"
@@ -54,7 +56,26 @@ func (r *Registry) Actor(name string) (map[string]interface{}, error) {
if handler == nil {
return nil, nil
}
- return views.RenderActor(handler.handlerCfg.Name, r.cfg.Domain)
+ aso := models.NewKeypair(handler.handlerCfg)
+ result, err := r.persister.Find(aso)
+ if err != nil {
+ return nil, err
+ }
+ buf := bytes.NewBuffer(result)
+ dec := gob.NewDecoder(buf)
+ var keypair models.Keypair
+ err = dec.Decode(&keypair)
+ if err != nil {
+ return nil, err
+ }
+ privKey := &keypair.PrivateKey
+ pemdata := pem.EncodeToMemory(
+ &pem.Block{
+ Type: "PUBLIC KEY",
+ Bytes: x509.MarshalPKCS1PublicKey(&privKey.PublicKey),
+ },
+ )
+ return views.RenderActor(handler.handlerCfg.Name, r.cfg.Domain, string(pemdata))
}
func (r *Registry) OutboxCollection(name string) (map[string]interface{}, error) {
diff --git a/urls/urls.go b/urls/urls.go
index d2bfb4a..8b3a7fa 100644
--- a/urls/urls.go
+++ b/urls/urls.go
@@ -10,6 +10,10 @@ func linkTo(name, base string, path ...string) (*url.URL, error) {
if err != nil {
return nil, fmt.Errorf("could not build %s url: %w", name, err)
}
+ u, err = url.PathUnescape(u)
+ if err != nil {
+ return nil, fmt.Errorf("could not unescape %s url: %w", name, err)
+ }
uri, err := url.Parse(u)
if err != nil {
return nil, fmt.Errorf("could not parse %s url: %w", name, err)
@@ -29,6 +33,10 @@ func UrlProfile(name, domain string) (*url.URL, error) {
return linkTo("outbox", domain, "actors", name)
}
+func UrlProfileKey(name, domain string) (*url.URL, error) {
+ return linkTo("outbox", domain, "actors", name+"#main-key")
+}
+
func UrlFollowers(name, domain string) (*url.URL, error) {
return linkTo("outbox", domain, "actors", name, "followers")
}
diff --git a/views/actor.go b/views/actor.go
index a91044a..48aaa0b 100644
--- a/views/actor.go
+++ b/views/actor.go
@@ -7,7 +7,7 @@ import (
"github.com/go-fed/activity/streams"
)
-func RenderActor(name, domain string) (map[string]interface{}, error) {
+func RenderActor(name, domain, pem string) (map[string]interface{}, error) {
inbox, err := urls.UrlInbox(name, domain)
if err != nil {
return nil, err
@@ -29,6 +29,11 @@ func RenderActor(name, domain string) (map[string]interface{}, error) {
return nil, err
}
+ actorUrlKey, err := urls.UrlProfileKey(name, domain)
+ if err != nil {
+ return nil, err
+ }
+
followingUrl, err := urls.UrlFollowing(name, domain)
if err != nil {
return nil, err
@@ -70,5 +75,23 @@ func RenderActor(name, domain string) (map[string]interface{}, error) {
followingProp.SetIRI(followingUrl)
p.SetActivityStreamsFollowing(followingProp)
+ pemProp := streams.NewW3IDSecurityV1PublicKeyPemProperty()
+ pemProp.Set(pem)
+
+ ownerProp := streams.NewW3IDSecurityV1OwnerProperty()
+ ownerProp.Set(actorUrl)
+
+ pubkeyId := streams.NewJSONLDIdProperty()
+ pubkeyId.Set(actorUrlKey)
+
+ pubKey := streams.NewW3IDSecurityV1PublicKey()
+ pubKey.SetW3IDSecurityV1PublicKeyPem(pemProp)
+ pubKey.SetW3IDSecurityV1Owner(ownerProp)
+ pubKey.SetJSONLDId(pubkeyId)
+
+ pubKeyProp := streams.NewW3IDSecurityV1PublicKeyProperty()
+ pubKeyProp.AppendW3IDSecurityV1PublicKey(pubKey)
+ p.SetW3IDSecurityV1PublicKey(pubKeyProp)
+
return streams.Serialize(p)
}