<def-group>
  <definition class="compliance" id="sshd_use_strong_kex" version="1">
    {{{ oval_metadata("Limit the Key Exchange Algorithms to those which are FIPS-approved.") }}}
    <criteria comment="SSH is configured correctly or is not installed"
        operator="OR">
      <criteria comment="sshd is not installed" operator="AND">
        <extend_definition comment="sshd is not required or requirement is unset"
            definition_ref="sshd_not_required_or_unset" />
        {{% if product in ['opensuse', 'sle12', 'sle15'] %}}
        <extend_definition comment="package openssh removed"
            definition_ref="package_openssh_removed" />
        {{% else %}}
        <extend_definition comment="package openssh-server removed"
            definition_ref="package_openssh-server_removed" />
        {{% endif %}}
      </criteria>
      <criteria comment="sshd is installed and configured" operator="AND">
        <extend_definition comment="sshd is required or requirement is unset"
            definition_ref="sshd_required_or_unset" />
        {{% if product in ['opensuse', 'sle12', 'sle15'] %}}
        <extend_definition comment="package openssh installed"
            definition_ref="package_openssh_installed" />
        {{% else %}}
        <extend_definition comment="package openssh-server installed"
            definition_ref="package_openssh-server_installed" />
        {{% endif %}}
        <criterion comment="Check KexAlgorithms in /etc/ssh/sshd_config"
            test_ref="test_sshd_use_strong_kex" />
      </criteria>
    </criteria>
  </definition>

  <ind:variable_test check="at least one"
  comment="tests the value of KexAlgorithms setting in the /etc/ssh/sshd_config file"
  id="test_sshd_use_strong_kex" version="1">
    <ind:object object_ref="obj_sshd_use_strong_kex" />
    <ind:state state_ref="ste_sshd_use_strong_kex" />
  </ind:variable_test>

  <ind:variable_object id="obj_sshd_use_strong_kex" version="1">
    <ind:var_ref>var_sshd_config_kex</ind:var_ref>
  </ind:variable_object>

  <ind:variable_state comment="approved strong kex" id="ste_sshd_use_strong_kex" version="1">
    <ind:value operation="equals" datatype="string" var_ref="var_sshd_strong_kex" var_check="at least one" />
  </ind:variable_state>

  <ind:textfilecontent54_object id="obj_sshd_config_kex" version="1">
    <ind:filepath>/etc/ssh/sshd_config</ind:filepath>
    <ind:pattern operation="pattern match">^[\s]*(?i)KexAlgorithms(?-i)[\s]+([\w,-@]+)+[\s]*(?:#.*)?$</ind:pattern>
    <ind:instance datatype="int">1</ind:instance>
  </ind:textfilecontent54_object>

  <local_variable id="var_sshd_config_kex" datatype="string" version="1" comment="KEXs values splitted on comma">
    <split delimiter=",">
      <object_component item_field="subexpression" object_ref="obj_sshd_config_kex" />
    </split>
  </local_variable>

  <local_variable id="var_sshd_strong_kex" datatype="string" version="1" comment="approved strong KEX values splitted on comma">
    <split delimiter=",">
      <variable_component var_ref="sshd_strong_kex" />
    </split>
  </local_variable>
  <external_variable comment="SSH Approved KEX by FIPS" datatype="string" id="sshd_strong_kex" version="1" />
</def-group>
