diff options
Diffstat (limited to 'activitypub')
-rw-r--r-- | activitypub/actor.go | 10 | ||||
-rw-r--r-- | activitypub/util.go | 8 | ||||
-rw-r--r-- | activitypub/webfinger.go | 12 |
3 files changed, 21 insertions, 9 deletions
diff --git a/activitypub/actor.go b/activitypub/actor.go index c6283c8..e54088d 100644 --- a/activitypub/actor.go +++ b/activitypub/actor.go @@ -951,8 +951,7 @@ func (actor Actor) Verify(signature string, verify string) error { sig, _ := base64.StdEncoding.DecodeString(signature) if actor.PublicKey.PublicKeyPem == "" { - // TODO: this should be Finger but its not getting PublicKeyPem atm - _actor, err := GetActorFromDB(actor.Id) + _actor, err := FingerActor(actor.Id) if err != nil { return util.MakeError(err, "Verify") @@ -962,7 +961,12 @@ func (actor Actor) Verify(signature string, verify string) error { } block, _ := pem.Decode([]byte(actor.PublicKey.PublicKeyPem)) - pub, _ := x509.ParsePKIXPublicKey(block.Bytes) + + pub, err := x509.ParsePKIXPublicKey(block.Bytes) + + if err != nil { + return util.MakeError(err, "Verify") + } hashed := sha256.New() hashed.Write([]byte(verify)) diff --git a/activitypub/util.go b/activitypub/util.go index f53d8e5..274493f 100644 --- a/activitypub/util.go +++ b/activitypub/util.go @@ -282,6 +282,12 @@ func GetActorByNameFromDB(name string) (Actor, error) { return nActor, util.MakeError(err, "GetActorByNameFromDB") } + nActor.PublicKey, err = GetActorPemFromDB(publicKeyPem) + + if err != nil { + return nActor, util.MakeError(err, "GetActorFromDB") + } + if nActor.Id != "" && nActor.PublicKey.PublicKeyPem == "" { if err := CreatePublicKeyFromPrivate(&nActor, publicKeyPem); err != nil { return nActor, util.MakeError(err, "GetActorByNameFromDB") @@ -345,7 +351,7 @@ func GetActorFromDB(id string) (Actor, error) { err := config.DB.QueryRow(query, id).Scan(&nActor.Type, &nActor.Id, &nActor.Name, &nActor.PreferredUsername, &nActor.Inbox, &nActor.Outbox, &nActor.Following, &nActor.Followers, &nActor.Restricted, &nActor.Summary, &publicKeyPem) if err != nil { - return nActor, util.MakeError(err, "GetActorFromDB") + return nActor, nil } nActor.PublicKey, err = GetActorPemFromDB(publicKeyPem) diff --git a/activitypub/webfinger.go b/activitypub/webfinger.go index 276a791..8dce506 100644 --- a/activitypub/webfinger.go +++ b/activitypub/webfinger.go @@ -122,20 +122,22 @@ func FingerRequest(actor string, instance string) (*http.Response, error) { if len(finger.Links) > 0 { for _, e := range finger.Links { if e.Type == "application/activity+json" { - req, err := http.NewRequest("GET", e.Href, nil) + req, err = http.NewRequest("GET", e.Href, nil) if err != nil { return resp, util.MakeError(err, "FingerRequest") } - req.Header.Set("Accept", config.ActivityStreams) - resp, _ := util.RouteProxy(req) - - return resp, nil + break } } } + req.Header.Set("Accept", config.ActivityStreams) + if resp, err = util.RouteProxy(req); err != nil { + return resp, util.MakeError(err, "FingerRequest") + } + return resp, nil } |