diff --git a/.gitignore b/.gitignore index 6b19c37..91cee0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.snip -storage \ No newline at end of file +storage +verify.go diff --git a/actor.go b/actor.go index a9e7321..7ef06df 100644 --- a/actor.go +++ b/actor.go @@ -14,7 +14,7 @@ import ( "time" "github.com/gologme/log" - + "crypto/sha256" "crypto" "crypto/rand" "crypto/rsa" @@ -50,6 +50,7 @@ type Actor struct { OnReceiveContent func(map[string]interface{}) attachment []interface {} gateways []interface {} + proof map[string]interface{} } // ActorToSave is a stripped down actor representation @@ -62,6 +63,7 @@ type ActorToSave struct { Followers, Following, Rejected, Requested map[string]interface{} Attachment []interface {} Ed25519PrivateKey,Ed25519PublicKey string + Proof map[string]interface{} } // MakeActor creates and returns a new local actor we can act // 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 = append(gateways,baseURL) attachment := make([]interface{},0) + proof := make(map[string]interface{}) + proof["type"] = "DataIntegrityProof" + proof["proofPurpose"] = "assertionMethod" actor := Actor{ Name: name, summary: summary, @@ -98,6 +103,7 @@ func MakeActor(name, summary, actorType string) (Actor, error) { } actor.ed25519PrivateKey = e2_priv actor.ed25519PublicKey = e2_pub + proof["verificationMethod"] = "did:key:" + base58.Encode(e2_pub) publicKey := privateKey.PublicKey actor.publicKey = publicKey actor.privateKey = privateKey @@ -130,7 +136,13 @@ func MakeActor(name, summary, actorType string) (Actor, error) { Bytes: publicKeyDer, } 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() if err != nil { return actor, err @@ -150,7 +162,7 @@ func (a *Actor) GetOutboxIRI() *url.URL { // from the data in .json // This does not preserve events so use with caution 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) if os.IsNotExist(err) { log.Info(key) @@ -215,6 +227,7 @@ func LoadActor(key string) (Actor, error) { ed25519PublicKey: decodeEd2PublicKey, ed25519PrivateKey: decodeEd2PrivateKey, gateways: jsonData["Attachment"].([]interface{}), + proof: jsonData["Proof"].(map[string]interface{}), } actor.OnFollow = func(activity map[string]interface{}) { actor.Accept(activity) } @@ -249,6 +262,7 @@ func (a *Actor) save() error { Attachment: a.attachment, Ed25519PublicKey: encodedEd25519pub, Ed25519PrivateKey: encodedEd25519priv, + Proof: a.proof, } actorJSON, err := json.MarshalIndent(actorToSave, "", "\t") if err != nil { @@ -285,6 +299,9 @@ func (a *Actor) whoAmI() string { "owner": baseURL + ".well-known/apgateway/" + encoded + "/actor", "publicKeyPem": a.publicKeyPem, } + if a.proof != nil { + self["proof"] = a.proof + } self["gateways"] = a.gateways self["sameAs"] = []string{"ap://did:key:" + encoded + "/actor"} selfString, _ := json.Marshal(self) @@ -531,7 +548,7 @@ func (a *Actor) signedHTTPGet(address string) (string, error) { } 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) return responseText, nil diff --git a/http.go b/http.go index ab4a90c..ca3c8d7 100644 --- a/http.go +++ b/http.go @@ -64,6 +64,7 @@ func Serve(actors map[string]Actor) { w.Header().Set("content-type", "application/activity+json; charset=utf-8") log.Info("Remote server " + r.RemoteAddr + " just fetched our /actor endpoint") username := mux.Vars(r)["actor"] + username = username[8:] log.Info(username) if username == ".well-known" || username == "favicon.ico" { log.Info("well-known, skipping...") diff --git a/remoteActor.go b/remoteActor.go index 788b320..d852f19 100644 --- a/remoteActor.go +++ b/remoteActor.go @@ -8,8 +8,6 @@ import ( "crypto/rsa" ) -// RemoteActor is a type that holds an actor - // that we want to interact with type RemoteActor struct { iri, outbox, inbox, sharedInbox string url string @@ -18,9 +16,6 @@ type RemoteActor struct { 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) { info, err := get(a,iri) if err != nil { @@ -54,9 +49,14 @@ func NewRemoteActor(a Actor,iri string) (RemoteActor, error) { url: url, publicKey: spkiKey, la: a, + info: info, }, err } +func (ra RemoteActor) GetRaw() (map[string]interface{}){ + return ra.info +} + func (ra RemoteActor) getLatestPosts(number int) (map[string]interface{}, error) { return get(ra.la,ra.outbox) }