<?xml version="1.0" encoding="utf-8"?>
<?xml-model href="rfc7991bis.rnc"?>
<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>

<rfc xmlns:xi="http://www.w3.org/2001/XInclude"
     ipr="trust200902" submissionType="IETF" category="std" version="3" docName="draft-misell-acme-onion-01">
  <front>
    <title abbrev="ACME for .onion Domains">Automated Certificate Management Environment (ACME) Extensions for ".onion" Domain Names</title>
    <seriesInfo name="Internet-Draft" status="standard" value="draft-misell-acme-onion-01"/>
    <author fullname="Q Misell" initials="Q" role="editor" surname="Misell">
      <organization abbrev="AS207960">AS207960 Cyfyngedig</organization>
      <address>
        <postal>
          <street>13 Pen-y-lan Terrace</street>
          <city>Caerdydd</city>
          <code>CF23 9EU</code>
          <country>United Kingdom</country>
        </postal>
        <email>q@magicalcodewit.ch</email>
        <email>q@as207970.net</email>
        <uri>https://magicalcodewit.ch</uri>
      </address>
    </author>
    <area>sec</area>
    <workgroup>Internet Engineering Task Force</workgroup>

    <abstract>
      <t>The documents defines extensions to the Automated Certificate Management Environment (ACME) to allow for the
        automatic issuance of certificates to Tor hidden services (".onion" domains).</t>
    </abstract>

    <note removeInRFC="true">
      <name>Discussion</name>
      <t>Source for this draft and an issue tracker can be found at
        <eref target="https://github.com/AS207960/acme-onion"/>.</t>
      <t>The project website and a reference implementation can be found at
        <eref target="https://acmeforonions.org"/>.</t>
    </note>
  </front>

  <middle>
    <section>
      <name>Introduction</name>
      <t>The Tor network has the ability to host "Onion Services" <xref target="tor-rend-spec-v3"/>
        <xref target="tor-address-spec"/> only accessible via the Tor network. These use the special use ".onion"
        top-level domain <xref target="RFC7686"/> to identify these services. These can be used as any other domain
        name could, but do not form part of the DNS infrastructure.</t>
      <t>The Automated Certificate Management Environment (ACME) <xref target="RFC8555"/> defines challenges for
        validating control of DNS identifiers, and whilst a ".onion" domain may appear as a DNS name, it requires
        special consideration to validate control of one such that ACME could be used on ".onion" domains.</t>
      <t>In order to allow ACME to be utilised to issue certificates to ".onion" domains this document specifies
        challenges suitable to validate control of these domains. Additionally this document defines an alternative
        to the DNS Certification Authority Authorization (CAA) Resource Record <xref target="RFC8659"/> that can be
        used with ".onion" domains.</t>

      <section>
        <name>Requirements Language</name>
        <t>The key words <bcp14>MUST</bcp14>, <bcp14>MUST NOT</bcp14>, <bcp14>REQUIRED</bcp14>, <bcp14>SHALL</bcp14>,
          <bcp14>SHALL NOT</bcp14>, <bcp14>SHOULD</bcp14>, <bcp14>SHOULD NOT</bcp14>, <bcp14>RECOMMENDED</bcp14>,
          <bcp14>NOT RECOMMENDED</bcp14>, <bcp14>MAY</bcp14>, and <bcp14>OPTIONAL</bcp14> in this document are to be
          interpreted as described in <xref target="BCP14"/> when, and only when, they appear in all capitals,
          as shown here.</t>
      </section>
    </section>

    <section>
      <name>Identifier</name>
      <t><xref target="RFC8555"/> defines the "dns" identifier type. This identifier type <bcp14>MUST</bcp14> be used
        when requesting a certificate for a ".onion" domain. The value of identifier <bcp14>MUST</bcp14> be the textual
        representation as defined in <xref target="tor-address-spec"/> §3. The value <bcp14>MAY</bcp14>
        include subdomain labels. Version 2 addresses <bcp14>MUST NOT</bcp14> be used as these are now considered
        insecure.</t>
      <t>Example identifiers:</t>
      <sourcecode type="json">
{
  "type": "dns",
  "value": "bbcweb3hytmzhn5d532owbu6oqadra5z3ar726vq5kgwwn6aucdccrad.onion"
}
      </sourcecode>
      <sourcecode type="json">
{
  "type": "dns",
  "value": "www.bbcweb3hytmzhn5d532owbu6oqadra5z3ar726vq5kgwwn6aucdccrad.onion"
}
      </sourcecode>
    </section>

    <section>
      <name>Identifier Validation Challenges</name>
      <t>The CA/Browser Forum Baseline Requirements <xref target="cabf-br" /> §B.2 define methods accepted by
        the CA industry for validation of ".onion" domains. This document incorporates these methods into ACME
        challenges.</t>
      <section>
        <name>Existing challenges</name>
        <section>
          <name>Existing "dns-01" Challenge</name>
          <t>The existing "dns-01" challenge <bcp14>MUST NOT</bcp14> be used to validate ".onion" domains.</t>
        </section>
        <section>
          <name>Existing "http-01" Challenge</name>
          <t>The "http-01" challenge is defined as in <xref target="RFC8555"/> §8.3 may be used to validate a ".onion"
            domain, with the modifications defined in this standard.</t>
          <t>The ACME server <bcp14>SHOULD</bcp14> follow redirects; note that these may be redirects to non ".onion"
            services, and the server <bcp14>SHOULD</bcp14> honour these.</t>
        </section>
        <section>
          <name>Existing "tls-alpn-01" Challenge</name>
          <t>The "tls-alpn-01" challenge is defined as in <xref target="RFC8737"/> may be used to validate a ".onion"
            domain, with the modifications defined in this standard.</t>
        </section>
      </section>
      <section>
        <name>New "onion-csr-01" Challenge</name>
        <t>The two methods already defined in ACME and allowed by the CA/BF do not allow issuance of wildcard
          certificates. This new validation method incorporates the specially signed CSR (as defined by
          <xref target="cabf-br" /> § B.2.b) into ACME to allow for the issuance of wildcard certificates.</t>
        <t>To this end a new challenge type called "onion-csr-01" is defined, with the following fields:</t>
        <dl>
          <dt>type (required, string)</dt>
          <dd>The string "onion-csr-01"</dd>
          <dt>nonce (required, string)</dt>
          <dd>A Base64 <xref target="RFC4648"/> encoded nonce, including padding characters.
            It <bcp14>MUST</bcp14> contain at least 64 bits of entropy. It <bcp14>MUST NOT</bcp14> be valid for more
            than 30 days.</dd>
          <dt>authKey (optional, object)</dt>
          <dd>The Ed25519 public key encoded as per <xref target="RFC8037"/>.</dd>
        </dl>
        <sourcecode type="json">
{
  "type": "onion-csr-01",
  "url": "https://example.com/acme/chall/bbc625c5",
  "status": "pending",
  "nonce": "bI6/MRqV4gw=",
  "authKey": { ... }
}
        </sourcecode>
        <t>Clients may prove control over the key associated with the ".onion" service by generating their CSR with the
          following additional extension attributes and signing it with the private key of the ".onion" domain:</t>
        <ul>
          <li>A caSigningNonce attribute containing the nonce provided in the challenge. This <bcp14>MUST</bcp14>
            be raw bytes, and not the base64 encoded value provided in the challenge object.</li>
          <li>An applicantSigningNonce containing a nonce generated by the client. This <bcp14>MUST</bcp14> have at
            least 64 bits of entropy. This <bcp14>MUST</bcp14> be raw bytes.</li>
        </ul>
        <t>These additional attributes have the following format</t>
        <sourcecode type="asn.1">
