Description
Specification
Our current encryption/decryption layer sits on top of LevelDB. This causes problems for indexing #1 because when you want ot index something you'll need to expose keys, and keys have to be un-encrypted atm.
It may also increase performance of DB if encryption/decryption were operating at a block level rather at individual key-value level. It's the equivalent of using full-disk encryption and using leveldb on top.
We can't rely on OS provided full-disk encryption. So something that is in-between the current key-value DB like leveldb and the actual filesystem that is executed in JS or C++ would be needed.
There is a level-js
which is a abstract-leveldown compliant store that can be wrapped in levelup. It is leveldb implemented in pure-JS which relies on IndexedDB. Currently IndexedDB
doesn't exist natively on Node.js, but there are some implementations of it. This seems to give an opportunity to add a transparent encryption/decryption layer in between leveldb and IndexedDB.
Additional context
- Integrate Automatic Indexing into DB #1 (comment) - RocksDB at the C++ level has provision for incorporating encryption at a low level (not sure if this still key-value level or block level of abstraction)
- WIP: Integrating Automatic Indexing into DB #2 (comment) - discussion about level architecture in Node.js
level
is a library that bundlesleveldown
,level-js
,levelup
andencoding-down
to create a single batteries-included package- the difference between
leveldown
andlevel-js
is thatleveldown
uses the C++ leveldb library which only works in Node.js whilelevel-js
works on IndexedDB which exists in browsers - if
IndexedDB
were to exist in Node.js, one could uselevel-js
as an isomorphic library that works on browsers and Node.js, not sure about NativeScript though- using
IndexedDB
could allow us to put a transparent encryption/decryption layer in betweenIndexedDB
andlevel-js
, thus enabling us flexible indexing, and probably better security - there are only 2 libraries providing
IndexedDB
in Node.js:- https://github.com/bigeasy/indexeddb
- https://github.com/dumbmatter/fakeIndexedDB and FIDB persistence dumbmatter/fakeIndexedDB#12 (comment)
- if
fakeIndexedDB
becomesrealIndexedDB
via leveldb, then this should be possible in NS as well, but you are doing something a bit funny:levelup API -> level-js -> transparent encryption/decryption -> IndexedDB -> leveldb or whatever
, but this is sort of what happens in Chrome which implementsIndexedDB
using leveldb - see https://news.ycombinator.com/item?id=10188476 for discussion about IndexedDB in node.js
- if
- using
- the difference between
- Implement True Snapshot Isolation for LevelDB #4 - this may be impacted if IndexedDB is used
- https://github.com/cockroachdb/cockroach/blob/master/docs/RFCS/20171220_encryption_at_rest.md - CockroachDB has done this already we can compare this
Tasks
- - Investigate how level-js uses
IndexedDB
- - Attempt to implement or find a persistent
IndexedDB
, perhaps by being implemented by leveldb or sqlite, it seems like any performant implementation would have to use C++ at some point, also there are bunch of wrapper libraries, but not sure which ones actually perform real persistence - - Integrate this into PK