diff options
Diffstat (limited to 'server/helpers/peertube-crypto.ts')
-rw-r--r-- | server/helpers/peertube-crypto.ts | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index bc6f1d074..66060bde2 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts | |||
@@ -1,16 +1,16 @@ | |||
1 | import { compare, genSalt, hash } from 'bcrypt' | ||
2 | import { createSign, createVerify } from 'crypto' | ||
1 | import { Request } from 'express' | 3 | import { Request } from 'express' |
4 | import { cloneDeep } from 'lodash' | ||
2 | import { BCRYPT_SALT_SIZE, HTTP_SIGNATURE, PRIVATE_RSA_KEY_SIZE } from '../initializers/constants' | 5 | import { BCRYPT_SALT_SIZE, HTTP_SIGNATURE, PRIVATE_RSA_KEY_SIZE } from '../initializers/constants' |
6 | import { MActor } from '../types/models' | ||
3 | import { createPrivateKey, getPublicKey, promisify1, promisify2, sha256 } from './core-utils' | 7 | import { createPrivateKey, getPublicKey, promisify1, promisify2, sha256 } from './core-utils' |
4 | import { jsonld } from './custom-jsonld-signature' | 8 | import { jsonld } from './custom-jsonld-signature' |
5 | import { logger } from './logger' | 9 | import { logger } from './logger' |
6 | import { cloneDeep } from 'lodash' | ||
7 | import { createSign, createVerify } from 'crypto' | ||
8 | import * as bcrypt from 'bcrypt' | ||
9 | import { MActor } from '../types/models' | ||
10 | 10 | ||
11 | const bcryptComparePromise = promisify2<any, string, boolean>(bcrypt.compare) | 11 | const bcryptComparePromise = promisify2<any, string, boolean>(compare) |
12 | const bcryptGenSaltPromise = promisify1<number, string>(bcrypt.genSalt) | 12 | const bcryptGenSaltPromise = promisify1<number, string>(genSalt) |
13 | const bcryptHashPromise = promisify2<any, string | number, string>(bcrypt.hash) | 13 | const bcryptHashPromise = promisify2<any, string | number, string>(hash) |
14 | 14 | ||
15 | const httpSignature = require('http-signature') | 15 | const httpSignature = require('http-signature') |
16 | 16 | ||
@@ -129,7 +129,7 @@ export { | |||
129 | 129 | ||
130 | // --------------------------------------------------------------------------- | 130 | // --------------------------------------------------------------------------- |
131 | 131 | ||
132 | function hash (obj: any): Promise<any> { | 132 | function hashObject (obj: any): Promise<any> { |
133 | return jsonld.promises | 133 | return jsonld.promises |
134 | .normalize(obj, { | 134 | .normalize(obj, { |
135 | algorithm: 'URDNA2015', | 135 | algorithm: 'URDNA2015', |
@@ -151,12 +151,12 @@ function createSignatureHash (signature: any) { | |||
151 | delete signatureCopy.id | 151 | delete signatureCopy.id |
152 | delete signatureCopy.signatureValue | 152 | delete signatureCopy.signatureValue |
153 | 153 | ||
154 | return hash(signatureCopy) | 154 | return hashObject(signatureCopy) |
155 | } | 155 | } |
156 | 156 | ||
157 | function createDocWithoutSignatureHash (doc: any) { | 157 | function createDocWithoutSignatureHash (doc: any) { |
158 | const docWithoutSignature = cloneDeep(doc) | 158 | const docWithoutSignature = cloneDeep(doc) |
159 | delete docWithoutSignature.signature | 159 | delete docWithoutSignature.signature |
160 | 160 | ||
161 | return hash(docWithoutSignature) | 161 | return hashObject(docWithoutSignature) |
162 | } | 162 | } |