id-pkix  OBJECT IDENTIFIER ::=
  { iso(1) identified-organization(3) dod(6) internet(1) security(5)
    mechanisms(5) pkix(7) }

id-pe OBJECT IDENTIFIER ::= { id-pkix 1 }

cabf OBJECT IDENTIFIER ::=
  { joint-iso-itu-t(2) international-organizations(23)
    ca-browser-forum(140) }

cabf-caSigningNonce OBJECT IDENTIFIER ::= { cabf 41 }

caSigningNonce ATTRIBUTE ::= {
  WITH SYNTAX             OCTET STRING
  EQUALITY MATCHING RULE  octetStringMatch
  SINGLE VALUE            TRUE
  ID                      { cabf-caSigningNonce }
}

cabf-applicantSigningNonce OBJECT IDENTIFIER ::= { cabf 42 }

applicantSigningNonce ATTRIBUTE ::= {
  WITH SYNTAX             OCTET STRING
  EQUALITY MATCHING RULE  octetStringMatch
  SINGLE VALUE            TRUE
  ID                      { cabf-applicantSigningNonce }
}
        </sourcecode>
        <t>In a variation to the usual state machine of ACME, a client need not respond to the challenge. The act of
          POSTing a CSR to the finalization endpoint is in itself a response to the challenge. The challenge and order
          progress directly to either the "valid" or "invalid" state without passing through "processing" or "ready"
          (respectively).</t>
        <t>In the case of a CSR posted to the finalization endpoint that does not include the above extensions
          the order <bcp14>SHOULD</bcp14> remain in the "pending" state and <bcp14>SHOULD NOT</bcp14> transition to the
          "invalid" state. Only in the case that an "onion-csr-01" CSR is POSTed to the finalization endpoint that
          subsequently fails validation <bcp14>MUST</bcp14> the order transition to the "invalid" state.</t>
      </section>
    </section>

    <section>
      <name>Client authentication to hidden services</name>
      <t>Some hidden services do not wish to be accessible to the entire Tor network, and so encrypt their hidden
        service descriptor with the keys of clients authorized to connect. Without a way for the CA to signal what key
        it will use to connect these services will not be able to obtain a certificate using http-01 or tls-alpn-01,
        nor enforce CAA with any validation method.</t>
      <t>To this end, an additional field in the challenge object is defined to allow the ACME server to advertise the
        Ed25519 public key it will use (as per <xref target="tor-rend-spec-v3"/> INTRO-AUTH) to authenticate itself when
        retrieving the hidden service descriptor.</t>
      <dl>
        <dt>authKey (optional, object)</dt>
        <dd>The Ed25519 public key encoded as per <xref target="RFC8037"/>.</dd>
      </dl>
      <t>ACME servers <bcp14>MUST NOT</bcp14> use the same public key with multiple hidden services.
        ACME servers <bcp14>MAY</bcp14> re-use public keys for re-validation of the same hidden service.</t>
      <t>There is no method to communicate to the CA that client authentication is required; instead the ACME server
        <bcp14>MUST</bcp14> attempt to calculate its CLIENT-ID as per <xref target="tor-rend-spec-v3"/> FIRST-LAYER-CLIENT-BEHAVIOR.
        If no "auth-client" line in the first layer hidden service descriptor matches the computed client-id then the server
        <bcp14>MUST</bcp14> assume that the hidden service does not require client authentication and proceed accordingly.</t>
      <t>In the case the Ed25519 is novel to the client it will have to resign and republish its hidden service
        descriptor. It <bcp14>SHOULD</bcp14> wait some (indeterminate) amount of time for the new descriptor to
        propagate the Tor hidden service directory servers, before. This should take no more than a few minutes. CAs
        <bcp14>MUST NOT</bcp14> expire challenges before a reasonable time to allow publication of the new descriptor
        (this document suggests at least 30 minutes).</t>
    </section>

    <section>
      <name>Certification Authority Authorization (CAA)</name>
      <t>".onion" domains are not part of the DNS, and as such a variation on CAA <xref target="RFC8659"/> is required
        to allow restrictions to be placed on certificate issuance.</t>
      <t>To this end a new field is added to the second layer hidden service descriptor
        <xref target="tor-rend-spec-v3" /> § 2.5.2.2. with the following format:</t>
      <sourcecode>
