chore: format
This commit is contained in:
parent
3272b908c6
commit
2f7b3070ee
@ -116,7 +116,9 @@ export default async (job: Bull.Job<InboxJobData>): Promise<string> => {
|
||||
}
|
||||
|
||||
if (httpSignatureValidated) {
|
||||
if (!verifySignature(signature, authUser.key)) return `skip: Invalid HTTP signature`;
|
||||
if (!verifySignature(signature, authUser.key)) {
|
||||
return "skip: Invalid HTTP signature";
|
||||
}
|
||||
}
|
||||
|
||||
// また、signatureのsignerは、activity.actorと一致する必要がある
|
||||
|
@ -36,7 +36,9 @@ export async function checkFetch(req: IncomingMessage): Promise<number> {
|
||||
let signature;
|
||||
|
||||
try {
|
||||
signature = httpSignature.parseRequest(req, { headers: ["(request-target)", "host", "date"] });
|
||||
signature = httpSignature.parseRequest(req, {
|
||||
headers: ["(request-target)", "host", "date"],
|
||||
});
|
||||
} catch (e) {
|
||||
return 401;
|
||||
}
|
||||
@ -138,21 +140,38 @@ export async function getSignatureUser(req: IncomingMessage): Promise<{
|
||||
return await dbResolver.getAuthUserFromApId(getApId(keyId.toString()));
|
||||
}
|
||||
|
||||
export function verifySignature(sig: IParsedSignature, key: UserPublickey): boolean {
|
||||
if (!['hs2019', 'rsa-sha256'].includes(sig.algorithm.toLowerCase())) return false;
|
||||
export function verifySignature(
|
||||
sig: IParsedSignature,
|
||||
key: UserPublickey,
|
||||
): boolean {
|
||||
if (!["hs2019", "rsa-sha256"].includes(sig.algorithm.toLowerCase()))
|
||||
return false;
|
||||
try {
|
||||
return verify('rsa-sha256', Buffer.from(sig.signingString, 'utf8'), key.keyPem, Buffer.from(sig.params.signature, 'base64'));
|
||||
}
|
||||
catch {
|
||||
return verify(
|
||||
"rsa-sha256",
|
||||
Buffer.from(sig.signingString, "utf8"),
|
||||
key.keyPem,
|
||||
Buffer.from(sig.params.signature, "base64"),
|
||||
);
|
||||
} catch {
|
||||
// Algo not supported
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function verifyDigest(body: string, digest: string | string[] | undefined): boolean {
|
||||
export function verifyDigest(
|
||||
body: string,
|
||||
digest: string | string[] | undefined,
|
||||
): boolean {
|
||||
digest = toSingle(digest);
|
||||
if (body == null || digest == null || !digest.toLowerCase().startsWith('sha-256='))
|
||||
if (
|
||||
body == null ||
|
||||
digest == null ||
|
||||
!digest.toLowerCase().startsWith("sha-256=")
|
||||
)
|
||||
return false;
|
||||
|
||||
return createHash('sha256').update(body).digest('base64') === digest.substring(8);
|
||||
return (
|
||||
createHash("sha256").update(body).digest("base64") === digest.substring(8)
|
||||
);
|
||||
}
|
||||
|
@ -50,7 +50,9 @@ function inbox(ctx: Router.RouterContext) {
|
||||
let signature;
|
||||
|
||||
try {
|
||||
signature = httpSignature.parseRequest(ctx.req, { headers: ['(request-target)', 'digest', 'host', 'date'] });
|
||||
signature = httpSignature.parseRequest(ctx.req, {
|
||||
headers: ["(request-target)", "digest", "host", "date"],
|
||||
});
|
||||
} catch (e) {
|
||||
ctx.status = 401;
|
||||
return;
|
||||
@ -93,8 +95,7 @@ async function parseJsonBodyOrFail(ctx: Router.RouterContext, next: Koa.Next) {
|
||||
|
||||
try {
|
||||
await koaBodyParser(ctx, next);
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
ctx.status = 400;
|
||||
return;
|
||||
}
|
||||
|
@ -25,8 +25,7 @@ const assets = `${_dirname}/../../server/file/assets/`;
|
||||
const MAX_BYTE_RANGES = 10;
|
||||
|
||||
const commonReadableHandlerGenerator =
|
||||
(ctx: Koa.Context) =>
|
||||
(e: Error): void => {
|
||||
(ctx: Koa.Context) => (e: Error): void => {
|
||||
serverLogger.error(e);
|
||||
ctx.status = 500;
|
||||
ctx.set("Cache-Control", "max-age=300");
|
||||
|
Loading…
Reference in New Issue
Block a user