ciphersweet-js icon indicating copy to clipboard operation
ciphersweet-js copied to clipboard

Using in the browser

Open andreialecu opened this issue 5 years ago • 7 comments

I'm thinking of using this in the browser, as I've read in the documentation that it should be supported.

Basically I need to store some sensitive user data, but don't want the hassle of having to deal with the security side of it. It would be better just not having access or storing the unencrypted data at all in our backend/databases.

So I'm thinking of letting the user enter a key into the web app, then use client side javascript to deal with decryption of data. The key would be stored probably in localStorage, and on every new browser they connect from, they'd need to re-enter the key in order to be able to decrypt or update the sensitive data.

Does this sound feasible to implement using ciphersweet?

andreialecu avatar Dec 04 '19 20:12 andreialecu

It's feasible, but you're probably better off using the AWS JavaScript Encryption SDK.

At the very least, you're going to want to use KMS to manage your keys.

paragonie-security avatar Mar 25 '20 07:03 paragonie-security

The purpose behind using ciphersweet for this was for searchable encryption. I'm not sure AWS encryption can help with that.

andreialecu avatar Mar 25 '20 08:03 andreialecu

The purpose behind CipherSweet is also symmetric-key encryption, and you'd be giving out your encryption key via JavaScript to anyone who accessed the page.

You can use CipherSweet only for the indexing purposes, and then use something else (e.g. the AWS Encryption SDK, backed by KMS) for record encryption. Or you could use something like SodiumPlus for crypto_box_seal() on the data encryption, against a static public key.

paragonie-security avatar Mar 25 '20 23:03 paragonie-security

Thank you for the insight. The purpose is to not have access to the Customer data at all from the service provider side.

From what I understand encrypting via KMS does not ensure that. The owner of the AWS account can still decrypt data. That is what we're trying to avoid.

Regarding giving out the encryption key, yes. I am aware of that. But the Encrypted data would still be secured by regular permissions on the user account, only an authorized account (by checking a JWT, for example) could retrieve the encrypted blob and then decrypt it locally.

So it would be an additional layer over a classic permission/ACL layer.

Does this still sound terribly wrong? :)

andreialecu avatar Mar 26 '20 09:03 andreialecu

Hi @paragonie-security! I have been trying to use this in the browser and failed so far, due to dependencies that couldn't be resolved. I tried a very simple example and got errors regarding the dependency fs and others. I tried mocking them with webpack, I tried using ployfills. Nothing seemed to work.

Does this actually work in the browser? And if so, is there and example implemantion somewhere you could point me to?

Any help would be really appreciated!

Best, Tobias

Example Code

import {
  BlindIndex,
  CipherSweet,
  EncryptedField,
  FIPSCrypto,
  StringProvider,
} from "ciphersweet-js";

export async function foo() {
  const cipherSweet = new CipherSweet(
    new StringProvider(
      "4e1c44f87b4cdf21808762970b356891db180a9dd9850e7baf2a79ff3ab8a2fc"
    ),
    new FIPSCrypto()
  );

  let ssn = new EncryptedField(cipherSweet, "contacts", "rezeptTyp")
    // Add a blind index for the "last 4 of SSN":
    .addBlindIndex(
      new BlindIndex(
        // Name (used in key splitting):
        "rezeptTyp",
        // List of Transforms:
        [],
        // Bloom filter size (bits)
        16
      )
    );

  // Some example parameters:
  let contactInfo = {
    name: "John Smith",
    ssn: "123-45-6789",
    email: "[email protected]",
  };

  const result = await ssn.prepareForStorage(contactInfo["ssn"]);

  return result;
}

Error Messages

image-20210721-210527

tbelch-at-eHealth-Tec avatar Aug 11 '21 08:08 tbelch-at-eHealth-Tec

I'm interested in a browser-based install, as well. I think most of the reqs are available in browser, such as browserFS and buffer but ofc these need to be thoughtfully included for security concerns.

34r7h avatar Sep 13 '21 10:09 34r7h

@paragonie-security coming here with similar concern. Does what @andreialecu says seem terrible?

Btw, @andreialecu I wonder, did you end up with the way you suggested?

liflovs avatar Mar 21 '23 08:03 liflovs