Commit 1474ab33 authored by Jigsaw52's avatar Jigsaw52
Browse files

Add --format argument to --key-expiration option. #30045

parent 700e8a8b
Loading
Loading
Loading
Loading

changes/feature30045

0 → 100644
+6 −0
Original line number Diff line number Diff line
  o Minor features (admin tools):
    - Add new --format argument to -key-expiration option to allow
      specifying the time format of expiration date. Adds Unix
      timestamp format support. Patch by Daniel Pinto. Closes
      ticket 30045.
+10 −4
Original line number Diff line number Diff line
@@ -174,16 +174,22 @@ The following options in this section are only recognized on the
    If the file descriptor is not specified, the passphrase is read
    from the terminal by default.

[[opt-key-expiration]] **`--key-expiration`** [__purpose__]::
[[opt-key-expiration]] **`--key-expiration`** [__purpose__] [**`--format`** **`iso8601`**|**`timestamp`**]::
    The __purpose__ specifies which type of key certificate to determine
    the expiration of.  The only currently recognised __purpose__ is
    "sign". +
     +
    Running **`tor --key-expiration sign`** will attempt to find your
    signing key certificate and will output, both in the logs as well
    as to stdout, the signing key certificate's expiration time in
    ISO-8601 format.  For example, the output sent to stdout will be
    of the form: "signing-cert-expiry: 2017-07-25 08:30:15 UTC"
    as to stdout.  The optional **`--format`** argument lets you specify
    the time format.  Currently, **`iso8601`** and **`timestamp`** are
    supported.  If **`--format`** is not specified, the signing key
    certificate's expiration time will be in ISO-8601 format.  For example,
    the output sent to stdout will be of the form:
    "signing-cert-expiry: 2017-07-25 08:30:15 UTC".  If **`--format`** **`timestamp`**
    is specified, the signing key certificate's expiration time will be in
    Unix timestamp format. For example, the output sent to stdout will be of the form:
    "signing-cert-expiry: 1500971415".

[[opt-dbg]] **--dbg-**...::
    Tor may support other options beginning with the string "dbg". These
+2 −2
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ problem file-size /src/app/config/config.c 7525
problem include-count /src/app/config/config.c 81
problem function-size /src/app/config/config.c:options_act() 381
problem function-size /src/app/config/config.c:options_validate_cb() 794
problem function-size /src/app/config/config.c:options_init_from_torrc() 198
problem function-size /src/app/config/config.c:options_init_from_torrc() 231
problem function-size /src/app/config/config.c:options_init_from_string() 103
problem function-size /src/app/config/config.c:options_init_logs() 125
problem function-size /src/app/config/config.c:parse_bridge_line() 104
@@ -47,7 +47,7 @@ problem function-size /src/app/config/config.c:parse_dir_fallback_line() 101
problem function-size /src/app/config/config.c:port_parse_config() 435
problem function-size /src/app/config/config.c:parse_ports() 132
problem function-size /src/app/config/resolve_addr.c:resolve_my_address_v4() 197
problem file-size /src/app/config/or_options_st.h 1050
problem file-size /src/app/config/or_options_st.h 1069
problem include-count /src/app/main/main.c 71
problem function-size /src/app/main/main.c:dumpstats() 102
problem function-size /src/app/main/main.c:tor_init() 109
+35 −0
Original line number Diff line number Diff line
@@ -2468,6 +2468,8 @@ static const struct {
  { .name="--key-expiration",
    .takes_argument=ARGUMENT_OPTIONAL,
    .command=CMD_KEY_EXPIRATION },
  { .name="--format",
    .takes_argument=ARGUMENT_NECESSARY },
  { .name="--newpass" },
  { .name="--no-passphrase" },
  { .name="--passphrase-fd",
@@ -4425,6 +4427,39 @@ options_init_from_torrc(int argc, char **argv)
    }
  }

  const config_line_t *format_line = config_line_find(cmdline_only_options,
                                                      "--format");
  if (format_line) {
    if (command == CMD_KEY_EXPIRATION) {
      const char *v = format_line->value;
      // keep the same order as enum key_expiration_format
      const char *formats[] = { "iso8601", "timestamp" };
      const int formats_len = sizeof(formats) / sizeof(formats[0]);
      int format = -1;
      for (int i = 0; i < formats_len; i++) {
        if (!strcmp(v, formats[i])) {
          format = i;
          break;
        }
      }

      if (format < 0) {
        log_err(LD_CONFIG, "Invalid --format value %s", escaped(v));
        retval = -1;
        goto err;
      } else {
        get_options_mutable()->key_expiration_format = format;
      }
    } else {
      log_err(LD_CONFIG, "--format specified without --key-expiration!");
      retval = -1;
      goto err;
    }
  } else {
    get_options_mutable()->key_expiration_format =
      KEY_EXPIRATION_FORMAT_ISO8601;
  }

  if (config_line_find(cmdline_only_options, "--newpass")) {
    if (command == CMD_KEYGEN) {
      get_options_mutable()->change_key_passphrase = 1;
+5 −0
Original line number Diff line number Diff line
@@ -944,6 +944,11 @@ struct or_options_t {
   * ed25519 identity key except from tor --keygen */
  int OfflineMasterKey;

  enum {
    KEY_EXPIRATION_FORMAT_ISO8601 = 0,
    KEY_EXPIRATION_FORMAT_TIMESTAMP
  } key_expiration_format;

  enum {
    FORCE_PASSPHRASE_AUTO=0,
    FORCE_PASSPHRASE_ON,
Loading