я не помню что я там делал
This commit is contained in:
parent
6abe95cb24
commit
5d649c992f
4 changed files with 29 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
*.snip
|
*.snip
|
||||||
storage
|
storage
|
||||||
|
verify.go
|
||||||
|
|
25
actor.go
25
actor.go
|
@ -14,7 +14,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gologme/log"
|
"github.com/gologme/log"
|
||||||
|
"crypto/sha256"
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
|
@ -50,6 +50,7 @@ type Actor struct {
|
||||||
OnReceiveContent func(map[string]interface{})
|
OnReceiveContent func(map[string]interface{})
|
||||||
attachment []interface {}
|
attachment []interface {}
|
||||||
gateways []interface {}
|
gateways []interface {}
|
||||||
|
proof map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActorToSave is a stripped down actor representation
|
// ActorToSave is a stripped down actor representation
|
||||||
|
@ -62,6 +63,7 @@ type ActorToSave struct {
|
||||||
Followers, Following, Rejected, Requested map[string]interface{}
|
Followers, Following, Rejected, Requested map[string]interface{}
|
||||||
Attachment []interface {}
|
Attachment []interface {}
|
||||||
Ed25519PrivateKey,Ed25519PublicKey string
|
Ed25519PrivateKey,Ed25519PublicKey string
|
||||||
|
Proof map[string]interface{}
|
||||||
}
|
}
|
||||||
// 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
|
||||||
|
@ -73,6 +75,9 @@ func MakeActor(name, summary, actorType string) (Actor, error) {
|
||||||
gateways := make([]interface{},0)
|
gateways := make([]interface{},0)
|
||||||
gateways = append(gateways,baseURL)
|
gateways = append(gateways,baseURL)
|
||||||
attachment := make([]interface{},0)
|
attachment := make([]interface{},0)
|
||||||
|
proof := make(map[string]interface{})
|
||||||
|
proof["type"] = "DataIntegrityProof"
|
||||||
|
proof["proofPurpose"] = "assertionMethod"
|
||||||
actor := Actor{
|
actor := Actor{
|
||||||
Name: name,
|
Name: name,
|
||||||
summary: summary,
|
summary: summary,
|
||||||
|
@ -98,6 +103,7 @@ func MakeActor(name, summary, actorType string) (Actor, error) {
|
||||||
}
|
}
|
||||||
actor.ed25519PrivateKey = e2_priv
|
actor.ed25519PrivateKey = e2_priv
|
||||||
actor.ed25519PublicKey = e2_pub
|
actor.ed25519PublicKey = e2_pub
|
||||||
|
proof["verificationMethod"] = "did:key:" + base58.Encode(e2_pub)
|
||||||
publicKey := privateKey.PublicKey
|
publicKey := privateKey.PublicKey
|
||||||
actor.publicKey = publicKey
|
actor.publicKey = publicKey
|
||||||
actor.privateKey = privateKey
|
actor.privateKey = privateKey
|
||||||
|
@ -130,7 +136,13 @@ func MakeActor(name, summary, actorType string) (Actor, error) {
|
||||||
Bytes: publicKeyDer,
|
Bytes: publicKeyDer,
|
||||||
}
|
}
|
||||||
actor.publicKeyPem = string(pem.EncodeToMemory(&publicKeyBlock))
|
actor.publicKeyPem = string(pem.EncodeToMemory(&publicKeyBlock))
|
||||||
|
hashActor := sha256.New()
|
||||||
|
hashActor.Write([]byte(actor.whoAmI()))
|
||||||
|
hashActorRes := hashActor.Sum(nil)
|
||||||
|
signature,err := e2_priv.Sign(nil,hashActorRes, &ed25519.Options{})
|
||||||
|
signatureBase58 := base58.Encode(signature)
|
||||||
|
proof["proofValue"] = signatureBase58
|
||||||
|
actor.proof = proof
|
||||||
err = actor.save()
|
err = actor.save()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return actor, err
|
return actor, err
|
||||||
|
@ -150,7 +162,7 @@ func (a *Actor) GetOutboxIRI() *url.URL {
|
||||||
// from the data in <name>.json
|
// from the data in <name>.json
|
||||||
// This does not preserve events so use with caution
|
// This does not preserve events so use with caution
|
||||||
func LoadActor(key string) (Actor, error) {
|
func LoadActor(key string) (Actor, error) {
|
||||||
jsonFile := storage + slash + "actors" + slash + key + slash + key + ".json"
|
jsonFile := storage + slash + "actors" + slash + key + slash + "actor.json"
|
||||||
fileHandle, err := os.Open(jsonFile)
|
fileHandle, err := os.Open(jsonFile)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
log.Info(key)
|
log.Info(key)
|
||||||
|
@ -215,6 +227,7 @@ func LoadActor(key string) (Actor, error) {
|
||||||
ed25519PublicKey: decodeEd2PublicKey,
|
ed25519PublicKey: decodeEd2PublicKey,
|
||||||
ed25519PrivateKey: decodeEd2PrivateKey,
|
ed25519PrivateKey: decodeEd2PrivateKey,
|
||||||
gateways: jsonData["Attachment"].([]interface{}),
|
gateways: jsonData["Attachment"].([]interface{}),
|
||||||
|
proof: jsonData["Proof"].(map[string]interface{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
actor.OnFollow = func(activity map[string]interface{}) { actor.Accept(activity) }
|
actor.OnFollow = func(activity map[string]interface{}) { actor.Accept(activity) }
|
||||||
|
@ -249,6 +262,7 @@ func (a *Actor) save() error {
|
||||||
Attachment: a.attachment,
|
Attachment: a.attachment,
|
||||||
Ed25519PublicKey: encodedEd25519pub,
|
Ed25519PublicKey: encodedEd25519pub,
|
||||||
Ed25519PrivateKey: encodedEd25519priv,
|
Ed25519PrivateKey: encodedEd25519priv,
|
||||||
|
Proof: a.proof,
|
||||||
}
|
}
|
||||||
actorJSON, err := json.MarshalIndent(actorToSave, "", "\t")
|
actorJSON, err := json.MarshalIndent(actorToSave, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -285,6 +299,9 @@ func (a *Actor) whoAmI() string {
|
||||||
"owner": baseURL + ".well-known/apgateway/" + encoded + "/actor",
|
"owner": baseURL + ".well-known/apgateway/" + encoded + "/actor",
|
||||||
"publicKeyPem": a.publicKeyPem,
|
"publicKeyPem": a.publicKeyPem,
|
||||||
}
|
}
|
||||||
|
if a.proof != nil {
|
||||||
|
self["proof"] = a.proof
|
||||||
|
}
|
||||||
self["gateways"] = a.gateways
|
self["gateways"] = a.gateways
|
||||||
self["sameAs"] = []string{"ap://did:key:" + encoded + "/actor"}
|
self["sameAs"] = []string{"ap://did:key:" + encoded + "/actor"}
|
||||||
selfString, _ := json.Marshal(self)
|
selfString, _ := json.Marshal(self)
|
||||||
|
@ -531,7 +548,7 @@ func (a *Actor) signedHTTPGet(address string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
responseData, _ := ioutil.ReadAll(resp.Body)
|
responseData, _ := ioutil.ReadAll(resp.Body)
|
||||||
fmt.Println("GET request succeeded:", iri.String(), req.Header, resp.StatusCode, resp.Status, "\n", FormatJSON(responseData))
|
//fmt.Println("GET request succeeded:", iri.String(), req.Header, resp.StatusCode, resp.Status, "\n", FormatJSON(responseData))
|
||||||
|
|
||||||
responseText := string(responseData)
|
responseText := string(responseData)
|
||||||
return responseText, nil
|
return responseText, nil
|
||||||
|
|
1
http.go
1
http.go
|
@ -64,6 +64,7 @@ func Serve(actors map[string]Actor) {
|
||||||
w.Header().Set("content-type", "application/activity+json; charset=utf-8")
|
w.Header().Set("content-type", "application/activity+json; charset=utf-8")
|
||||||
log.Info("Remote server " + r.RemoteAddr + " just fetched our /actor endpoint")
|
log.Info("Remote server " + r.RemoteAddr + " just fetched our /actor endpoint")
|
||||||
username := mux.Vars(r)["actor"]
|
username := mux.Vars(r)["actor"]
|
||||||
|
username = username[8:]
|
||||||
log.Info(username)
|
log.Info(username)
|
||||||
if username == ".well-known" || username == "favicon.ico" {
|
if username == ".well-known" || username == "favicon.ico" {
|
||||||
log.Info("well-known, skipping...")
|
log.Info("well-known, skipping...")
|
||||||
|
|
|
@ -8,8 +8,6 @@ import (
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RemoteActor is a type that holds an actor
|
|
||||||
// that we want to interact with
|
|
||||||
type RemoteActor struct {
|
type RemoteActor struct {
|
||||||
iri, outbox, inbox, sharedInbox string
|
iri, outbox, inbox, sharedInbox string
|
||||||
url string
|
url string
|
||||||
|
@ -18,9 +16,6 @@ type RemoteActor struct {
|
||||||
la Actor
|
la Actor
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRemoteActor returns a remoteActor which holds
|
|
||||||
// all the info required for an actor we want to
|
|
||||||
// interact with (not essentially sitting in our instance)
|
|
||||||
func NewRemoteActor(a Actor,iri string) (RemoteActor, error) {
|
func NewRemoteActor(a Actor,iri string) (RemoteActor, error) {
|
||||||
info, err := get(a,iri)
|
info, err := get(a,iri)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -54,9 +49,14 @@ func NewRemoteActor(a Actor,iri string) (RemoteActor, error) {
|
||||||
url: url,
|
url: url,
|
||||||
publicKey: spkiKey,
|
publicKey: spkiKey,
|
||||||
la: a,
|
la: a,
|
||||||
|
info: info,
|
||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ra RemoteActor) GetRaw() (map[string]interface{}){
|
||||||
|
return ra.info
|
||||||
|
}
|
||||||
|
|
||||||
func (ra RemoteActor) getLatestPosts(number int) (map[string]interface{}, error) {
|
func (ra RemoteActor) getLatestPosts(number int) (map[string]interface{}, error) {
|
||||||
return get(ra.la,ra.outbox)
|
return get(ra.la,ra.outbox)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue