WhisperSystems/TextSecure-iOS — pull request #52 by nabla-c0d3 (2013-12-30 06:25:28+00:00)
Title: Add TSUserKeysDatabase and change a few things with how DBs work

Hey, sorry for the massive pull request... Hopefully it's the last time, but it was difficult to split the various changes in smaller pull requests. Here's what I've been up to:

* Create TSStorageMasterKey, which now contains the db encryption master key methods. I did this because I wanted to create a new DB to store the user's TS keys and wanted this DB to be protected with the user's passphrase. Now any class can use TSStorageMasterKey to encrypt something locally (doesn't even have to be a DB).
* Create TSUserKeysDatabase, which can be used to generate and retrieve the user's identity and pre keys. I took it out of TSKeyManager because I wanted these keys to have their own class.
* Rename TSEncryptedDatabase to TSMessagesDatabase. I needed the TSEncryptedDatabase name for something else (see the next bullet point) and it also clarifies the purpose of this class.
* Create TSEncryptedDatabase2 (temporary name). This is a generic class to encrypt a database using the TSStorageMasterKey. It's nice because it's now very easy to create new encrypted databases to store various things; TextSecure's Android version does something like this. TSUserKeysDatabase and TSMessagesDatabase both use it. It also moves the encryption code out of the Database classes (things like databaseLock() ) so these classes are simpler to use and now only focus on storing data (as it should be for a DB).
* Fully integrate TSECKeyPair, remove ECKeyPair.
* Add unit tests for all the above.

Overall it should be easier/less annoying to use DBs (no need deal with things like lock() anymore) compared to the previous thing I wrote. And we can now have as many encrypted DBs as we want if that's needed. Lastly, I can now change how db encryption works without having to touch your stuff (the DB code to store data, etc.).

The project passes unit tests and I could register and do the same things as before... I haven't tried sending actual messages cause I don't know anyone's phone number :(. But I do get a 200 OK from the server when sending a message to myself. Let me know if I broke something and I should be able to fix it.
Thanks!