<?xml version="1.0" encoding="UTF-8"?>
<!--
  Device:2 Root Data Model: Common Object definitions [Security]

  Copyright (c) 2010-2023, Broadband Forum

  Redistribution and use in source and binary forms, with or
  without modification, are permitted provided that the following
  conditions are met:

  1. Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above
     copyright notice, this list of conditions and the following
     disclaimer in the documentation and/or other materials
     provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its
     contributors may be used to endorse or promote products
     derived from this software without specific prior written
     permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

  The above license is used as a license under copyright only.
  Please reference the Forum IPR Policy for patent licensing terms
  <https://www.broadband-forum.org/ipr-policy>.

  Any moral rights which are necessary to exercise under the above
  license grant are also deemed granted under this license.

  Comments or questions about this Broadband Forum data model should be
  directed to <info@broadband-forum.org>.
-->

<dm:document
    xmlns:dm="urn:broadband-forum-org:cwmp:datamodel-1-10"
    xmlns:dmr="urn:broadband-forum-org:cwmp:datamodel-report-1-0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
      urn:broadband-forum-org:cwmp:datamodel-1-10
        https://www.broadband-forum.org/cwmp/cwmp-datamodel-1-10.xsd
      urn:broadband-forum-org:cwmp:datamodel-report-1-0
        https://www.broadband-forum.org/cwmp/cwmp-datamodel-report-1-0.xsd"
    spec="urn:broadband-forum-org:tr-181-2-21-0-security"
    file="tr-181-2-21-0-security.xml">

  <import file="tr-069-biblio.xml" spec="urn:broadband-forum-org:tr-069"/>

  <import file="tr-106-types.xml" spec="urn:broadband-forum-org:tr-106">
    <component name="Alias"/>
  </import>

  <import file="tr-181-2-root.xml"
      spec="urn:broadband-forum-org:tr-181-2-21-root">
    <component name="Root"/>
  </import>

   <component name="TLSClient">
    <component ref="ClientCerts"/>

    <parameter name="CipherList" access="readOnly" version="2.21">
      <description>
        Each item in this list specifies a cipher that the TLS client is allowed to use.
        When {{empty}} the system defaults are used.
      </description>
      <syntax>
        <list/>
        <string/>
      </syntax>
    </parameter>
  </component>

  <component name="TLSServer">
    <component ref="ServerCerts"/>
    
    <parameter name="CipherList" access="readOnly" version="2.21">
      <description>
        Each item in this list specifies a cipher that the TLS server is allowed to use.
        When {{empty}} the system defaults are used.
      </description>
      <syntax>
        <list/>
        <string/>
      </syntax>
    </parameter>
  </component>

  <component name="ClientCerts">
    <component ref="ClientCertsNoDefault"/>
    <parameter base="Certificate">
      <syntax>
        <string/>
        <default type="object" value=""/>
      </syntax>
    </parameter>
    <parameter base="CABundle">
      <syntax>
        <string/>
        <default type="object" value=""/>
      </syntax>
    </parameter>
  </component>
 
  <component name="ClientCertsNoDefault">
    <parameter name="Certificate" access="readWrite" version="2.0">
      <description>
        Specifies the client certificate that must be presented to the remote server for mutual authentication.
        This certificate is used to authenticate the client by the remote server, ensuring that the remote server is communicating with a trusted client.
        The client certificate must be issued by a trusted Certificate Authority (CA) and should match the client's private key.
        This parameter is applicable only when a TLS session is being used.
      </description>
      <syntax>
        <string>
          <pathRef refType="strong" targetParent=".Security.Certificate." targetType="row"/>
        </string>
      </syntax>
    </parameter>

    <parameter name="CABundle" access="readWrite" version="2.19">
      <description>
        Specifies the group of CA certificate(s) that the client must use to validate the certificate presented by the remote server.
        These CA certificates form a trust chain that the server certificate must match, ensuring that only servers with trusted certificates can establish a connection.
        This parameter supports multiple CA certificates to accommodate different server certificate issuers.
        This parameter is applicable only when a TLS session is being used.
      </description>
      <syntax>
        <string>
          <pathRef refType="strong" targetParent=".Security.CABundle." targetType="row"/>
        </string>
      </syntax>
    </parameter>
  </component>

  <component name="ServerCerts">
    <component ref="ServerCertsNoDefault"/>
    <parameter base="Certificate">
      <syntax>
        <string/>
        <default type="object" value=""/>
      </syntax>
    </parameter>
    <parameter base="CABundle">
      <syntax>
        <string/>
        <default type="object" value=""/>
      </syntax>
    </parameter>
  </component>

  <component name="ServerCertsNoDefault">
    <parameter name="Certificate" access="readWrite" version="2.16">
      <description>
        Specifies the server certificate to be presented by the server during the TLS handshake.
        This certificate is used to authenticate the server to remote clients, ensuring that the clients are connecting to a legitimate server.
        The server certificate must be issued by a trusted Certificate Authority (CA) and should match the server's private key.
        This parameter is applicable only when a TLS session is being used.
      </description>
      <syntax>
        <string>
          <pathRef refType="strong" targetParent=".Security.Certificate." targetType="row"/>
        </string>
      </syntax>
    </parameter>

    <parameter name="CABundle" access="readWrite" version="2.19">
      <description>
        Specifies the group of CA certificate(s) that the server must use to validate the certificate presented by the remote client.
        These CA certificates form a trust chain that the client certificate must match, ensuring that only clients with trusted certificates can establish a connection.
        This parameter supports multiple CA certificates to accommodate different client certificate issuers.
        This parameter is applicable only when a TLS session is being used.
      </description>
      <syntax>
        <string>
          <pathRef refType="strong" targetParent=".Security.CABundle." targetType="row"/>
        </string>
      </syntax>
    </parameter>
  </component>

  <component name="Security">
    <object name="Device.Security." access="readOnly" minEntries="1"
        maxEntries="1" version="2.4">
      <description>
        This object contains general information related to managing security
        features on the device.
      </description>

      <parameter name="CertificateNumberOfEntries" access="readOnly">
        <description>
          {{numentries}}
        </description>
        <syntax>
          <unsignedInt/>
        </syntax>
      </parameter>

      <parameter name="CABundleNumberOfEntries" access="readOnly" version="2.19">
        <description>
          {{numentries}}
        </description>
        <syntax>
          <unsignedInt/>
        </syntax>
      </parameter>
    </object>

    <object name="Device.Security.Certificate.{i}." access="readOnly"
        numEntriesParameter="CertificateNumberOfEntries" minEntries="0"
        maxEntries="unbounded" version="2.4">
      <description>
        This table provides information about all types of public key-based
        credentials, such as X.509 certificates, see {{bibref|RFC5280}}.
      </description>
      <uniqueKey functional="false">
        <parameter ref="Alias"/>
      </uniqueKey>
      <uniqueKey functional="true">
        <parameter ref="SerialNumber"/>
        <parameter ref="Issuer"/>
      </uniqueKey>
      <uniqueKey functional="true">
        <parameter ref="Name"/>
      </uniqueKey>

      <parameter name="Enable" access="readWrite">
        <description>
          Enables or disables this certificate.
        </description>
        <syntax>
          <boolean/>
        </syntax>
      </parameter>

      <component ref="Alias" version="2.21"/>

      <parameter name="Name" access="readOnly" version="2.21">
        <description>
          User-defined name to identify and categorize the certificate (e.g.,
          "mqtt-broker", "webserver", "vpn-client"). The implementation MAY
          use this name to determine which secure storage to use and how to
          persist the key.
        </description>
        <syntax>
          <string>
            <size maxLength="64"/>
          </string>
        </syntax>
      </parameter>

      <parameter name="LastModif" access="readOnly">
        <description>
          The last modification time of this certificate.
        </description>
        <syntax>
          <dateTime/>
        </syntax>
      </parameter>

      <parameter name="SerialNumber" access="readOnly">
        <description>
          The Serial Number field in an X.509 certificate, see
          {{bibref|RFC5280}}.
        </description>
        <syntax>
          <string>
            <size maxLength="64"/>
          </string>
        </syntax>
      </parameter>

      <parameter name="Issuer" access="readOnly">
        <description>
          The Issuer field in an X.509 certificate, see {{bibref|RFC5280}};
          i.e. the Distinguished Name (DN) of the entity who has signed the
          certificate.
        </description>
        <syntax>
          <string>
            <size maxLength="256"/>
          </string>
        </syntax>
      </parameter>

      <parameter name="NotBefore" access="readOnly">
        <description>
          The beginning of the certificate validity period; i.e. the Not Before
          field in an X.509 certificate, see {{bibref|RFC5280}}.
        </description>
        <syntax>
          <dateTime/>
        </syntax>
      </parameter>

      <parameter name="NotAfter" access="readOnly">
        <description>
          The end of the certificate validity period; i.e., the Not After field
          in an X.509 certificate, see {{bibref|RFC5280}}.
        </description>
        <syntax>
          <dateTime/>
        </syntax>
      </parameter>

      <parameter name="Subject" access="readOnly">
        <description>
          The Distinguished Name (DN) of the entity associated with the Public
          Key; i.e., the Subject field in an X.509 certificate, see
          {{bibref|RFC5280}}.
        </description>
        <syntax>
          <string>
            <size maxLength="256"/>
          </string>
        </syntax>
      </parameter>

      <parameter name="SubjectAlt" access="readOnly">
        <description>
          {{list}} Each item specifies an identity that is bound to the
          certificate's subject, and thus bound to the Public Key.

          The Subject Alternative Names extension field in an X.509 certificate,
          see {{bibref|RFC5280}}.
        </description>
        <syntax>
          <list>
            <size maxLength="256"/>
          </list>
          <string/>
        </syntax>
      </parameter>

      <parameter name="SignatureAlgorithm" access="readOnly">
        <description>
          The algorithm used in signing the certificate; i.e. the Signature
          Algorithm field in an X.509 certificate, see {{bibref|RFC5280}}.
        </description>
        <syntax>
          <string>
            <size maxLength="256"/>
          </string>
        </syntax>
      </parameter>
    </object>

    <object name="Device.Security.CABundle.{i}." access="readOnly"
        numEntriesParameter="CABundleNumberOfEntries" minEntries="0"
        maxEntries="unbounded" version="2.19">
      <description>
        This table stores information about a group of Certificate Authorities (CAs).
        A CA is a trusted entity that issues digital certificates used to verify the identity of servers,
        clients, or other entities in secure communication protocols like TLS.

        This group defines a collection of trusted CA certificates that can be used to validate server certificates during TLS connections.
      </description>
      <uniqueKey functional="false">
        <parameter ref="Name"/>
      </uniqueKey>

      <parameter name="Enable" access="readWrite">
        <description>
          Enables or disables this CA group.

          When disabled, the certificates within this group will not be used for validation.
        </description>
        <syntax>
          <boolean/>
        </syntax>
      </parameter>

      <parameter name="Name" access="readOnly">
        <description>
          The textual name assigned to this CA group for identification.
        </description>
        <syntax>
          <string/>
        </syntax>
      </parameter>

      <parameter name="CACertificates" access="readWrite" version="2.19">
        <description>
          Specifies the CA certificate(s) that the client must use to validate the certificate presented by the remote server.
          These CA certificates form a trust chain that the server certificate must match, ensuring that only servers with trusted certificates can establish a connection.
          This parameter supports multiple CA certificates to accommodate different server certificate issuers.
          This parameter is applicable only when a TLS session is being used.
        </description>
        <syntax>
          <list/>
          <string>
            <pathRef refType="strong" targetParent=".Security.Certificate." targetType="row"/>
          </string>
        </syntax>
      </parameter>
    </object>
  </component>

  <component name="SecurityUSP">
    <object base="Device.Security.Certificate.{i}." >
      <command name="GetCertificateURI()" async="false" version="2.20">
        <description>
          Returns the path to the X.509 certificate and its corresponding private key that is
          associated with the entry of the {{object}} table.
        </description>
        <output>
          <parameter name="CertificateURI">
            <description>
              The absolute or relative path to the certificate file,
              specified as an {{bibref|RFC8089}} (The file URI Scheme).
            </description>
            <syntax>
              <dataType ref="FileURI"/>
            </syntax>
          </parameter>

          <parameter name="PrivateKeyURI">
            <description>
              The URI for the private key associated with this certificate, formatted according to
              {{bibref|RFC7512}}. This URI should point to the key's location on a hardware security
              module (HSM) or other cryptographic token.

              For security reasons, the URI MUST NOT include any PIN information (e.g.,`pin-value`). The
              service responsible for managing the token should inject the required PIN at runtime. This
              practice prevents unauthorized access and malicious reuse of the private key by other
              services. 
            </description>
            <syntax>
              <string/>
            </syntax>
          </parameter>
        </output>
      </command>

      <command name="Delete()" async="false" version="2.21">
        <description>
          Deletes the certificate.
        </description>
      </command>
    </object>

    <object base="Device.Security.CABundle.{i}.">
      <command name="CADir()" async="false">
        <description>
          Returns the path to the directory containing CA certificates.

          This is necessary for services, especially microservices in host or
          container environments requiring mTLS, to locate the appropriate
          CA certificates during configuration.

          Depending on the security requirements a service-specific CA directory
          may be required.
        </description>
        <output>
          <parameter name="CADir">
            <description>
              This parameter specifies the absolute or relative path to the
              directory containing the CA certificate bundle,
              specified as an {{bibref|RFC8089}} URI (The file URI Scheme).
            </description>
            <syntax>
              <dataType ref="FileURI"/>
            </syntax>
          </parameter>
        </output>
      </command>

      <command name="CAFile()" async="false">
        <description>
          Returns the path to a file containing one or more CA certificates.

          This is necessary for services, especially microservices in host or
          container environments requiring mTLS, to locate the appropriate
          CA certificates during configuration.

          Depending on the security requirements a service-specific CA file
          may be required.
        </description>
        <output>
          <parameter name="CAFile">
            <description>
              The absolute or relative path to the file containing the
              CA certificate(s), specified as an {{bibref|RFC8089}} URI (The file URI Scheme).
            </description>
            <syntax>
              <dataType ref="FileURI"/>
            </syntax>
          </parameter>
        </output>
      </command>

      <command name="Update()" async="false" version="2.21">
        <description>
          Updates the CA bundle with new certificate content. The new
          bundle completely replaces the existing CA certificates.

          For example, if the current bundle contains 5 CA
          certificates and the new bundle contains only 3 CA
          certificates, the 2 CA certificates that are not present in
          the new bundle will be deleted.

          If the update fails, the previous bundle is kept as-is.

          The device SHOULD reject the operation with the following
          fault codes for specific error conditions:

          * If the bundle does not contain valid PEM formatted
           certificates, the device SHOULD reject the operation with a
           7265 (Invalid PEM Format) fault code.

          * If the bundle could not be imported, the device SHOULD
           reject the operation with a 7262 (Failed To Import Bundle)
           fault code.

          * If one or more certificates in the bundle could not be
           imported, the device SHOULD reject the operation with a 7263
           (Failed To Import Certificate) fault code.

          * If there is insufficient disk space to store the CA bundle,
           the device SHOULD reject the operation with a 7266
           (Insufficient Disk Space) fault code.
        </description>
        <input>
          <parameter name="Bundle" mandatory="true">
            <description>
              One or more X.509 CA certificates in PEM format,
              concatenated into a single PEM file.
            </description>
            <syntax>
              <hexBinary/>
            </syntax>
          </parameter>
        </input>
        <output>
          <parameter name="NumberOfCertificates">
            <description>
              The number of CA certificates successfully installed
              from the bundle.
            </description>
            <syntax>
              <unsignedInt/>
            </syntax>
          </parameter>
        </output>
      </command>

      <command name="Delete()" async="false" version="2.21">
        <description>
          Deletes the CA bundle.
        </description>
      </command>
    </object>

    <object base="Device.Security.">
      <parameter name="SupportedBundleFormats" access="readOnly"
          version="2.21">
        <description>
          Each item indicates a bundle format that is supported by the
          {{command|AddCertificateBundle()}} command.
        </description>
        <syntax>
          <list/>
          <string>
            <enumeration value="PKCS12"/>
            <enumeration value="PEM"/>
          </string>
        </syntax>
      </parameter>

      <command name="AddCertificateBundle()" async="false" version="2.21">
        <description>
          The device installs the new bundle and updates the
          `Device.Security.Certificate.{i}`. The bundle (e.g., PKCS#12,
          PEM) contains both a certificate and a private key.

          If a certificate with the same
          {{param|Device.Security.Certificate.{i}.SerialNumber}} and
          {{param|Device.Security.Certificate.{i}.Issuer}} already
          exists in the device, the existing certificate is replaced
          with the new certificate, and the {{param|Certificate}}
          output parameter references the updated entry.

          The device SHOULD reject the operation with the following
          fault codes for specific error conditions:

          * If the specified bundle format is not supported, the device
           SHOULD reject the operation with a 7260 (Bundle Format Not
           Supported) fault code.

          * If the bundle signature verification fails, the device
           SHOULD reject the operation with a 7261 (Bundle Signature
           Failure) fault code.

          * If the bundle could not be imported, the device SHOULD
           reject the operation with a 7262 (Failed To Import Bundle)
           fault code.

          * If the certificate in the bundle could not be imported, the
           device SHOULD reject the operation with a 7263 (Failed To
           Import Certificate) fault code.

          * If the private key in the bundle could not be imported, the
           device SHOULD reject the operation with a 7264 (Failed To
           Import Private Key) fault code.

          * If the certificate has a SerialNumber and Issuer that match an
           existing certificate with a different Name, the device SHOULD
           reject the operation with a 7270 (Certificate Identity Conflict)
           fault code.
        </description>
        <input>
          <parameter name="Alias">
            <description>
              An optional input the Controller can use to specify the
              {{param|.Security.Certificate.{i}.Alias}} value for the added entry. 
              
              If provided as an input and the value already exists in
              {{object|.Security.Certificate.{i}}}, this command will fail.
            </description>
            <syntax>
              <dataType ref="Alias"/>
            </syntax>
          </parameter>

          <parameter name="Name" mandatory="true">
            <description>
              User-defined name to identify the certificate.

              If a certificate with the same Name already exists in
              {{object|.Security.Certificate.{i}.}}, the existing certificate will be
              replaced with the certificate from the bundle.
            </description>
            <syntax>
              <string>
                <size maxLength="64"/>
              </string>
            </syntax>
          </parameter>

          <parameter name="BundleFormat" mandatory="true">
            <description>
              The format of the bundle.
            </description>
            <syntax>
              <string>
                <enumerationRef
                    targetParam="SupportedBundleFormats"/>
              </string>
            </syntax>
          </parameter>

          <parameter name="Bundle" mandatory="true">
            <description>
              The bundle containing the certificate and private key.
              It is good practice for the bundle to be encrypted and
              signed.

              How the bundle is decrypted, verified, and installed on
              the system depends on the device design and is
              considered implementation specific.
            </description>
            <syntax>
              <hexBinary/>
            </syntax>
          </parameter>
        </input>
        <output>
          <parameter name="Certificate">
            <description>
              Specifies the location where the certificate was
              installed.
            </description>
            <syntax>
              <string>
                <pathRef refType="strong"
                    targetParent=".Security.Certificate."
                    targetType="row"/>
              </string>
            </syntax>
          </parameter>
        </output>
      </command>

      <command name="AddCABundle()" async="false" version="2.21">
        <description>
          The device installs the new CA bundle and adds an entry to
          the {{object|Device.Security.CABundle.{i}.}} table.

          If a CA bundle with the same
          {{param|Device.Security.CABundle.{i}.Name}} already exists
          in the device, the device SHOULD reject the operation with a
          7267 (Duplicate CA Bundle Name) fault code.

          The device SHOULD reject the operation with the following
          fault codes for specific error conditions:

          * If the bundle does not contain valid PEM formatted
           certificates, the device SHOULD reject the operation with a
           7265 (Invalid PEM Format) fault code.

          * If the bundle could not be imported, the device SHOULD
           reject the operation with a 7262 (Failed To Import Bundle)
           fault code.

          * If one or more certificates in the bundle could not be
           imported, the device SHOULD reject the operation with a 7263
           (Failed To Import Certificate) fault code.

          * If there is insufficient disk space to store the CA bundle,
           the device SHOULD reject the operation with a 7266
           (Insufficient Disk Space) fault code.
        </description>
        <input>
          <parameter name="Name" mandatory="true">
            <description>
              The name of the new CA bundle.
            </description>
            <syntax>
              <string/>
            </syntax>
          </parameter>

          <parameter name="Bundle" mandatory="true">
            <description>
              One or more X.509 CA certificates in PEM format,
              concatenated into a single PEM file.
            </description>
            <syntax>
              <hexBinary/>
            </syntax>
          </parameter>
        </input>
        <output>
          <parameter name="CABundle">
            <description>
              Specifies the location where the CA bundle was installed.
            </description>
            <syntax>
              <string>
                <pathRef refType="strong"
                    targetParent=".Security.CABundle." targetType="row"/>
              </string>
            </syntax>
          </parameter>

          <parameter name="NumberOfCertificates">
            <description>
              The number of CA certificates successfully installed
              from the bundle.
            </description>
            <syntax>
              <unsignedInt/>
            </syntax>
          </parameter>
        </output>
      </command>
    </object>
  </component>

  <model name="Security:2.21">
    <component ref="Root"/>
    <component ref="Security"/>
  </model>
</dm:document>
