Skip to content

Inefficiency in SNI policy parsing #7607

Open

Description

@zwoop

It seems that rather than parsing these types of "text" configs once, we parse it over and over again (strcmp()) on each transaction hitting this code:

std::string_view
HttpSM::get_outbound_sni() const
{
  using namespace ts::literals;
  ts::TextView zret;
  ts::TextView policy{t_state.txn_conf->ssl_client_sni_policy, ts::TextView::npos};

  if (policy.empty() || !strcmp(policy, "host"_tv)) {
    // By default the host header field value is used for the SNI.
    int len;
    char const *ptr = t_state.hdr_info.server_request.host_get(&len);
    zret.assign(ptr, len);
  } else if (ua_txn && !strcmp(policy, "server_name"_tv)) {
    zret.assign(ua_txn->get_netvc()->get_server_name(), ts::TextView::npos);
  } else if (policy.front() == '@') { // guaranteed non-empty from previous clause
    zret = policy.remove_prefix(1);
  } else {
    // If other is specified, like "remap" and "verify_with_name_source", the remapped origin name is used for the SNI value
    zret.assign(t_state.server_info.name, ts::TextView::npos);
  }
  return zret;
}

Activity

  1. added this to the 10.0.0 milestone on Mar 16, 2021
  2. masaori335 commented on Mar 16, 2021

    @masaori335
    Contributor

    set_tls_options has the same issue (proxy.config.ssl.client.verify.server.policy/proxy.config.ssl.client.verify.server.properties), I think.

    static void
    set_tls_options(NetVCOptions &opt, const OverridableHttpConfigParams *txn_conf)
    {
    char *verify_server = nullptr;
    if (txn_conf->ssl_client_verify_server_policy == nullptr) {
    opt.verifyServerPolicy = YamlSNIConfig::Policy::UNSET;
    } else {
    verify_server = txn_conf->ssl_client_verify_server_policy;
    if (strcmp(verify_server, "DISABLED") == 0) {
    opt.verifyServerPolicy = YamlSNIConfig::Policy::DISABLED;
    } else if (strcmp(verify_server, "PERMISSIVE") == 0) {
    opt.verifyServerPolicy = YamlSNIConfig::Policy::PERMISSIVE;
    } else if (strcmp(verify_server, "ENFORCED") == 0) {
    opt.verifyServerPolicy = YamlSNIConfig::Policy::ENFORCED;
    } else {
    Warning("%s is invalid for proxy.config.ssl.client.verify.server.policy. Should be one of DISABLED, PERMISSIVE, or ENFORCED",
    verify_server);
    opt.verifyServerPolicy = YamlSNIConfig::Policy::UNSET;
    }
    }
    if (txn_conf->ssl_client_verify_server_properties == nullptr) {
    opt.verifyServerProperties = YamlSNIConfig::Property::UNSET;
    } else {
    verify_server = txn_conf->ssl_client_verify_server_properties;
    if (strcmp(verify_server, "SIGNATURE") == 0) {
    opt.verifyServerProperties = YamlSNIConfig::Property::SIGNATURE_MASK;
    } else if (strcmp(verify_server, "NAME") == 0) {
    opt.verifyServerProperties = YamlSNIConfig::Property::NAME_MASK;
    } else if (strcmp(verify_server, "ALL") == 0) {
    opt.verifyServerProperties = YamlSNIConfig::Property::ALL_MASK;
    } else if (strcmp(verify_server, "NONE") == 0) {
    opt.verifyServerProperties = YamlSNIConfig::Property::NONE;
    } else {
    Warning("%s is invalid for proxy.config.ssl.client.verify.server.properties. Should be one of SIGNATURE, NAME, or ALL",
    verify_server);
    opt.verifyServerProperties = YamlSNIConfig::Property::NONE;
    }
    }
    }

  3. self-assigned this
    on Mar 23, 2021
  4. added a commit that references this issue on Mar 25, 2021
  5. SolidWallOfCode commented on Mar 29, 2021

    @SolidWallOfCode
    Member

    The tricky bit here is the value is not strictly an enumeration. It can have an arbitrary value as long as that value starts with "@". In such a case, the "@" is removed and the literal value is used as the outbound SNI. This means a string is required in some cases. What would be needed is an enumeration and a string, with the string set only when it's explicitly specified by a plugin.

  6. ywkaras commented on Mar 29, 2021

    @ywkaras

    It's unclear to me how using this function,

    /// Convert a string to an enumeration value.
    , leads to a simpler resolution of this issue. It is roughly equivalent to just: https://github.com/ywkaras/trafficserver/blob/b0453b157dba0b4d26bf8856f5f7198e2d9241e6/include/tscpp/util/CodeOrStr.h#L180

  7. removed their assignment
    on Mar 30, 2021
  8. github-actions commented on Mar 31, 2022

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. Marking it stale to flag it for further consideration by the community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions