<?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.21 (Ruby 3.3.6) -->
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-robert-mimi-attachments-03" category="info" tocInclude="true" sortRefs="true" symRefs="true" version="3">
  <!-- xml2rfc v2v3 conversion 3.25.0 -->
  <front>
    <title abbrev="MIMI">MIMI Attachments</title>
    <seriesInfo name="Internet-Draft" value="draft-robert-mimi-attachments-03"/>
    <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="January" day="10"/>
    <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>
      </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:
H4sIAAAAAAAAA81Ya28buRX9zl9B2MDW2UpKmi0KVI6DNWK3DZJsCjvZ/VAU
FmeGkgjNDGdJjmRtkPz2nktynpJ2s/3SBoj1GPI+zj338FLT6ZQ55XI55+9e
v3vNr50T6bqQpbNMJImR2/CAZTotRYFlmRFLNzU6kcZNC1Woqej2TJ99x1Lh
5Eqb/ZyrcqkZU5WZc2dq654/e/bXZ8+ZMFLM+b1Ma6Pcnm3kfqdNNuevSydN
Kd30hlwwZp0osweR6xJu99KySs35v5xOJ9xq44xcWrzbF/Tm34yJ2q21mTM+
5fBs5/xuxu98mIzjX4j+TlRrIfP+A21WolS/CKd0Oef/XGtZqkd+982NfyoL
oXKkIt3yexM2h9xnqS46X29m/I1eJ0Z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