-
Notifications
You must be signed in to change notification settings - Fork 2
Description
-
Implement end-to-end private chat encryption like in telegram so that server hosted only the encrypted text and had no access to the key... or not to host the text altogether, just keep it in client's browser history or something. Anyway the idea is to make sure server has no way to get the actual text, so that if some government guys barged into my office I could honestly say them "sorry guys, it is not possible to leak you the chat history, all communication happens on client side".
I'll think about it more and update when I have a solution.
короче, я кажется знаю что делать с секурностью:
- Пользователь генерирует как в ssh приватный и публичный ключи.
- Посылает публичный ключ через сервер собеседнику.
- Собеседник криптует свои сообщения через этот публичный ключ и отправляет обратно.
- Пользователь исполльзует свой приватный ключ чтоб расшифровать эти сообщения.
https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API
I will write a scratch code with key generation after I deal with the rock-paper-scissors game.
Upd.: no, this won't work either. Server could replace your public key with it's own before sending it to your buddy and decrypt what he sends.
Ok, I came up with a genious idea yet again. To store public key on a service instead of passing it through the server and to check it every couple seconds. Here are the steps:
- Take user's private/public keys from window.localStorage if any, else generate them with CryptHelper.js and store to the localStorage.
- Every Math.random() * 10` seconds check that value on the service is either empty or matches the user's public key with:
If it does not match, show the error to the user with BIG RED LETTERS and do not allow him to send encrypted messages. In addition, show him a button "It's OK, I simply logged from different device" - if he presses it, rewrite the value in the service (see further) and continue normally.
fetch('https://keyvalue.immanuel.co/api/KeyVal/GetValue/7p6a4g00/${atob(userEmail)}/${base64PublicKey}', {method: 'GET'}).then(out => out.text()).then(txt => console.log(txt));
- Store public key on the service: (publicKey is an ArrayBuffer, so it should be base64-encoded as well)
fetch(`https://keyvalue.immanuel.co/api/KeyVal/UpdateValue/7p6a4g00/${atob(userEmail)}/${base64PublicKey}`, {method: 'POST'}).then(out => console.log(out));
- Retrieve the public key of your buddy from window.localStorage or with GetValue of the service same way as above, but with atob of his email and write to localStorage.
- Encrypt the message user is willing to send with
CryptHelper.js::encrypt
and your buddy's public key. - Send it to the server using
func=sendPrivateMessage
andencryption=CryptHelper_v001
(possibly will need toatob()
the message before sending to server). - To decrypt incoming messages from
func=getPrivateMessages
withencryption=CryptHelper_v001
useCryptHelper::decrypt
and the private key.