summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAcid Chicken (硫酸鶏) <root@acid-chicken.com>2019-02-01 19:59:12 +0900
committerAya Morisawa <AyaMorisawa4869@gmail.com>2019-02-01 19:59:12 +0900
commit40e177fa9639b1c62184a41cd9d64eecfa527f45 (patch)
tree3e5a95006e080c3fd31d750856b363264815ef70 /src
parentCreate type definition for 'deepcopy' (#4000) (diff)
downloadsharkey-40e177fa9639b1c62184a41cd9d64eecfa527f45.tar.gz
sharkey-40e177fa9639b1c62184a41cd9d64eecfa527f45.tar.bz2
sharkey-40e177fa9639b1c62184a41cd9d64eecfa527f45.zip
Create type definition for 'http-signature' (#4049)
* Create type definition for 'http-signature' * Follow lint
Diffstat (limited to 'src')
-rw-r--r--src/@types/http-signature.d.ts75
-rw-r--r--src/queue/processors/http/process-inbox.ts2
-rw-r--r--src/remote/activitypub/request.ts2
-rw-r--r--src/server/activitypub.ts2
4 files changed, 78 insertions, 3 deletions
diff --git a/src/@types/http-signature.d.ts b/src/@types/http-signature.d.ts
new file mode 100644
index 0000000000..6366b2addd
--- /dev/null
+++ b/src/@types/http-signature.d.ts
@@ -0,0 +1,75 @@
+declare module 'http-signature' {
+ import { IncomingMessage, ClientRequest } from 'http';
+
+ interface ISignature {
+ keyId: string;
+ algorithm: string;
+ headers: string[];
+ signature: string;
+ }
+
+ interface IOptions {
+ headers?: string[];
+ algorithm?: string;
+ strict?: boolean;
+ authorizationHeaderName?: string;
+ }
+
+ interface IParseRequestOptions extends IOptions {
+ clockSkew?: number;
+ }
+
+ interface IParsedSignature {
+ scheme: string;
+ params: ISignature;
+ signingString: string;
+ }
+
+ type RequestSignerConstructorOptions =
+ IRequestSignerConstructorOptionsFromProperties |
+ IRequestSignerConstructorOptionsFromFunction;
+
+ interface IRequestSignerConstructorOptionsFromProperties {
+ keyId: string;
+ key: string | Buffer;
+ algorithm?: string;
+ }
+
+ interface IRequestSignerConstructorOptionsFromFunction {
+ sign?: (data: string, cb: (err: any, sig: ISignature) => void) => void;
+ }
+
+ class RequestSigner {
+ constructor(options: RequestSignerConstructorOptions);
+
+ public writeHeader(header: string, value: string): string;
+
+ public writeDateHeader(): string;
+
+ public writeTarget(method: string, path: string): void;
+
+ public sign(cb: (err: any, authz: string) => void): void;
+ }
+
+ interface ISignRequestOptions extends IOptions {
+ keyId: string;
+ key: string;
+ httpVersion?: string;
+ }
+
+ export function parse(request: IncomingMessage, options?: IParseRequestOptions): IParsedSignature;
+ export function parseRequest(request: IncomingMessage, options?: IParseRequestOptions): IParsedSignature;
+
+ export function sign(request: ClientRequest, options: ISignRequestOptions): boolean;
+ export function signRequest(request: ClientRequest, options: ISignRequestOptions): boolean;
+ export function createSigner(): RequestSigner;
+ export function isSigner(obj: any): obj is RequestSigner;
+
+ export function sshKeyToPEM(key: string): string;
+ export function sshKeyFingerprint(key: string): string;
+ export function pemToRsaSSHKey(pem: string, comment: string): string;
+
+ export function verify(parsedSignature: IParsedSignature, pubkey: string | Buffer): boolean;
+ export function verifySignature(parsedSignature: IParsedSignature, pubkey: string | Buffer): boolean;
+ export function verifyHMAC(parsedSignature: IParsedSignature, secret: string): boolean;
+}
diff --git a/src/queue/processors/http/process-inbox.ts b/src/queue/processors/http/process-inbox.ts
index 1ab5f094ee..32ac7aebd7 100644
--- a/src/queue/processors/http/process-inbox.ts
+++ b/src/queue/processors/http/process-inbox.ts
@@ -1,7 +1,7 @@
import * as bq from 'bee-queue';
import * as debug from 'debug';
-const httpSignature = require('http-signature');
+import * as httpSignature from 'http-signature';
import parseAcct from '../../../misc/acct/parse';
import User, { IRemoteUser } from '../../../models/user';
import perform from '../../../remote/activitypub/perform';
diff --git a/src/remote/activitypub/request.ts b/src/remote/activitypub/request.ts
index 9baab83740..366d7e19a4 100644
--- a/src/remote/activitypub/request.ts
+++ b/src/remote/activitypub/request.ts
@@ -1,5 +1,5 @@
import { request } from 'https';
-const { sign } = require('http-signature');
+import { sign } from 'http-signature';
import { URL } from 'url';
import * as debug from 'debug';
import * as crypto from 'crypto';
diff --git a/src/server/activitypub.ts b/src/server/activitypub.ts
index 30dc6395e0..20a8ee9794 100644
--- a/src/server/activitypub.ts
+++ b/src/server/activitypub.ts
@@ -1,7 +1,7 @@
import { ObjectID } from 'mongodb';
import * as Router from 'koa-router';
const json = require('koa-json-body');
-const httpSignature = require('http-signature');
+import * as httpSignature from 'http-signature';
import { createHttpJob } from '../queue';
import { renderActivity } from '../remote/activitypub/renderer';