X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fpeertube-crypto.ts;h=5c182961d4a8a41e1413ea1d33bc99df1a191178;hb=19ca8ca93975d99c16ab94c1526a34be74f63b95;hp=04a8d5681d6be87cc97746a35efff993b5f59413;hpb=efc32059d980c51793e8e9ac0fb6a885a8026f94;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index 04a8d5681..5c182961d 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -1,20 +1,8 @@ -import * as jsonld from 'jsonld' -import * as jsig from 'jsonld-signatures' -jsig.use('jsonld', jsonld) - -import { - PRIVATE_RSA_KEY_SIZE, - BCRYPT_SALT_SIZE -} from '../initializers' -import { - bcryptComparePromise, - bcryptGenSaltPromise, - bcryptHashPromise, - createPrivateKey, - getPublicKey -} 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 ] } @@ -47,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)