aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/customValidators.js4
-rw-r--r--server/helpers/logger.js10
-rw-r--r--server/helpers/peertubeCrypto.js50
-rw-r--r--server/helpers/requests.js51
-rw-r--r--server/helpers/utils.js4
5 files changed, 58 insertions, 61 deletions
diff --git a/server/helpers/customValidators.js b/server/helpers/customValidators.js
index 20c41f5da..a5ae32780 100644
--- a/server/helpers/customValidators.js
+++ b/server/helpers/customValidators.js
@@ -1,8 +1,8 @@
1'use strict' 1'use strict'
2 2
3var validator = require('validator') 3const validator = require('validator')
4 4
5var customValidators = { 5const customValidators = {
6 eachIsRemoteVideosAddValid: eachIsRemoteVideosAddValid, 6 eachIsRemoteVideosAddValid: eachIsRemoteVideosAddValid,
7 eachIsRemoteVideosRemoveValid: eachIsRemoteVideosRemoveValid, 7 eachIsRemoteVideosRemoveValid: eachIsRemoteVideosRemoveValid,
8 isArray: isArray 8 isArray: isArray
diff --git a/server/helpers/logger.js b/server/helpers/logger.js
index 1c15a0edd..d3fce4cc9 100644
--- a/server/helpers/logger.js
+++ b/server/helpers/logger.js
@@ -1,13 +1,13 @@
1// Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ 1// Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/
2'use strict' 2'use strict'
3 3
4var config = require('config') 4const config = require('config')
5var path = require('path') 5const path = require('path')
6var winston = require('winston') 6const winston = require('winston')
7winston.emitErrs = true 7winston.emitErrs = true
8 8
9var logDir = path.join(__dirname, '..', '..', config.get('storage.logs')) 9const logDir = path.join(__dirname, '..', '..', config.get('storage.logs'))
10var logger = new winston.Logger({ 10const logger = new winston.Logger({
11 transports: [ 11 transports: [
12 new winston.transports.File({ 12 new winston.transports.File({
13 level: 'debug', 13 level: 'debug',
diff --git a/server/helpers/peertubeCrypto.js b/server/helpers/peertubeCrypto.js
index 7e65c43e1..3826ebaf6 100644
--- a/server/helpers/peertubeCrypto.js
+++ b/server/helpers/peertubeCrypto.js
@@ -1,18 +1,18 @@
1'use strict' 1'use strict'
2 2
3var config = require('config') 3const config = require('config')
4var crypto = require('crypto') 4const crypto = require('crypto')
5var fs = require('fs') 5const fs = require('fs')
6var openssl = require('openssl-wrapper') 6const openssl = require('openssl-wrapper')
7var path = require('path') 7const path = require('path')
8var ursa = require('ursa') 8const ursa = require('ursa')
9 9
10var logger = require('./logger') 10const logger = require('./logger')
11 11
12var certDir = path.join(__dirname, '..', '..', config.get('storage.certs')) 12const certDir = path.join(__dirname, '..', '..', config.get('storage.certs'))
13var algorithm = 'aes-256-ctr' 13const algorithm = 'aes-256-ctr'
14 14
15var peertubeCrypto = { 15const peertubeCrypto = {
16 checkSignature: checkSignature, 16 checkSignature: checkSignature,
17 createCertsIfNotExist: createCertsIfNotExist, 17 createCertsIfNotExist: createCertsIfNotExist,
18 decrypt: decrypt, 18 decrypt: decrypt,
@@ -22,8 +22,8 @@ var peertubeCrypto = {
22} 22}
23 23
24function checkSignature (public_key, raw_data, hex_signature) { 24function checkSignature (public_key, raw_data, hex_signature) {
25 var crt = ursa.createPublicKey(public_key) 25 const crt = ursa.createPublicKey(public_key)
26 var is_valid = crt.hashAndVerify('sha256', new Buffer(raw_data).toString('hex'), hex_signature, 'hex') 26 const is_valid = crt.hashAndVerify('sha256', new Buffer(raw_data).toString('hex'), hex_signature, 'hex')
27 return is_valid 27 return is_valid
28} 28}
29 29
@@ -43,22 +43,22 @@ function decrypt (key, data, callback) {
43 fs.readFile(getCertDir() + 'peertube.key.pem', function (err, file) { 43 fs.readFile(getCertDir() + 'peertube.key.pem', function (err, file) {
44 if (err) return callback(err) 44 if (err) return callback(err)
45 45
46 var my_private_key = ursa.createPrivateKey(file) 46 const my_private_key = ursa.createPrivateKey(file)
47 var decrypted_key = my_private_key.decrypt(key, 'hex', 'utf8') 47 const decrypted_key = my_private_key.decrypt(key, 'hex', 'utf8')
48 var decrypted_data = symetricDecrypt(data, decrypted_key) 48 const decrypted_data = symetricDecrypt(data, decrypted_key)
49 49
50 return callback(null, decrypted_data) 50 return callback(null, decrypted_data)
51 }) 51 })
52} 52}
53 53
54function encrypt (public_key, data, callback) { 54function encrypt (public_key, data, callback) {
55 var crt = ursa.createPublicKey(public_key) 55 const crt = ursa.createPublicKey(public_key)
56 56
57 symetricEncrypt(data, function (err, dataEncrypted) { 57 symetricEncrypt(data, function (err, dataEncrypted) {
58 if (err) return callback(err) 58 if (err) return callback(err)
59 59
60 var key = crt.encrypt(dataEncrypted.password, 'utf8', 'hex') 60 const key = crt.encrypt(dataEncrypted.password, 'utf8', 'hex')
61 var encrypted = { 61 const encrypted = {
62 data: dataEncrypted.crypted, 62 data: dataEncrypted.crypted,
63 key: key 63 key: key
64 } 64 }
@@ -72,8 +72,8 @@ function getCertDir () {
72} 72}
73 73
74function sign (data) { 74function sign (data) {
75 var myKey = ursa.createPrivateKey(fs.readFileSync(certDir + 'peertube.key.pem')) 75 const myKey = ursa.createPrivateKey(fs.readFileSync(certDir + 'peertube.key.pem'))
76 var signature = myKey.hashAndSign('sha256', data, 'utf8', 'hex') 76 const signature = myKey.hashAndSign('sha256', data, 'utf8', 'hex')
77 77
78 return signature 78 return signature
79} 79}
@@ -93,7 +93,7 @@ function certsExist (callback) {
93function createCerts (callback) { 93function createCerts (callback) {
94 certsExist(function (exist) { 94 certsExist(function (exist) {
95 if (exist === true) { 95 if (exist === true) {
96 var string = 'Certs already exist.' 96 const string = 'Certs already exist.'
97 logger.warning(string) 97 logger.warning(string)
98 return callback(new Error(string)) 98 return callback(new Error(string))
99 } 99 }
@@ -129,8 +129,8 @@ function generatePassword (callback) {
129} 129}
130 130
131function symetricDecrypt (text, password) { 131function symetricDecrypt (text, password) {
132 var decipher = crypto.createDecipher(algorithm, password) 132 const decipher = crypto.createDecipher(algorithm, password)
133 var dec = decipher.update(text, 'hex', 'utf8') 133 let dec = decipher.update(text, 'hex', 'utf8')
134 dec += decipher.final('utf8') 134 dec += decipher.final('utf8')
135 return dec 135 return dec
136} 136}
@@ -139,8 +139,8 @@ function symetricEncrypt (text, callback) {
139 generatePassword(function (err, password) { 139 generatePassword(function (err, password) {
140 if (err) return callback(err) 140 if (err) return callback(err)
141 141
142 var cipher = crypto.createCipher(algorithm, password) 142 const cipher = crypto.createCipher(algorithm, password)
143 var crypted = cipher.update(text, 'utf8', 'hex') 143 let crypted = cipher.update(text, 'utf8', 'hex')
144 crypted += cipher.final('hex') 144 crypted += cipher.final('hex')
145 callback(null, { crypted: crypted, password: password }) 145 callback(null, { crypted: crypted, password: password })
146 }) 146 })
diff --git a/server/helpers/requests.js b/server/helpers/requests.js
index e19afa5ca..17b1127c0 100644
--- a/server/helpers/requests.js
+++ b/server/helpers/requests.js
@@ -1,19 +1,19 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var config = require('config') 4const config = require('config')
5var request = require('request') 5const request = require('request')
6var replay = require('request-replay') 6const replay = require('request-replay')
7 7
8var constants = require('../initializers/constants') 8const constants = require('../initializers/constants')
9var logger = require('./logger') 9const logger = require('./logger')
10var peertubeCrypto = require('./peertubeCrypto') 10const peertubeCrypto = require('./peertubeCrypto')
11 11
12var http = config.get('webserver.https') ? 'https' : 'http' 12const http = config.get('webserver.https') ? 'https' : 'http'
13var host = config.get('webserver.host') 13const host = config.get('webserver.host')
14var port = config.get('webserver.port') 14const port = config.get('webserver.port')
15 15
16var requests = { 16const requests = {
17 makeMultipleRetryRequest: makeMultipleRetryRequest 17 makeMultipleRetryRequest: makeMultipleRetryRequest
18} 18}
19 19
@@ -23,8 +23,8 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) {
23 callbackEach = null 23 callbackEach = null
24 } 24 }
25 25
26 var url = http + '://' + host + ':' + port 26 const url = http + '://' + host + ':' + port
27 var signature 27 let signature
28 28
29 // Add signature if it is specified in the params 29 // Add signature if it is specified in the params
30 if (all_data.method === 'POST' && all_data.data && all_data.sign === true) { 30 if (all_data.method === 'POST' && all_data.data && all_data.sign === true) {
@@ -43,7 +43,7 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) {
43 } 43 }
44 } 44 }
45 45
46 var params = { 46 const params = {
47 url: pod.url + all_data.path, 47 url: pod.url + all_data.path,
48 method: all_data.method 48 method: all_data.method
49 } 49 }
@@ -52,19 +52,16 @@ function makeMultipleRetryRequest (all_data, pods, callbackEach, callback) {
52 if (all_data.method === 'POST' && all_data.data) { 52 if (all_data.method === 'POST' && all_data.data) {
53 // Encrypt data ? 53 // Encrypt data ?
54 if (all_data.encrypt === true) { 54 if (all_data.encrypt === true) {
55 // TODO: ES6 with let 55 peertubeCrypto.encrypt(pod.publicKey, JSON.stringify(all_data.data), function (err, encrypted) {
56 ;(function (copy_params, copy_url, copy_pod, copy_signature) { 56 if (err) return callback(err)
57 peertubeCrypto.encrypt(pod.publicKey, JSON.stringify(all_data.data), function (err, encrypted) { 57
58 if (err) return callback(err) 58 params.json = {
59 59 data: encrypted.data,
60 copy_params.json = { 60 key: encrypted.key
61 data: encrypted.data, 61 }
62 key: encrypted.key 62
63 } 63 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
64 64 })
65 makeRetryRequest(copy_params, copy_url, copy_pod, copy_signature, callbackEachRetryRequest)
66 })
67 })(params, url, pod, signature)
68 } else { 65 } else {
69 params.json = { data: all_data.data } 66 params.json = { data: all_data.data }
70 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest) 67 makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
diff --git a/server/helpers/utils.js b/server/helpers/utils.js
index d2c9ad8b2..1f7839673 100644
--- a/server/helpers/utils.js
+++ b/server/helpers/utils.js
@@ -1,8 +1,8 @@
1'use strict' 1'use strict'
2 2
3var logger = require('./logger') 3const logger = require('./logger')
4 4
5var utils = { 5const utils = {
6 cleanForExit: cleanForExit 6 cleanForExit: cleanForExit
7} 7}
8 8