Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tls] add socket parameter, setServername and ALPNprotocols support #3457

Merged
merged 33 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
16778f3
add socket parameter support
cirospaciari Jun 29, 2023
b15c9f2
refactor #socket
cirospaciari Jun 29, 2023
67c6076
add test and more fixs
cirospaciari Jun 29, 2023
2aec815
some fixes
cirospaciari Jun 29, 2023
d0a41be
bump uws
cirospaciari Jun 29, 2023
c90b27a
handlers fix
cirospaciari Jun 29, 2023
3b530ea
more fixes
cirospaciari Jun 30, 2023
7ba0aa3
fix node net and node tls tests
cirospaciari Jun 30, 2023
fa379e4
fix duplicate port
cirospaciari Jun 30, 2023
b411217
fix deinit on CallbackJobs
cirospaciari Jun 30, 2023
8360440
cleanup
cirospaciari Jun 30, 2023
e48d5e2
add setImmediate repro
cirospaciari Jun 30, 2023
ab32393
add test to setImmediate
cirospaciari Jun 30, 2023
94cadc8
this is necessary?
cirospaciari Jun 30, 2023
0d2b833
fix prependOnce on native listener
cirospaciari Jul 1, 2023
e5b4a58
try to findout the error on nodemailer CI
cirospaciari Jul 1, 2023
e26a2cd
show error message
cirospaciari Jul 1, 2023
89357a1
Update bun.lockb
Jarred-Sumner Jul 2, 2023
912f955
prettier
Jarred-Sumner Jul 2, 2023
663db5b
Use exact versions of packages
Jarred-Sumner Jul 2, 2023
b56a0bc
add alpnProtocol support
cirospaciari Jul 2, 2023
6afbc1c
update
cirospaciari Jul 2, 2023
431d4c9
emit error when connect fails on net.Socket
cirospaciari Jul 2, 2023
ca607a6
format
cirospaciari Jul 2, 2023
efc85fc
fix _write and cleanup
cirospaciari Jul 2, 2023
36defad
fixup
cirospaciari Jul 2, 2023
bae9c03
fix connect, add alpn test
cirospaciari Jul 3, 2023
4d2508b
fix socket.io
cirospaciari Jul 3, 2023
c7cd24a
add socket parameter to TLSSocket
cirospaciari Jul 3, 2023
a34520d
add TLSSocket socket first parameter
cirospaciari Jul 3, 2023
68b783e
fixup and _start
cirospaciari Jul 3, 2023
7c49b26
remove flask tests
cirospaciari Jul 3, 2023
163f985
fmt
cirospaciari Jul 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/bun.js/api/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3794,6 +3794,8 @@ pub const Timer = struct {
result.then(globalThis, this, CallbackJob__onResolve, CallbackJob__onReject);
},
}
} else {
this.deinit();
}
}
};
Expand Down
543 changes: 506 additions & 37 deletions src/bun.js/api/bun/socket.zig

Large diffs are not rendered by default.

