X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fpeertube-crypto.ts;h=5c182961d4a8a41e1413ea1d33bc99df1a191178;hb=9a515f76ef1478927408ca411fe9d2152ebc096c;hp=74e4cc703b3641de211adcab14ff7cd47e30ab7f;hpb=8d468a16fd33ec2660c3c59b3f7def53eb0cc4a1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index 74e4cc703..5c182961d 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -1,5 +1,5 @@ import { BCRYPT_SALT_SIZE, PRIVATE_RSA_KEY_SIZE } from '../initializers' -import { AccountInstance } from '../models/account/account-interface' +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' @@ -13,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 ] } @@ -35,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)