<?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.29 (Ruby 3.4.4) -->
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-robert-mimi-attachments-04" category="info" tocInclude="true" sortRefs="true" symRefs="true" version="3">
  <!-- xml2rfc v2v3 conversion 3.29.0 -->
  <front>
    <title abbrev="MIMI">MIMI Attachments</title>
    <seriesInfo name="Internet-Draft" value="draft-robert-mimi-attachments-04"/>
    <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="2025" month="July" day="07"/>
    <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>
        <t>draft-03</t>
        <ul spacing="normal">
          <li>
            <t>Version bump to prevent expiration</t>
          </li>
        </ul>
        <t>draft-04</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:
H4sIAAAAAAAAA81Ya28buRX9zl9B2MDW2UqKmwYFKsfBGpHbBkk2hZ3sfigK
izNDSYRmhrMkR7I2SH57zyU5Lz12k35pA8R6DHkf5557eKnxeMyccrmc8nev
373mN86JdFXI0lkmksTITXjAMp2WosCyzIiFGxudSOPGhSrUWHR7xpfPWSqc
XGqzm3JVLjRjqjJT7kxt3bPLy79ePmPCSDHl9zKtjXI7tpa7rTbZlL8unTSl
dOMZuWDMOlFmDyLXJdzupGWVmvJ/OZ2OuNXGGbmweLcr6M2/GRO1W2kzZXzM
4dlO+d2E3/kwGce/EP2dqFZC5v0H2ixFqX4V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