Add shared db locking.

  * Improve bootstrap sequence:
    - stages are more organized.
    - there are less useless requests to server.
  * Improve shared db access:
    - instantiate the shared db only once.
    - also results in less requests to server.
  * Handle unicode passphrases.
  * Move some common functions and global variables to common.
  * Improve security of recovery document:
    - access to the recovery document now depends on the user password.
  * Improve documentation.