Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Signature Algorithm #2501

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading