|
32 | 32 |
|
33 | 33 | ## Client-side Encryption
|
34 | 34 |
|
35 |
| -* Darim supports client-side encryption to protect the user's secrect from others including server. |
36 |
| - |
37 |
| -### Generate keys |
38 |
| - |
39 |
| - |
40 |
| - |
41 |
| -1. When a user finishes the sign-up process, the secret key and public key are generated on the client-side. |
42 |
| -1. The client encrypts the secret key by public key and saevs the encrypted secret key in local storage. |
| 35 | +Darim supports client-side encryption to protect the user's secrect from others including server. |
| 36 | + |
| 37 | +### Key generation |
| 38 | + |
| 39 | +```mermaid |
| 40 | +%%{init: {'theme': 'neutral'}}%% |
| 41 | +sequenceDiagram |
| 42 | + Note over client: generates<br>secret and public |
| 43 | + Note over client: encrypts secret<br>using public |
| 44 | + client ->> local storage: set(encrypted_secret) |
| 45 | + client ->> server: POST /public_key { public } |
| 46 | + server ->> rdb: INSERT public |
| 47 | + rdb -->> server: [OK 200] |
| 48 | + server -->> client: [OK 200] |
| 49 | +``` |
| 50 | + |
| 51 | +1. When a user finishes the sign-up process, a secret key and public key are generated on the client-side. |
| 52 | +1. The client encrypts the secret key using the public key and saves the encrypted secret key to local storage. |
43 | 53 | 1. The public key is sent to the server, and the server stores it.
|
44 | 54 |
|
45 | 55 | ### Read & Write
|
46 | 56 |
|
47 |
| - |
48 |
| - |
49 |
| -1. When a user creates the plaintext post, the client requests the public key to the server. |
| 57 | +```mermaid |
| 58 | +%%{init: {'theme': 'neutral'}}%% |
| 59 | +sequenceDiagram |
| 60 | + Note over client: creates a new post |
| 61 | + client ->> local storage: get(encrypted_secret) |
| 62 | + local storage -->> client: encrypted_secret |
| 63 | + client ->> server: GET /public_key |
| 64 | + server ->> rdb: SELECT public |
| 65 | + rdb -->> server: [OK 200] { public } |
| 66 | + server -->> client: [OK 200] { public } |
| 67 | + Note over client: decrypts<br>encrypted_secret<br>using public |
| 68 | + Note over client: encrypts the post<br>using secret |
| 69 | + client ->> server: POST /post { encrypted_post } |
| 70 | + server ->> rdb: INSERT encrypted_post |
| 71 | + rdb -->> server: [OK 200] |
| 72 | + server -->> client: [OK 200] |
| 73 | +``` |
| 74 | + |
| 75 | +1. After a user creates a new plaintext post, the client requests the public key to the server. |
50 | 76 | 1. The client decrypts the encrypted secret key in the local storage using the public key from the server.
|
51 | 77 | 1. The plaintext post is encrypted by the secret key decrypted by the public key.
|
52 | 78 | 1. The encrypted post is sent to the server, and the server stores it.
|
53 | 79 |
|
54 | 80 | > * At this point, the server can only know encrypted post.
|
55 |
| -> * When the client requests the server to read the post, whole flows are reversed. |
| 81 | +> * If the client reads a post, the flow is the same until the client requests to create a post to the server. |
56 | 82 |
|
57 | 83 | ## License
|
58 | 84 |
|
|
0 commit comments