diff --git a/src/Config.zig b/src/Config.zig index 73c7f3a7..680a99a8 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -23,6 +23,8 @@ const Allocator = std.mem.Allocator; const log = @import("log.zig"); const dump = @import("browser/dump.zig"); +const WebBotAuth = @import("browser/WebBotAuth.zig"); + pub const RunMode = enum { help, fetch, @@ -161,6 +163,17 @@ pub fn cdpTimeout(self: *const Config) usize { }; } +pub fn webBotAuth(self: *const Config) ?WebBotAuth { + return switch (self.mode) { + inline .serve, .fetch, .mcp => |opts| WebBotAuth{ + .key_file = opts.common.web_bot_auth_key_file orelse return null, + .keyid = opts.common.web_bot_auth_keyid orelse return null, + .domain = opts.common.web_bot_auth_domain orelse return null, + }, + .help, .version => null, + }; +} + pub fn maxConnections(self: *const Config) u16 { return switch (self.mode) { .serve => |opts| opts.cdp_max_connections, @@ -227,6 +240,10 @@ pub const Common = struct { log_format: ?log.Format = null, log_filter_scopes: ?[]log.Scope = null, user_agent_suffix: ?[]const u8 = null, + + web_bot_auth_key_file: ?[]const u8 = null, + web_bot_auth_keyid: ?[]const u8 = null, + web_bot_auth_domain: ?[]const u8 = null, }; /// Pre-formatted HTTP headers for reuse across Http and Client. @@ -334,6 +351,14 @@ pub fn printUsageAndExit(self: *const Config, success: bool) void { \\--user_agent_suffix \\ Suffix to append to the Lightpanda/X.Y User-Agent \\ + \\--web_bot_auth_key_file + \\ Path to the Ed25519 private key PEM file. + \\ + \\--web_bot_auth_keyid + \\ The JWK thumbprint of your public key. + \\ + \\--web_bot_auth_directory + \\ Your domain e.g. yourdomain.com ; // MAX_HELP_LEN| @@ -855,5 +880,32 @@ fn parseCommonArg( return true; } + if (std.mem.eql(u8, "--web_bot_auth_key_file", opt)) { + const str = args.next() orelse { + log.fatal(.app, "missing argument value", .{ .arg = "--web_bot_auth_key_file" }); + return error.InvalidArgument; + }; + common.web_bot_auth_key_file = try allocator.dupe(u8, str); + return true; + } + + if (std.mem.eql(u8, "--web_bot_auth_keyid", opt)) { + const str = args.next() orelse { + log.fatal(.app, "missing argument value", .{ .arg = "--web_bot_auth_keyid" }); + return error.InvalidArgument; + }; + common.web_bot_auth_keyid = try allocator.dupe(u8, str); + return true; + } + + if (std.mem.eql(u8, "--web_bot_auth_domain", opt)) { + const str = args.next() orelse { + log.fatal(.app, "missing argument value", .{ .arg = "--web_bot_auth_domain" }); + return error.InvalidArgument; + }; + common.web_bot_auth_domain = try allocator.dupe(u8, str); + return true; + } + return false; } diff --git a/src/network/WebBotAuth.zig b/src/network/WebBotAuth.zig new file mode 100644 index 00000000..4af598fb --- /dev/null +++ b/src/network/WebBotAuth.zig @@ -0,0 +1,23 @@ +// Copyright (C) 2023-2026 Lightpanda (Selecy SAS) +// +// Francis Bouvier +// Pierre Tachoire +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +const WebBotAuth = @This(); + +key_file: []const u8, +keyid: []const u8, +domain: []const u8,