X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fpeertube-crypto.ts;h=313c12e26fe07f78b1bca2db159602037fdcb05d;hb=0405ab52dc0f445b88f8de76e30d6e6719196023;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..313c12e26 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 ] } @@ -49,10 +40,11 @@ function isSignatureVerified (fromAccount: AccountInstance, signedDocument: obje }) } -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)