Concordium / concordium-reference-wallet-ios

Reference wallet for the Concordium blockchain
Apache License 2.0
11 stars 10 forks source link

Keys do not work properly after restore and import in certain scenario #173

Closed jens-concordium closed 2 years ago

jens-concordium commented 2 years ago

Bug Description

This bug is potentially related to the missing keys problem caused by restoring an iOS device from an iCloud backup.

Recap of the iCloud backup problem, as background info: If a user had the Concordium wallet while creating a backup of the whole iOS device to iCloud, all data from the Concordium wallet would be kept in the backup except keys. After restoring an iOS device from the iCloud backup, it would look like the accounts and identities were still there, but they couldn't be used for anything, because the keys were not here. Importing an old backup on top of the accounts and IDs with no keys wouldn't help, as the wallet saw them as duplicates, hence not importing the keys from the backup.

Part of the fix for the problem, was to let the wallet check if keys existed for accounts and IDs, and then let the user know about it. The affected accounts would be marked as "read-only", as that would allow the wallet to import the keys from a valid backup, without seeing the accounts as duplicates

The potential new problem: We've received a report from a user who had bought a new iPhone, which was then setup via an iCloud backup that contained an earlier version of the wallet. After restoring the phone, the Concordium wallet was updated to the newest version and the user imported a valid backup on top of what existed in the wallet after the phone restore.

The keys for the users accounts and IDs were added as intended, and everything seemed to be okay, except when the user tried to make a transfer from the account. The user was then met by the same error as for the previous iCloud problem: "An error occured". This indicated that the keys might still be missing.

Using the validation option in the More menu, the app let the user know that everything should be fine. A new export made from the wallet even had a size of 71kB, so that seemed to contain everything as well.

The identity could be used to make more accounts, so those keys were functioning properly.

Lastly, the user tried to update the passcode, but that didn't work, which could indicate that there are still a problem with some of the keys.

So all in all, it seems like the keys are imported in 1.2(33), but for some reason they might not work properly for some accounts.

We need to investigate what exactly is happening with the keys for those accounts.

Versions

mh-concordium commented 2 years ago

How to reproduce:

iPhone SE - iOS 14.8.1 Testnet Mobile Wallet 1.0.7 and 1.2.33

Install 1.0.7 Testnet Mobile Wallet and set it up with account and ID

  1. Install 1.0(7) Testnet Mobile Wallet from Test Flight. iOS will inform you about turning OFF automatic updates because of old build installation. Open Concordium Wallet and Agree to Terms.
  2. Create Passcode (I have used 123456) and continue without biometrics.
  3. Getting started, dialogue opens. Select “I want to create my initial account”. Name the account “TestMH”.
  4. Provide identity name “MH”. Continue to Identity providers.
  5. Select Concordium testnet IP. Submit the form with default values. Select Finish and wait until the account is created.
  6. Validate that account was created and claim 100 CCD for testing.

Validate app version and export Concordium ID to iPhone

  1. Validate app version - 1.0(7).
  2. Export Concordium ID.
  3. Select export and create export password (I have used 123456).
  4. Use the option save to files and save on my phone.
  5. Name the export file (exportTestMH).
  6. Validate size of the export file ~ 42KB.

Make iCloud backup and restore iPhone from the backup

  1. Make iCloud backup (Settings->Apple ID->iCloud). Note down the time of the backup.
  2. Erase iphone (Settings->General->Reset->Erase All Content and Settings).
  3. When iPone starts up again, select the default options on the startup and select it to restore from iCloud.

Install the latest Testnet Mobile Wallet from Test Flight and import Concordium ID

  1. After the restore, attempt to start the Testnet Wallet will prompt the message “Unable to install Concordium ID”. Select OK.
  2. Open Test Flight and install the latest version of Testnet Wallet.
  3. After the installation, start the application. Accept the terms and create Passcode.
  4. When “Are you new here?” dialogue opens up, select “I want to import existing accounts”.
  5. Message appears explaining how to import on iOS. Select “Okay, got it!”
  6. Press Home button. Application is in the background.
  7. Open Files on iPhone. Concordium ID file named exportTestMH is visible (42KB). Select file and tap on share. Open with Concordium Testnet Wallet.
  8. Type export password (123456). Import was successful. It seems that account already existed. (Only keys are missing, future version of wallet will block any data ending up in the cloud to avoid this)

Validate ID, attempt to transfer CCDs

  1. Validate app version. About -> 1.2.33
  2. Validate IDs and Accounts. Pass.
  3. Attempt to send CCD to a random address. Fail. “An error occurred. Please try again.”
  4. Attempt to create a new account and add it to the existing identity. Pass.
  5. Attempt to change password. Fail.
  6. Attempt to restart application and then send 100 CCD. Fail.
  7. Attempt to make new export was successful, however export file was somewhat smaller ~40KB.

NOTES: I could see that there was something wrong with the timestamp on the iCloud backup. I have made the backup 07/02/22 - 22:00 but when restoring the latest backup is from 13:00 which is the same backup but the time zone seems off.

First time I have reproduced the issue, I could see that something was wrong with the import. Import has failed.After I have restarted the application, I was able to import but the issue as above described was still here. All the 29 steps above was the second attempt.

Attachments: Video1 - Before restoring iPhone: Video1 Video2 - After restoring iPhone: Video2

concordium-cl commented 2 years ago

So it confirms our suspicion that the previous fix only applies to the normal import (via More > Import) but not to the initial import (directly after installation of app).

Additionally, we must look into why it validates correctly in step 25.