X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Fhelpers%2Fpeertube-crypto.ts;h=1d9cab2ce282e86b5f7095098524e608fc0a5eb8;hb=0b6f531653a7a24f82ad65564479a70a9326301a;hp=b8f7c782ae7b88ba88463d14f156d43d65a9dec1;hpb=f304a1580b5ce7b6c5f9e25cd3ddc63ca8d8c6a1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index b8f7c782a..1d9cab2ce 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -5,7 +5,7 @@ import { cloneDeep } from 'lodash' import { sha256 } from '@shared/extra-utils' import { BCRYPT_SALT_SIZE, HTTP_SIGNATURE, PRIVATE_RSA_KEY_SIZE } from '../initializers/constants' import { MActor } from '../types/models' -import { createPrivateKey, getPublicKey, promisify1, promisify2 } from './core-utils' +import { generateRSAKeyPairPromise, promisify1, promisify2 } from './core-utils' import { jsonld } from './custom-jsonld-signature' import { logger } from './logger' @@ -15,13 +15,10 @@ const bcryptHashPromise = promisify2(hash) const httpSignature = require('@peertube/http-signature') -async function createPrivateAndPublicKeys () { +function createPrivateAndPublicKeys () { logger.info('Generating a RSA key...') - const { key } = await createPrivateKey(PRIVATE_RSA_KEY_SIZE) - const { publicKey } = await getPublicKey(key) - - return { privateKey: key, publicKey } + return generateRSAKeyPairPromise(PRIVATE_RSA_KEY_SIZE) } // User password checks @@ -51,11 +48,18 @@ function isHTTPSignatureVerified (httpSignatureParsed: any, actor: MActor): bool } function parseHTTPSignature (req: Request, clockSkew?: number) { - const headers = req.method === 'POST' - ? HTTP_SIGNATURE.REQUIRED_HEADERS.POST - : HTTP_SIGNATURE.REQUIRED_HEADERS.ALL + const requiredHeaders = req.method === 'POST' + ? [ '(request-target)', 'host', 'digest' ] + : [ '(request-target)', 'host' ] + + const parsed = httpSignature.parse(req, { clockSkew, headers: requiredHeaders }) + + const parsedHeaders = parsed.params.headers + if (!parsedHeaders.includes('date') && !parsedHeaders.includes('(created)')) { + throw new Error(`date or (created) must be included in signature`) + } - return httpSignature.parse(req, { clockSkew, headers }) + return parsed } // JSONLD