-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replicate to remote CouchDB #44
Comments
um it's supposed to send it unencrypted, how have you setup the replication |
I'm doing
This will not send changes to my couch. However if I do
|
I don't know it that helps, but I noticed that if I don't use crypto-pouch, so if I don't do
then, when changing a pouch doc, pouch does a
which replies with
which leads to my data being replicated in my CouchDB. However, when using Any idea why this is happening? |
Ok, I think I narrowed it down a bit further. Replication is successful when creating new documents on the client. However the problem appears in the case of a fresh start with an empty PouchDB, and in case the remote CouchDB already has data. These data will be replicated on the client, but any further editing on the client will not result in a replication, unless the call to Since using live replication, pouch does not emit a |
this is likely an issue with transform-pouch which we use under the hood |
So, after some further investigation, I used the following code to encrypt my Pouch after the initial replication:
This works fine, and all data from my CouchDB get in my Pouch on page reload, then get encrypted, and in case I change them in my browser, the get back to my CouchDB unencrypted. However, if I keep the app running, and at the same time I create a new doc direct in my Couch, it gets replicated in my Pouch, but any editing on the client will not replicate back to CouchDB. |
In might have to do with this transform-pouch issue |
I have a solution for this; have two pouchdb instances, one with crypto pouch loaded as a plugin, one without. Do all your document manipulation in your crypto instance, but setup replication in your blank instance. It's a little hacky, but was a 2-3 line change for me that works out the box. Data is sent to the server encrypted, and you could then set up the couch server to be able to decrypt given the same password. I am using this for a zero knowledge application where the server doesn't have access to any user data, its just a dumb store. |
@jackkleeman your approach seems interesting. Could you elaborate? This is worth a blog post. 😬 |
@fredguth what a blast from the past! Here is a gist showing the general idea: One of the PouchDB instances has no idea the db is encrypted, it just relays the documents as it sees them. The other instance is the one used for actual db operations. They both use the same db name, which actually works, they don't need to be told to sync to each other, interestingly. At least, this worked a year ago! If you want to post about it, please do! |
Hi, Original code
What we did to solve this issue was to create 2 DBs, one encrypted DB that replicates data from Couchdb into a local Pouchdb (pull changes). One not encrypted remote DB but with no data stored that will push changes. Adapted code
All get/query requests are done with the localdb and all put/post requests are done with remoteDB. Also we had to modify crypto pouch index.js file, to add '_revisions' to ignore variable |
This seems like an ancient (and critical!) error without much hope of ever getting fixed, but I just thought I would document my findings: Replicate a document from a remote couch to a local encrypted pouch, make a change to that document, put it to the local pouch and then replicate it back to the remote couch. The replication result will show that 1 file has been updated:
But in reality, the remote couch never gets the updated doc. If you do the same, but instead of using a remote couch as the starting point, and just use an unencrypted local pouch, then the updates seem to replicate fine. Bottom line: If you use crypto-pouch it will fail if you try and edit documents and replicate them to a remote couch. |
I'm still fighting this one. Here's the simplest test I can come up with now. No need to even use a remote couchdb, can be demonstrated with just local pouchdbs
|
1 years later, and one afternoon later in my case: I believe the issue here is the same: In summary: don't blacklist the keys you don't want to encrypt, instead whitelist the keys you want to encrypt. |
Looks like this is still an issue. You can reproduce it like this: const assert = require('assert').strict
const PouchDB = require('pouchdb')
PouchDB.plugin(require('crypto-pouch'))
const NAME = '.test'
const PASSWORD = 'hello world'
const DOC = { _id: 'a', hello: 'world' }
const DDOC = {
_id: '_design/test',
views: {
test: {
map: function(doc) {
emit(doc.hello)
}.toString()
}
}
}
const db = new PouchDB(NAME)
const db2 = new PouchDB(NAME + '2')
db.crypto(PASSWORD).then(async () => {
await db.put(DOC)
await db.put(DDOC)
await db.replicate.to(db2)
const result = await db2.allDocs({ include_docs: true })
assert.equal(result.rows.length, 2)
console.log('ok')
}).catch((err) => {
console.error(err)
}).then(async () => {
await db.destroy()
await db2.destroy()
}) You will see output like this:
|
It looks like this happens because crypto-pouch encrypts payloads before a We will have to generate our own _rev values since we have to intercept the document prior to writing to disk. |
@garbados Rather than generating our own rev values, I was wondering why we're discarding fields from the outgoing doc in This also makes me wonder if there are other fields we should add to the |
I've put up a PR that patched the decrypted doc with ignored fields attached to the encrypted doc, like |
Hi, I've been struggling since some days to replicate data to a remote couchDB after I've encrypted my local Pouch with crypto-pouch.
First I thought it was not working because I was using a filter, as mentioned in issue 37. I removed the filter and still couldn't make it work.
After testing, I could finally achieve replication after applying the
crypto
function to my remote database as well, using the same password.If that's the way it works, could you please make it more clear in your documentation?
Then, I noticed that this way, the data in my remote Couch were been inserted encrypted after the replication.
Is there a way to keep encrypted data on the client, but sent it unencrypted to the remote DB?
Many thanks in advance.
The text was updated successfully, but these errors were encountered: