Skip to content

Commit

Permalink
Tune Signature Algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Dec 2, 2023
1 parent 230ab7c commit 0e2fc00
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"highlight.js": "10.6.0",
"htmlescape": "1.1.1",
"http-proxy-agent": "5.0.0",
"http-signature": "git+https://github.com/mei23/node-http-signature#v1.6.0-mei",
"@peertube/http-signature": "1.7.0",
"https-proxy-agent": "5.0.1",
"insert-text-at-cursor": "0.3.0",
"ioredis": "5.3.2",
Expand Down
36 changes: 17 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/@types/http-signature.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module 'http-signature' {
declare module '@peertube/http-signature' {
import { IncomingMessage, ClientRequest } from 'http';

interface ISignature {
Expand Down
2 changes: 1 addition & 1 deletion src/queue/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as httpSignature from 'http-signature';
import * as httpSignature from '@peertube/http-signature';
import config from '../config';
import { InboxInfo, InboxRequestData, WebpushDeliverJobData } from './types';
import { deliverQueue, webpushDeliverQueue, inboxQueue, inboxLazyQueue, dbQueue } from './queues';
Expand Down
2 changes: 1 addition & 1 deletion src/queue/processors/inbox.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Bull from 'bull';
import * as httpSignature from 'http-signature';
import * as httpSignature from '@peertube/http-signature';
import { IRemoteUser } from '../../models/user';
import perform from '../../remote/activitypub/perform';
import { resolvePerson } from '../../remote/activitypub/models/person';
Expand Down
2 changes: 1 addition & 1 deletion src/queue/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as httpSignature from 'http-signature';
import * as httpSignature from '@peertube/http-signature';
import { IActivity } from '../remote/activitypub/type';
import * as webpush from 'web-push';

Expand Down
14 changes: 13 additions & 1 deletion src/server/activitypub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ObjectID } from 'mongodb';
import * as Router from '@koa/router';
import * as coBody from 'co-body';
import * as crypto from 'crypto';
import * as httpSignature from 'http-signature';
import * as httpSignature from '@peertube/http-signature';

import { renderActivity } from '../remote/activitypub/renderer';
import Note, { INote } from '../models/note';
Expand Down Expand Up @@ -71,6 +71,18 @@ async function inbox(ctx: Router.RouterContext) {
return;
}

// Validate signature algorithm
if (!signature.algorithm.toLowerCase().match(/^((dsa|rsa|ecdsa)-(sha256|sha384|sha512)|ed25519-sha512|hs2019)$/)) {
logger.warn(`inbox: invalid signature algorithm ${signature.algorithm}`);
ctx.status = 401;
ctx.message = 'Invalid Signature Algorithm';
return;

// hs2019
// keyType=ED25519 => ed25519-sha512
// keyType=other => (keyType)-sha256
}

// Digestヘッダーの検証
const digest = ctx.req.headers.digest;

Expand Down

1 comment on commit 0e2fc00

@mei23
Copy link
Owner Author

@mei23 mei23 commented on 0e2fc00 Dec 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTTP Signatureの鍵のアルゴリズムを明確にして調整

鍵: dsa, rsa, ecdsa, ed25519(追加)
署名: md5(削除), sha1(削除), sha256, sha384, sha512

なお、ed25519の場合は常にsha512になります。

hs2019を指定した場合は
ed25519鍵が与えられた場合は、ed25519-sha512として扱い
それ以外は、鍵-sha256として扱います。

空の場合は、rsa-sha256として扱っていたのは削除されます。

Please sign in to comment.