Internet-Draft Key Service Specification TCP March 2024
Leptons Expires 18 September 2024 [Page]
Workgroup:
Network Working Group
Internet-Draft:
rfce-0001
Published:
Intended Status:
Informational
Expires:
Author:
K. Leptons

Key Service Specification TCP

Abstract

A simple protocol for management and authentication key over the Transmission Control Protocol (TCP) or Transport Layer Security (TLS).

Status of This Memo

This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.

Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

This Internet-Draft will expire on 18 September 2024.

Table of Contents

1. Key

1.1. General

Key are used together for authentication from client to server. A key MUST be 160 bits, unique, and generated by a strong cryptography algorithm such as RAND_bytes(3) from OpenSSL. There are three kinds of key StandardKey, RootKey and ClientKey. They are described in next sections.

The first 64 bits of a key called key identity. The identity MUST be unique. There are three key identities StandardKeyId, RootKeyId and ClientKeyId respectively.

1.2. Standard Key

Standard key is used for authentication from client to server as a standard user, see Section 3. The key does not support other operations than authentication. It's managed by root user via the protocol, see Section 1.3.

1.3. Root Key

Root key is used for authentication from client to sever as a root user, see Section 4. The key supports management StandardKey via the protocol:

1.4. Client Key

Client key reprents for the client that has permission to communicate with the server. Without ClientKey, other type of keys cannot be authenticated to the server. This called two key authentication. There are two use cases:

  • Using with StandardKey for authentication as a standard user. See Section 3.2.
  • Using with RootKey for authentication as a root user. See Section 4.2.

1.5. Text Representation

For humans, a key MUST be encoded as Base36, which is:

  • The set of representation symbol is 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.
  • Symbol 0 represents for 0, 1 for 1, A for 10, B for 11, Z for 35, and so on.
  • Divide each block of 5 symbols by hyphen -.

For example, the key 0x3E29F382F292A26FDD6BAEF64614BEAFFE62CDBC can be display as below:

+------------ 6 blocks ------------+
|                                  |
v                                  v
79ETG-6PA79-MTO58-R4554-CZSU2-HHYJSS
              ^
              |
              +--- Block of 5 symbols

2. Client

2.1. General

The communication between client and server is sequenced. If the client sends a message to server, then it MUST wait for a response message. Break this rule may lead to unspecified behaviors.

2.2. Handshake

Handshake is mandatory to establish the protocol. Client MUST connect to server over TCP or TLS. Then it MUST send Handshake message to server and wait for HandshakeResult. If returned status other than Success then the client MUST terminate the connection.

If handshake successfully then client and server are ready to communicate by messages. See Section 3 and Section 4 for more operations.

Client                                                         Server
  |                                                               |
  |    Connect TCP/TLS                                            |
  |==============================================================>|
  |<--------------------------------------------------------------|
  |                                                         Ok    |
  |                                                               |
  |                                                               |
  |    Handshake                                                  |
  |==============================================================>|
  |<--------------------------------------------------------------|
  |                                            HandshakeResult    |
  |                                                               |

2.3. Ping

If authentication successfully then client MUST send Ping message to server and wait for Pong to keep the connection. Ping message MUST be send periodically before ConnectionTimeout reached, but do not reach RateLimit.

3. Client as Standard User

3.1. General

Client                                                         Server
  |                                                               |
  |    AuthenticateStandard                                       |
  |==============================================================>|
  |<--------------------------------------------------------------|
  |                                 AuthenticateStandardResult    |
  |                                                               |
  |                                                               |
  |    Ping                                                       |
  |==============================================================>|
  |<--------------------------------------------------------------|
  |                                                       Pong    |
  |                                                               |

3.2. Authenticate

Client MUST send AuthenticateStandard message to server and wait for AuthenticateStandardResult. If returned status other than Success then the client MUST terminate the connection. The client MAY try authentication later.

4. Client as Root User

4.1. General