48 changes: 22 additions & 26 deletions src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ pub const ServerConfig = struct {
request_cert: i32 = 0,
reject_unauthorized: i32 = 0,
ssl_ciphers: [*c]const u8 = null,
protos: [*c]const u8 = null,
protos_len: usize = 0,

const log = Output.scoped(.SSLConfig, false);

Expand Down Expand Up @@ -215,6 +217,7 @@ pub const ServerConfig = struct {
"dh_params_file_name",
"passphrase",
"ssl_ciphers",
"protos",
};

inline for (fields) |field| {
Expand Down Expand Up @@ -270,6 +273,9 @@ pub const ServerConfig = struct {

pub fn inJS(global: *JSC.JSGlobalObject, obj: JSC.JSValue, exception: JSC.C.ExceptionRef) ?SSLConfig {
var result = zero;
var arena: @import("root").bun.ArenaAllocator = @import("root").bun.ArenaAllocator.init(bun.default_allocator);
defer arena.deinit();

if (!obj.isObject()) {
JSC.throwInvalidArguments("tls option expects an object", .{}, global, exception);
return null;
Expand Down Expand Up @@ -301,7 +307,6 @@ pub const ServerConfig = struct {

var i: u32 = 0;
var valid_count: u32 = 0;
var arena: @import("root").bun.ArenaAllocator = @import("root").bun.ArenaAllocator.init(bun.default_allocator);
while (i < count) : (i += 1) {
const item = js_obj.getIndex(global, i);
if (JSC.Node.StringOrBuffer.fromJS(global, arena.allocator(), item, exception)) |sb| {
Expand All @@ -317,24 +322,20 @@ pub const ServerConfig = struct {
valid_count += 1;
any = true;
} else {
arena.deinit();
// mark and free all CA's
result.cert = native_array;
result.deinit();
return null;
}
} else {
global.throwInvalidArguments("key argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile", .{});
arena.deinit();
// mark and free all keys
result.key = native_array;
result.deinit();
return null;
}
}

arena.deinit();

if (valid_count == 0) {
bun.default_allocator.free(native_array);
} else {
Expand All @@ -356,7 +357,6 @@ pub const ServerConfig = struct {
}
} else {
const native_array = bun.default_allocator.alloc([*c]const u8, 1) catch unreachable;
var arena: @import("root").bun.ArenaAllocator = @import("root").bun.ArenaAllocator.init(bun.default_allocator);
if (JSC.Node.StringOrBuffer.fromJS(global, arena.allocator(), js_obj, exception)) |sb| {
const sliced = sb.slice();
if (sliced.len > 0) {
Expand All @@ -369,14 +369,11 @@ pub const ServerConfig = struct {
}
} else {
global.throwInvalidArguments("key argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile", .{});
arena.deinit();
// mark and free all certs
result.key = native_array;
result.deinit();
return null;
}

arena.deinit();
}
}

Expand All @@ -394,6 +391,22 @@ pub const ServerConfig = struct {
}
}

if (obj.getTruthy(global, "ALPNProtocols")) |protocols| {
if (JSC.Node.StringOrBuffer.fromJS(global, arena.allocator(), protocols, exception)) |sb| {
const sliced = sb.slice();
if (sliced.len > 0) {
result.protos = bun.default_allocator.dupeZ(u8, sliced) catch unreachable;
result.protos_len = sliced.len;
}

any = true;
} else {
global.throwInvalidArguments("ALPNProtocols argument must be an string, Buffer or TypedArray", .{});
result.deinit();
return null;
}
}

if (obj.getTruthy(global, "cert")) |js_obj| {
if (js_obj.jsType().isArray()) {
const count = js_obj.getLength(global);
Expand All @@ -403,7 +416,6 @@ pub const ServerConfig = struct {
var i: u32 = 0;
var valid_count: u32 = 0;

var arena: @import("root").bun.ArenaAllocator = @import("root").bun.ArenaAllocator.init(bun.default_allocator);
while (i < count) : (i += 1) {
const item = js_obj.getIndex(global, i);
if (JSC.Node.StringOrBuffer.fromJS(global, arena.allocator(), item, exception)) |sb| {
Expand All @@ -419,24 +431,20 @@ pub const ServerConfig = struct {
valid_count += 1;
any = true;
} else {
arena.deinit();
// mark and free all CA's
result.cert = native_array;
result.deinit();
return null;
}
} else {
global.throwInvalidArguments("cert argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile", .{});
arena.deinit();
// mark and free all certs
result.cert = native_array;
result.deinit();
return null;
}
}

arena.deinit();

if (valid_count == 0) {
bun.default_allocator.free(native_array);
} else {
Expand All @@ -458,7 +466,6 @@ pub const ServerConfig = struct {
}
} else {
const native_array = bun.default_allocator.alloc([*c]const u8, 1) catch unreachable;
var arena: @import("root").bun.ArenaAllocator = @import("root").bun.ArenaAllocator.init(bun.default_allocator);
if (JSC.Node.StringOrBuffer.fromJS(global, arena.allocator(), js_obj, exception)) |sb| {
const sliced = sb.slice();
if (sliced.len > 0) {
Expand All @@ -471,14 +478,11 @@ pub const ServerConfig = struct {
}
} else {
global.throwInvalidArguments("cert argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile", .{});
arena.deinit();
// mark and free all certs
result.cert = native_array;
result.deinit();
return null;
}

arena.deinit();
}
}

Expand Down Expand Up @@ -518,7 +522,6 @@ pub const ServerConfig = struct {
var i: u32 = 0;
var valid_count: u32 = 0;

var arena: @import("root").bun.ArenaAllocator = @import("root").bun.ArenaAllocator.init(bun.default_allocator);
while (i < count) : (i += 1) {
const item = js_obj.getIndex(global, i);
if (JSC.Node.StringOrBuffer.fromJS(global, arena.allocator(), item, exception)) |sb| {
Expand All @@ -534,24 +537,20 @@ pub const ServerConfig = struct {
valid_count += 1;
any = true;
} else {
arena.deinit();
// mark and free all CA's
result.cert = native_array;
result.deinit();
return null;
}
} else {
global.throwInvalidArguments("ca argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile", .{});
arena.deinit();
// mark and free all CA's
result.cert = native_array;
result.deinit();
return null;
}
}

arena.deinit();

if (valid_count == 0) {
bun.default_allocator.free(native_array);
} else {
Expand All @@ -573,7 +572,6 @@ pub const ServerConfig = struct {
}
} else {
const native_array = bun.default_allocator.alloc([*c]const u8, 1) catch unreachable;
var arena: @import("root").bun.ArenaAllocator = @import("root").bun.ArenaAllocator.init(bun.default_allocator);
if (JSC.Node.StringOrBuffer.fromJS(global, arena.allocator(), js_obj, exception)) |sb| {
const sliced = sb.slice();
if (sliced.len > 0) {
Expand All @@ -586,13 +584,11 @@ pub const ServerConfig = struct {
}
} else {
JSC.throwInvalidArguments("ca argument must be an string, Buffer, TypedArray, BunFile or an array containing string, Buffer, TypedArray or BunFile", .{}, global, exception);
arena.deinit();
// mark and free all certs
result.ca = native_array;
result.deinit();
return null;
}
arena.deinit();
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/bun.js/api/sockets.classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@ function generate(ssl) {
authorized: {
getter: "getAuthorized",
},
alpnProtocol: {
getter: "getALPNProtocol",
},
write: {
fn: "write",
length: 3,
},
wrapTLS: {
fn: "wrapTLS",
length: 1,
},
open: {
fn: "open",
length: 0,
},
end: {
fn: "end",
length: 3,
Expand Down Expand Up @@ -82,6 +93,11 @@ function generate(ssl) {
fn: "reload",
length: 1,
},

setServername: {
fn: "setServername",
length: 1,
},
},
finalize: true,
construct: true,
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/bindings/JSSink.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// AUTO-GENERATED FILE. DO NOT EDIT.
// Generated by 'make generate-sink' at 2023-06-25T17:34:54.187Z
// Generated by 'make generate-sink' at 2023-07-02T16:19:51.440Z
// To regenerate this file, run:
//
// make generate-sink
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/bindings/JSSink.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/bun.js/bindings/JSSinkLookupTable.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Automatically generated from src/bun.js/bindings/JSSink.cpp using /Users/silas/Workspace/opensource/bun/src/bun.js/WebKit/Source/JavaScriptCore/create_hash_table. DO NOT EDIT!
// Automatically generated from src/bun.js/bindings/JSSink.cpp using /home/cirospaciari/Repos/bun/src/bun.js/WebKit/Source/JavaScriptCore/create_hash_table. DO NOT EDIT!



Expand Down
Loading
Loading