]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/peertube-crypto.ts
Add import http enabled configuration
[github/Chocobozzz/PeerTube.git] / server / helpers / peertube-crypto.ts
index c4c735cb84f6517b6ed4e3cb525c06bf25d01807..5c182961d4a8a41e1413ea1d33bc99df1a191178 100644 (file)
@@ -1,5 +1,5 @@
 import { BCRYPT_SALT_SIZE, PRIVATE_RSA_KEY_SIZE } from '../initializers'
-import { AccountModel } from '../models/account/account'
+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: AccountModel, 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: AccountModel, signedDocument: object)
 
   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: AccountModel, 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)