X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fpeertube-crypto.js;h=610cb16cdbaec505dc0379bb5bfc679fdcaf86d4;hb=b981a525c37d226b3fa59287a6ce338f54583d0c;hp=1ff638b04ecce144a71698c9eaffea2efcef8391;hpb=c4403b29ad4db097af528a7f04eea07e0ed320d0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/peertube-crypto.js b/server/helpers/peertube-crypto.js index 1ff638b04..610cb16cd 100644 --- a/server/helpers/peertube-crypto.js +++ b/server/helpers/peertube-crypto.js @@ -1,7 +1,6 @@ 'use strict' const bcrypt = require('bcrypt') -const crypto = require('crypto') const fs = require('fs') const openssl = require('openssl-wrapper') const ursa = require('ursa') @@ -9,15 +8,11 @@ const ursa = require('ursa') const constants = require('../initializers/constants') const logger = require('./logger') -const algorithm = 'aes-256-ctr' - const peertubeCrypto = { checkSignature, comparePassword, createCertsIfNotExist, cryptPassword, - decrypt, - encrypt, sign } @@ -57,34 +52,6 @@ function cryptPassword (password, callback) { }) } -function decrypt (key, data, callback) { - fs.readFile(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.key.pem', function (err, file) { - if (err) return callback(err) - - const myPrivateKey = ursa.createPrivateKey(file) - const decryptedKey = myPrivateKey.decrypt(key, 'hex', 'utf8') - const decryptedData = symetricDecrypt(data, decryptedKey) - - return callback(null, decryptedData) - }) -} - -function encrypt (publicKey, data, callback) { - const crt = ursa.createPublicKey(publicKey) - - symetricEncrypt(data, function (err, dataEncrypted) { - if (err) return callback(err) - - const key = crt.encrypt(dataEncrypted.password, 'utf8', 'hex') - const encrypted = { - data: dataEncrypted.crypted, - key: key - } - - callback(null, encrypted) - }) -} - function sign (data) { const myKey = ursa.createPrivateKey(fs.readFileSync(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.key.pem')) const signature = myKey.hashAndSign('sha256', data, 'utf8', 'hex') @@ -143,29 +110,3 @@ function createCerts (callback) { }) }) } - -function generatePassword (callback) { - crypto.randomBytes(32, function (err, buf) { - if (err) return callback(err) - - callback(null, buf.toString('utf8')) - }) -} - -function symetricDecrypt (text, password) { - const decipher = crypto.createDecipher(algorithm, password) - let dec = decipher.update(text, 'hex', 'utf8') - dec += decipher.final('utf8') - return dec -} - -function symetricEncrypt (text, callback) { - generatePassword(function (err, password) { - if (err) return callback(err) - - const cipher = crypto.createCipher(algorithm, password) - let crypted = cipher.update(text, 'utf8', 'hex') - crypted += cipher.final('hex') - callback(null, { crypted: crypted, password: password }) - }) -}