Giter Club home page Giter Club logo

Comments (4)

snej avatar snej commented on May 26, 2024

Here's an idea for an API. The idea is that the application registers a block that when called creates an object that knows how to transform data. One transformer object is created for each attachment, and it's passed all the data of the attachment in one or more chunks, and returns the encoded (or decoded) data in chunks.

@protocol CBLAttachmentTransformer : NSObject
/** Transforms the next byte range of an attachment. This method will be called zero of more times, passing in
    contiguous ranges of the attachment data with competed=false, and then once on the last section of the
    data with completed=true. It should output contiguous portions of the encoded data. */
- (NSData*) transformBytes: (NSData*)inputBytes completed: (bool)completed;
@end

/** Returns a new CBLAttachmentTransformer instance that's ready to start encoding or decoding an
    attachment, depending on the setting of the 'encoding' flag. */
typedef id<CBLAttachmentTransformer> (^CBLAttachmentTransformerFactory)(bool encoding);

Somewhere (either globally or on the CBLManager instance) there is a property of type CBLAttachmentTransformerFactory that the application can set to its own block value.

from couchbase-lite-ios.

 avatar commented on May 26, 2024

I would vote to have the SHA-1 digest of the encoded blob not the original.

My reasoning is:

  1. I might wish to store the same data encrypted by two different private keys in the same blob store, not possible if the blob key is based on the unencrypted "in the clear" data.

  2. Creating the digest from the original unencrypted data opens up the possibility of determining the content of an encrypted blob by comparing the digest with known "in the clear" data. A hacker would have to already have the original data or it's "in the clear" digest, but they could use this information to find out who has a copy of the data even when it is encrypted.

from couchbase-lite-ios.

nl avatar nl commented on May 26, 2024

The only way I got this to work was to hook the API into more places than described above.
-[CBLAttachment body] is one of those places: it has a conditional branch which returns data from straight from a file URL. -getAttachmentForSequence:... looks suspicious too.

from couchbase-lite-ios.

snej avatar snej commented on May 26, 2024

I've just finished implementing database/attachment encryption — see the feature/encryption branch. Encrypting the attachments turned out to be hard because, as mentioned above, there were leaks in the abstraction where callers could discover the attachment file. So I had to do a lot of refactoring in CBLDatabase+Attachments. I didn't add a delegate API, I just implemented the encryption/decryption directly in CBLBlobStore.

from couchbase-lite-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.