Skip to content

Commit

Permalink
Check Signature Algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Dec 2, 2023
1 parent 09b401e commit f1e07f4
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"highlight.js": "10.6.0",
"html-minifier": "4.0.0",
"http-proxy-agent": "5.0.0",
"http-signature": "1.3.6",
"@peertube/http-signature": "1.7.0",
"https-proxy-agent": "5.0.1",
"insert-text-at-cursor": "0.3.0",
"ip-cidr": "3.0.11",
Expand Down
30 changes: 15 additions & 15 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 { ILocalUser, User } from '../models/entities/user';
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 perform from '../../remote/activitypub/perform';
import Logger from '../../services/logger';
import { registerOrFetchInstanceDoc } from '../../services/register-or-fetch-instance-doc';
Expand Down
3 changes: 1 addition & 2 deletions src/queue/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//import { ObjectID } from 'mongodb';
import * as httpSignature from 'http-signature';
import * as httpSignature from '@peertube/http-signature';
import { ILocalUser, User } from '../models/entities/user';
import { IActivity } from '../remote/activitypub/type';

Expand Down
14 changes: 13 additions & 1 deletion src/server/activitypub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import config from '../config';
import * as coBody from 'co-body';
import * as crypto from 'crypto';
import { IActivity } from '../remote/activitypub/type';
import * as httpSignature from 'http-signature';
import * as httpSignature from '@peertube/http-signature';
import Logger from '../services/logger';
import { inspect } from 'util';

Expand Down Expand Up @@ -61,6 +61,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
2 changes: 1 addition & 1 deletion test/ap-request.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'assert';
import { genRsaKeyPair } from '../src/misc/gen-key-pair';
import { createSignedPost, createSignedGet } from '../src/remote/activitypub/ap-request';
const httpSignature = require('http-signature');
const httpSignature = require('@peertube/http-signature');

export const buildParsedSignature = (signingString: string, signature: string, algorithm: string) => {
return {
Expand Down

0 comments on commit f1e07f4

Please sign in to comment.