Skip to content
Closed
Show file tree
Hide file tree
Changes from 97 commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
d6d1414
add test file
alii May 7, 2025
35152da
errors
alii May 7, 2025
87c520d
Specify all tls versions according to Node
alii May 7, 2025
addc357
basic wireup of tls min/max
alii May 7, 2025
37a55d2
more zig
alii May 7, 2025
b6ea92f
more
alii May 7, 2025
9059426
add the other minmax test
alii May 8, 2025
0332642
more coverage, and slightly related ProcessEnv should not extend Impo…
alii May 8, 2025
4f1233e
fix test impl
alii May 8, 2025
7b0e470
changes
alii May 8, 2025
563b8f5
consume values
alii May 8, 2025
14ea951
assign tls versions
alii May 8, 2025
aae850e
`catch unreachable;` increased
alii May 8, 2025
bd51d5e
do set min tls
alii May 8, 2025
2baa668
default to 1.2 min
alii May 8, 2025
f32b6d0
stuff
alii May 8, 2025
4098051
debug
alii May 8, 2025
7c57c3c
rm debug
alii May 8, 2025
23fd3b8
change how versions get passed
alii May 8, 2025
5b767a9
pass tls versions as openssl values
alii May 8, 2025
82a019a
pass openssl values in nativeland
alii May 8, 2025
ef6b9da
nativeland changes
alii May 8, 2025
4037fe9
debug
alii May 8, 2025
5dbd814
Merge branch 'main' of github.com:oven-sh/bun into ali/tls-min-max-cl…
alii May 8, 2025
6cb5e1c
revert openssl changes for dead path
alii May 8, 2025
4c14c7e
unused constants
alii May 8, 2025
38ff15a
rm
alii May 8, 2025
8a22127
2 more test files
alii May 8, 2025
b6530ba
2 more test files
alii May 8, 2025
d91ca54
add min v1.1 test file
alii May 8, 2025
90be0a5
fix node cli args, other diff cleanup
alii May 8, 2025
d60da18
fix cli failing arg test
alii May 8, 2025
0626a0f
Fix bad words count
alii May 8, 2025
8380a8f
rm debug logs
alii May 8, 2025
5986566
add validations test
alii May 8, 2025
de05784
partially complete validation
alii May 8, 2025
da62a89
housekeeping
alii May 8, 2025
821848f
more validation
alii May 8, 2025
040b00d
rm
alii May 8, 2025
629b677
fix alpn
alii May 8, 2025
416121f
rm
alii May 8, 2025
a5a8966
proper check for checkServerIdentity
alii May 8, 2025
2091132
clearer naming for tls cli binding logic
alii May 8, 2025
3d25000
rm secureprotocol
alii May 8, 2025
2283341
Support "instance of" in ERR_INVALID_ARG_TYPE
alii May 8, 2025
164675c
use ERR_INVALID_ARG_TYPE for Buffer instance
alii May 8, 2025
0ecf930
change ERR_TLS_INVALID_PROTOCOL_VERSION builtin
alii May 8, 2025
8ef431c
Revert 2283341efdca75b3dce065d18d972c6c9e9a68c8
alii May 8, 2025
97324e2
add min-version 1.0 test file
alii May 8, 2025
b3b276b
ticket keys test?
alii May 8, 2025
187dc46
passing
alii May 8, 2025
94293cd
use ERR_TLS_INVALID_PROTOCOL_VERSION new signature
alii May 8, 2025
f728d17
Merge branch 'main' of github.com:oven-sh/bun into ali/tls-min-max-cl…
alii May 8, 2025
9e0bdfa
update sources
alii May 9, 2025
df92e99
dont organize imports for zig
alii May 9, 2025
be32a2f
propogate err
alii May 9, 2025
f88344a
Merge branch 'main' of github.com:oven-sh/bun into ali/tls-min-max-cl…
alii May 9, 2025
74e369e
debug
alii May 9, 2025
dfa4dee
fix bun-types
alii May 9, 2025
d72e605
Merge branch 'main' into ali/tls-min-max-cli-and-test
alii May 9, 2025
2798379
net changes, ERR_TLS_PROTOCOL_VERSION_CONFLICT fix message
alii May 9, 2025
7d5ae23
Merge branch 'main' of github.com:oven-sh/bun into ali/tls-min-max-cl…
alii May 9, 2025
0b9cdc0
refactor tls version resolution
alii May 9, 2025
6f398a1
`bun run prettier`
alii May 9, 2025
5bdc738
passes
alii May 10, 2025
2d04dcf
`bun run prettier`
alii May 10, 2025
f3b769f
fix tls exports
alii May 10, 2025
f7fc34d
Merge branch 'ali/tls-min-max-cli-and-test' of github.com:oven-sh/bun…
alii May 10, 2025
d3fcad8
Merge branch 'main' of github.com:oven-sh/bun into ali/tls-min-max-cl…
alii May 10, 2025
ef0c48a
`bun run prettier`
alii May 10, 2025
f8fd2c2
glob sources
alii May 10, 2025
7d8b741
Merge branch 'ali/tls-min-max-cli-and-test' of github.com:oven-sh/bun…
alii May 10, 2025
9b05d51
temporarily ignore socket hang up (lol)
alii May 10, 2025
1ecd74a
call socket hang up
alii May 10, 2025
36cc379
revert bun.zig
alii May 10, 2025
14fe8df
export tls
alii May 10, 2025
ec5bb50
revert cli.zig, apply tls changes
alii May 10, 2025
3512087
Merge branch 'main' of github.com:oven-sh/bun into ali/tls-min-max-cl…
alii May 10, 2025
2cfec42
accidental removal
alii May 10, 2025
0c72bb5
revert imports in server.zig
alii May 10, 2025
7b64f89
fix imports uws.zig
alii May 10, 2025
28a6ba9
refactor out tls validation logic
alii May 10, 2025
2a36a4a
apply tls options
alii May 12, 2025
2e6eaae
Merge branch 'main' of github.com:oven-sh/bun into ali/tls-min-max-cl…
alii May 12, 2025
72eb996
isolate test cases for now
alii May 12, 2025
a55e27a
fix: check min/max version for ssl context re-use
alii May 12, 2025
043f24a
commiting to pair with ciro
alii May 12, 2025
210d4fc
Merge branch 'main' into ali/tls-min-max-cli-and-test
alii May 12, 2025
763c017
from node
alii May 12, 2025
aea9697
revert net.ts
alii May 12, 2025
f044b44
bun happy eyeballs message
alii May 12, 2025
cb05ed0
net
alii May 12, 2025
ace91ce
match node logic
alii May 12, 2025
5eec63b
dont allow numerical assignment of min/max versions
alii May 12, 2025
5f65bf5
debugging
alii May 13, 2025
e91d022
rm
alii May 13, 2025
27dd1e8
rm
alii May 13, 2025
a257dc2
debug
alii May 13, 2025
67a26f0
Merge branch 'main' of github.com:oven-sh/bun into ali/tls-min-max-cl…
alii May 13, 2025
4b04480
changes
alii May 13, 2025
0c9208c
changes
alii May 13, 2025
2c91911
hm
alii May 13, 2025
7a52e75
rm
alii May 14, 2025
382e848
isolate test, other debug
alii May 14, 2025
c3bdf0e
fix it
alii May 14, 2025
a7e9b1e
add more tests
alii May 14, 2025
9268977
rejection test
alii May 14, 2025
f2be87e
ssl test file, new err code
alii May 14, 2025
5154101
fix errno
alii May 14, 2025
1fed307
broken
alii May 14, 2025
881a1f2
Merge branch 'main' of github.com:oven-sh/bun into ali/tls-min-max-cl…
alii May 14, 2025
ff7c049
Works up to here!
alii May 14, 2025
7d59378
thse are all passing
alii May 14, 2025
2bbac60
also passing
alii May 14, 2025
7f2b54e
for now two failings
alii May 14, 2025
5fb30c8
debugs
alii May 14, 2025
18e3443
passing!
alii May 14, 2025
99a76fb
checkpoint
alii May 15, 2025
0257a24
debug
alii May 15, 2025
4befd51
Works
alii May 15, 2025
527e59d
nice
alii May 15, 2025
10fc8ad
Merge branch 'main' into ali/tls-min-max-cli-and-test
alii May 15, 2025
b86a462
merge
alii May 15, 2025
1b19c8c
Merge branch 'ali/tls-min-max-cli-and-test' of github.com:oven-sh/bun…
alii May 15, 2025
3d94247
restart
alii May 15, 2025
f893b08
passing
alii May 15, 2025
ceca54e
failing
alii May 15, 2025
f5047e9
debug
alii May 15, 2025
447216a
peek openssl error queue for real reason(🤦‍♂️)
alii May 15, 2025
234fa60
Almost all cases passing
alii May 15, 2025
a1b374b
old/invalid protocol
alii May 15, 2025
6154c5d
define secure_protocol_method
alii May 15, 2025
670d6b5
debug
alii May 15, 2025
6ab9b1c
secure protocol property plumbing
alii May 15, 2025
8786ff8
almost there
alii May 15, 2025
4a663f3
passing bar these
alii May 15, 2025
2d57bb1
isolate failure
alii May 15, 2025
9317dc2
try
alii May 16, 2025
5e267af
2 failing
alii May 16, 2025
bdeaea6
remove redundant bloat
alii May 16, 2025
00e8701
rm
alii May 16, 2025
0acdedd
some debloat
alii May 16, 2025
447a9a6
debloat
alii May 16, 2025
29a8a45
Merge branch 'main' into ali/tls-min-max-cli-and-test
alii May 16, 2025
bf87b05
check verify error code
alii May 16, 2025
a1124d6
Merge branch 'ali/tls-min-max-cli-and-test' of github.com:oven-sh/bun…
alii May 16, 2025
4042785
debug
alii May 16, 2025
3afa13b
fix: properly map non min/max vers related error codes
alii May 16, 2025
372b0c3
remove logs
alii May 16, 2025
38686f4
define consts earlier
alii May 17, 2025
53dd1f9
Merge branch 'main' of github.com:oven-sh/bun into ali/tls-min-max-cl…
alii May 19, 2025
2f635c4
Merge branch 'main' of github.com:oven-sh/bun into ali/tls-min-max-cl…
alii May 22, 2025
7749bf7
glob srcs
alii May 22, 2025
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,5 @@ codegen-for-zig-team.tar.gz
*.sock
scratch*.{js,ts,tsx,cjs,mjs}

