Sometimes there might be a need for an application to sign a data form (&xep0004;) using other credentials than provided by the XMPP account or connection. An example can
be automatic account creation using &xep0077;. Many server operators disable the in-band registration feature since it makes it possible for malicious
users or robots to freely create accounts on the server. One way to combat robots, has been through the use of &xep0158;. But in some cases, like in the Internet of Things,
it is not robots that are the problem, but malicious users.
</p>
<p>
This document describes a method whereby forms can be signed using other credentials. This can be used in an In-band registration form to sign the form with the credentials
of a special account on the server with permissions to create new XMPP accounts, with perhaps a limit on number of accounts that can be created. This method can be used by
manufacturers of devices for Internet of Things, so that devices can create accounts automatically on XMPP servers in an orderly fashion, and manufacturers are allowed to
administer and control their automatically created accounts separately. It also provides a mechanism whereby server operators can monitor who is responsible for account creation
</note>) has been chosen in favor of a method where the user can select an authentication method from a list of available methods, modelled in the likeness of SASL. The main reason is
to avoid multiple callbacks during form signature. The idea is to make form signature possible without having to do any intermediate server callbacks, or having to change the original
request returning the form. The method is still extensible, allowing possible future extensions. The form signing algorithm to use is defined by the FORM_TYPE parameter in the form
<section1topic='Signing a form'anchor='signingform'>
<p>
A form that needs to be signed by the client using external credentials, shows this by including a hidden <strong>FORM_TYPE</strong> field valued
<strong>urn:xmpp:xdata:signature:oauth1</strong>. The sub-namespace <strong>:oauth1</strong> identifies the algorithm to be used, in this case OAUTH v1.0.
The form contains a set of invisible parameters that the underlying software signing the form and supporting this specification must understand. These are:
</p>
<tablecaption='OAUTH parameters'>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
<tr>
<td>oauth_version</td>
<td>Must be 1.0. Is not changed by the client performing the signing.</td>
</tr>
<tr>
<td>oauth_signature_method</td>
<td>Specifies the signature method, or hash function, to use when signing the form. This can be changed by the client. Possible values are: HMAC-SHA1, RSA-SHA1 and PLAINTEXT.</td>
</tr>
<tr>
<td>oauth_token</td>
<td>This is a token provided by the server to the client. This parameter might not be available if the server has provided the client with this token earlier during the session.</td>
</tr>
<tr>
<td>oauth_token_secret</td>
<td>This is a temporary secret shared between the server and client, and is related to the token. This parameter might not be available if the server has provided the client with this token earlier during the session.</td>
</tr>
<tr>
<td>oauth_nonce</td>
<td>A nonce value that the client has to set. Can be a random alphanumerical string.</td>
</tr>
<tr>
<td>oauth_timestamp</td>
<td>Number of seconds since 1st of January 1970, 00:00:00 GMT. The client has to set this at the time of signature.</td>
</tr>
<tr>
<td>oauth_consumer_key</td>
<td>A key identifying the account doing the signing of the form. The client has to set this to identify who performs the signature.</td>
</tr>
<tr>
<td>oauth_signature</td>
<td>The signature, signing the form. The client has to set this with the signature of the form, as calculated and described below.</td>
</tr>
</table>
<p>
Before calculating the signature, the following functions need to be defined:
</p>
<dl>
<di>
<dt>Base64(x)</dt>
<dd>
<p>
Converts the sequence of octets <strong>x</strong> into a Base-64 encoded string.
</p>
</dd>
</di>
<di>
<dt>Escape(s)</dt>
<dd>
<p>
The string <strong>s</strong> are escaped using the &rfc3986; percent-encoding (%xx) mechanism. Characters not in the unreserved character set (§ 2.3) MUST be encoded.
Characters in the unreserved character set MUST NOT be encoded. Hexadecimal characters in encodings MUST be upper case. Text names and values MUST first be normalized
using Normalization Form C (NFC) as defined in <spanclass='ref'>
<linkurl='http://unicode.org/reports/tr15/#Norm_Forms'>Unicode Standard Annex #15, Unicode Normalization Forms</link>
</span><note>
Unicode Standard Annex #15, Unicode Normalization Forms <<linkurl='http://unicode.org/reports/tr15/#Norm_Forms'>http://unicode.org/reports/tr15/#Norm_Forms</link>>.
Unreserved characters are alphanumeric characters (a-z, A-Z, 0-9), hyphen ('-'), period ('.'), underscore ('_') and tilde ('~').
</p>
</dd>
</di>
<di>
<dt>H(x)</dt>
<dd>
<p>
Corresponds to the Hash-function to use, according to the parameter <strong>oauth_signature_method</strong>. It computes the hash value of the octets <strong>x</strong>,
and returns a sequence of octets.
</p>
</dd>
</di>
</dl>
<p>
To calculate the signature of the form, follow the steps in the following subsections, in the same order.
You choose Hash function by setting the parameter <strong>oauth_signature_method</strong> to either <strong>HMAC-SHA1</strong>, <strong>RSA-SHA1</strong> or <strong>PLAINTEXT</strong>.
First, all form parameters to be signed, including hidden parameters and the OAUTH parameters except <strong>oauth_token_secret</strong> and <strong>oauth_signature</strong>,
are sorted by variable name (<strong>var</strong>).
Each (name, value) pair in the list of sorted parameters are first transformed into pairs of <strong>Escape(name)=Escape(value)</strong> segments, and then concatenated
into one string, where each segment is delimited using an ampersand ('&') character.
<section2topic='Calculating Signature Base String (BStr)'anchor='bstr'>
<p>
The Signature Base String (BStr) is then formed concatenating <strong>Escape(type)</strong> (the form type used when submitting the form),
<strong>Escape(to)</strong> (the full destination address, including resource, if any) and <strong>Escape(PStr)</strong>, using ampersands ('&') as
delimiter.
</p>
<examplecaption='Calculating Signature Base String'>
Once the signature has been calculated, the corresponding parameter <strong>oauth_signature</strong> has to be set in the form before sending it to the destination
When the recipient receives the signed formm it performs the same calculations as above, based on the parameters received, and knowledge of the shared secret which it
can look up by using the parameter <strong>oauth_consumer_key</strong>.
</p>
</section2>
</section1>
<section1topic='Use Cases'anchor='usecases'>
<section2topic='Securing In-Band Registration of new accounts'anchor='ibr'>
<p>
As mentioned above, a major use case for signing forms, is in-band registration for creating new accounts on an XMPP Server, as defined in XEP-0077.
</p>
<examplecaption='Entity Requests Registration Fields from Host'>
<![CDATA[
<iqtype='get'
from='juliet@capulet.com/balcony'
to='contests.shakespeare.lit'
id='reg3'>
<queryxmlns='jabber:iq:register'/>
</iq>]]>
</example>
<examplecaption='Host Returns Registration Form to Entity requiring signature'>
<![CDATA[
<iqtype='result'
from='contests.shakespeare.lit'
to='juliet@capulet.com/balcony'
id='reg3'>
<queryxmlns='jabber:iq:register'>
<instructions>
Use the enclosed form to register. If your Jabber client does not
support Data Forms, visit http://www.shakespeare.lit/contests.php
<p>If an entity supports signing forms as specified herein, it MUST advertise that fact by returning a feature of "urn:xmpp:xdata:signature:oauth1" in response to &xep0030; information requests.</p>
<examplecaption="Service discovery information request">
In order for an application to determine whether an entity supports this protocol, where possible it SHOULD use the dynamic, presence-based profile of service discovery defined
in &xep0115;. However, if an application has not received entity capabilities information from an entity, it SHOULD use explicit service discovery instead.
<section2topic='Signature algorithms and namespaces'anchor='namespaces'>
<p>
This document only specifies signatures using OAUTH v1.0. Each entity that supports form signatures using this method, reports this by including the
namespace <strong>urn:xmpp:xdata:signature:oauth1</strong> in its features. The specification is extensible, in that it can allow for future signature
methods to be used, by defining new namespaces replacing <strong>oauth1</strong> by another string corresponding to the desired method, but leaving the
base part of the namespace <strong>urn:xmpp:xdata:signature:</strong> intact.
The PLAINTEXT signature method should only be used if SSL/TLS is used by both the entity signing the form as well as the creator of the form. If the creator of the form
is a server, this later part can be ignored. If unsure, PLAINTEXT should only be used in development & debugging cycles of an application, and not in production environments.
If the server provides information to be used in signing a form, it must also verify that the client only changes values it is allowed to change. An alternative is to
not use the values provided by the client for the corresponding server-side parameters when calculating the signature on the server side. This makes sure a client
cannot willfully alter server-side parameters when it returns the signed form.
&xep0068; defines a process for standardizing the fields used within Data Forms qualified by a particular namespace, and XEP-0128 describes how to use
field standardization in the context of service discovery. This section registers fields for server information scoped by the "urn:xmpp:xdata:signature:oauth1" FORM_TYPE.
</p>
<examplecaption="Registry submission">
<![CDATA[
<form_type>
<name>urn:xmpp:xdata:signature:oauth1</name>
<doc>XEP-xxxx</doc>
<desc>
Forms that require signatures using OAuth v1.0 signature algorithm.
</desc>
<field
var='oauth_version'
type='hidden'
label='OAuth version. Must be 1.0.'/>
<field
var='oauth_signature_method'
type='hidden'
label='OAuth signature method. Can be "HMAC-SHA1", "RSA-SHA1" or "PLAINTEXT".'/>
<field
var='oauth_token'
type='hidden'
label='OAuth token. Provided by the creator of the form.'/>
<field
var='oauth_token_secret'
type='hidden'
label='OAuth token secret. Provided by the creator of the form.'/>
<field
var='oauth_nonce'
type='hidden'
label='Nonce value. Random string, created by the entity signing the form.'/>
<field
var='oauth_timestamp'
type='hidden'
label='Seconds since 1st of January 1970, 00:00:00 GMT. Value provided by the entity signing the form.'/>
<field
var='oauth_consumer_key'
type='hidden'
label='Consumer Key, identifying the entity signing the form using an external set of credentials. Value provided by the entity signing the form.'/>
<field
var='oauth_signature'
type='hidden'
label='Form signature. Value provided by the entity signing the form.'/>