"caa" SP flags SP tag SP value NL
[Any number of times]
      </sourcecode>
      <t>The contents of "flag", "tag", and "value" are as per <xref target="RFC8659"/> § 4.1.1. Multiple CAA records may
       be present, as is the case in the DNS. CAA records in a hidden service descriptor are to be treated the same by
       CAs as if they had been in the DNS for the ".onion" domain.</t>
      <t>A hidden service's second layer descriptor using CAA may look something like the following:</t>
      <sourcecode>
create2-formats 2
single-onion-service
caa 0 issue "example.com"
caa 0 iodef "mailto:security@example.com"
caa 128 validationmethods "onion-csr-01"
introduction-point AwAGsAk5nSMpAhRqhMHbTFCTSlfhP8f5PqUhe6DatgMgk7kSL3KHCZUZ3C6tXDeRfM9SyNY0DlgbF8q+QSaGKCs=
...
      </sourcecode>
      <section>
        <name>Relevant Resource Record Set</name>
        <t>In the absence of the possibility of delegation from a ".onion" domain as there is in the DNS there is no
          need, nor indeed any possibility to search up a the DNS tree for a relevant CAA record set. Instead all
          subdomains under a ".onion" domain share the same CAA record set. That is all of these share a CAA record
          set with "a.onion":</t>
        <ul>
          <li>b.a.onion</li>
          <li>c.a.onion</li>
          <li>e.d.a.onion</li>
        </ul>
        <t>But these do not:</t>
        <ul>
          <li>b.c.onion</li>
          <li>c.d.onion</li>
          <li>e.c.d.onion</li>
        </ul>
      </section>
      <section>
        <name>When to check CAA</name>
        <t>If the hidden service has client authentication enabled then it will be impossible for the CAA to decrypt
          the second layer descriptor to read the CAA records until the CAAs public key has been added to first layer
          descriptor. To this end a CA <bcp14>SHOULD</bcp14> wait until the client responds to an authorization, and
          treat this as indication that their public key has been added and that the CA will be able to decrypt the
          second layer descriptor.</t>
      </section>
      <section>
        <name>Preventing mis-issuance by unknown CAs</name>
        <t>As the CAA records are in the second layer descriptor and in the case of a hidden service requiring client
          authentication it is impossible to read them without the hidden service trusting a CA's public key, a method is
          required to signal that there are CAA records present (but not reveal their contents, which may disclose
          unwanted information about the hidden service operator).</t>
        <t>To this end a new field is added to the first layer hidden service descriptor
          <xref target="tor-rend-spec-v3" /> § 2.5.1.2. with the following format:</t>
        <sourcecode>