Client                                                         Server
  |                                                               |
  |    AuthenticateRoot                                           |
  |==============================================================>|
  |<--------------------------------------------------------------|
  |                                     AuthenticateRootResult    |
  |                                                               |
  |                                                               |
  |    NewStandardKey                                             |
  |==============================================================>|
  |<--------------------------------------------------------------|
  |                                      NewStandardKeyResult     |
  |                                                               |
  |                                                               |
  |    EnableStandardKey                                          |
  |==============================================================>|
  |<--------------------------------------------------------------|
  |                                   EnableStandardKeyResult     |
  |                                                               |
  |                                                               |
  |    DisabledStandardKey                                        |
  |==============================================================>|
  |<--------------------------------------------------------------|
  |                                  DisableStandardKeyResult     |
  |                                                               |
  |                                                               |
  |    FindStandardKey                                            |
  |==============================================================>|
  |<--------------------------------------------------------------|
  |                                     FindStandardKeyResult     |
  |                                                               |
  |                                                               |
  |    Ping                                                       |
  |==============================================================>|
  |<--------------------------------------------------------------|
  |                                                       Pong    |
  |                                                               |

4.2. Authenticate

Client MUST send AuthenticateRoot message to server and wait for AuthenticateRootMessage. If returned status is other than Success then the client MUST terminate connection. The client MAY try authentication later.

4.3. New Standard Key

Client MUST send NewStandardKey message to server and wait for NewStandardKeyResult result. The client MUST keep the connection, what ever the result is.

4.4. Enable Standard Key

Client MUST send EnableStandardKey message to server and wait for EnableStandardKey. The client MUST keep the connection, what ever the result is.

4.5. Disable Standard Key

Client MUST send DisableStandardKey message to server and wait for DisableStandardKey. The client MUST keep the connection, what ever the result is.

4.6. Find Standard Key

Client MUST send FindStandardKey message to server and wait for FindStandardKey. The client MUST keep the connection, what ever the result is.

5. Server

5.1. Handshake

With a new TCP/TLS connection, the sever MUST wait for Handshake message and respond HandshakeResult.

If server does not accepts client IP for some reasons, then it MUST terminate the connection.

If the server does not support protocol Version, then it MUST respond status VersionNotSupported and terminate the connection.

If client sends a non Handshake message, then the server MUST respond status MessageTypeInvalid and terminate the connection.

Otherwise, the server MUST respond status Ok.

After handshake success, the server MUST accept one of the following messages AuthenticateStandard or AuthenticateRoot. If client sends other messages, then the server MUST respond MessageTypeInvalid and terminate the connection.

5.2. Authenticate Standard

After handshake success, server MUST accept AuthenticateStandard message and respond AuthenticateStandardResult.

If keys are invalid, then server MUST responds status Unauthorized and terminate the connection.

If keys are valid and there is no authenticated connection with the same key, then the server MUST respond status Ok. If there is a connection with the same key, then response status AuthenticationConflict.

After AuthenticateStandard success, the server MUST accept only Ping message. Otherwise, it MUST terminate the connection.

5.3. Authenticate Root

After handshake success, server MUST accept AuthenticateRoot message, and respond AuthenticateRootResult.

If keys are invalid, then server MUST responds status Unauthorized and terminate the connection.

If keys are valid, then the server MUST respond status Ok.

After AuthenticateRoot success, the server MUST accept the following messages: NewStandardKey, EnableStandardKey, DisableStandardKey, FindStandardKey, and Ping. Otherwise, it MUST terminate the connection.

5.4. New Standard Key

With a root connection, server MUST accept NewStandardKey message and respond NewStandardKeyResult.

If NoteLength and Note is invalid, then server MUST respond status MessageDataInvalid. If there are no more key identities, then server MUST respond status Exhausted.

A key MUST be generated by strong cryptography algorithm. If success, then save the key and respond it with status Ok.

5.5. Enable Standard Key

With a root connection, server MUST accept EnableStandardKey message and respond EnableStandardKeyResult.

If the key is not existed, then response status NotFound. If the key is existed and it's already enabled, then response status NotChanged.

