Lightpanda: the headless browser designed for AI and automation
ops: add --http-curves flags
Karl Seguin4e5c8c1a97e7
diff --git a/src/Config.zig b/src/Config.zigindex 99943d5e9..4a9f3da9b 100644--- a/src/Config.zig+++ b/src/Config.zig@@ -273,6 +273,7 @@ const CommonOptions = .{.{ .name = "http_cache_dir", .type = ?[]const u8 },.{ .name = "http_cache_entry_limit", .type = ?u32, .default = 1000 },.{ .name = "http_debug", .type = bool },+ .{ .name = "http_curves", .type = ?[:0]const u8, .validator = httpCurvesValidator },.{ .name = "render_font", .type = []const u8, .multiple = true },.{ .name = "web_bot_auth_key_file", .type = ?[]const u8 },.{ .name = "web_bot_auth_keyid", .type = ?[]const u8 },@@ -783,6 +784,13 @@ pub fn httpDebug(self: *const Config) bool {};}+pub fn httpCurves(self: *const Config) ?[:0]const u8 {+ return switch (self.mode) {+ inline .serve, .fetch, .mcp, .agent => |opts| opts.http_curves,+ else => null,+ };+}+pub fn renderFonts(self: *const Config) []const []const u8 {return switch (self.mode) {inline .serve, .fetch, .mcp, .agent => |opts| opts.render_font.items,@@ -1683,6 +1691,21 @@ fn timezoneValidator(allocator: Allocator, args: *std.process.Args.Iterator, fiefield.* = try allocator.dupeSentinel(u8, str, 0);}+// libcurl only stores the string; BoringSSL parses it at handshake time, so+// a bad name would fail every request with a misleading SslCipher error.+fn httpCurvesValidator(allocator: Allocator, args: *std.process.Args.Iterator, field: *?[:0]const u8) !void {+ const str = args.next() orelse return error.MissingArgument;++ const ctx = crypto.SSL_CTX_new(crypto.TLS_method()) orelse return error.OutOfMemory;+ defer crypto.SSL_CTX_free(ctx);++ if (crypto.SSL_CTX_set1_curves_list(ctx, str) != 1) {+ log.fatal(.app, "invalid option value", .{ .arg = "--http-curves", .value = str, .hint = "must be a colon-separated list such as X25519MLKEM768:X25519:P-256:P-384" });+ return error.InvalidArgument;+ }+ field.* = try allocator.dupeSentinel(u8, str, 0);+}+/// A BCP 47 tag restricted to what ICU and the Accept-Language derivation/// need: a 2-3 letter language followed by 2-8 character alphanumeric subtags.pub fn validateLocale(tag: []const u8) !void {diff --git a/src/help.zon b/src/help.zonindex b6cfecd39..0e612b22c 100644--- a/src/help.zon+++ b/src/help.zon@@ -454,6 +454,10 @@\\ Time in ms to establish an HTTP connection before timing out. 0 means\\ never.\\ Defaults to 8000.+ \\ --http-curves+ \\ Colon-separated key exchange groups offered in the TLS handshake,+ \\ in preference order, e.g. "X25519:P-256:P-384". Passed to+ \\ libcurl's CURLOPT_SSL_EC_CURVES.\\ --http-debug\\ Enables libcurl verbose output. Output written directly to stderr\\ by licurl and does not follow the configured log format.diff --git a/src/network/http.zig b/src/network/http.zigindex b1e159592..f76cf8396 100644--- a/src/network/http.zig+++ b/src/network/http.zig@@ -497,6 +497,10 @@ pub const Connection = struct {}}+ if (config.httpCurves()) |list| {+ try libcurl.curl_easy_setopt(self._easy, .ssl_ec_curves, list.ptr);+ }+if (config.httpDebug()) {try libcurl.curl_easy_setopt(self._easy, .verbose, true);}diff --git a/src/sys/libcrypto.zig b/src/sys/libcrypto.zigindex 33d442895..37c3c9cf2 100644--- a/src/sys/libcrypto.zig+++ b/src/sys/libcrypto.zig@@ -176,6 +176,13 @@ pub extern fn X509_STORE_load_locations(store: *X509_STORE, file: ?[*:0]const u8const struct_ssl_ctx_st = opaque {};pub const SSL_CTX = struct_ssl_ctx_st;pub extern fn SSL_CTX_set1_verify_cert_store(ctx: ?*SSL_CTX, store: ?*X509_STORE) c_int;+pub extern fn SSL_CTX_new(method: *const SSL_METHOD) ?*SSL_CTX;+pub extern fn SSL_CTX_free(ctx: *SSL_CTX) void;+pub extern fn SSL_CTX_set1_curves_list(ctx: *SSL_CTX, curves: [*:0]const u8) c_int;++const struct_ssl_method_st = opaque {};+pub const SSL_METHOD = struct_ssl_method_st;+pub extern fn TLS_method() *const SSL_METHOD;/// Returns the desired digest by its name.pub fn findDigest(name: []const u8) error{Invalid}!*const EVP_MD {diff --git a/src/sys/libcurl.zig b/src/sys/libcurl.zigindex 3d31fad0a..27afabe0c 100644--- a/src/sys/libcurl.zig+++ b/src/sys/libcurl.zig@@ -232,6 +232,7 @@ const CurlOption = enum(c.CURLoption) {opensocket_data = c.CURLOPT_OPENSOCKETDATA,ssl_ctx_function = c.CURLOPT_SSL_CTX_FUNCTION,ssl_ctx_data = c.CURLOPT_SSL_CTX_DATA,+ ssl_ec_curves = c.CURLOPT_SSL_EC_CURVES,};pub const CurlHttpVersion = enum(c_long) {@@ -638,6 +639,7 @@ pub fn curl_easy_setopt(easy: *Curl, comptime option: CurlOption, value: anytype.user_pwd,.proxy_user_pwd,.copy_post_fields,+ .ssl_ec_curves,=> @as(?[*]const u8, value),.http_header => @as(?*CurlSList, value),