"caa-critical" NL
[At most once]
        </sourcecode>
        <t>If a CA encounters this flag it <bcp14>MUST NOT</bcp14> proceed with issuance until it can decrypt and
          parse the CAA records from the second layer descriptor.</t>
      </section>
    </section>

    <section anchor="IANA">
      <name>IANA Considerations</name>
      <section>
        <name>Validation Methods</name>
        <t>Per this document, one new entry has been added to the "ACME Validation Methods" registry defined in
          <xref target="RFC8555"/> §9.7.8. This entry is defined below:</t>
        <table>
          <name>New entries</name>
          <thead>
            <tr>
              <th>Label</th>
              <th>Identifier Type</th>
              <th>ACME</th>
              <th>Reference</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>onion-csr-01</td>
              <td>dns</td>
              <td>Y</td>
              <td>This document</td>
            </tr>
          </tbody>
        </table>
      </section>
    </section>

    <section anchor="Security">
      <name>Security Considerations</name>
      <section anchor="security-id-dns">
        <name>Use of "dns" identifier type</name>
        <t>The re-use of the "dns" identifier type for a domain not actually in the DNS infrastructure raises questions
          regarding its suitability. The reasons the author wish to pursue this path in the first place are detailed
          in <xref target="use-of-id-dns"/>. It is felt that there is little security concern in reuse of the "dns"
          identifier type with regards the mis-issuance by CAs that are not aware of ".onion" domains.</t>
        <section>
          <name>"http-01" Challenge</name>
          <t>The CA would follow the procedure set out in <xref target="RFC8555"/> §8.3 which specifies that the CA
            should "Dereference the URL using an HTTP GET request". Given that ".onion" require special handling to
            dereference, this de-referencing will fail, disallowing issuance.</t>
        </section>
        <section>
          <name>"tls-alpn-01" Challenge</name>
          <t>The CA would follow the procedure set out in <xref target="RFC8737"/> §3 which specifies that the CA
            "resolves the domain name being validated and chooses one of the IP addresses returned for validation".
            Given that ".onion" are not resolvable to IP addresses, this de-referencing will fail, disallowing
            issuance.</t>
        </section>
        <section>
          <name>"dns-01" Challenge</name>
          <t>The CA would follow the procedure set out in <xref target="RFC8555"/> §8.4 which specifies that the CA
            should "query for TXT records for the validation domain name".
            Given that ".onion" are not present in the DNS infrastructure, this query will fail, disallowing
            issuance.</t>
        </section>
      </section>
      <section>
        <name>Key Authorization with "onion-csr-01"</name>
        <t>The "onion-csr-01" challenge does not make use of the key authorization string defined in
          <xref target="RFC8555"/> §8.1. This does not weaken the integrity of authorizations.</t>
        <t>The key authorization exists to ensure that an attacker observing the validation channel can observe the
          correct validation response, but cannot compromise the integrity of authorizations as the response only be
          used with the account key for which it was generated. As the validation channel for this challenge is
          ACME itself, and ACME already requires that the request be signed by the account, the key authorization is
          not required.</t>
      </section>
      <section>
        <name>Use of Tor for non ".onion" domains</name>
        <t>An ACME server <bcp14>MUST NOT</bcp14> utilise Tor for the validation of non ".onion" domains, due to the
          risk of possible exit hijacking.</t>
      </section>
      <section>
        <name>Security of CAA records</name>
        <t>The second layer descriptor is encrypted and MACed in a way that only a party with access to the secret key
          of the hidden service could manipulate what is published there. For more information about this process see
          <xref target="tor-rend-spec-v3"/> § 2.5.3.</t>
      </section>
      <section>
        <name>Access of the Tor network</name>
        <t>The ACME server <bcp14>MUST</bcp14> make its own connection to the hidden service via the Tor network,
          and <bcp14>MUST NOT</bcp14> outsource this, such as by using Tor2Web.</t>
      </section>
    </section>
  </middle>

  <back>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>

        <referencegroup anchor="BCP14" target="https://www.rfc-editor.org/info/bcp14">
          <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2119.xml"/>
          <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8174.xml"/>
        </referencegroup>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.4648.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.7686.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8037.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8555.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8659.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8737.xml"/>

        <reference anchor="tor-address-spec" target="https://spec.torproject.org/address-spec">
          <front>
            <title>Special Hostnames in Tor</title>
            <author fullname="Nick Mathewson" initials="N." surname="Nick Mathewson">
              <organization>The Tor Project</organization>
            </author>
          </front>
        </reference>

        <reference anchor="tor-rend-spec-v3" target="https://spec.torproject.org/rend-spec-v3">
          <front>
            <title>Tor Rendezvous Specification - Version 3</title>
            <author>
              <organization>The Tor Project</organization>
            </author>
          </front>
        </reference>

        <reference anchor="cabf-br" target="https://cabforum.org/wp-content/uploads/CA-Browser-Forum-BR-1.8.6.pdf">
          <front>
            <title>Baseline Requirements for the Issuance and Management of Publicly-Trusted Certificates</title>
            <author>
              <organization>CA/Browser Forum</organization>
            </author>
          </front>
        </reference>

      </references>
      <references>
        <name>Informative References</name>

        <reference anchor="onion-services-setup" target="https://community.torproject.org/onion-services/setup/">
          <front>
            <title>Set Up Your Onion Service</title>
            <author>
              <organization>The Tor Project</organization>
            </author>
          </front>
        </reference>
      </references>
    </references>

    <section anchor="use-of-id-dns">
      <name>Discussion on the use of the "dns" identifier type</name>
      <t>The reasons for utilising the "dns" identifier type in ACME and not defining a new identifier type for
        ".onion" domains may not seem obvious at first glance. After all, ".onion" domains are not part of the DNS
        infrastructure and as such why should they use the "dns" identifier type?</t>
      <t>The CA/Browser Forum Baseline Requirements <xref target="cabf-br"/> §B.2.a.ii define, and this standard allows,
        using the "http-01" or "tls-alpn-01" validation methods already present in ACME (with some considerations).
        Given the situation of a web server placed behind a Tor terminating proxy (as per the setup suggested by the
        Tor project <xref target="onion-services-setup"/>), existing ACME tooling can be blind to the fact that a
        ".onion" domain is being utilised, as they simply receive an incoming TCP connection as they would regardless
        (albeit from the Tor terminating proxy).</t>
      <t>An example of this would be Certbot placing the ACME challenge response file in the webroot of an NGINX web
        server. Neither Certbot nor NGINX would require any modification to be aware of any special handling for
        ".onion" domains.</t>
      <t>This does raise some questions regarding security within existing implementations, however the authors believe
        this is of little concern, as per <xref target="security-id-dns"/>.</t>
    </section>

    <section anchor="Acknowledgements" numbered="false">
      <name>Acknowledgements</name>
      <t>With thanks to the Open Technology Fund for funding the work that went into this document.</t>
      <t>The authors also wish to thank the following for their input on this document:</t>
      <ul>
        <li>Iain R. Learmonth</li>
        <li>Jan-Frederik Rieckers</li>
      </ul>
    </section>
  </back>
</rfc>
