Files
cashId/README.md
T

342 lines
13 KiB
Markdown
Raw Normal View History

*Status: Incomplete draft*<br/>
*BitID source: https://github.com/bitid/bitid*
2018-09-21 18:46:37 +00:00
2018-09-21 17:04:02 +00:00
# Abstract
2018-09-21 16:52:51 +00:00
CashID is an open protocol that allows secure authentication based on the public key cryptography infrastructure that is currently present in the Bitcoin Cash ecosystem. Each user can prove to a service provider that they controls a specific Bitcoin Cash address by signing a challenge request, as well as provide optional metadata.
2018-09-21 17:04:02 +00:00
2018-09-21 17:04:02 +00:00
# Motivation
Passwords is an inherently flawed concept based on sharing secrets that is increasingly getting hidden away from the users by means of password managers, permanent sessions and single-signon features. Public key cryptography provides a more secure method for authentication where the users secret is never shared.
Secure authentication with optional metadata is useful, for example to...
2018-09-21 17:04:02 +00:00
* Register to a service as a 1-step process.
* Register to a service automatically as part of a payment.
* Authenticate to a service to login without a password.
* Authenticate to a service to act as 2FA complementing existing passwords.
* Provide access control to locks based on payment.
2018-09-21 17:04:02 +00:00
# Specification
When a user needs to access a physical or digital restricted area they are given a **Challenge request** by the service provider. The identity manager presents the request to the user and allows the them to choose a suitable keypair to represent their identity.
2018-09-21 17:04:02 +00:00
If metadata was requested the identity manager provides the user the option to select which data to use for each metadata field, as well as the option to not supply information for any given field. If the user denies sharing of metadata for a field marked as required, the identity manager aborts the request.
2018-09-23 18:34:52 +00:00
Once approved by the user, the identity manager signs the challenge request, adds the metadata that was approved by the user and sends a **Challenge response** back to the service provider.
2018-09-23 18:34:52 +00:00
2018-09-24 08:40:15 +00:00
The service provider validates the request, public key and signature of the response and returns a confirmation response. If the confirmation response contains a status message it is shown to the user.
The service provider can now use the public key as the users identifier and perform the requested action.
## Challenge request
The request consists of an **Intent**, **Domain**, **Path** and set of **Parameters**.
2018-09-22 09:07:06 +00:00
2018-09-22 06:28:41 +00:00
```
cashid:domain.tld/cashid?a=action&d=data&r=required&o=optional&x=nonce
2018-09-22 06:28:41 +00:00
```
2018-09-22 09:07:06 +00:00
**Part** | **Example** | **Description**
--- | --- | ---
Intent | cashid: | Protocol identifier
Domain | domain.tld | Fully qualified domain name
Path | /cashid | Path to a request manager
Parameters | ?a=action<br/>&d=data<br/>&r=required<br/>&o=optional<br />&x=nonce | Various parameters
2018-09-22 09:07:06 +00:00
### Parameters
Every request must have a **Nonce** parameter and may also have an **Action**, **Data**, **Required** and **Optional** parameter.
2018-09-22 06:45:36 +00:00
**Letter** | **Name** | **Description**
--- | --- | ---
a | Action | Name of the action the user authenticates to perform
d | Data | Data relevant to the requested action
r | Required | List of metadata that the action needs to function
o | Optional | List of metadata that the action can use but still works without
x | Nonce | Random data unique for this request
2018-09-24 08:40:15 +00:00
### Nonce
The **Nonce** parameter acts as a replay-protection mechanism, by making each request challenge and response unique. Each **Nonce** can only be used a single time during its lifespan and should expire if left unused for a significant amount of time.
The service provider should not process requests that it has not issued nonces for, except for **User actions** that have a valid and recent **Timestamp** as their nonce value.
### Action and Data
The optional **Action** parameter is used to describe the action that the user authenticates to perform. When a **Data** parameter is present, the **Action** also determines how to interpret it.
2018-09-24 06:35:47 +00:00
When omitted, the **Action** is assumed to mean authenticate without a specified reason.
**Action** | **Description**
--- | ---
auth | Identifies the user to the service provider
2018-09-24 06:35:47 +00:00
2018-09-24 08:40:15 +00:00
<br />
**Service actions** can only be requested by the service provider.
**Action** | **Description** | **Data**
--- | --- | ---
login | Grants the user access to digital services | Session identification ID used to link the login request with an active anonymous session
sign | Asks the user to cryptographically sign a message | Message text that the identity is requested to sign
2018-09-24 08:40:15 +00:00
<br />
**User actions** can be sent unsolicited to the service provider.
**Value** | **Description**
--- | ---
delete | Requests the service provider to delete this identity and related metadata
logout | Requests the service provider to close all active sessions for this identity
revoke | Informs the service provider that this identity has been compromised
update | Informs the service provider about changes to identity, position or contact metadata
2018-09-24 08:40:15 +00:00
<br />
2018-09-24 08:40:15 +00:00
**Custom actions** may be used to enable more usecases. If an identity manager parses a request with a custom action it does not understand, it should inform the user and must abort the request.
### Required and Optional Metadata
The **Required** and **Optional** parameters allow the service to request personal information from the user. In order to do this in the least amount of space, the information is shorthanded by a letter and a string of numbers representing various pieces of personal information. For **Optional** metadata, the numbers after a letter can be omitted to request all fields in that category. The same metadata fields can only be requested in either **Required** or **Optional** scope, not both. The field numbers in each category has to be listed in sorted order, starting with the lowest number.
2018-09-21 18:06:12 +00:00
**Identification** is represented by the letter **i** followed by a list of numbers corresponding to the following table.
2018-09-22 06:45:36 +00:00
**Number** | **Name** | **Data type** | **Description**
--- | --- | --- | ---
1 | Name | String | The first or given name of the person
2 | Family | String | The last name, surname of family name of the person
3 | Nickname | String | A nickname or username
4 | Age | Integer | The number of years the person has lived
5 | Gender | String | The sex of the person, usually "Male" or "Female"
6 | Birthdate | Date | The date of birth... what format? (YYYY-MM-DD?)
8 | Picture | String | URL to a profile picture, or Base64 encoded image
9 | National | string | National identification numbers, such as passport, drivers license and citizenship numbers.
<br />
**Position** is represented by the letter **p** followed by a list of numbers corresponding to the following table.
2018-09-22 06:45:36 +00:00
**Number** | **Name** | **Data type** | **Description**
--- | --- | --- | ---
1 | Country | String | Name of the nation
2 | State | String | Name of the state or province
3 | City | String | Name of the city
4 | Street name | String | Name of the street, without the street number
5 | Street number | String | The street number
6 | Residence | String | Building or apartment number that uniquely reference a residence
9 | Coordinate | String | Geographical position as specificed in [RFC5870](https://tools.ietf.org/html/rfc5870)<br/>*For example: "geo:13.4125,103.8667"*
<br />
2018-09-21 18:06:12 +00:00
**Contact information** is represented by the letter **c** followed by a list of numbers corresponding to the following table.
2018-09-22 06:45:36 +00:00
**Number** | **Name** | **Data type** | **Description**
--- | --- | --- | ---
1 | Email | String | Email address
2018-09-22 10:36:21 +00:00
2 | Instant | String | Instant Messenger protocol handle
3 | Social | string | Social media service handle or URL
4 | Mobile phone number | string | Personal cellphone number
5 | Home phone number | string | Residence phone number
6 | Work phone number | string | Work phone number
7 | Postal label | string | Postal label for a physical address to which a service can send letters and packages
## Challenge Response
2018-09-24 06:47:39 +00:00
When the identity manager is ready to submit a **Challenge response** it forms a **Response URL** by appending the **Domain** and **Path** components to a **https://** scheme identifier.
```
https://domain.tld/cashid
^ ^ ^
cashid: domain.tld/cashid?a=action&d=data&r=required&o=optional&x=nonce
```
It then sends the **Response data** as a **JSON** encoded object with the following members:
2018-09-22 06:45:36 +00:00
**Member** | **Data type** | **Description**
--- | --- | ---
2018-09-24 06:47:39 +00:00
request | String | The challenge request URI
address | String | Address used to sign the request
signature | String | Signature for the request
metadata | String | Requested metadata fields
2018-09-24 06:47:39 +00:00
### Address
The **Address** field should be a valid Bitcoin Cash address in the CashAddr format.
### Signature
The **Signature** must comply to the "\x18Bitcoin Signed Message:\n#{message.size.chr}#{message}" format.
### Metadata
Metadata is stored as a JSON object with property names matching the requested field names. Fields that has multiple values (for example social media accounts) is stored as a JSON object with property names matching their identifier and the data matching the field description.
For example, if the request contains **r=i12&o=c** the metadata part of the request answer would look like this:
```javascript
metadata:
{
'name': 'John',
'last name': 'Doe',
'email': 'johndoe@gmail.com',
'social':
{
'facebook': 'https://facebook.com/johndoe',
'twitter': 'https://twitter.com/johndoe'
}
}
```
*Note that there is two fields for social media presence and no fields for optional contact data the user did not want to supply*
2018-09-24 08:40:15 +00:00
## Request confirmation
2018-09-24 08:40:15 +00:00
The service provider should supply a **Request confirmation** containing a **Status code** and optionally a **Status message**.
2018-09-22 06:45:36 +00:00
**Member** | **Data type** | **Description**
--- | --- | ---
2018-09-24 08:40:15 +00:00
Status | Integer | Code that identifies the request status.
Message | String | Additional information to show the user.
2018-09-24 08:40:15 +00:00
<br />
**Code** | **Error message** | **Description**
--- | --- | ---
0 | Authentication successful | ...
1 | Malformed request | ...
2 | Malformed URI | ...
3 | Timeout (nonce has expired) | ...
4 | Nonce has been already used | ...
5 | Required metadata is missing | ... (would be nice to also specify which one...)
6 | Metadata format is not supported | ... (again, would be nice to specify the exact problem...)
7 | Service temporary unavailable | ... (or Busy, try again later)
8 | Signature verification failed | ...
9 | Access denied for this identity | ... (can be more detailed ban reason...)
10 | Access revoked | This identity was marked as compromised and cannot be used anymore.
# Resources
2018-09-21 17:04:02 +00:00
## Examples
### Minimal authentication request
2018-09-24 06:55:54 +00:00
The smallest possible request only authenticates a user.
```
cashid:domain.tld/path?x=2671757324
```
The JSON encoded response for a user with address **???** will be sent to **https://domain.tld/path**:
2018-09-24 06:55:54 +00:00
```javascript
{
'request': 'cashid:domain.tld/path?x=2671757324',
'address': '???',
'signature': '???'
}
```
2018-09-24 08:40:15 +00:00
The service provider will validate the request and return a **Authentication successful** status message:
```javascript
{
2018-09-24 08:40:15 +00:00
'status': 0
}
```
### Login to a website
The **login** action at **cashtalk.org** can make use of **Name** and **Last Name**, for example to update user profiles.
```
cashid:cashtalk.org/auth?a=login&d=15366-4133-6141-9638&o=i12&x=13534642624
```
### Registration for a newsletter
The **register** action at **example.com** requires **Name**, **Last Name**, **Country** and **Email** to work, and will use **Picture**, **Age**, **Gender** and **City** if provided.
```
cashid:example.com/cashid?a=register&r=i12l1c1&o=i567l3&x=95261230581
```
### Verification...
The **verify** action (2FA) at **bankers.net** requires that the address **qqzafeafd...** authenticates
```
cashid:bankers.net/api/v1/cashid?a=verify&data=qqzafeafd...&x=23563567325
```
### Account removal
The user initiated request to **delete** their user data from **sensitive.cash**
```
cashid:sensitive.cash/api/cashid?a=delete
```
## Implementation support
In order to reduce implementation costs and increase implementation conformity, this specification supplies extra material that can be helpful to developers.
### Regular expressions
To parse a **Challenge request** into its parts
```javascript
/(?P<scheme>cashid:)[\/]*(?P<domain>[^\/])+(?P<path>\/[^\?]+)(?P<parameters>\?.+)?/
```
To parse the **Parameters** into their parts
```javascript
```
To parse the **Metadata** fields into their parts
```javascript
```
2018-09-24 09:25:18 +00:00
### Libraries
2018-09-21 17:04:02 +00:00
2018-09-24 09:25:18 +00:00
**CashID** specific libraries:
* ???
**Bitcoin Cash** generic libraries:
* bitcoincashjs
## TODO
These items is an ad-hoc todo list of things to do make CashID useful and widespread, and does not necessarily belong in the specification document.
* QR code guidelines (case)
* code examples
* a website with interface/workflow example, similar to BitID
* interface guidelines (color-coding privacy impact, etc.)
* What about localization? Are local languages allowed for metadata or not?
2018-09-24 09:25:18 +00:00
* favicon or something more advanced to help identify the site in IDM (guideline)
2018-09-22 10:56:07 +00:00
* Oath1/2 server that authenticates with CashID, as a compatibiltiy bridge.
* Introduction video in the style of we-use-coins