*.bun-build
*.bun-build
**/.claude/settings.local.json
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"zig.zls.path": "${workspaceFolder}/vendor/zig/zls.exe",
"zig.formattingProvider": "zls",
"zig.zls.enableInlayHints": false,

"[zig]": {
"editor.tabSize": 4,
"editor.useTabStops": false,
Expand Down
3 changes: 3 additions & 0 deletions cmake/ZigSources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ src/bun.js/node/node_http_binding.zig
src/bun.js/node/node_net_binding.zig
src/bun.js/node/node_os.zig
src/bun.js/node/node_process.zig
src/bun.js/node/node_tls_binding.zig
src/bun.js/node/node_util_binding.zig
src/bun.js/node/node_zlib_binding.zig
src/bun.js/node/nodejs_error_code.zig
Expand Down Expand Up @@ -222,6 +223,7 @@ src/bun.js/webcore/Response.zig
src/bun.js/webcore/S3Client.zig
src/bun.js/webcore/S3File.zig
src/bun.js/webcore/S3Stat.zig
src/bun.js/webcore/ScriptExecutionContext.zig
src/bun.js/webcore/Sink.zig
src/bun.js/webcore/streams.zig
src/bun.js/webcore/TextDecoder.zig
Expand Down Expand Up @@ -580,6 +582,7 @@ src/system_timer.zig
src/test/fixtures.zig
src/test/recover.zig
src/thread_pool.zig
src/tls.zig
src/tmp.zig
src/toml/toml_lexer.zig
src/toml/toml_parser.zig
Expand Down
2 changes: 1 addition & 1 deletion packages/bun-types/overrides.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export {};

declare global {
namespace NodeJS {
interface ProcessEnv extends Bun.Env, ImportMetaEnv {}
interface ProcessEnv extends Bun.Env {}

interface Process {
readonly version: string;
Expand Down
21 changes: 19 additions & 2 deletions packages/bun-usockets/src/crypto/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1140,14 +1140,31 @@ SSL_CTX *create_ssl_context_from_bun_options(
/* Create the context */
SSL_CTX *ssl_context = SSL_CTX_new(TLS_method());


/* Default options we rely on - changing these will break our logic */
SSL_CTX_set_read_ahead(ssl_context, 1);
/* we should always accept moving write buffer so we can retry writes with a
* buffer allocated in a different address */
SSL_CTX_set_mode(ssl_context, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
if (options.min_tls_version > 0) {
if (!SSL_CTX_set_min_proto_version(ssl_context, options.min_tls_version)) {
free_ssl_context(ssl_context);
return NULL;
}
} else {

if (!SSL_CTX_set_min_proto_version(ssl_context, TLS1_2_VERSION)) {
free_ssl_context(ssl_context);
return NULL;
}
}

/* Anything below TLS 1.2 is disabled */
SSL_CTX_set_min_proto_version(ssl_context, TLS1_2_VERSION);
if (options.max_tls_version > 0) {
if (!SSL_CTX_set_max_proto_version(ssl_context, options.max_tls_version)) {
free_ssl_context(ssl_context);
return NULL;
}
}

/* The following are helpers. You may easily implement whatever you want by
* using the native handle directly */
Expand Down
2 changes: 2 additions & 0 deletions packages/bun-usockets/src/libusockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ struct us_bun_socket_context_options_t {
int request_cert;
unsigned int client_renegotiation_limit;
unsigned int client_renegotiation_window;
unsigned int min_tls_version;
unsigned int max_tls_version;
};

/* Return 15-bit timestamp for this context */
Expand Down
2 changes: 2 additions & 0 deletions packages/bun-uws/src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ namespace uWS {
int request_cert = 0;
unsigned int client_renegotiation_limit = 3;
unsigned int client_renegotiation_window = 600;
unsigned int min_tls_version = 0;
unsigned int max_tls_version = 0;

/* Conversion operator used internally */
operator struct us_bun_socket_context_options_t() const {
Expand Down
12 changes: 12 additions & 0 deletions src/bun.js/api/bun/socket.zig
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,12 @@ pub const Listener = struct {
return globalObject.throwValue(err);
};

if (ssl_enabled and create_err != .none) {
const js_err = create_err.toJS(globalObject);
uws.us_socket_context_free(1, socket_context);
return globalObject.throwValue(js_err);
}

if (ssl_enabled) {
if (ssl.?.protos) |p| {
protos = p[0..ssl.?.protos_len];
Expand Down Expand Up @@ -1220,6 +1226,12 @@ pub const Listener = struct {
return globalObject.throwValue(err.toErrorInstance(globalObject));
};

if (ssl_enabled and create_err != .none) {
const js_err = create_err.toJS(globalObject);
uws.us_socket_context_free(1, socket_context);
return globalObject.throwValue(js_err);
}

if (ssl_enabled) {
if (ssl.?.protos) |p| {
protos = p[0..ssl.?.protos_len];
Expand Down
23 changes: 22 additions & 1 deletion src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ pub const ServerConfig = struct {
client_renegotiation_limit: u32 = 0,
client_renegotiation_window: u32 = 0,

min_version: ?u16 = null,
max_version: ?u16 = null,

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

pub fn asUSockets(this: SSLConfig) uws.us_bun_socket_context_options_t {
Expand Down Expand Up @@ -685,6 +688,14 @@ pub const ServerConfig = struct {
ctx_opts.request_cert = this.request_cert;
ctx_opts.reject_unauthorized = this.reject_unauthorized;

if (this.min_version) |version| {
ctx_opts.min_tls_version = version;
}

if (this.max_version) |version| {
ctx_opts.max_tls_version = version;
}

return ctx_opts;
}

Expand Down Expand Up @@ -715,7 +726,7 @@ pub const ServerConfig = struct {

{
//numbers
const fields = .{ "secure_options", "request_cert", "reject_unauthorized", "low_memory_mode" };
const fields = .{ "secure_options", "request_cert", "reject_unauthorized", "low_memory_mode", "min_version", "max_version" };

inline for (fields) |field| {
const lhs = @field(thisConfig, field);
Expand Down Expand Up @@ -1040,6 +1051,16 @@ pub const ServerConfig = struct {
any = true;
}

if (try obj.getTruthy(global, "minVersion")) |min_version| {
result.min_version = @as(u16, @intCast(min_version.toInt32()));
any = true;
}

if (try obj.getTruthy(global, "maxVersion")) |max_version| {
result.max_version = @as(u16, @intCast(max_version.toInt32()));
any = true;
}

if (try obj.getTruthy(global, "ciphers")) |ssl_ciphers| {
var sliced = try ssl_ciphers.toSlice(global, bun.default_allocator);
defer sliced.deinit();
Expand Down
20 changes: 20 additions & 0 deletions src/bun.js/node/node_tls_binding.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const std = @import("std");

const bun = @import("bun");
const JSC = bun.JSC;

pub fn getDefaultMinTLSVersionFromCLIFlag(_: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue {
if (bun.tls.min_tls_version_from_cli_flag) |version| {
return JSC.JSValue.jsNumber(version);
}

return JSC.JSValue.jsNull();
}

pub fn getDefaultMaxTLSVersionFromCLIFlag(_: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue {
if (bun.tls.max_tls_version_from_cli_flag) |version| {
return JSC.JSValue.jsNumber(version);
}

return JSC.JSValue.jsNull();
}
1 change: 1 addition & 0 deletions src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ pub const Bunfig = @import("./bunfig.zig").Bunfig;

pub const HTTPThread = @import("./http.zig").HTTPThread;
pub const http = @import("./http.zig");
pub const tls = @import("./tls.zig");

pub const Analytics = @import("./analytics/analytics_thread.zig");

Expand Down
27 changes: 27 additions & 0 deletions src/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ pub const Arguments = struct {
clap.parseParam("--zero-fill-buffers Boolean to force Buffer.allocUnsafe(size) to be zero-filled.") catch unreachable,
clap.parseParam("--redis-preconnect Preconnect to $REDIS_URL at startup") catch unreachable,
clap.parseParam("--no-addons Throw an error if process.dlopen is called, and disable export condition \"node-addons\"") catch unreachable,
clap.parseParam("--tls-max-v1.2 Set the maximum TLS version to 1.2") catch unreachable,
clap.parseParam("--tls-max-v1.3 Set the maximum TLS version to 1.3") catch unreachable,
clap.parseParam("--tls-min-v1.0 Set the minimum TLS version to 1") catch unreachable,
clap.parseParam("--tls-min-v1.1 Set the minimum TLS version to 1.1") catch unreachable,
clap.parseParam("--tls-min-v1.2 Set the minimum TLS version to 1.2") catch unreachable,
clap.parseParam("--tls-min-v1.3 Set the minimum TLS version to 1.3") catch unreachable,
};

const auto_or_run_params = [_]ParamType{
Expand Down Expand Up @@ -754,6 +760,27 @@ pub const Arguments = struct {
}
}

// TLS version flags here are specified in ascending order for MAX, and descending order for MIN
// because Node will use the maximum value for --tls-max and the minimum value for --tls-min
// See comments on:
// - https://bun.sh/reference/node/tls/DEFAULT_MAX_VERSION
// - https://bun.sh/reference/node/tls/DEFAULT_MIN_VERSION

// if (args.flag("--tls-max-v1.0")) bun.tls.max_tls_version = 0x0301;
// if (args.flag("--tls-max-v1.1")) bun.tls.max_tls_version = 0x0302;
if (args.flag("--tls-max-v1.2")) bun.tls.max_tls_version_from_cli_flag = 0x0303;
if (args.flag("--tls-max-v1.3")) bun.tls.max_tls_version_from_cli_flag = 0x0304;

if (args.flag("--tls-min-v1.3")) bun.tls.min_tls_version_from_cli_flag = 0x0304;
if (args.flag("--tls-min-v1.2")) bun.tls.min_tls_version_from_cli_flag = 0x0303;
if (args.flag("--tls-min-v1.1")) bun.tls.min_tls_version_from_cli_flag = 0x0302;
if (args.flag("--tls-min-v1.0")) bun.tls.min_tls_version_from_cli_flag = 0x0301;

if (bun.tls.min_tls_version_from_cli_flag != null and bun.tls.max_tls_version_from_cli_flag != null) {
Output.errGeneric("either --tls-min-v1.x or --tls-max-v1.x can be used, not both", .{});
Global.exit(1);
}

ctx.debug.offline_mode_setting = if (args.flag("--prefer-offline"))
Bunfig.OfflineMode.offline
else if (args.flag("--prefer-latest"))
Expand Down
2 changes: 2 additions & 0 deletions src/deps/uws.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2538,6 +2538,8 @@ pub const us_bun_socket_context_options_t = extern struct {
request_cert: i32 = 0,
client_renegotiation_limit: u32 = 3,
client_renegotiation_window: u32 = 600,
min_tls_version: u32 = 0,
max_tls_version: u32 = 0,
};

pub const create_bun_socket_error_t = enum(c_int) {
Expand Down
3 changes: 2 additions & 1 deletion src/js/builtins.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ declare function $makeAbortError(message?: string, options?: { cause: Error }):
*/
declare function $ERR_INVALID_ARG_TYPE(argName: string, expectedType: string, actualValue: any): TypeError;
declare function $ERR_INVALID_ARG_TYPE(argName: string, expectedTypes: string[], actualValue: any): TypeError;
declare function $ERR_INVALID_ARG_TYPE(message: string): TypeError;
declare function $ERR_INVALID_ARG_VALUE(name: string, value: any, reason?: string): TypeError;
declare function $ERR_UNKNOWN_ENCODING(enc: string): TypeError;
declare function $ERR_STREAM_DESTROYED(method: string): Error;
Expand All @@ -680,7 +681,7 @@ declare function $ERR_MISSING_ARGS(...args: [string, ...string[]]): TypeError;
*/
declare function $ERR_MISSING_ARGS(oneOf: string[]): TypeError;
declare function $ERR_INVALID_RETURN_VALUE(expected_type: string, name: string, actual_value: any): TypeError;
declare function $ERR_TLS_INVALID_PROTOCOL_VERSION(a: string, b: string): TypeError;
declare function $ERR_TLS_INVALID_PROTOCOL_VERSION(a: import("tls").SecureVersion, b: "maximum" | "minimum"): TypeError;
declare function $ERR_TLS_PROTOCOL_VERSION_CONFLICT(a: string, b: string): TypeError;
declare function $ERR_INVALID_IP_ADDRESS(ip: any): TypeError;
declare function $ERR_INVALID_ADDRESS_FAMILY(addressType, host, port): RangeError;
Expand Down
Loading
Loading