diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-22 10:43:11 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-22 10:43:11 +0200 |
commit | 5c5e587307a27e173333789b5b5167d35f468b01 (patch) | |
tree | 94e3721caf2e11d38fd5f4112c0fc98da89ac535 /server/helpers/peertube-crypto.ts | |
parent | 1b42d73f44811eec1b7ddd72dd0d640a57c3376c (diff) | |
parent | b5fecbf44192144d1ca27c23a0b53922de288c10 (diff) | |
download | PeerTube-5c5e587307a27e173333789b5b5167d35f468b01.tar.gz PeerTube-5c5e587307a27e173333789b5b5167d35f468b01.tar.zst PeerTube-5c5e587307a27e173333789b5b5167d35f468b01.zip |
Merge branch 'feature/strong-model-types' into develop
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, |