If the key is existed and it's disabled, then enable it and response status Ok.

5.6. Disable Standard Key

With a root connection, server MUST accept DisableStandardKey message and respond DisableStandardKeyResult.

If the key is not existed, then response status NotFound. If the key is existed and it's already disabled, then response status NotChanged.

If the key is existed and it's enabled, then disable it. If there are any connection that is authenticated by the key, then terminate it. Finally, response status Ok.

5.7. Find Standard Key

With a root connection, server MUST accept FindStandardKey message and respond FindStandardKeyResult.

If the key is not existed, then response status NotFound. Otherwise, respond status Ok and key's data.

5.8. Ping

With an authenticated connection, the server accepts Ping message and responds Pong.

6. Server Configuration

6.1. ConnectionTimeout

If client does not send any message after ConnectionTimeout is reached, then server MUST terminate the connection.

6.2. RateLimit

This configuration includes two value RateLimitQuota and RateLimitInterval. If client sends too many messages in a time span, then server MUST terminate the connection. Too many mean that more than RateLimitQuota messages in RateLimitInterval milliseconds.

7. Status

Status is a 8 bits unsigned integer that indicate a success or failed message. There are message that does not contain status. There are list of status:

7.1. Success

Success status in range [0x10, 0x1F]. There are status:

  • 0x10 - Ok. General success.
  • 0x11 - NotChanged. Write operation successfully but there is no changes from peer.

7.2. Client Error

Client error status is in range [0x20, 0x2F]. There are status:

  • 0x20 - MessageTypeInvalid. The peer does not accept message type.
  • 0x21 - MessageDataInvalid. The data part is invalid.
  • 0x22 - Unauthorized. Invalid credential.
  • 0x23 - NotFound. The resource does not exist.
  • 0x24 - AuthenticationConflict. There is already connection that is authenticated by the same key.

7.3. Server Error

Server error status is in range [0x30, 0x3F]. There are status:

  • 0x30 - InternalError. The server has a hard time.
  • 0x31 - VersionNotSupported. The protocol is not supported by the server.
  • 0x32 - Exhausted. Cannot create a new resource.

8. Message

8.1. General

A message includes two parts: Type and Data. Type is 16 bits and included for any messages. Data may be zero or multi-bytes. There are finite message types, and they are specified in the next sections.

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | Type of message.                  |
|---------------+---------------+-----------------------------------+
| 0 or          | Variant       | Data of message.                  |
| multi-bytes   |               |                                   |
+---------------+---------------+-----------------------------------+

8.2. Handshake

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x1000.                   |
|---------------+---------------+-----------------------------------+
| 8 bits        | Version       | The protocol version              |
|               |               | MUST be 0x01.                     |
+---------------+---------------+-----------------------------------+

8.3. HandshakeResult

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x1001.                   |
+---------------+---------------+-----------------------------------+
| 8 bits        | Status        | 0x10 = Ok                         |
|               |               | 0x30 = InternalError              |
|               |               | 0x31 = VersionNotSupported        |
+---------------+---------------+-----------------------------------+

8.4. AuthenticateStandard

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x2000.                   |
+---------------+---------------+-----------------------------------+
| 160 bits      | ClientKey     |                                   |
+---------------+---------------+-----------------------------------+
| 160 bits      | StandardKey   |                                   |
+---------------+---------------+-----------------------------------+

8.5. AuthenticateStandardResult

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x2001.                   |
+---------------+---------------+-----------------------------------+
| 8 bits        | Status        | 0x10 = Ok                         |
|               |               | 0x22 = Unauthorized               |
|               |               | 0x24 = AuthenticationConflict     |
|               |               | 0x30 = InternalError              |
+---------------+---------------+-----------------------------------+

8.6. AuthenticateRoot

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x3000.                   |
+---------------+---------------+-----------------------------------+
| 160 bits      | ClientKey     |                                   |
+---------------+---------------+-----------------------------------+
| 160 bits      | RootKey       |                                   |
+---------------+---------------+-----------------------------------+

