]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Allow server.port to be an integer in JSON
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 29 Aug 2025 18:16:04 +0000 (12:16 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 29 Aug 2025 18:20:57 +0000 (12:20 -0600)
The old string parser still works too.

For #50.

docs/usage.md
src/config.c
src/config/str.c
src/config/str.h
src/object/certificate.c
src/types/uri.c

index c60b8183534dd0f614eb8e315ae23fb881a4ae7f..1e51477bca727b54c1c856795baede1558f408c5 100644 (file)
@@ -93,7 +93,7 @@ description: Guide to use arguments of FORT Validator.
        [--work-offline=true|false]
        [--daemon=true|false]
        [--server.address=<sequence of strings>]
-       [--server.port=<string>]
+       [--server.port=<unsigned integer or service string>]
        [--server.backlog=<unsigned integer>]
        [--server.interval.validation=<unsigned integer>]
        [--server.interval.refresh=<unsigned integer>]
@@ -373,13 +373,13 @@ Use wildcards to bind to all available addresses. Note that, for historical reas
 
 ### `--server.port`
 
-- **Type:** String
+- **Type:** String or integer
 - **Availability:** `argv` and JSON
-- **Default:** `"323"`
+- **Default:** `323`
 
 TCP port or service the server address(es) will be bound to, if [`--server.address`](#--serveraddress) doesn't override it.
 
-This is a string because a service alias can be used as a valid value. The available aliases are commonly located at `/etc/services`. (See '`$ man 5 services`'.)
+This can be a string because it's not necessarily a port; it's technically a service alias. (For example, if you enter "`http`," it will be resolved to 80). The available aliases are commonly located at `/etc/services`. (See '`$ man 5 services`'.)
 
 > ![img/warn.svg](img/warn.svg) The default port is privileged. To improve security, either change or jail it. See [Non root port binding](run.html#non-root-port-binding).
 
@@ -974,7 +974,7 @@ The configuration options are mostly the same as the ones from the `argv` interf
                        "192.0.2.1",
                        "2001:db8::1"
                ],
-               "<a href="#--serverport">port</a>": "8323",
+               "<a href="#--serverport">port</a>": 8323,
                "<a href="#--serverbacklog">backlog</a>": 4096,
                "interval": {
                        "<a href="#--serverintervalvalidation">validation</a>": 3600,
index 36b953abf9ca6a089fb3c86a28d6950d9c09a0da..22238406c459b43f953415b6d809bf1a59f185e6 100644 (file)
@@ -336,7 +336,7 @@ static const struct option_field options[] = {
        }, {
                .id = 5001,
                .name = "server.port",
-               .type = &gt_string,
+               .type = &gt_service,
                .offset = offsetof(struct rpki_config, server.port),
                .doc = "Default port to which RTR server addresses will bind itself to. Can be a string, in which case a number will be resolved. If all of the addresses have a port, this value isn't utilized.",
                .json_null_allowed = false,
index 2ac77c2e6a2a6db45d05f8ea9336d03392a51981..a43d0a6f173837f51977a6036634aea48fba9c49 100644 (file)
@@ -80,6 +80,43 @@ const struct global_type gt_string = {
        .arg_doc = "<string>",
 };
 
+static int
+service_parse_json(struct option_field const *opt, json_t *json, void *result)
+{
+       json_int_t intval;
+       char *strval;
+       int written;
+
+       if (json_is_integer(json)) {
+               intval = json_integer_value(json);
+               if (intval < 1 || 65535 < intval) {
+                       return pr_op_err("'%s' is out of range (1-65535).",
+                           opt->name);
+               }
+
+               strval = pmalloc(6);
+               written = snprintf(strval, 6, JSON_INTEGER_FORMAT, intval);
+               if (written < 0 || 6 <= written)
+                       return pr_op_err("Cannot convert '%s' to string: snprintf returned %d",
+                           opt->name, written);
+
+               DEREFERENCE(result) = strval;
+               return 0;
+       }
+
+       return string_parse_json(opt, json, result);
+}
+
+const struct global_type gt_service = {
+       .has_arg = required_argument,
+       .size = sizeof(char *),
+       .print = string_print,
+       .parse.argv = string_parse_argv,
+       .parse.json = service_parse_json,
+       .free = string_free,
+       .arg_doc = "<port>",
+};
+
 /**
  * *result must not be freed nor long-term stored.
  */
index f78f7292451201a4588b8747248577e0776ae11f..d7f98e468f90ba57b2119a5f0de9d723eb86095c 100644 (file)
@@ -4,6 +4,7 @@
 #include "config/types.h"
 
 extern const struct global_type gt_string;
+extern const struct global_type gt_service;
 
 int parse_json_string(json_t *, char const *, char const **);
 
index 0fa0cdd2de64fd955b900f2ac7b213be88484f24..731c9b82c03fbaaa2b857700601fb95a60033c5e 100644 (file)
@@ -544,7 +544,7 @@ validate_public_key(X509 *cert, enum cert_type type)
                if ((evppkey = X509_get0_pubkey(cert)) == NULL)
                        return val_crypto_err("X509_get0_pubkey() returned NULL");
                if (X509_verify(cert, evppkey) != 1)
-                       return -EINVAL;
+                       return val_crypto_err("TA validation failed.");
        }
 
        return 0;
index e1dfd873adf2c2f7583306e7510723f2c7f1ef9b..c6e2039d25de926f49b4e142dee971ed150b922f 100644 (file)
@@ -136,7 +136,7 @@ is_valid_mft_file_chara(uint8_t chara)
            || (chara == '_');
 }
 
-/* RFC 6486bis, section 4.2.2 */
+/* RFC 9286, section 4.2.2 */
 static int
 validate_mft_file(IA5String_t *ia5)
 {