From 77ee1329837d2fb087089ff9f7ac1c58ef645e68 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 15 Apr 2020 12:55:16 -0400 Subject: [PATCH] Fix errors on actors missing public keys --- lib/activitypub/activity.ts | 4 ++-- lib/activitypub/federate.ts | 4 +++- lib/activitypub/middleware/http-signature.ts | 2 +- lib/entity/Actor.ts | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/activitypub/activity.ts b/lib/activitypub/activity.ts index fc2df0b..67e7513 100644 --- a/lib/activitypub/activity.ts +++ b/lib/activitypub/activity.ts @@ -56,8 +56,8 @@ export interface ActorObject { endpoints?: { sharedInbox?: string; } - publicKey: { - publicKeyPem: string; + publicKey?: { + publicKeyPem?: string; }; icon: string | object | (string | object)[]; } diff --git a/lib/activitypub/federate.ts b/lib/activitypub/federate.ts index de6f991..3746f4b 100644 --- a/lib/activitypub/federate.ts +++ b/lib/activitypub/federate.ts @@ -67,7 +67,9 @@ async function cacheActor(actorObject: ActorObject) { actor.displayName = actorObject.name; actor.inbox = actorObject.inbox; actor.iconURL = iconURL; - actor.publicKeyPem = actorObject.publicKey.publicKeyPem; + if (actorObject.publicKey && actorObject.publicKey.publicKeyPem) { + actor.publicKeyPem = actorObject.publicKey.publicKeyPem; + } actor.isFollower = false; await getConnection().manager.save(actor); } diff --git a/lib/activitypub/middleware/http-signature.ts b/lib/activitypub/middleware/http-signature.ts index 4f583b8..f614ec4 100644 --- a/lib/activitypub/middleware/http-signature.ts +++ b/lib/activitypub/middleware/http-signature.ts @@ -25,7 +25,7 @@ export = async (req: Request, res: Response, next: NextFunction) => { console.log(`Could not retrieve actor ${req.body.actor} to validate HTTP signature for`, req.body); res.status(401).end("Could not retrieve actor to validate HTTP signature"); } - } else if (!validate(req, actor.publicKey.publicKeyPem)) { + } else if (!actor.publicKey || !actor.publicKey.publicKeyPem || !validate(req, actor.publicKey.publicKeyPem)) { console.log(`Could not validate HTTP signature for ${req.body.actor}`); res.status(401).end("Could not validate HTTP signature"); } else { diff --git a/lib/entity/Actor.ts b/lib/entity/Actor.ts index 4e4e7c7..708d40b 100644 --- a/lib/entity/Actor.ts +++ b/lib/entity/Actor.ts @@ -23,8 +23,8 @@ export default class Actor { @Column() iconURL: string; - @Column() - publicKeyPem: string; + @Column({ nullable: true }) + publicKeyPem: string | null; @OneToMany(type => Note, note => note.actor) notes: Note[];