From 4d46723011508ab8febd2eac99524f166e6d7d95 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 11 Sep 2018 10:16:25 +0200 Subject: [PATCH] update protocol --- PROTOCOL.md | 58 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/PROTOCOL.md b/PROTOCOL.md index c94add3..d0d1fd2 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -4,31 +4,32 @@ Vocabulary +- A `hash` or `digest` is a fixed-length string that is the output of a hash function. - A `token` is a fixed-length string sent by a client to a server to authenticate. - A `private key` is a fairly unique and hardly guessable data that is generated by a machine and never shared. - A `request` is sent from a client to a server, the server sends back a `response`. ## Abstract -After designing some APIs, I found out that you must have at some point a *token* system to authenticate to your server. For the simplest design, the server generates a unique token for each client, this token will then be sent over each request to authenticate. +After designing some APIs, I found out that you must have at some point a *token* system to authenticate to your server. For the simplest design, the server attributes a unique token for each client, this token will then be sent over each request to authenticate. > The server may also regenerate the token at some time to avoid token theft. An easy MITM attack could be to repeat a previously sent request while the token is still valid or even catch the client *token* and build a malicious request with its authentication. > In this document we will assume that what travels through the network is public, so any MITM can store it. Obviously I highly recommend using TLS for communicating, but we look here for a consistent token system, it only can be better through TLS. -A good alternative could be to use a *one-time token* where each request features a unique token. This design implies that the token travels through the network - which we consider public - before being used so any MITM can catch it. To overcome this flaw we could have a system where *one key* can generate all the tokens in a consistent manner. If so, the tokens do not have to be sent and can be guessed from the key. But this also implies that the key is shared at some point. +A good alternative could be to use a *one-time token* where each request features a unique token. This design implies that the token is sent from the server to the client before being used ; so any MITM can catch it. To overcome this flaw we could have a system where *one key* is used to generate all the tokens in a consistent manner. If so, the tokens do not have to be sent and can be guessed from the key. But this also implies that the key is shared at some point between the client and the server. -A better solution would be to generate a private key on each client and use it to generate a token for each request. Also, to avoid to share the key and allow the server to easily check tokens, we would like a system where each token can be checked from the previous token without having to know the private key (because it is private...). It would avoid attackers to repeat requests (because each token is unique) or guess the private key because it is never over the network but only on the client. In addition short-lived one-time passwords have a mechanism that we could use to build a time-dependent system. +A better solution would be to generate a private key on each client and use it to generate a token for each request. Also, to avoid to share the key and allow the server to easily check tokens, we would like a system where each token can be checked from the previous token without having to know the private key (because it is private...). It would avoid attackers to repeat requests (because each token is unique) or guess the private key because it never travels over the network. In addition short-lived one-time passwords have a mechanism that we could use to build a time-dependent system. **What we need** -1. Generate a *public token* for each request from a fixed *private key* +1. Generate a *unique token* for each request from a fixed *private key* 2. The token *never* to be the same 3. The token to be easily checked directly from the previous one 4. Each token to be only valid a few seconds after sending it 5. Each token to give no clue that could help guessing the next token. -6. A system where no key is shared ; only clients do the key processing and the server only to process simple checking algorithm +6. A system where no key is shared ; only clients do the key processing and the server only to process a simple checking algorithm **Technology requirements** @@ -42,7 +43,7 @@ This document will define and bundle 2 distinct protocols to make up a token sys 1. a Stateless Time Scrambling Protocol to take care of the request's invalidation over time. 2. a Stateless Cyclic Hash Algorithm to use a private key as a one-time token generator in a way that no clue is given over published tokens (*i.e. one-way function*). -3. A key renewal mechanism in a way that no clue is given over neither the old nor the new key. +3. A key renewal mechanism in a way that no clue is given over neither the old nor the new key. 4. A rescue protocol to resynchronise the client with a new key in a way that no clue is given over the network and the client has to process a "proof of work". @@ -71,9 +72,9 @@ These variables are both on the server and clients. They are specific to the ser | Variable | Name | Description | |:--------:|:----:|:------------| -| $W$ | time window | A number of seconds that is typically the maximum transmission time from end to end. It will be used by the *time-scrambling aspect*. The lower the number, the less time an attacker has to try to brute-force the tokens. | +| $W$ | time window | A number of seconds that is typically the maximum transmission time from end to end. It will be used by the *time-scrambling protocol*. The lower the number, the less time an attacker has to try to brute-force the tokens. | | $min$ | resynchonization range | A number that is used to resynchronize the client if there is a communication issue (*e.g. lost request, lost response, attack*). The higher the value, the higher the challenge for the client to recover the authentication, thus the harder for an attacker to guess it. | -| $sec$ | security range | A number that is used to resynchronize the client if there is a communication shift (*e.g. lost request, lost response, attack*). It corresponds of the number of desynchronizations the client can handle before never being able to gain the authentication again. | +| $belt$ | security range | A number that is used to resynchronize the client if there is a communication shift (*e.g. lost request, lost response, attack*). It corresponds of the number of desynchronizations the client can handle before never being able to gain the authentication again. | | $max$ | maximum nonce | A number that is used to cap the value of client's nonces. A too high value will result on keys that will never be replaced, thus making them open to long-processing attacks (*e.g. brute-force*). | #### 2. Client keyset @@ -103,14 +104,14 @@ In each request, the client will send a pair of time-scrambled hashes $(x_1, x_2 The client implements 3 protocols according to the **keyset state** : - 0 : `NORMAL` - default authentication protocol. -- 1 : `SWITCH` - default protocol variation to switch to a new keyset when the current one is consumed (*i.e. when $n$ if less or equal to $min+sec$*). +- 1 : `SWITCH` - default protocol variation to switch to a new keyset when the current one is consumed (*i.e. when $n$ if less or equal to $min+belt$*). - 2 : `RESCUE` - process the proof of work after receiving the server's challenge when there is a desynchronisation and generate a new keyset. When the client switches to a new key, it has to store the new keyset along the current one, in order not to lose its authentication if the network fails. - $(K,n,s)$ - the current keyset - $(K',n',s')$ - the new keyset -#### A. `NORMAL` protocol +#### A. `NORMAL` protocol (state 0) | Step | Calculation | @@ -119,44 +120,47 @@ When the client switches to a new key, it has to store the new keyset along the | `2` | $t\_c = \mid \frac{t\_{now}}{W}\mid$ | | `3` | $x\_1 = h^{n}(K) \oplus h(t\_c)$ | | `4` | $x\_2 = x\_1 \oplus (t\_c \ \mathbb{Z}\_{(2)})$ | +| `5` | if $i <= min+belt \Rightarrow s = 1$ | Send $x_1$ and $x_2$. -#### B. `SWITCH` protocol +#### B. `SWITCH` protocol (state 1) | Step | Calculation | |:--------:|:------| | `1` | $t\_c = \mid \frac{t\_{now}}{W}\mid$ | | `2` | $x\_1 = h^{n}(K) \oplus h(t\_c)$ | -| `3` | Generate $(K',n',s')$ until
| +| `3` | Generate $(K',n',s')$ until
| | `4` | $x\_2 = h^{n'}(K') \oplus h(t\_c)$ | Send $x_1$ and $x_2$. -#### C. `RESCUE` protocol +If the response succeeds, replace the key with the new one : $K = K', n = n', s = 0$ + +#### C. `RESCUE` protocol (state 2) This protocol is processed when the server sends the 2 hashes $(y_1, y_2)$ to the client (instead of the standard response). It means that the server has received a wrong hash, so it sends the rescue challenge to the client. | Step | Calculation | |:--------:|:------| -| `1` | $m_s = y_1 \oplus y_2$ -| `2` | $t\_c = \mid \frac{t\_{now}}{W} \mid $, $m\_c = t\_c \mathbb{Z}\_{(2)}$ -| `3` | $t'\_s = t\_c - \parallel m\_c - m\_s\parallel$ -| `4` | $T = x\_1 \oplus h(t'\_s)$ -| `5` | Find $N \in [min ; n-min[,\ h^{N}(K) = T$. -| `6` | $x\_1 = h^N(K) \oplus h(t\_c)$ -| `7` | Generate $(K',n',s')$ until :
| -| `8` | $x\_2 = h^{n'}(K') \oplus h(t\_c)$ | +| `1` | $t\_c = \mid \frac{t\_{now}}{W} \mid $, $m\_c = t\_c \ \mathbb{Z}\_{(2)}$ +| `2` | $t'\_s = t\_c - \parallel m\_c - (y_1 \oplus y_2)\parallel$ +| `3` | $T = x\_1 \oplus h(t'\_s)$ +| `4` | Find $N \in [min ; n-min[,\ h^{N}(K) = T$. +| `5` | $x\_1 = h^N(K) \oplus h(t\_c)$ +| `6` | Generate $(K',n',s')$ until :
| +| `7` | $x\_2 = h^{n'}(K') \oplus h(t\_c)$ | Send $x_1$ and $x_2$. +If the response succeeds, replace the key with the new one : $K = K', n = n', s = 0$ ## 2. Server management When receiving a pair of hashes $(x_1, x_2)$, the server has to : 1. Unscramble the request using the time-scrambling algorithm -2. Check the token held into $x_1$ : - - `VALID` $\rightarrow$ authenticated : store the token held into $x_2$, forward request to the logic unit +2. Check the token $t_1$ held into $x_1$ : + - `VALID` $\rightarrow$ authenticated : store the token $t_2$ held into $x_2$, forward request to the logic unit - `INVALID` $\rightarrow$ not authenticated : send the challenge hashes $(y_1, y_2)$. #### 1. Unscramble the request @@ -168,7 +172,13 @@ When receiving a pair of hashes $(x_1, x_2)$, the server has to : | `3` | $t'\_c = t\_s - \parallel m_c - m_s \parallel$ | | `4` | $t\_1 = x\_1 \oplus h(t'\_c)$ | | `5` | $t\_2 = x\_2 \oplus h(t'\_c)$ | -| `6` | Token is valid if $h(t_1) = T$ | + + +If $h(t_1) = T$ : +- $t_1$ is valid +- store the next token $T=t_2$ + +Else, go to the [invalid request management](#2-invalid-request-management). #### 2. Invalid request management