tamf / whisper-secret-messages

Share text-based information securely and anonymously over the internet.
2 stars 3 forks source link

Encrypt the secret before sending #5

Closed tamf closed 3 years ago

tamf commented 3 years ago

The secret should be encrypted in the client (front-end) before sending to the function

tamf commented 3 years ago

use AES? https://stackoverflow.com/questions/29584051/javascript-encrypt-form-before-sending-with-aes

Some browsers have limitations in generating random numbers. Don't use Math.random for anything cryptography related https://security.stackexchange.com/questions/194107/should-i-encrypt-sensitive-form-data-with-javascript-on-the-client

https://bitwiseshiftleft.github.io/sjcl/ https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API/ If we can't trust the server at all, then client-side encryption is useless because the server serves the client page. https://security.stackexchange.com/questions/51703/how-to-best-use-javascript-to-encrypt-client-side-so-the-server-never-sees-it

Bitwarden uses AES-CBC to encrypt Vault data. PBKDF2 SHA-256 is used to derive the encryption key from a given passphrase. https://bitwarden.com/help/article/what-encryption-is-used/ Bitwarden uses Web Crypto.

Lastpass also uses AES-256 CBC

OpenPGP is also an option https://github.com/jhaals/yopass https://github.com/openpgpjs/openpgpjs#browser-plain-files

Good workflow that we should consider following in principle

Why HTTPS is not enough https://tozny.com/blog/end-to-end-encryption-vs-https/

Use Web Crypto and libsodium https://share.labs.tozny.com/faq

tamf commented 3 years ago

in conclusion, let's use Web Crypto to do AES-CBC using the custom passphrase. If a custom passphrase isn't given then generate random 64 char passphrase and include it in the sharing link. At this time I don't see the point of generating hashes and storing the final hash on the server.

tamf commented 3 years ago

https://github.com/diafygi/webcrypto-examples#aes-cbc https://github.com/AKASHAorg/easy-web-crypto/blob/7ede92c4b3ac9b85136916b51185d55e8c68cffe/dist/esm/web-crypto.js#L309 https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/deriveKey

tamf commented 3 years ago

https://bradyjoslin.com/blog/encryption-webcrypto/ https://www.youtube.com/watch?v=lbt2_M1hZeg

tamf commented 3 years ago

https://github.com/mdn/dom-examples/blob/master/web-crypto/encrypt-decrypt/aes-cbc.js

PQTran commented 3 years ago

If I understand correctly, encryption and decryption is going to be applied at both client-side and server-side. In order to use AES, we need to generate a key, and use a cipher inorder to generate cipher text (encryption). Does the key get transmitted to the server-side (and client-side in order to work in different sessions) along with the cipher text?

tamf commented 3 years ago

Encryption and decryption will be done only client side. For now, the server will not apply additional encryption for data at rest (in Firestore)

The key is not sent to the server. Only the cipher text is sent to the server. The user will be given a url which would encode the salt and secret id. If no passphrase is provided maybe the url would simply include the key and id

tamf commented 3 years ago

https://github.com/tamf/whisper-secret-messages/pull/25