aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/peertube-crypto.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-08-15 11:53:26 +0200
committerChocobozzz <me@florianbigard.com>2019-08-19 17:26:35 +0200
commit453e83ea5d81d203ba34bc43cd5c2c750ba40568 (patch)
tree604e02f4343d13a4ba42e1fb7527ba6ab9111712 /server/helpers/peertube-crypto.ts
parent13176a07a95984a53cc59aec5217f2ce9806d1bc (diff)
downloadPeerTube-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.ts9
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'
8import { createVerify } from 'crypto' 8import { createVerify } from 'crypto'
9import { buildDigest } from '../lib/job-queue/handlers/utils/activitypub-http-utils' 9import { buildDigest } from '../lib/job-queue/handlers/utils/activitypub-http-utils'
10import * as bcrypt from 'bcrypt' 10import * as bcrypt from 'bcrypt'
11import { MActor } from '../typings/models'
11 12
12const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare) 13const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare)
13const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt) 14const 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
49function isHTTPSignatureVerified (httpSignatureParsed: any, actor: ActorModel): boolean { 50function 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
59async function isJsonLDSignatureVerified (fromActor: ActorModel, signedDocument: any): Promise<boolean> { 60async 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
96async function isJsonLDRSA2017Verified (fromActor: ActorModel, signedDocument: any) { 97async 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
133function signJsonLDObject (byActor: ActorModel, data: any) { 134function 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,