Add signature to remote note lookup
This commit is contained in:
parent
80e90c7985
commit
d9fc2c061d
3 changed files with 13 additions and 2 deletions
|
@ -3,6 +3,7 @@ import { getUserKeypair } from "@/misc/keypair-store.js";
|
||||||
import type { User } from "@/models/entities/user.js";
|
import type { User } from "@/models/entities/user.js";
|
||||||
import { getResponse } from "../../misc/fetch.js";
|
import { getResponse } from "../../misc/fetch.js";
|
||||||
import { createSignedPost, createSignedGet } from "./ap-request.js";
|
import { createSignedPost, createSignedGet } from "./ap-request.js";
|
||||||
|
import { apLogger } from "@/remote/activitypub/logger.js";
|
||||||
|
|
||||||
export default async (user: { id: User["id"] }, url: string, object: any) => {
|
export default async (user: { id: User["id"] }, url: string, object: any) => {
|
||||||
const body = JSON.stringify(object);
|
const body = JSON.stringify(object);
|
||||||
|
@ -35,6 +36,7 @@ export default async (user: { id: User["id"] }, url: string, object: any) => {
|
||||||
* @param url URL to fetch
|
* @param url URL to fetch
|
||||||
*/
|
*/
|
||||||
export async function signedGet(url: string, user: { id: User["id"] }) {
|
export async function signedGet(url: string, user: { id: User["id"] }) {
|
||||||
|
apLogger.debug("running signedGet on url: " + url);
|
||||||
const keypair = await getUserKeypair(user.id);
|
const keypair = await getUserKeypair(user.id);
|
||||||
|
|
||||||
const req = createSignedGet({
|
const req = createSignedGet({
|
||||||
|
|
|
@ -23,6 +23,7 @@ import renderCreate from "@/remote/activitypub/renderer/create.js";
|
||||||
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
||||||
import renderFollow from "@/remote/activitypub/renderer/follow.js";
|
import renderFollow from "@/remote/activitypub/renderer/follow.js";
|
||||||
import { shouldBlockInstance } from "@/misc/should-block-instance.js";
|
import { shouldBlockInstance } from "@/misc/should-block-instance.js";
|
||||||
|
import { apLogger } from "@/remote/activitypub/logger.js";
|
||||||
|
|
||||||
export default class Resolver {
|
export default class Resolver {
|
||||||
private history: Set<string>;
|
private history: Set<string>;
|
||||||
|
@ -34,6 +35,10 @@ export default class Resolver {
|
||||||
this.recursionLimit = recursionLimit;
|
this.recursionLimit = recursionLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setUser(user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
public getHistory(): string[] {
|
public getHistory(): string[] {
|
||||||
return Array.from(this.history);
|
return Array.from(this.history);
|
||||||
}
|
}
|
||||||
|
@ -102,6 +107,9 @@ export default class Resolver {
|
||||||
this.user = await getInstanceActor();
|
this.user = await getInstanceActor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apLogger.debug("getting object from remote, authenticated as user:");
|
||||||
|
apLogger.debug(JSON.stringify(this.user, null, 2));
|
||||||
|
|
||||||
const object = (
|
const object = (
|
||||||
this.user
|
this.user
|
||||||
? await signedGet(value, this.user)
|
? await signedGet(value, this.user)
|
||||||
|
|
|
@ -127,6 +127,7 @@ async function fetchAny(
|
||||||
|
|
||||||
// fetching Object once from remote
|
// fetching Object once from remote
|
||||||
const resolver = new Resolver();
|
const resolver = new Resolver();
|
||||||
|
resolver.setUser(me);
|
||||||
const object = await resolver.resolve(uri);
|
const object = await resolver.resolve(uri);
|
||||||
|
|
||||||
// /@user If a URI other than the id is specified,
|
// /@user If a URI other than the id is specified,
|
||||||
|
@ -144,8 +145,8 @@ async function fetchAny(
|
||||||
|
|
||||||
return await mergePack(
|
return await mergePack(
|
||||||
me,
|
me,
|
||||||
isActor(object) ? await createPerson(getApId(object)) : null,
|
isActor(object) ? await createPerson(getApId(object), resolver) : null,
|
||||||
isPost(object) ? await createNote(getApId(object), undefined, true) : null,
|
isPost(object) ? await createNote(getApId(object), resolver, true) : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue