Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 5a72de2

Browse files
authored
Enable ssl configuration for Internal IO (#888)
* Enable ssl configuration for RawTransport * Add passphrase interface in internalIO addon * Add internal configuration in scripts * Update boost dependency for CentOS * Add document for preparing cert materials
1 parent 89cfb15 commit 5a72de2

File tree

9 files changed

+370
-62
lines changed

9 files changed

+370
-62
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Open WebRTC Toolkit Internal Transport
2+
3+
## How to enable TLS
4+
5+
Place `server.crt`, `server.key`, `dh2048.pem` under `cert` directory.
6+
7+
## OpenSSL example for certificate files
8+
9+
// Generate a private key
10+
openssl genrsa -des3 -out server.key 1024
11+
12+
// Generate Certificate signing request
13+
openssl req -new -key server.key -out server.csr
14+
15+
// Sign certificate with private key
16+
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
17+
18+
// Generate dhparam file
19+
openssl dhparam -out dh2048.pem 2048

scripts/release/initauth.js

Lines changed: 75 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@ readline.on('SIGINT', () => {
2828
readline.close();
2929
});
3030

31-
const question = input => new Promise((resolve) => {
31+
const question = (input) => new Promise((resolve) => {
3232
readline.question(input, (answer) => {
3333
resolve(answer);
3434
});
3535
});
3636

37-
const saveAuth = (obj, filename, cb) => {
37+
const saveAuth = (obj, filename) => new Promise((resolve, reject) => {
3838
const lock = (obj) => {
3939
cipher.lock(cipher.k, obj, filename, (err) => {
40-
process.stdout.write(err || 'done!\n');
41-
cb(err);
40+
if (!err) {
41+
process.stdout.write(err || 'done!\n');
42+
resolve();
43+
} else {
44+
reject(err);
45+
}
4246
});
4347
};
4448
if (fs.existsSync(filename)) {
@@ -47,54 +51,109 @@ const saveAuth = (obj, filename, cb) => {
4751
res = Object.assign(res, obj);
4852
lock(res);
4953
} else {
50-
cb(err);
54+
reject(err);
5155
}
5256
});
5357
} else {
5458
lock(obj);
5559
}
56-
};
60+
});
5761

58-
const updateRabbit = (cb) => {
62+
const updateRabbit = () => new Promise((resolve, reject) => {
5963
question('Update RabbitMQ account?[yes/no]')
6064
.then((answer) => {
6165
answer = answer.toLowerCase();
6266
if (answer !== 'y' && answer !== 'yes') {
63-
cb();
67+
resolve();
6468
return;
6569
}
6670
question(`(${authBase}) Enter username of rabbitmq: `)
6771
.then((username) => {
6872
question(`(${authBase}) Enter password of rabbitmq: `)
6973
.then((password) => {
7074
mutableStdout.muted = false;
71-
saveAuth({ rabbit: { username, password } }, authStore, cb);
75+
saveAuth({ rabbit: { username, password } }, authStore)
76+
.then(resolve)
77+
.catch(reject);
7278
});
7379
mutableStdout.muted = true;
7480
});
7581
});
76-
};
82+
});
7783

78-
const updateMongo = (cb) => {
84+
const updateMongo = () => new Promise((resolve, reject) => {
7985
question('Update MongoDB account?[yes/no]')
8086
.then((answer) => {
8187
answer = answer.toLowerCase();
8288
if (answer !== 'y' && answer !== 'yes') {
83-
cb();
89+
resolve();
8490
return;
8591
}
8692
question(`(${authBase}) Enter username of mongodb: `)
8793
.then((username) => {
8894
question(`(${authBase}) Enter password of mongodb: `)
8995
.then((password) => {
9096
mutableStdout.muted = false;
91-
saveAuth({ mongo: { username, password } }, authStore, cb);
97+
saveAuth({ mongo: { username, password } }, authStore)
98+
.then(resolve)
99+
.catch(reject);
92100
});
93101
mutableStdout.muted = true;
94102
});
95103
});
96-
};
104+
});
97105

98-
updateRabbit(() => {
99-
updateMongo(()=> readline.close())
106+
const updateInternal = () => new Promise((resolve, reject) => {
107+
question('Update internal passphrase?[yes/no]')
108+
.then((answer) => {
109+
answer = answer.toLowerCase();
110+
if (answer !== 'y' && answer !== 'yes') {
111+
resolve();
112+
return;
113+
}
114+
question(`(${authBase}) Enter internal passphrase: `)
115+
.then((passphrase) => {
116+
mutableStdout.muted = false;
117+
saveAuth({ internalPass: passphrase }, authStore)
118+
.then(resolve)
119+
.catch(reject);
120+
});
121+
mutableStdout.muted = true;
122+
});
100123
});
124+
125+
const options = {};
126+
const parseArgs = () => {
127+
if (process.argv.includes('--rabbitmq')) {
128+
options.rabbit = true;
129+
}
130+
if (process.argv.includes('--mongodb')) {
131+
options.mongo = true;
132+
}
133+
if (process.argv.includes('--internal')) {
134+
options.internal = true;
135+
}
136+
if (Object.keys(options).length === 0) {
137+
options.rabbit = true;
138+
options.mongo = true;
139+
}
140+
return Promise.resolve();
141+
}
142+
143+
parseArgs()
144+
.then(() => {
145+
if (options.rabbit) {
146+
return updateRabbit();
147+
}
148+
})
149+
.then(() => {
150+
if (options.mongo) {
151+
return updateMongo();
152+
}
153+
})
154+
.then(() => {
155+
if (options.internal) {
156+
return updateInternal();
157+
}
158+
})
159+
.finally(() => readline.close());

source/agent/InternalConnectionFactory.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ try {
2222

2323
var cf = 'leaf_cert.pem';
2424
var kf = 'leaf_cert.pkcs8';
25+
var cipher;
26+
try {
27+
cipher = require('../cipher');
28+
cipher.unlock(cipher.k, cipher.astore, function cb (err, authConfig) {
29+
if (!err) {
30+
if (authConfig.internalPass) {
31+
internalIO.setPassphrase(authConfig.internalPass);
32+
}
33+
} else {
34+
log.debug('Unlock error:', err);
35+
}
36+
});
37+
} catch (e) {
38+
log.info('Failed to set secure for internal IO');
39+
}
2540

2641
// Wrapper object for sctp-connection and tcp/udp-connection
2742
function InConnection(prot, minport, maxport) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (C) <2019> Intel Corporation
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#ifndef BUILDING_NODE_EXTENSION
6+
#define BUILDING_NODE_EXTENSION
7+
#endif
8+
9+
#include "InternalConfig.h"
10+
#include <RawTransport.h>
11+
12+
using namespace v8;
13+
14+
void setPassphrase(const FunctionCallbackInfo<Value>& args) {
15+
String::Utf8Value param0(args[0]->ToString());
16+
std::string p = std::string(*param0);
17+
owt_base::RawTransport<owt_base::Protocol::TCP>::setPassphrase(p);
18+
}
19+
20+
void InitInternalConfig(v8::Local<v8::Object> exports) {
21+
Isolate* isolate = Isolate::GetCurrent();
22+
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, setPassphrase);
23+
exports->Set(String::NewFromUtf8(isolate, "setPassphrase"), tpl->GetFunction());
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (C) <2019> Intel Corporation
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#ifndef INTERNALCONFIG_H
6+
#define INTERNALCONFIG_H
7+
8+
#include <node.h>
9+
10+
void InitInternalConfig(v8::Local<v8::Object> exports);
11+
12+
#endif

source/agent/addons/internalIO/addon.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "InternalInWrapper.h"
66
#include "InternalOutWrapper.h"
77
#include "InternalIOWrapper.h"
8+
#include "InternalConfig.h"
89

910
#include <node.h>
1011

@@ -15,6 +16,7 @@ void InitAll(Handle<Object> exports) {
1516
InternalOut::Init(exports);
1617
SctpIn::Init(exports);
1718
SctpOut::Init(exports);
19+
InitInternalConfig(exports);
1820
}
1921

2022
NODE_MODULE(addon, InitAll)

source/agent/addons/internalIO/binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'InternalInWrapper.cc',
77
'InternalOutWrapper.cc',
88
'InternalIOWrapper.cc',
9+
'InternalConfig.cc',
910
'../../../core/owt_base/InternalIn.cpp',
1011
'../../../core/owt_base/InternalOut.cpp',
1112
'../../../core/owt_base/InternalSctp.cpp',

0 commit comments

Comments
 (0)