aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-07-07 16:57:28 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-07-07 18:23:18 +0200
commit709756b8e183f67ef9bf8f7bc149af4736260350 (patch)
treedc5e52878a6f56c69a4589e058e830c57b025a05 /server/helpers
parent18c8e945089bff49d2c617c411c8a8f4575989ad (diff)
downloadPeerTube-709756b8e183f67ef9bf8f7bc149af4736260350.tar.gz
PeerTube-709756b8e183f67ef9bf8f7bc149af4736260350.tar.zst
PeerTube-709756b8e183f67ef9bf8f7bc149af4736260350.zip
Async signature and various fixes
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/peertube-crypto.ts13
-rw-r--r--server/helpers/requests.ts36
2 files changed, 22 insertions, 27 deletions
diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts
index 8e8001cd6..0c73e8539 100644
--- a/server/helpers/peertube-crypto.ts
+++ b/server/helpers/peertube-crypto.ts
@@ -1,5 +1,5 @@
1import * as crypto from 'crypto' 1import * as crypto from 'crypto'
2import * as fs from 'fs' 2import * as Promise from 'bluebird'
3import { join } from 'path' 3import { join } from 'path'
4 4
5import { 5import {
@@ -52,18 +52,15 @@ function sign (data: string|Object) {
52 dataString = JSON.stringify(data) 52 dataString = JSON.stringify(data)
53 } catch (err) { 53 } catch (err) {
54 logger.error('Cannot sign data.', { error: err }) 54 logger.error('Cannot sign data.', { error: err })
55 return '' 55 return Promise.resolve('')
56 } 56 }
57 } 57 }
58 58
59 sign.update(dataString, 'utf8') 59 sign.update(dataString, 'utf8')
60 60
61 // TODO: make async 61 return getMyPrivateCert().then(myKey => {
62 const certPath = join(CONFIG.STORAGE.CERT_DIR, PRIVATE_CERT_NAME) 62 return sign.sign(myKey, SIGNATURE_ENCODING)
63 const myKey = fs.readFileSync(certPath) 63 })
64 const signature = sign.sign(myKey.toString(), SIGNATURE_ENCODING)
65
66 return signature
67} 64}
68 65
69function comparePassword (plainPassword: string, hashPassword: string) { 66function comparePassword (plainPassword: string, hashPassword: string) {
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts
index b31074373..183f6df0d 100644
--- a/server/helpers/requests.ts
+++ b/server/helpers/requests.ts
@@ -33,7 +33,6 @@ type MakeSecureRequestParams = {
33 method: 'GET'|'POST' 33 method: 'GET'|'POST'
34 toPod: PodInstance 34 toPod: PodInstance
35 path: string 35 path: string
36 sign: boolean
37 data?: Object 36 data?: Object
38} 37}
39function makeSecureRequest (params: MakeSecureRequestParams) { 38function makeSecureRequest (params: MakeSecureRequestParams) {
@@ -47,31 +46,30 @@ function makeSecureRequest (params: MakeSecureRequestParams) {
47 return rej(new Error('Cannot make a secure request with a non POST method.')) 46 return rej(new Error('Cannot make a secure request with a non POST method.'))
48 } 47 }
49 48
50 // Add signature if it is specified in the params 49 const host = CONFIG.WEBSERVER.HOST
51 if (params.sign === true) {
52 const host = CONFIG.WEBSERVER.HOST
53 50
54 let dataToSign 51 let dataToSign
55 if (params.data) { 52 if (params.data) {
56 dataToSign = params.data 53 dataToSign = params.data
57 } else { 54 } else {
58 // We do not have data to sign so we just take our host 55 // We do not have data to sign so we just take our host
59 // It is not ideal but the connection should be in HTTPS 56 // It is not ideal but the connection should be in HTTPS
60 dataToSign = host 57 dataToSign = host
61 } 58 }
62 59
60 sign(dataToSign).then(signature => {
63 requestParams.json['signature'] = { 61 requestParams.json['signature'] = {
64 host, // Which host we pretend to be 62 host, // Which host we pretend to be
65 signature: sign(dataToSign) 63 signature
66 } 64 }
67 }
68 65
69 // If there are data informations 66 // If there are data informations
70 if (params.data) { 67 if (params.data) {
71 requestParams.json['data'] = params.data 68 requestParams.json['data'] = params.data
72 } 69 }
73 70
74 request.post(requestParams, (err, response, body) => err ? rej(err) : res({ response, body })) 71 request.post(requestParams, (err, response, body) => err ? rej(err) : res({ response, body }))
72 })
75 }) 73 })
76} 74}
77 75