<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!-- generated by https://github.com/cabo/kramdown-rfc version 1.7.17 (Ruby 3.3.3) -->
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-robert-mimi-attachments-02" category="info" tocInclude="true" sortRefs="true" symRefs="true" version="3">
  <!-- xml2rfc v2v3 conversion 3.22.0 -->
  <front>
    <title abbrev="MIMI">MIMI Attachments</title>
    <seriesInfo name="Internet-Draft" value="draft-robert-mimi-attachments-02"/>
    <author initials="R." surname="Robert" fullname="Raphael Robert">
      <organization>Phoenix R&amp;D</organization>
      <address>
        <email>ietf@raphaelrobert.com</email>
      </address>
    </author>
    <author initials="K." surname="Kohbrok" fullname="Konrad Kohbrok">
      <organization>Phoenix R&amp;D</organization>
      <address>
        <email>konrad.kohbrok@datashrine.de</email>
      </address>
    </author>
    <date year="2024" month="July" day="03"/>
    <area>Security</area>
    <keyword>Internet-Draft</keyword>
    <abstract>
      <?line 24?>

<t>This document describes MIMI Attachments.</t>
    </abstract>
  </front>
  <middle>
    <?line 28?>

<section anchor="introduction">
      <name>Introduction</name>
      <t>Attachments are known from email, where they are used to attach files to an
email message. Attachments are also used in instant messaging, where they are
used to attach files, images, videos, etc.</t>
      <t>The main difference between attachments and other messages is that attachments
are bigger in size and their content is typically saved in files on the client
side. Since downloading attachments can be expensive for instant messaging
clients, it is common to download attachments only on demand, e.g. when the user
clicks on the attachment.</t>
      <t>draft-mimi-content defines various message content formats that can be used in
either MLS application messages or attachments. This document describes how
attachments are used in MIMI.</t>
      <section anchor="change-log">
        <name>Change Log</name>
        <t>draft-01</t>
        <ul spacing="normal">
          <li>
            <t>Version bump to prevent expiration</t>
          </li>
        </ul>
        <t>draft-02</t>
        <ul spacing="normal">
          <li>
            <t>Version bump to prevent expiration</t>
          </li>
        </ul>
      </section>
    </section>
    <section anchor="access-control-quotas">
      <name>Access control &amp; quotas</name>
      <t>Attachments are bound to a specific MLS group. Only members of the group can
access the attachment. The Delivery Service enforces this access control.</t>
      <t>The Delivery Service can keep track of the size of attachments for each group,
its total number, who uploaded them, etc. This information can be used to
enforce quotas on the size of attachments, the number of attachments, etc.</t>
    </section>
    <section anchor="distribution">
      <name>Distribution</name>
      <t>Since attachments are not directly distributed as messages, they are distributed
over the MIMI Delivery Service.</t>
      <section anchor="uploading-attachments">
        <name>Uploading attachments</name>
        <t>When a client wants to send an attachment, it first uploads the attachment to
the Delivery Service. The Delivery Service returns a token that can be used to
download the attachment. The client then sends a message that contains the URL
and cryptographic key material to the intended recipients.</t>
        <t>TODO: This probably become part of <em>draft-robert-mimi-delivery-service</em>.</t>
        <t>The client first encrypts the attachment as descibed in <xref target="encryption"/> and then
uploads it to the DS using the following message:</t>
        <sourcecode type="tls"><![CDATA[
struct {
  opaque group_id<V>;
  opaque content<V>;
} UploadAttachmentRequest;
]]></sourcecode>
        <t>Upon succes, the Delivery Service returns the following message:</t>
        <sourcecode type="tls"><![CDATA[
struct {
  opaque token<V>;
} UploadAttachmentResponse;
]]></sourcecode>
      </section>
      <section anchor="sending-attachments">
        <name>Sending attachments</name>
        <t>Once clients have uploaded an attachment to the Delivery Service, they can send
messages that contain a reference to the attachment. The client sets the
contentType of the body as follows:</t>
        <sourcecode type="tls"><![CDATA[
body.contentType = "message/external-body; access-type=token;" +
  "token=<token>; nonce=<nonce>; hash=<hash>";
]]></sourcecode>
        <t>The token is the token that was received from the Delivery Service as part of
the UploadAttachmentResponse message. The nonce is a random byte sequence that
is used in the key derivation descibed in <xref target="encryption"/>. The hash is the hash
of the plaintext attachment content, as defined in <xref target="encryption"/>. The hash acts
as a commitment hash for the attachment content.</t>
        <t>TODO: This needs to be better aligned with draft-ietf-mimi-content.</t>
      </section>
      <section anchor="receiving-attachments">
        <name>Receiving attachments</name>
        <t>When a client receives a message that contains a reference to an attachment, it
