X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fpeertube-crypto.ts;h=b8f7c782ae7b88ba88463d14f156d43d65a9dec1;hb=419b520ca4434d17f3505013174e195c3a316716;hp=bc6f1d0748cb0a78615ef396cbd9f95460593426;hpb=903353d67a8d0fdda8465ed6c57b77a9a5afbe92;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index bc6f1d074..b8f7c782a 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -1,18 +1,19 @@ +import { compare, genSalt, hash } from 'bcrypt' +import { createSign, createVerify } from 'crypto' import { Request } from 'express' +import { cloneDeep } from 'lodash' +import { sha256 } from '@shared/extra-utils' import { BCRYPT_SALT_SIZE, HTTP_SIGNATURE, PRIVATE_RSA_KEY_SIZE } from '../initializers/constants' -import { createPrivateKey, getPublicKey, promisify1, promisify2, sha256 } from './core-utils' +import { MActor } from '../types/models' +import { createPrivateKey, getPublicKey, promisify1, promisify2 } from './core-utils' import { jsonld } from './custom-jsonld-signature' import { logger } from './logger' -import { cloneDeep } from 'lodash' -import { createSign, createVerify } from 'crypto' -import * as bcrypt from 'bcrypt' -import { MActor } from '../types/models' -const bcryptComparePromise = promisify2(bcrypt.compare) -const bcryptGenSaltPromise = promisify1(bcrypt.genSalt) -const bcryptHashPromise = promisify2(bcrypt.hash) +const bcryptComparePromise = promisify2(compare) +const bcryptGenSaltPromise = promisify1(genSalt) +const bcryptHashPromise = promisify2(hash) -const httpSignature = require('http-signature') +const httpSignature = require('@peertube/http-signature') async function createPrivateAndPublicKeys () { logger.info('Generating a RSA key...') @@ -129,7 +130,7 @@ export { // --------------------------------------------------------------------------- -function hash (obj: any): Promise { +function hashObject (obj: any): Promise { return jsonld.promises .normalize(obj, { algorithm: 'URDNA2015', @@ -151,12 +152,12 @@ function createSignatureHash (signature: any) { delete signatureCopy.id delete signatureCopy.signatureValue - return hash(signatureCopy) + return hashObject(signatureCopy) } function createDocWithoutSignatureHash (doc: any) { const docWithoutSignature = cloneDeep(doc) delete docWithoutSignature.signature - return hash(docWithoutSignature) + return hashObject(docWithoutSignature) }