Wrap ca_file_name option

This commit is contained in:
Alex Hultman 2019-12-05 21:30:49 +01:00
parent 2c87f3593d
commit d9c86f3e93
2 changed files with 64 additions and 66 deletions

View File

@ -17,7 +17,7 @@ if (isMainThread) {
/* I guess main thread joins by default? */
} else {
/* Here we are inside a worker thread */
const app = uWS./*SSL*/App({
const app = uWS.SSLApp({
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'

View File

@ -256,28 +256,20 @@ template <typename APP>
void uWS_App(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
Local<FunctionTemplate> appTemplate = FunctionTemplate::New(isolate);
appTemplate->SetClassName(String::NewFromUtf8(isolate, std::is_same<APP, uWS::SSLApp>::value ? "uWS.SSLApp" : "uWS.App", NewStringType::kNormal).ToLocalChecked());
APP *app;
/* Read the options object if any */
us_socket_context_options_t options = {};
if (args.Length() == 1) {
Local<Object> optionsObject = Local<Object>::Cast(args[0]);
/* These won't outlive the function, uSockets will have to copy strings it wants to keep! */
std::string keyFileName;
std::string certFileName;
std::string passphrase;
std::string dhParamsFileName;
/* Name differs based on type */
if (std::is_same<APP, uWS::SSLApp>::value) {
appTemplate->SetClassName(String::NewFromUtf8(isolate, "uWS.SSLApp", NewStringType::kNormal).ToLocalChecked());
/* We fill these below */
us_socket_context_options_t ssl_options = {};
/* Read the options object (SSL options) */
if (args.Length() == 1) {
Local<Object> optionsObject = Local<Object>::Cast(args[0]);
std::string caFileName;
/* Key file name */
NativeString keyFileNameValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "key_file_name", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked());
@ -286,7 +278,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
}
if (keyFileNameValue.getString().length()) {
keyFileName = keyFileNameValue.getString();
ssl_options.key_file_name = keyFileName.c_str();
options.key_file_name = keyFileName.c_str();
}
/* Cert file name */
@ -296,7 +288,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
}
if (certFileNameValue.getString().length()) {
certFileName = certFileNameValue.getString();
ssl_options.cert_file_name = certFileName.c_str();
options.cert_file_name = certFileName.c_str();
}
/* Passphrase */
@ -306,7 +298,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
}
if (passphraseValue.getString().length()) {
passphrase = passphraseValue.getString();
ssl_options.passphrase = passphrase.c_str();
options.passphrase = passphrase.c_str();
}
/* DH params file name */
@ -316,19 +308,25 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
}
if (dhParamsFileNameValue.getString().length()) {
dhParamsFileName = dhParamsFileNameValue.getString();
ssl_options.dh_params_file_name = dhParamsFileName.c_str();
options.dh_params_file_name = dhParamsFileName.c_str();
}
/* CA file name */
NativeString caFileNameValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "ca_file_name", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked());
if (caFileNameValue.isInvalid(args)) {
return;
}
if (caFileNameValue.getString().length()) {
caFileName = caFileNameValue.getString();
options.ca_file_name = caFileName.c_str();
}
/* ssl_prefer_low_memory_usage */
ssl_options.ssl_prefer_low_memory_usage = BooleanValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "ssl_prefer_low_memory_usage", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked());
options.ssl_prefer_low_memory_usage = BooleanValue(isolate, optionsObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "ssl_prefer_low_memory_usage", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked());
}
/* uSockets should really copy strings it wants to keep */
app = new APP(ssl_options);
} else {
appTemplate->SetClassName(String::NewFromUtf8(isolate, "uWS.App", NewStringType::kNormal).ToLocalChecked());
app = new APP;
}
/* uSockets copies strings here */
APP *app = new APP(options);
/* Throw if we failed to construct the app */
if (app->constructorFailed()) {