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

Commit b4e5597

Browse files
committed
QUIC agent reads certificate path from configuration file.
1 parent a39c1fa commit b4e5597

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

source/agent/addons/quic/QuicTransportServer.cc

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,8 @@ Nan::Persistent<v8::Function> QuicTransportServer::s_constructor;
2121

2222
DEFINE_LOGGER(QuicTransportServer, "QuicTransportServer");
2323

24-
// TODO: Certificate and key path is hard coded here. Read them from toml file later.
25-
const std::string certPath = "/tmp/certs/leaf_cert.pem";
26-
const std::string keyPath = "/tmp/certs/leaf_cert.pkcs8";
27-
28-
QuicTransportServer::QuicTransportServer(int port, const std::string& certPath, const std::string& keyPath)
29-
: m_quicServer(QuicFactory::getQuicTransportFactory()->CreateQuicTransportServer(port, certPath.c_str(), keyPath.c_str()))
24+
QuicTransportServer::QuicTransportServer(int port, const std::string& pfxPath, const std::string& password)
25+
: m_quicServer(QuicFactory::getQuicTransportFactory()->CreateQuicTransportServer(port, pfxPath.c_str(), password.c_str()))
3026
{
3127
m_quicServer->SetVisitor(this);
3228
ELOG_DEBUG("QuicTransportServer::QuicTransportServer");
@@ -52,12 +48,13 @@ NAN_METHOD(QuicTransportServer::newInstance)
5248
ELOG_DEBUG("Not construct call.");
5349
return;
5450
}
55-
if (info.Length() == 0) {
56-
return Nan::ThrowTypeError("Port is required.");
51+
if (info.Length() < 3) {
52+
return Nan::ThrowTypeError("No enough arguments are provided.");
5753
}
58-
// Default port number is not specified in https://tools.ietf.org/html/draft-vvv-webtransport-quic-01.
59-
int minPort = info[0]->IntegerValue();
60-
QuicTransportServer* obj = new QuicTransportServer(minPort, certPath, keyPath);
54+
int port = info[0]->IntegerValue();
55+
v8::String::Utf8Value pfxPath(Nan::To<v8::String>(info[1]).ToLocalChecked());
56+
v8::String::Utf8Value password(Nan::To<v8::String>(info[2]).ToLocalChecked());
57+
QuicTransportServer* obj = new QuicTransportServer(port, *pfxPath, *password);
6158
obj->Wrap(info.This());
6259
uv_async_init(uv_default_loop(), &obj->m_asyncOnConnection, &QuicTransportServer::onConnectionCallback);
6360
info.GetReturnValue().Set(info.This());

source/agent/addons/quic/QuicTransportServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class QuicTransportServer : public Nan::ObjectWrap, owt::quic::QuicTransportServ
3333
void onClose() override;
3434

3535
QuicTransportServer() = delete;
36-
explicit QuicTransportServer(int port, const std::string& certPath, const std::string& keyPath);
36+
explicit QuicTransportServer(int port, const std::string& pfxPath, const std::string& password);
3737

3838
private:
3939
static NAN_METHOD(newInstance);

source/agent/quic/dist.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"webtransport/test/quicTransportServerTest.js"
3939
],
4040
"cert": [
41+
"../../../cert/certificate.pfx",
4142
"../../../cert/.owt.keystore"
4243
]
4344
}

source/agent/quic/index.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const QuicTransportStreamPipeline =
2323
require('./webtransport/quicTransportStreamPipeline');
2424
const log = logger.getLogger('QuicNode');
2525
const addon = require('./build/Release/quic');
26+
const cipher = require('../cipher');
27+
const path = require('path');
2628

2729
log.info('QUIC transport node.')
2830

@@ -42,20 +44,31 @@ module.exports = function (rpcClient, selfRpcId, parentRpcId, clusterWorkerIP) {
4244
rpcClient.remoteCast(controller, 'onSessionProgress', [sessionId, direction, status]);
4345
};
4446

45-
const quicTransportServer =
46-
new QuicTransportServer(addon, global.config.quic.port);
47-
quicTransportServer.start();
48-
quicTransportServer.on('streamadded', (stream) => {
47+
const keystore = path.resolve(path.dirname(global.config.quic.keystorePath), cipher.kstore);
48+
log.info('before unlock');
49+
cipher.unlock(cipher.k, keystore, (error, password) => {
50+
log.info('unlocked.');
51+
if (error) {
52+
log.error('Failed to read certificate and key.');
53+
return;
54+
}
55+
log.info('path is '+path.resolve(global.config.quic.keystorePath));
56+
const quicTransportServer = new QuicTransportServer(
57+
addon, global.config.quic.port, path.resolve(global.config.quic.keystorePath),
58+
password);
59+
quicTransportServer.start();
60+
quicTransportServer.on('streamadded', (stream) => {
4961
const conn = connections.getConnection(stream.contentSessionId);
5062
if (conn) {
51-
// TODO: verify transport ID.
52-
conn.connection.quicStream(stream);
63+
// TODO: verify transport ID.
64+
conn.connection.quicStream(stream);
5365
} else {
5466
log.warn(
5567
'Cannot find a pipeline for QUIC stream. Content session ID: ' +
5668
stream.contentSessionId);
5769
stream.close();
5870
}
71+
});
5972
});
6073

6174
const createStreamPipeline =

source/agent/quic/webtransport/quicTransportServer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ const zeroUuid = '00000000000000000000000000000000';
2323
const authenticationTimeout = 10;
2424

2525
module.exports = class QuicTransportServer extends EventEmitter {
26-
constructor(addon, port) {
26+
constructor(addon, port, pfxPath, password) {
2727
super();
28-
this._server = new addon.QuicTransportServer(port);
28+
this._server = new addon.QuicTransportServer(port, pfxPath, password);
2929
this._connections = new Map(); // Key is transport ID.
3030
this._streams = new Map(); // Key is content session ID.
3131
this._unAuthenticatedConnections = []; // When it's authenticated, it will be moved to this.connections.

0 commit comments

Comments
 (0)