upload files
This commit is contained in:
parent
7bed027302
commit
07cd0a20c8
3 changed files with 121 additions and 18 deletions
49
actor.go
49
actor.go
|
@ -3,6 +3,7 @@ package activityserve
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -20,7 +21,7 @@ import (
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
|
"crypto/ed25519"
|
||||||
"github.com/dchest/uniuri"
|
"github.com/dchest/uniuri"
|
||||||
"github.com/go-fed/httpsig"
|
"github.com/go-fed/httpsig"
|
||||||
)
|
)
|
||||||
|
@ -41,6 +42,9 @@ type Actor struct {
|
||||||
privateKey crypto.PrivateKey
|
privateKey crypto.PrivateKey
|
||||||
publicKeyPem string
|
publicKeyPem string
|
||||||
privateKeyPem string
|
privateKeyPem string
|
||||||
|
ed25519PublicKey ed25519.PublicKey
|
||||||
|
ed25519PrivateKey ed25519.PrivateKey
|
||||||
|
public string
|
||||||
publicKeyID string
|
publicKeyID string
|
||||||
OnFollow func(map[string]interface{})
|
OnFollow func(map[string]interface{})
|
||||||
OnReceiveContent func(map[string]interface{})
|
OnReceiveContent func(map[string]interface{})
|
||||||
|
@ -56,8 +60,8 @@ type ActorToSave struct {
|
||||||
Name, Summary, ActorType, IRI, PublicKey, PrivateKey string
|
Name, Summary, ActorType, IRI, PublicKey, PrivateKey string
|
||||||
Followers, Following, Rejected, Requested map[string]interface{}
|
Followers, Following, Rejected, Requested map[string]interface{}
|
||||||
Attachment []interface {}
|
Attachment []interface {}
|
||||||
|
Ed25519PrivateKey,Ed25519PublicKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeActor creates and returns a new local actor we can act
|
// MakeActor creates and returns a new local actor we can act
|
||||||
// on behalf of. It also creates its files on disk
|
// on behalf of. It also creates its files on disk
|
||||||
func MakeActor(name, summary, actorType string) (Actor, error) {
|
func MakeActor(name, summary, actorType string) (Actor, error) {
|
||||||
|
@ -96,8 +100,14 @@ func MakeActor(name, summary, actorType string) (Actor, error) {
|
||||||
// create actor's keypair
|
// create actor's keypair
|
||||||
rng := rand.Reader
|
rng := rand.Reader
|
||||||
privateKey, err := rsa.GenerateKey(rng, 2048)
|
privateKey, err := rsa.GenerateKey(rng, 2048)
|
||||||
|
e2_pub, e2_priv,err := ed25519.GenerateKey(rng)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("Can't create ed25519 keys")
|
||||||
|
log.Info(err)
|
||||||
|
}
|
||||||
|
actor.ed25519PrivateKey = e2_priv
|
||||||
|
actor.ed25519PublicKey = e2_pub
|
||||||
publicKey := privateKey.PublicKey
|
publicKey := privateKey.PublicKey
|
||||||
|
|
||||||
actor.publicKey = publicKey
|
actor.publicKey = publicKey
|
||||||
actor.privateKey = privateKey
|
actor.privateKey = privateKey
|
||||||
|
|
||||||
|
@ -190,7 +200,8 @@ func LoadActor(name string) (Actor, error) {
|
||||||
log.Info(err)
|
log.Info(err)
|
||||||
return Actor{}, err
|
return Actor{}, err
|
||||||
}
|
}
|
||||||
|
decodeEd2PublicKey,err := base64.StdEncoding.DecodeString(jsonData["Ed25519PublicKey"].(string))
|
||||||
|
decodeEd2PrivateKey,err := base64.StdEncoding.DecodeString(jsonData["Ed25519PrivateKey"].(string))
|
||||||
actor := Actor{
|
actor := Actor{
|
||||||
Name: name,
|
Name: name,
|
||||||
summary: jsonData["Summary"].(string),
|
summary: jsonData["Summary"].(string),
|
||||||
|
@ -208,6 +219,8 @@ func LoadActor(name string) (Actor, error) {
|
||||||
followersIRI: baseURL + name + "/followers",
|
followersIRI: baseURL + name + "/followers",
|
||||||
publicKeyID: baseURL + name + "#main-key",
|
publicKeyID: baseURL + name + "#main-key",
|
||||||
attachment: jsonData["Attachment"].([]interface{}),
|
attachment: jsonData["Attachment"].([]interface{}),
|
||||||
|
ed25519PublicKey: decodeEd2PublicKey,
|
||||||
|
ed25519PrivateKey: decodeEd2PrivateKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
actor.OnFollow = func(activity map[string]interface{}) { actor.Accept(activity) }
|
actor.OnFollow = func(activity map[string]interface{}) { actor.Accept(activity) }
|
||||||
|
@ -262,7 +275,8 @@ func (a *Actor) save() error {
|
||||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||||
os.MkdirAll(dir, 0755)
|
os.MkdirAll(dir, 0755)
|
||||||
}
|
}
|
||||||
|
encodedEd25519pub := base64.StdEncoding.EncodeToString(a.ed25519PublicKey)
|
||||||
|
encodedEd25519priv := base64.StdEncoding.EncodeToString(a.ed25519PrivateKey)
|
||||||
actorToSave := ActorToSave{
|
actorToSave := ActorToSave{
|
||||||
Name: a.Name,
|
Name: a.Name,
|
||||||
Summary: a.summary,
|
Summary: a.summary,
|
||||||
|
@ -275,15 +289,16 @@ func (a *Actor) save() error {
|
||||||
PublicKey: a.publicKeyPem,
|
PublicKey: a.publicKeyPem,
|
||||||
PrivateKey: a.privateKeyPem,
|
PrivateKey: a.privateKeyPem,
|
||||||
Attachment: a.attachment,
|
Attachment: a.attachment,
|
||||||
|
Ed25519PublicKey: encodedEd25519pub,
|
||||||
|
Ed25519PrivateKey: encodedEd25519priv,
|
||||||
}
|
}
|
||||||
|
|
||||||
actorJSON, err := json.MarshalIndent(actorToSave, "", "\t")
|
actorJSON, err := json.MarshalIndent(actorToSave, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("error Marshalling actor json")
|
log.Info("error Marshalling actor json")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// log.Info(actorToSave)
|
//log.Info(actorToSave)
|
||||||
// log.Info(string(actorJSON))
|
//log.Info(string(actorJSON))
|
||||||
err = ioutil.WriteFile(storage+slash+"actors"+slash+a.Name+slash+a.Name+".json", actorJSON, 0644)
|
err = ioutil.WriteFile(storage+slash+"actors"+slash+a.Name+slash+a.Name+".json", actorJSON, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("WriteFileJson ERROR: %+v", err)
|
log.Printf("WriteFileJson ERROR: %+v", err)
|
||||||
|
@ -294,22 +309,22 @@ func (a *Actor) save() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Actor) whoAmI() string {
|
func (a *Actor) whoAmI() string {
|
||||||
|
encoded := base64.StdEncoding.EncodeToString(a.ed25519PublicKey)
|
||||||
self := make(map[string]interface{})
|
self := make(map[string]interface{})
|
||||||
self["@context"] = context()
|
self["@context"] = context()
|
||||||
self["type"] = a.actorType
|
self["type"] = a.actorType
|
||||||
self["id"] = baseURL + a.Name
|
self["id"] = baseURL + ".well-known/apgateway/" + encoded + "/actor"
|
||||||
self["name"] = a.Name
|
self["name"] = nil
|
||||||
self["preferredUsername"] = a.Name
|
self["preferredUsername"] = a.Name
|
||||||
self["summary"] = a.summary
|
self["summary"] = a.summary
|
||||||
self["inbox"] = baseURL + a.Name + "/inbox"
|
self["inbox"] = baseURL + ".well-known/apgateway/" + encoded + "/inbox"
|
||||||
self["outbox"] = baseURL + a.Name + "/outbox"
|
self["outbox"] = baseURL + ".well-known/apgateway/" + encoded + "/outbox"
|
||||||
self["followers"] = baseURL + a.Name + "/peers/followers"
|
self["followers"] = baseURL + ".well-known/apgateway/" + encoded + "/peers/followers"
|
||||||
self["following"] = baseURL + a.Name + "/peers/following"
|
self["following"] = baseURL + ".well-known/apgateway/" + encoded + "/peers/following"
|
||||||
self["attachment"] = a.attachment
|
self["attachment"] = a.attachment
|
||||||
self["publicKey"] = map[string]string{
|
self["publicKey"] = map[string]string{
|
||||||
"id": baseURL + a.Name + "#main-key",
|
"id": baseURL + ".well-known/apgateway/" + encoded + "#main-key",
|
||||||
"owner": baseURL + a.Name,
|
"owner": baseURL + ".well-known/apgateway/" + encoded + "/actor",
|
||||||
"publicKeyPem": a.publicKeyPem,
|
"publicKeyPem": a.publicKeyPem,
|
||||||
}
|
}
|
||||||
selfString, _ := json.Marshal(self)
|
selfString, _ := json.Marshal(self)
|
||||||
|
|
2
http.go
2
http.go
|
@ -364,7 +364,7 @@ func Serve(actors map[string]Actor) {
|
||||||
gorilla.HandleFunc("/{actor}/inbox", inboxHandler)
|
gorilla.HandleFunc("/{actor}/inbox", inboxHandler)
|
||||||
gorilla.HandleFunc("/{actor}/inbox/", inboxHandler)
|
gorilla.HandleFunc("/{actor}/inbox/", inboxHandler)
|
||||||
gorilla.HandleFunc("/{actor}/", actorHandler)
|
gorilla.HandleFunc("/{actor}/", actorHandler)
|
||||||
gorilla.HandleFunc("/{actor}", actorHandler)
|
gorilla.HandleFunc("/.well-known/apgateway/{actor}/actor", actorHandler)
|
||||||
gorilla.HandleFunc("/{actor}/item/{hash}", postHandler)
|
gorilla.HandleFunc("/{actor}/item/{hash}", postHandler)
|
||||||
http.Handle("/", gorilla)
|
http.Handle("/", gorilla)
|
||||||
|
|
||||||
|
|
88
silverpill.json
Normal file
88
silverpill.json
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://www.w3.org/ns/did/v1",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
"https://w3id.org/security/data-integrity/v1",
|
||||||
|
"https://w3id.org/security/multikey/v1",
|
||||||
|
{
|
||||||
|
"MitraJcsEip191Signature2022": "mitra:MitraJcsEip191Signature2022",
|
||||||
|
"PropertyValue": "schema:PropertyValue",
|
||||||
|
"VerifiableIdentityStatement": "mitra:VerifiableIdentityStatement",
|
||||||
|
"featured": "toot:featured",
|
||||||
|
"gateways": "mitra:gateways",
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"mitra": "http://jsonld.mitra.social#",
|
||||||
|
"proofPurpose": "sec:proofPurpose",
|
||||||
|
"proofValue": "sec:proofValue",
|
||||||
|
"sameAs": "schema:sameAs",
|
||||||
|
"schema": "http://schema.org/",
|
||||||
|
"subscribers": "mitra:subscribers",
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"value": "schema:value"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"alsoKnownAs": [
|
||||||
|
"https://mitra.social/users/followbot"
|
||||||
|
],
|
||||||
|
"assertionMethod": [
|
||||||
|
{
|
||||||
|
"controller": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor",
|
||||||
|
"id": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor#main-key",
|
||||||
|
"publicKeyMultibase": "z4MXj1wBzi9jUstyPArehoipP2vta2h8poW9baePvKQHTtZp8cdQKNkx3qSpQYPwzo9CoD75xaiaPLaHYFybdsTKLJAf8if2GiXCTf96BALKxyy9bLgSUUaxX9VsvV5Z7FtHNCBnvuuF1sqtbSBq8Ex9KgZFgZjXXTdFBwA6ad3F2okUXQYY9wjUpdCouchnUHxKrBnTTPz8cAJKXMdR6DpCUCFfdyjW7oDdaWqrUHBYZisFTouFWuogUkRb2MjWnjps7FtqqKSszpiSF9W7UxB4DdnQ3jvgqdZ7avWKPSJDVTeTRLP6iuv6XvSShLk8tEDJfornKFczuv2MuDiQTTYR9xAQM7htD31HPN1vAcPzEQ7krYRkU",
|
||||||
|
"type": "Multikey"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"controller": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor",
|
||||||
|
"id": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor#ed25519-key",
|
||||||
|
"publicKeyMultibase": "z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf",
|
||||||
|
"type": "Multikey"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"authentication": [
|
||||||
|
{
|
||||||
|
"controller": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor",
|
||||||
|
"id": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor#main-key",
|
||||||
|
"publicKeyMultibase": "z4MXj1wBzi9jUstyPArehoipP2vta2h8poW9baePvKQHTtZp8cdQKNkx3qSpQYPwzo9CoD75xaiaPLaHYFybdsTKLJAf8if2GiXCTf96BALKxyy9bLgSUUaxX9VsvV5Z7FtHNCBnvuuF1sqtbSBq8Ex9KgZFgZjXXTdFBwA6ad3F2okUXQYY9wjUpdCouchnUHxKrBnTTPz8cAJKXMdR6DpCUCFfdyjW7oDdaWqrUHBYZisFTouFWuogUkRb2MjWnjps7FtqqKSszpiSF9W7UxB4DdnQ3jvgqdZ7avWKPSJDVTeTRLP6iuv6XvSShLk8tEDJfornKFczuv2MuDiQTTYR9xAQM7htD31HPN1vAcPzEQ7krYRkU",
|
||||||
|
"type": "Multikey"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"controller": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor",
|
||||||
|
"id": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor#ed25519-key",
|
||||||
|
"publicKeyMultibase": "z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf",
|
||||||
|
"type": "Multikey"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"featured": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor/collections/featured",
|
||||||
|
"followers": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor/followers",
|
||||||
|
"following": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor/following",
|
||||||
|
"gateways": [
|
||||||
|
"https://public.mitra.social"
|
||||||
|
],
|
||||||
|
"id": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor",
|
||||||
|
"inbox": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor/inbox",
|
||||||
|
"manuallyApprovesFollowers": false,
|
||||||
|
"name": null,
|
||||||
|
"outbox": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor/outbox",
|
||||||
|
"preferredUsername": "silverpill",
|
||||||
|
"proof": {
|
||||||
|
"created": "2024-05-29T08:08:06.974875078Z",
|
||||||
|
"cryptosuite": "eddsa-jcs-2022",
|
||||||
|
"proofPurpose": "assertionMethod",
|
||||||
|
"proofValue": "z2GrXezAbsUh3jms2aer3MfRSLyKqqiei52t7Gie49YvWkmzfxK1Vqg3aNVD9hXMgCQdg1KLfRKZV7SLywbSzGnfJ",
|
||||||
|
"type": "DataIntegrityProof",
|
||||||
|
"verificationMethod": "did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf"
|
||||||
|
},
|
||||||
|
"publicKey": {
|
||||||
|
"id": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor#main-key",
|
||||||
|
"owner": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor",
|
||||||
|
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqcnHfgupRhkrzywzMnik\ncEg2WkfLiCvAxTpAlaDOPTdkd9MPPVhceNCeRpLzlsNeerU/A/9G/Oug7y9/0Aln\n7EL0NQvR47y6p0jegGguvsWMWwtWKcSg5uFAgEP93RFnqr/+S3KKZe4LrluYIVMu\n4tzsvZtJ7VxLsbDoXH59KtpspDQxk5fFKFk7Hsi3ba0zguxWibO5WhfqruFD1Fj+\nghuZtjMXaMcGpYctcz+R+uK3AHDI7Iqdzl8rjBB2exBS/VFXf4duFuiylZLLrCe7\n/1er0xICocaOxUhqTBcD5xI8MR3W5uFnEafWZLAgFqE1Xm2mNawHh33Nlq57Jn/e\nqQIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||||
|
},
|
||||||
|
"sameAs": [
|
||||||
|
"https://public.mitra.social/users/silverpill?fep_ef61=true",
|
||||||
|
"ap://did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor"
|
||||||
|
],
|
||||||
|
"subscribers": "https://public.mitra.social/.well-known/apgateway/did:key:z6MkuESiSXv58qijkRDtV262UsFpptPWcAXNpfarp4b1WjRf/actor/subscribers",
|
||||||
|
"type": "Person",
|
||||||
|
"url": "https://public.mitra.social/users/silverpill"
|
||||||
|
}
|
Loading…
Reference in a new issue