X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fpeertube-crypto.ts;h=5c182961d4a8a41e1413ea1d33bc99df1a191178;hb=9a515f76ef1478927408ca411fe9d2152ebc096c;hp=c61abfa8e70f43fd23c1965ae4b005054f149d35;hpb=9a27cdc27c900feaae5f6db4315c4ccdfc0c4493;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index c61abfa8e..5c182961d 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -1,17 +1,8 @@ -import { - PRIVATE_RSA_KEY_SIZE, - BCRYPT_SALT_SIZE -} from '../initializers' -import { - bcryptComparePromise, - bcryptGenSaltPromise, - bcryptHashPromise, - createPrivateKey, - getPublicKey -} from './core-utils' -import { logger } from './logger' -import { AccountInstance } from '../models/account/account-interface' +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' async function createPrivateAndPublicKeys () { logger.info('Generating a RSA key...') @@ -22,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 ] } @@ -44,15 +35,16 @@ function isSignatureVerified (fromAccount: AccountInstance, signedDocument: obje 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 jsig.promises.sign(data, options)