X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fpeertube-crypto.ts;h=5c182961d4a8a41e1413ea1d33bc99df1a191178;hb=8b60488020883c66d3831eacd030893ab184268f;hp=6d50e446f59a124488f2eb392e3212142d426e69;hpb=e4f97babf701481b55cc10fb3448feab5f97c867;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index 6d50e446f..5c182961d 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -1,20 +1,8 @@ -import * as jsig from 'jsonld-signatures' - -import { - PRIVATE_RSA_KEY_SIZE, - BCRYPT_SALT_SIZE -} from '../initializers' -import { - bcryptComparePromise, - bcryptGenSaltPromise, - bcryptHashPromise, - createPrivateKey, - getPublicKey, - jsonldSignPromise, - jsonldVerifyPromise -} from './core-utils' +import { BCRYPT_SALT_SIZE, PRIVATE_RSA_KEY_SIZE } from '../initializers' +import { ActorModel } from '../models/activitypub/actor' +import { bcryptComparePromise, bcryptGenSaltPromise, bcryptHashPromise, createPrivateKey, getPublicKey } from './core-utils' +import { jsig } from './custom-jsonld-signature' import { logger } from './logger' -import { AccountInstance } from '../models/account/account-interface' async function createPrivateAndPublicKeys () { logger.info('Generating a RSA key...') @@ -25,18 +13,18 @@ async function createPrivateAndPublicKeys () { return { privateKey: key, publicKey } } -function isSignatureVerified (fromAccount: AccountInstance, signedDocument: object) { +function isSignatureVerified (fromActor: ActorModel, signedDocument: object) { const publicKeyObject = { '@context': jsig.SECURITY_CONTEXT_URL, - '@id': fromAccount.url, + '@id': fromActor.url, '@type': 'CryptographicKey', - owner: fromAccount.url, - publicKeyPem: fromAccount.publicKey + owner: fromActor.url, + publicKeyPem: fromActor.publicKey } const publicKeyOwnerObject = { '@context': jsig.SECURITY_CONTEXT_URL, - '@id': fromAccount.url, + '@id': fromActor.url, publicKey: [ publicKeyObject ] } @@ -45,20 +33,21 @@ function isSignatureVerified (fromAccount: AccountInstance, signedDocument: obje publicKeyOwner: publicKeyOwnerObject } - return jsonldVerifyPromise(signedDocument, options) + return jsig.promises.verify(signedDocument, options) .catch(err => { - logger.error('Cannot check signature.', err) + logger.error('Cannot check signature.', { err }) return false }) } -function signObject (byAccount: AccountInstance, data: any) { +function signObject (byActor: ActorModel, data: any) { const options = { - privateKeyPem: byAccount.privateKey, - creator: byAccount.url + privateKeyPem: byActor.privateKey, + creator: byActor.url, + algorithm: 'RsaSignature2017' } - return jsonldSignPromise(data, options) + return jsig.promises.sign(data, options) } function comparePassword (plainPassword: string, hashPassword: string) {