first downloads the attachment from the Delivery Service using the following
message:</t>
        <sourcecode type="tls"><![CDATA[
struct {
  opaque group_id<V>;
  opaque token<V>;
} DownloadAttachmentRequest;
]]></sourcecode>
        <t>Upon succes, the Delivery Service returns the following message:</t>
        <sourcecode type="tls"><![CDATA[
struct {
  opaque content<V>;
} DownloadAttachmentResponse;
]]></sourcecode>
        <t>The client then decrypts the attachment using the nonce for the key derivation
 described in <xref target="encryption"/>.</t>
      </section>
      <section anchor="deleting-attachments">
        <name>Deleting attachments</name>
        <t>Attachments can either be deleted by members of the group (according to a
predefined policy), or by the Delivery Service after a predefined time.</t>
      </section>
      <section anchor="access-control">
        <name>Access control</name>
        <t>Attachments are bound to a specific MLS group. Only members of the group can
access the attachment. The Delivery Service enforces this access control.</t>
        <t>Attachments can however be shared between groups by either re-uploading the
attachment to the Delivery Service or by asking the Delivery Service to copy an
attachment to another group. Copying an attachment to another group is only
possible if both groups are located on the same Delivery Service, and the user
has access to both groups. It is an optimization to avoid re-uploading the same
attachment multiple times, but otherwise follows the same rules as uploading a
new attachment.</t>
      </section>
      <section anchor="encryption">
        <name>Encryption</name>
        <t>Attachments are encrypted using a nonce/key pair that is exported from the MLS
group exporter and combined with a randomly generated byte sequence on the
sender's side, and context data.</t>
        <artwork><![CDATA[
struct {
   opaque attachment_hash;
   uint64 sender_index;
} AttachmentContext;
]]></artwork>
        <t>Since attachments are specific to an MLS group, we reuse components the cipher
suite of the group:</t>
        <ul spacing="normal">
          <li>
            <t>KDF</t>
          </li>
          <li>
            <t>Hash</t>
          </li>
          <li>
            <t>AEAD</t>
          </li>
          <li>
            <t>ExpandWithLabel</t>
          </li>
        </ul>
        <t>The sender encrypts the attachment as follows:</t>
        <ul spacing="normal">
          <li>
            <t>Compute the hash of the attachment data:</t>
          </li>
        </ul>
        <artwork><![CDATA[
attachment_hash = Hash(plaintext)
]]></artwork>
        <ul spacing="normal">
          <li>
            <t>Generate a random byte sequence <tt>nonce</tt> of length <tt>KDF.Nh</tt> bytes.</t>
          </li>
          <li>
            <t>Set the context to the following values: <tt>AttachmentContext.hash</tt>
to the previously computed <tt>attachment_hash</tt> and
<tt>AttachmentContext.sender_index</tt> to the leaf index of the sender in the group.</t>
          </li>
          <li>
            <t>Compute a secret <tt>attachment_exporter_secret</tt> from the MLS group
exporter using the previously computed context and extracts
<tt>attachment_secret</tt> from it and the nonce:</t>
          </li>
        </ul>
        <artwork><![CDATA[
attachment_exporter_secret =
   MLS-Exporter("MIMI attachment", context, KDF.Nh)

attachment_secret =
   KDF.Extract(attachment_exporter_secret, nonce)
]]></artwork>
        <ul spacing="normal">
          <li>
            <t>Compute the nonce/key pair:</t>
          </li>
        </ul>
        <artwork><![CDATA[
attachment_nonce =
   ExpandWithLabel(attachment_secret, "nonce", "", AEAD.Nn)

attachment_key =
   ExpandWithLabel(attachment_secret, "key", "", AEAD.Nk)
]]></artwork>
        <ul spacing="normal">
          <li>
            <t>Encrypt the attachment using the key/nonce pair.</t>
          </li>
        </ul>
      </section>
    </section>
  </middle>
  <back>






  </back>
  <!-- ##markdown-source:
H4sIAAAAAAAAA81YbY8btxH+zl9B3AHpOZVk1ygCVOczcvBdU8N2HNzZyYei
OHF3KYnQ7nJDcqVTDPu39xmS+6aVErdfWgM+vSw5nHnmmWeGmk6nzCmXyzl/
9/rda37tnEjXhSydZSJJjNyGByzTaSkKLMuMWLqp0Yk0blqoQk1Ft2f67DlL
hZMrbfZzrsqlZkxVZs6dqa17/uzZ37BAGCnm/F6mtVFuzzZyv9Mmm/PXpZOm
lG56Q0cwZp0osweR6xLH7qVllZrzfzqdTrjVxhm5tHi3L+jNvxgTtVtrM2d8
ynGynfO7Gb/zbjKOf8H7O1Gthcz7D7RZiVL9JpzS5Zz/tNayVI/87psb/1QW
QuUIRbrl9yZsDrHPUl10Z72Z8Td6nRi96R32RpdGZIMHX3XYxu+bbcK+7zPh
hF0bVcpZJhmbTqdcJNYZkQKkD2tlO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