martinkasa / capacitor-secure-storage-plugin

Capacitor plugin for storing string values securly on iOS and Android.
MIT License
153 stars 55 forks source link

Android app saves data in localStorage #3

Closed nerdic-coder closed 4 years ago

nerdic-coder commented 4 years ago

When I use this plugin on an Android device/app it seems to be using the web implementation instead of the Android implementation. Can't see any error in the logs, all seems to compile alright.

Using Capacitor 1.3.0.

nerdic-coder commented 4 years ago

Same thing on iOS now when I checked. Seems like it's not detecting that it's running in native environment for some reason? Other native features in the app is working normally.

martinkasa commented 4 years ago

Hi @nerdic-coder,

please check if you have correct imports.

import 'capacitor-secure-storage-plugin';
import { Plugins } from '@capacitor/core';

const { SecureStoragePlugin } = Plugins;

What you described above happens when you import SecureStoragePlugin directly from capacitor-secure-storage-plugin.

r0boto commented 4 years ago

I faced the same problem as @nerdic-coder. I tried to update the capacitor using ionic capacitor update android which updates the following files by adding the plugin to dependencies. Unfortunately, after this step are values still visible in Chrome inspector on the Emulator & Real device.

capacitor.build.gradle

apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
    implementation project(':capacitor-secure-storage-plugin')

}

**capacitor.settings.gradle**
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
    implementation project(':capacitor-secure-storage-plugin')

}
martinkasa commented 4 years ago

@r0boto please check if you import plugin as I wrote above. I faced the same issue when vscode imported automatically SecureStoragePlugin from capacitor-secure-storage-plugin package.

Wrong:

import { SecureStoragePlugin } from 'capacitor-secure-storage-plugin';

Correct:

import 'capacitor-secure-storage-plugin';
import { Plugins } from '@capacitor/core';

const { SecureStoragePlugin } = Plugins;
r0boto commented 4 years ago

@martinkasa I checked it twice. I have the same import in the component where the plugin is used. The capacitor is in version 1.1.1

Note: Project is used with a combination of Ionic (version 5.4.1)

martinkasa commented 4 years ago

@r0boto check if you registered the plugin in your app in MainActivity.java file:

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      // Additional plugins you've installed go here
      // Ex: add(TotallyAwesomePlugin.class);
      add(SecureStoragePlugin.class);
    }});
  }
}
successiveoverrelaxation commented 4 years ago

@martinkasa is it possible to see where the encrypted data is on an ios simulator? I found my non secure data in _/Library/Developer/CoreSimulator/Devices/[DeviceID]/data/Containers/Data/Application/[AppID]/Library/WebKit/[PackageID]/WebsiteData/LocalStorage/capacitor_localhost0.localstorage but am curious to know where the secure data is.

martinkasa commented 4 years ago

Values are being saved to keychain. I do not know if there is some way how to see values in it. But for simple test you can save a value, the get a value to make sure it is saved. Then check via desktop safari inspector if you can see the value stored in localstorage on a mobile device or emulator. If it is not there, then , obviously, it is in keychain.

martinkasa commented 4 years ago

@r0boto is it working as expected? I tested it and it worked.

martinkasa commented 4 years ago

I added link to Capacitor docs how to register plugin for Android.