aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-11-27 18:25:35 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-11-27 18:25:35 +0100
commit38d78e5b82a30d1318e3cc2532b7ea22b8e163fa (patch)
tree3c4cdab683caf1e30c6e76ba78efeb0431fec932 /server/helpers
parentbf57d5eebf8b0fa2361b7973ce9772abd1bb4828 (diff)
downloadPeerTube-38d78e5b82a30d1318e3cc2532b7ea22b8e163fa.tar.gz
PeerTube-38d78e5b82a30d1318e3cc2532b7ea22b8e163fa.tar.zst
PeerTube-38d78e5b82a30d1318e3cc2532b7ea22b8e163fa.zip
Server: remove encryption when seending requests to other pods
We don't need it anymore since HTTPS is mandatory now
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/peertube-crypto.js48
-rw-r--r--server/helpers/requests.js17
2 files changed, 2 insertions, 63 deletions
diff --git a/server/helpers/peertube-crypto.js b/server/helpers/peertube-crypto.js
index 1ff638b04..2e07df00e 100644
--- a/server/helpers/peertube-crypto.js
+++ b/server/helpers/peertube-crypto.js
@@ -16,8 +16,6 @@ const peertubeCrypto = {
16 comparePassword, 16 comparePassword,
17 createCertsIfNotExist, 17 createCertsIfNotExist,
18 cryptPassword, 18 cryptPassword,
19 decrypt,
20 encrypt,
21 sign 19 sign
22} 20}
23 21
@@ -57,34 +55,6 @@ function cryptPassword (password, callback) {
57 }) 55 })
58} 56}
59 57
60function decrypt (key, data, callback) {
61 fs.readFile(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.key.pem', function (err, file) {
62 if (err) return callback(err)
63
64 const myPrivateKey = ursa.createPrivateKey(file)
65 const decryptedKey = myPrivateKey.decrypt(key, 'hex', 'utf8')
66 const decryptedData = symetricDecrypt(data, decryptedKey)
67
68 return callback(null, decryptedData)
69 })
70}
71
72function encrypt (publicKey, data, callback) {
73 const crt = ursa.createPublicKey(publicKey)
74
75 symetricEncrypt(data, function (err, dataEncrypted) {
76 if (err) return callback(err)
77
78 const key = crt.encrypt(dataEncrypted.password, 'utf8', 'hex')
79 const encrypted = {
80 data: dataEncrypted.crypted,
81 key: key
82 }
83
84 callback(null, encrypted)
85 })
86}
87
88function sign (data) { 58function sign (data) {
89 const myKey = ursa.createPrivateKey(fs.readFileSync(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.key.pem')) 59 const myKey = ursa.createPrivateKey(fs.readFileSync(constants.CONFIG.STORAGE.CERT_DIR + 'peertube.key.pem'))
90 const signature = myKey.hashAndSign('sha256', data, 'utf8', 'hex') 60 const signature = myKey.hashAndSign('sha256', data, 'utf8', 'hex')
@@ -151,21 +121,3 @@ function generatePassword (callback) {
151 callback(null, buf.toString('utf8')) 121 callback(null, buf.toString('utf8'))
152 }) 122 })
153} 123}
154
155function symetricDecrypt (text, password) {
156 const decipher = crypto.createDecipher(algorithm, password)
157 let dec = decipher.update(text, 'hex', 'utf8')
158 dec += decipher.final('utf8')
159 return dec
160}
161
162function symetricEncrypt (text, callback) {
163 generatePassword(function (err, password) {
164 if (err) return callback(err)
165
166 const cipher = crypto.createCipher(algorithm, password)
167 let crypted = cipher.update(text, 'utf8', 'hex')
168 crypted += cipher.final('hex')
169 callback(null, { crypted: crypted, password: password })
170 })
171}
diff --git a/server/helpers/requests.js b/server/helpers/requests.js
index 06109ce16..b0cda09fe 100644
--- a/server/helpers/requests.js
+++ b/server/helpers/requests.js
@@ -44,21 +44,8 @@ function makeSecureRequest (params, callback) {
44 44
45 // If there are data informations 45 // If there are data informations
46 if (params.data) { 46 if (params.data) {
47 // Encrypt data 47 requestParams.json.data = params.data
48 if (params.encrypt === true) { 48 request.post(requestParams, callback)
49 peertubeCrypto.encrypt(params.toPod.publicKey, JSON.stringify(params.data), function (err, encrypted) {
50 if (err) return callback(err)
51
52 requestParams.json.data = encrypted.data
53 requestParams.json.key = encrypted.key
54
55 request.post(requestParams, callback)
56 })
57 } else {
58 // No encryption
59 requestParams.json.data = params.data
60 request.post(requestParams, callback)
61 }
62 } else { 49 } else {
63 // No data 50 // No data
64 request.post(requestParams, callback) 51 request.post(requestParams, callback)