Today, I’m happy to tell you that Wi-Fi Sync is coming to 1Password for Android! In fact, it is already available in the latest beta, so you can join our beta family and try it out right now. In this edition of our DevBits series, I am going to talk about how we implemented Wi-Fi Sync in 1Password for Android.
Wi-Fi Sync in 1Password for Android uses only standard Android APIs. We don’t use any third-party libraries. All the required communication logic was written in-house (although inspirational ideas for WebSocket implementation were taken from elsewhere). Using Android APIs keeps the .apk file small and eliminates version incompatibility, licensing issues, or any other trouble that might arise when incorporating third-party code into the app.
Wi-Fi Sync in 1Password for Android consists of three parts: Network Service Discovery (NSD), Network Service Resolution, and the actual sync itself. Both the Network Service Discovery and Network Service Resolution are based on the NSD framework built in to Android. The sync is implemented using synchronous Websocket communication with a service provided by 1Password for Mac or 1Password for Windows.
Network Service Discovery
When you choose to sync using Wi-Fi in 1Password for Android, Network Service Discovery is launched asynchronously and continues to run in the background until you stop it. The service looks for all network services matching the type used by 1Password (in our case “_1password4._tcp.”).
This network service type matches the type used by the latest versions of 1Password on both Mac and Windows when Wi-Fi Sync is enabled. Any discovered Wi-Fi services are displayed in a list for you to select from in order to set up the initial sync. It is important to note that the service info found by NSD contains no information other than the service name and type.
Network Service Resolution
Once you have decided which service you want to use, the Network Service Resolution process is launched asynchronously for the chosen service. 1Password for Android is given the service credentials, including the IP address and port, so that communication with the server can be established. The service name is stored in 1Password preferences and used for subsequent communication sessions. This allows service discovery during incremental sync to automatically stop when a service matching the one stored in preferences is found.
Next, 1Password proceeds with service resolution. If the connection is successful, the actual sync process is launched using the provided service IP address and port. If service discovery is unable to discover the service in two seconds, or if the resolution is invalid, you will be asked to ensure that 1Password is running on the computer you are trying to sync with, and the sync attempt is aborted.
The actual sync
The actual sync process is handled by a subclass of Android’s AsyncTask that establishes synchronous communication with the server using the WebSocket protocol. In order to establish a connection, this task first requires valid service credentials (address and port) and a reference to the database manager. Once connected with the service, communication proceeds according to a proprietary JSON-based command protocol which is itself based on the WebSocket protocol.
Once 1Password for Android is successfully authenticated by the server it receives an item/folder list. Next, a request is made for items from the list which have been updated on the server, and these are then decrypted and saved in the 1Password for Android internal database.
In order to decrypt these items, your Master Password is requested during initial sync. Although the communication secret is stored in 1Password preferences, it should be noted that your Master Password is never stored in the system preferences or in the database.
Once the initial sync is complete and an incremental sync has begun, you may notice some minor differences between syncing with 1Password for Mac and 1Password for Windows. These differences are the result of architectural differences between the two versions, namely that 1Password for Windows doesn’t rely on an internal database. This results in slightly faster syncing with 1Password for Windows and the need to enter your Master Password on each incremental sync.
When the Wi-Fi Sync server has transmitted all of its updated items to 1Password for Android, and it has transmitted all of its updated items back to the Wi-Fi Sync server, the communication session is terminated and the network socket is closed. Detailed sync results of the latest session are written to the Diagnostics Report, which you can generate from the Settings > Advanced screen and review at any time.
At present, Wi-Fi Sync is designed to work between one computer and one or more mobile devices. We do not recommend switching between multiple desktops when syncing using Wi-Fi. Note that the sync method cannot be changed once it has been selected. For example, if your initial sync uses Wi-Fi, you cannot later switch to Dropbox. Because 1Password for Android supports sync with only the primary vault at this time, it is not possible to switch to a different vault once the Wi-Fi Sync connection to the chosen server has been established.
The addition of Wi-Fi Sync to 1Password for Android furthers our goal of placing you in control of your data. In addition to local storage and sync with Dropbox, you now have a third option for syncing your vault from your Android devices to your other devices. We hope you enjoy using it and welcome your feedback in our beta forums.