8.7. AuthenticateRootResult

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x3001.                   |
+---------------+---------------+-----------------------------------+
| 8 bits        | Status        | 0x10 = Ok                         |
|               |               | 0x22 = Unauthorized               |
|               |               | 0x30 = InternalError              |
+---------------+---------------+-----------------------------------+

8.8. NewStandardKey

This operation requires authenticated RootKey.

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x3002.                   |
+---------------+---------------+-----------------------------------+
| 8 bits        | NoteLength    |                                   |
+---------------+---------------+-----------------------------------+
| 0-255 bytes   | Note          | UTF-8 encoded                     |
+---------------+---------------+-----------------------------------+

8.9. NewStandardKeyResult

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x3003.                   |
+---------------+---------------+-----------------------------------+
| 8 bits        | Status        | 0x10 = Ok                         |
|               |               | 0x21 = MessageDataInvalid         |
|               |               | 0x30 = InternalError              |
|               |               | 0x32 = Exhausted                  |
|               |               |                                   |
|               |               | MUST include next blocks on       |
|               |               | success. Otherwise, skip it       |
+---------------+---------------+-----------------------------------+
| 160 bits      | Key           | Created key.                      |
+---------------+---------------+-----------------------------------+

8.10. EnableStandardKey

This operation requires authenticated RootKey.

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x3004                    |
+---------------+---------------+-----------------------------------+
| 64 bits       | KeyId         | MUST be the first 64 bits         |
|               |               | of StandardKey.                   |
+---------------+---------------+-----------------------------------+

8.11. EnableStandardKeyResult

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | 0x3005                            |
|---------------+---------------+-----------------------------------+
| 8 bits        | Status        | 0x10 = Ok                         |
|               |               | 0x11 = NotChanged                 |
|               |               | 0x23 = NotFound                   |
|               |               | 0x30 = InternalError              |
+---------------+---------------+-----------------------------------+

8.12. DisableStandardKey

This operation requires authenticated RootKey.

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x3006.                   |
+---------------+---------------+-----------------------------------+
| 64 bits       | KeyId         | MUST be the first 64 bits         |
|               |               | of StandardKey.                   |
+---------------+---------------+-----------------------------------+

8.13. DisableStandardKeyResult

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x3007.                   |
|---------------+---------------+-----------------------------------+
| 8 bits        | Status        | 0x10 = Ok                         |
|               |               | 0x11 = NotChanged                 |
|               |               | 0x23 = NotFound                   |
|               |               | 0x30 = InternalError              |
+---------------+---------------+-----------------------------------+

8.14. FindStandardKey

This operation requires authenticated RootKey.

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x3008.                   |
|---------------+---------------+-----------------------------------+
| 64 bits       | KeyId         | The first 64 bits of StandardKey. |
+---------------+---------------+-----------------------------------+

8.15. FindStandardKeyResult

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x3009.                   |
|---------------+---------------+-----------------------------------+
| 8 bits        | Status        | 0x10 = Ok                         |
|               |               | 0x23 = NotFound                   |
|               |               | 0x30 = InternalError              |
|               |               |                                   |
|               |               | MUST include next blocks on       |
|               |               | success. Otherwise, skip it.      |
|---------------+---------------+-----------------------------------+
| 8 bits        | Enabled       | 0x00 = No                         |
|               |               | 0x01 = Yes                        |
|---------------+---------------+-----------------------------------+
| 64 bits       | CreatedAt     | UNIX timestamp in seconds.        |
|---------------+---------------+-----------------------------------+
| 8 bits        | NoteLength    |                                   |
|---------------+---------------+-----------------------------------+
| 0-255 bytes   | Note          | UTF-8 encoded.                    |
+---------------+---------------+-----------------------------------+

8.16. Ping

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x1002.                   |
+---------------+---------------+-----------------------------------+

8.17. Pong

+===============+===============+===================================+
| Size          | Name          | Description                       |
+===============+===============+===================================+
| 16 bits       | Type          | MUST be 0x1003.                   |
+---------------+---------------+-----------------------------------+