diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-15 11:53:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-19 17:26:35 +0200 |
commit | 453e83ea5d81d203ba34bc43cd5c2c750ba40568 (patch) | |
tree | 604e02f4343d13a4ba42e1fb7527ba6ab9111712 /server/helpers/peertube-crypto.ts | |
parent | 13176a07a95984a53cc59aec5217f2ce9806d1bc (diff) | |
download | PeerTube-453e83ea5d81d203ba34bc43cd5c2c750ba40568.tar.gz PeerTube-453e83ea5d81d203ba34bc43cd5c2c750ba40568.tar.zst PeerTube-453e83ea5d81d203ba34bc43cd5c2c750ba40568.zip |
Stronger model typings
Diffstat (limited to 'server/helpers/peertube-crypto.ts')
-rw-r--r-- | server/helpers/peertube-crypto.ts | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index 1424949d0..085cd62c9 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts | |||
@@ -8,6 +8,7 @@ import { cloneDeep } from 'lodash' | |||
8 | import { createVerify } from 'crypto' | 8 | import { createVerify } from 'crypto' |
9 | import { buildDigest } from '../lib/job-queue/handlers/utils/activitypub-http-utils' | 9 | import { buildDigest } from '../lib/job-queue/handlers/utils/activitypub-http-utils' |
10 | import * as bcrypt from 'bcrypt' | 10 | import * as bcrypt from 'bcrypt' |
11 | import { MActor } from '../typings/models' | ||
11 | 12 | ||
12 | const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare) | 13 | const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare) |
13 | const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt) | 14 | const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt) |
@@ -46,7 +47,7 @@ function isHTTPSignatureDigestValid (rawBody: Buffer, req: Request): boolean { | |||
46 | return true | 47 | return true |
47 | } | 48 | } |
48 | 49 | ||
49 | function isHTTPSignatureVerified (httpSignatureParsed: any, actor: ActorModel): boolean { | 50 | function isHTTPSignatureVerified (httpSignatureParsed: any, actor: MActor): boolean { |
50 | return httpSignature.verifySignature(httpSignatureParsed, actor.publicKey) === true | 51 | return httpSignature.verifySignature(httpSignatureParsed, actor.publicKey) === true |
51 | } | 52 | } |
52 | 53 | ||
@@ -56,7 +57,7 @@ function parseHTTPSignature (req: Request, clockSkew?: number) { | |||
56 | 57 | ||
57 | // JSONLD | 58 | // JSONLD |
58 | 59 | ||
59 | async function isJsonLDSignatureVerified (fromActor: ActorModel, signedDocument: any): Promise<boolean> { | 60 | async function isJsonLDSignatureVerified (fromActor: MActor, signedDocument: any): Promise<boolean> { |
60 | if (signedDocument.signature.type === 'RsaSignature2017') { | 61 | if (signedDocument.signature.type === 'RsaSignature2017') { |
61 | // Mastodon algorithm | 62 | // Mastodon algorithm |
62 | const res = await isJsonLDRSA2017Verified(fromActor, signedDocument) | 63 | const res = await isJsonLDRSA2017Verified(fromActor, signedDocument) |
@@ -93,7 +94,7 @@ async function isJsonLDSignatureVerified (fromActor: ActorModel, signedDocument: | |||
93 | } | 94 | } |
94 | 95 | ||
95 | // Backward compatibility with "other" implementations | 96 | // Backward compatibility with "other" implementations |
96 | async function isJsonLDRSA2017Verified (fromActor: ActorModel, signedDocument: any) { | 97 | async function isJsonLDRSA2017Verified (fromActor: MActor, signedDocument: any) { |
97 | function hash (obj: any): Promise<any> { | 98 | function hash (obj: any): Promise<any> { |
98 | return jsonld.promises | 99 | return jsonld.promises |
99 | .normalize(obj, { | 100 | .normalize(obj, { |
@@ -130,7 +131,7 @@ async function isJsonLDRSA2017Verified (fromActor: ActorModel, signedDocument: a | |||
130 | return verify.verify(fromActor.publicKey, signedDocument.signature.signatureValue, 'base64') | 131 | return verify.verify(fromActor.publicKey, signedDocument.signature.signatureValue, 'base64') |
131 | } | 132 | } |
132 | 133 | ||
133 | function signJsonLDObject (byActor: ActorModel, data: any) { | 134 | function signJsonLDObject (byActor: MActor, data: any) { |
134 | const options = { | 135 | const options = { |
135 | privateKeyPem: byActor.privateKey, | 136 | privateKeyPem: byActor.privateKey, |
136 | creator: byActor.url, | 137 | creator: byActor.url, |